| 1 | /* |
| 2 | * Copyright (C) 2010 Francisco Jerez. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <core/device.h> |
| 28 | |
| 29 | #define NV04_PFB_BOOT_0 0x00100000 |
| 30 | # define NV04_PFB_BOOT_0_RAM_AMOUNT 0x00000003 |
| 31 | # define NV04_PFB_BOOT_0_RAM_AMOUNT_32MB 0x00000000 |
| 32 | # define NV04_PFB_BOOT_0_RAM_AMOUNT_4MB 0x00000001 |
| 33 | # define NV04_PFB_BOOT_0_RAM_AMOUNT_8MB 0x00000002 |
| 34 | # define NV04_PFB_BOOT_0_RAM_AMOUNT_16MB 0x00000003 |
| 35 | # define NV04_PFB_BOOT_0_RAM_WIDTH_128 0x00000004 |
| 36 | # define NV04_PFB_BOOT_0_RAM_TYPE 0x00000028 |
| 37 | # define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_8MBIT 0x00000000 |
| 38 | # define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT 0x00000008 |
| 39 | # define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT_4BANK 0x00000010 |
| 40 | # define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_16MBIT 0x00000018 |
| 41 | # define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBIT 0x00000020 |
| 42 | # define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBITX16 0x00000028 |
| 43 | # define NV04_PFB_BOOT_0_UMA_ENABLE 0x00000100 |
| 44 | # define NV04_PFB_BOOT_0_UMA_SIZE 0x0000f000 |
| 45 | #define NV04_PFB_DEBUG_0 0x00100080 |
| 46 | # define NV04_PFB_DEBUG_0_PAGE_MODE 0x00000001 |
| 47 | # define NV04_PFB_DEBUG_0_REFRESH_OFF 0x00000010 |
| 48 | # define NV04_PFB_DEBUG_0_REFRESH_COUNTX64 0x00003f00 |
| 49 | # define NV04_PFB_DEBUG_0_REFRESH_SLOW_CLK 0x00004000 |
| 50 | # define NV04_PFB_DEBUG_0_SAFE_MODE 0x00008000 |
| 51 | # define NV04_PFB_DEBUG_0_ALOM_ENABLE 0x00010000 |
| 52 | # define NV04_PFB_DEBUG_0_CASOE 0x00100000 |
| 53 | # define NV04_PFB_DEBUG_0_CKE_INVERT 0x10000000 |
| 54 | # define NV04_PFB_DEBUG_0_REFINC 0x20000000 |
| 55 | # define NV04_PFB_DEBUG_0_SAVE_POWER_OFF 0x40000000 |
| 56 | #define NV04_PFB_CFG0 0x00100200 |
| 57 | # define NV04_PFB_CFG0_SCRAMBLE 0x20000000 |
| 58 | #define NV04_PFB_CFG1 0x00100204 |
| 59 | #define NV04_PFB_SCRAMBLE(i) (0x00100400 + 4 * (i)) |
| 60 | |
| 61 | #define NV10_PFB_REFCTRL 0x00100210 |
| 62 | # define NV10_PFB_REFCTRL_VALID_1 (1 << 31) |
| 63 | |
| 64 | static inline struct io_mapping * |
| 65 | fbmem_init(struct nouveau_device *dev) |
| 66 | { |
| 67 | #ifdef __NetBSD__ |
| 68 | return bus_space_io_mapping_create_wc(nv_device_resource_tag(dev, 1), |
| 69 | nv_device_resource_start(dev, 1), |
| 70 | nv_device_resource_len(dev, 1)); |
| 71 | #else |
| 72 | return io_mapping_create_wc(nv_device_resource_start(dev, 1), |
| 73 | nv_device_resource_len(dev, 1)); |
| 74 | #endif |
| 75 | } |
| 76 | |
| 77 | static inline void |
| 78 | fbmem_fini(struct io_mapping *fb) |
| 79 | { |
| 80 | io_mapping_free(fb); |
| 81 | } |
| 82 | |
| 83 | #ifdef __NetBSD__ |
| 84 | /* |
| 85 | * XXX Consider using bus_space_reserve/map instead. Don't want to use |
| 86 | * bus_space_map because presumably that will eat too much KVA. |
| 87 | */ |
| 88 | |
| 89 | # define __iomem volatile |
| 90 | # define ioread32 fake_ioread32 |
| 91 | # define iowrite32 fake_iowrite32 |
| 92 | |
| 93 | static inline uint32_t |
| 94 | fake_ioread32(const void __iomem *p) |
| 95 | { |
| 96 | const uint32_t v = *(const uint32_t __iomem *)p; |
| 97 | |
| 98 | membar_consumer(); |
| 99 | |
| 100 | return v; |
| 101 | } |
| 102 | |
| 103 | static inline void |
| 104 | fake_iowrite32(uint32_t v, void __iomem *p) |
| 105 | { |
| 106 | |
| 107 | membar_producer(); |
| 108 | *(uint32_t __iomem *)p = v; |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | static inline u32 |
| 113 | fbmem_peek(struct io_mapping *fb, u32 off) |
| 114 | { |
| 115 | u8 __iomem *p = io_mapping_map_atomic_wc(fb, off & PAGE_MASK); |
| 116 | u32 val = ioread32(p + (off & ~PAGE_MASK)); |
| 117 | #ifdef __NetBSD__ |
| 118 | io_mapping_unmap_atomic(fb, __UNVOLATILE(p)); |
| 119 | #else |
| 120 | io_mapping_unmap_atomic(p); |
| 121 | #endif |
| 122 | return val; |
| 123 | } |
| 124 | |
| 125 | static inline void |
| 126 | fbmem_poke(struct io_mapping *fb, u32 off, u32 val) |
| 127 | { |
| 128 | u8 __iomem *p = io_mapping_map_atomic_wc(fb, off & PAGE_MASK); |
| 129 | iowrite32(val, p + (off & ~PAGE_MASK)); |
| 130 | #ifdef __NetBSD__ |
| 131 | membar_producer(); |
| 132 | io_mapping_unmap_atomic(fb, __UNVOLATILE(p)); |
| 133 | #else |
| 134 | wmb(); |
| 135 | io_mapping_unmap_atomic(p); |
| 136 | #endif |
| 137 | } |
| 138 | |
| 139 | static inline bool |
| 140 | fbmem_readback(struct io_mapping *fb, u32 off, u32 val) |
| 141 | { |
| 142 | fbmem_poke(fb, off, val); |
| 143 | return val == fbmem_peek(fb, off); |
| 144 | } |
| 145 | |
| 146 | #ifdef __NetBSD__ |
| 147 | # undef __iomem |
| 148 | # undef ioread32 |
| 149 | # undef iowrite32 |
| 150 | #endif |
| 151 | |