1 #ifndef __NVKM_FB_H__
2 #define __NVKM_FB_H__
3 #include <core/subdev.h>
4 
5 #include <subdev/mmu.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 NV_MEM_TYPE_VM 0x7f
22 #define NV_MEM_COMP_VM 0x03
23 
24 struct nvkm_mem {
25 	struct drm_device *dev;
26 
27 	struct nvkm_vma bar_vma;
28 	struct nvkm_vma vma[2];
29 	u8  page_shift;
30 
31 	struct nvkm_mm_node *tag;
32 	struct list_head regions;
33 	dma_addr_t *pages;
34 	u32 memtype;
35 	u64 offset;
36 	u64 size;
37 	struct sg_table *sg;
38 };
39 
40 struct nvkm_fb_tile {
41 	struct nvkm_mm_node *tag;
42 	u32 addr;
43 	u32 limit;
44 	u32 pitch;
45 	u32 zcomp;
46 };
47 
48 struct nvkm_fb {
49 	struct nvkm_subdev subdev;
50 
51 	bool (*memtype_valid)(struct nvkm_fb *, u32 memtype);
52 
53 	struct nvkm_ram *ram;
54 
55 	struct nvkm_mm vram;
56 	struct nvkm_mm tags;
57 
58 	struct {
59 		struct nvkm_fb_tile region[16];
60 		int regions;
61 		void (*init)(struct nvkm_fb *, int i, u32 addr, u32 size,
62 			     u32 pitch, u32 flags, struct nvkm_fb_tile *);
63 		void (*comp)(struct nvkm_fb *, int i, u32 size, u32 flags,
64 			     struct nvkm_fb_tile *);
65 		void (*fini)(struct nvkm_fb *, int i, struct nvkm_fb_tile *);
66 		void (*prog)(struct nvkm_fb *, int i, struct nvkm_fb_tile *);
67 	} tile;
68 };
69 
70 static inline struct nvkm_fb *
71 nvkm_fb(void *obj)
72 {
73 	/* fbram uses this before device subdev pointer is valid */
74 	if (nv_iclass(obj, NV_SUBDEV_CLASS) &&
75 	    nv_subidx(obj) == NVDEV_SUBDEV_FB)
76 		return obj;
77 
78 	return (void *)nvkm_subdev(obj, NVDEV_SUBDEV_FB);
79 }
80 
81 extern struct nvkm_oclass *nv04_fb_oclass;
82 extern struct nvkm_oclass *nv10_fb_oclass;
83 extern struct nvkm_oclass *nv1a_fb_oclass;
84 extern struct nvkm_oclass *nv20_fb_oclass;
85 extern struct nvkm_oclass *nv25_fb_oclass;
86 extern struct nvkm_oclass *nv30_fb_oclass;
87 extern struct nvkm_oclass *nv35_fb_oclass;
88 extern struct nvkm_oclass *nv36_fb_oclass;
89 extern struct nvkm_oclass *nv40_fb_oclass;
90 extern struct nvkm_oclass *nv41_fb_oclass;
91 extern struct nvkm_oclass *nv44_fb_oclass;
92 extern struct nvkm_oclass *nv46_fb_oclass;
93 extern struct nvkm_oclass *nv47_fb_oclass;
94 extern struct nvkm_oclass *nv49_fb_oclass;
95 extern struct nvkm_oclass *nv4e_fb_oclass;
96 extern struct nvkm_oclass *nv50_fb_oclass;
97 extern struct nvkm_oclass *g84_fb_oclass;
98 extern struct nvkm_oclass *gt215_fb_oclass;
99 extern struct nvkm_oclass *mcp77_fb_oclass;
100 extern struct nvkm_oclass *mcp89_fb_oclass;
101 extern struct nvkm_oclass *gf100_fb_oclass;
102 extern struct nvkm_oclass *gk104_fb_oclass;
103 extern struct nvkm_oclass *gk20a_fb_oclass;
104 extern struct nvkm_oclass *gm107_fb_oclass;
105 
106 #include <subdev/bios.h>
107 #include <subdev/bios/ramcfg.h>
108 
109 struct nvkm_ram_data {
110 	struct list_head head;
111 	struct nvbios_ramcfg bios;
112 	u32 freq;
113 };
114 
115 struct nvkm_ram {
116 	struct nvkm_object base;
117 	enum {
118 		NV_MEM_TYPE_UNKNOWN = 0,
119 		NV_MEM_TYPE_STOLEN,
120 		NV_MEM_TYPE_SGRAM,
121 		NV_MEM_TYPE_SDRAM,
122 		NV_MEM_TYPE_DDR1,
123 		NV_MEM_TYPE_DDR2,
124 		NV_MEM_TYPE_DDR3,
125 		NV_MEM_TYPE_GDDR2,
126 		NV_MEM_TYPE_GDDR3,
127 		NV_MEM_TYPE_GDDR4,
128 		NV_MEM_TYPE_GDDR5
129 	} type;
130 	u64 stolen;
131 	u64 size;
132 	u32 tags;
133 
134 	int ranks;
135 	int parts;
136 	int part_mask;
137 
138 	int  (*get)(struct nvkm_fb *, u64 size, u32 align, u32 size_nc,
139 		    u32 type, struct nvkm_mem **);
140 	void (*put)(struct nvkm_fb *, struct nvkm_mem **);
141 
142 	int  (*calc)(struct nvkm_fb *, u32 freq);
143 	int  (*prog)(struct nvkm_fb *);
144 	void (*tidy)(struct nvkm_fb *);
145 	u32 freq;
146 	u32 mr[16];
147 	u32 mr1_nuts;
148 
149 	struct nvkm_ram_data *next;
150 	struct nvkm_ram_data former;
151 	struct nvkm_ram_data xition;
152 	struct nvkm_ram_data target;
153 };
154 #endif
155