1 /* SPDX-License-Identifier: MIT */ 2 #ifndef __NVKM_FB_H__ 3 #define __NVKM_FB_H__ 4 #include <core/subdev.h> 5 #include <core/mm.h> 6 7 /* memory type/access flags, do not match hardware values */ 8 #define NV_MEM_ACCESS_RO 1 9 #define NV_MEM_ACCESS_WO 2 10 #define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO) 11 #define NV_MEM_ACCESS_SYS 4 12 #define NV_MEM_ACCESS_VM 8 13 #define NV_MEM_ACCESS_NOSNOOP 16 14 15 #define NV_MEM_TARGET_VRAM 0 16 #define NV_MEM_TARGET_PCI 1 17 #define NV_MEM_TARGET_PCI_NOSNOOP 2 18 #define NV_MEM_TARGET_VM 3 19 #define NV_MEM_TARGET_GART 4 20 21 #define NVKM_RAM_TYPE_VM 0x7f 22 #define NV_MEM_COMP_VM 0x03 23 24 struct nvkm_fb_tile { 25 struct nvkm_mm_node *tag; 26 u32 addr; 27 u32 limit; 28 u32 pitch; 29 u32 zcomp; 30 }; 31 32 struct nvkm_fb { 33 const struct nvkm_fb_func *func; 34 struct nvkm_subdev subdev; 35 36 struct nvkm_blob vpr_scrubber; 37 38 struct { 39 struct page *flush_page; 40 dma_addr_t flush_page_addr; 41 } sysmem; 42 43 struct nvkm_ram *ram; 44 45 struct { 46 struct mutex mutex; /* protects mm and nvkm_memory::tags */ 47 struct nvkm_mm mm; 48 } tags; 49 50 struct { 51 struct nvkm_fb_tile region[16]; 52 int regions; 53 } tile; 54 55 u8 page; 56 57 struct nvkm_memory *mmu_rd; 58 struct nvkm_memory *mmu_wr; 59 }; 60 61 int nvkm_fb_mem_unlock(struct nvkm_fb *); 62 63 void nvkm_fb_tile_init(struct nvkm_fb *, int region, u32 addr, u32 size, 64 u32 pitch, u32 flags, struct nvkm_fb_tile *); 65 void nvkm_fb_tile_fini(struct nvkm_fb *, int region, struct nvkm_fb_tile *); 66 void nvkm_fb_tile_prog(struct nvkm_fb *, int region, struct nvkm_fb_tile *); 67 68 int nv04_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 69 int nv10_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 70 int nv1a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 71 int nv20_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 72 int nv25_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 73 int nv30_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 74 int nv35_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 75 int nv36_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 76 int nv40_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 77 int nv41_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 78 int nv44_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 79 int nv46_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 80 int nv47_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 81 int nv49_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 82 int nv4e_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 83 int nv50_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 84 int g84_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 85 int gt215_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 86 int mcp77_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 87 int mcp89_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 88 int gf100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 89 int gf108_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 90 int gk104_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 91 int gk110_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 92 int gk20a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 93 int gm107_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 94 int gm200_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 95 int gm20b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 96 int gp100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 97 int gp102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 98 int gp10b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 99 int gv100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 100 int tu102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 101 int ga100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 102 int ga102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **); 103 104 #include <subdev/bios.h> 105 #include <subdev/bios/ramcfg.h> 106 107 struct nvkm_ram_data { 108 struct list_head head; 109 struct nvbios_ramcfg bios; 110 u32 freq; 111 }; 112 113 enum nvkm_ram_type { 114 NVKM_RAM_TYPE_UNKNOWN = 0, 115 NVKM_RAM_TYPE_STOLEN, 116 NVKM_RAM_TYPE_SGRAM, 117 NVKM_RAM_TYPE_SDRAM, 118 NVKM_RAM_TYPE_DDR1, 119 NVKM_RAM_TYPE_DDR2, 120 NVKM_RAM_TYPE_DDR3, 121 NVKM_RAM_TYPE_GDDR2, 122 NVKM_RAM_TYPE_GDDR3, 123 NVKM_RAM_TYPE_GDDR4, 124 NVKM_RAM_TYPE_GDDR5, 125 NVKM_RAM_TYPE_GDDR5X, 126 NVKM_RAM_TYPE_GDDR6, 127 NVKM_RAM_TYPE_HBM2, 128 }; 129 130 struct nvkm_ram { 131 const struct nvkm_ram_func *func; 132 struct nvkm_fb *fb; 133 enum nvkm_ram_type type; 134 u64 size; 135 136 #define NVKM_RAM_MM_SHIFT 12 137 #define NVKM_RAM_MM_ANY (NVKM_MM_HEAP_ANY + 0) 138 #define NVKM_RAM_MM_NORMAL (NVKM_MM_HEAP_ANY + 1) 139 #define NVKM_RAM_MM_NOMAP (NVKM_MM_HEAP_ANY + 2) 140 #define NVKM_RAM_MM_MIXED (NVKM_MM_HEAP_ANY + 3) 141 struct nvkm_mm vram; 142 u64 stolen; 143 struct mutex mutex; 144 145 int ranks; 146 int parts; 147 int part_mask; 148 149 u32 freq; 150 u32 mr[16]; 151 u32 mr1_nuts; 152 153 struct nvkm_ram_data *next; 154 struct nvkm_ram_data former; 155 struct nvkm_ram_data xition; 156 struct nvkm_ram_data target; 157 }; 158 159 int 160 nvkm_ram_get(struct nvkm_device *, u8 heap, u8 type, u8 page, u64 size, 161 bool contig, bool back, struct nvkm_memory **); 162 163 struct nvkm_ram_func { 164 u64 upper; 165 u32 (*probe_fbp)(const struct nvkm_ram_func *, struct nvkm_device *, 166 int fbp, int *pltcs); 167 u32 (*probe_fbp_amount)(const struct nvkm_ram_func *, u32 fbpao, 168 struct nvkm_device *, int fbp, int *pltcs); 169 u32 (*probe_fbpa_amount)(struct nvkm_device *, int fbpa); 170 void *(*dtor)(struct nvkm_ram *); 171 int (*init)(struct nvkm_ram *); 172 173 int (*calc)(struct nvkm_ram *, u32 freq); 174 int (*prog)(struct nvkm_ram *); 175 void (*tidy)(struct nvkm_ram *); 176 }; 177 #endif 178