• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_DEVICE_H__
3 #define __NVKM_DEVICE_H__
4 #include <core/oclass.h>
5 #include <core/intr.h>
6 enum nvkm_subdev_type;
7 
8 enum nvkm_device_type {
9 	NVKM_DEVICE_PCI,
10 	NVKM_DEVICE_AGP,
11 	NVKM_DEVICE_PCIE,
12 	NVKM_DEVICE_TEGRA,
13 };
14 
15 struct nvkm_device {
16 	const struct nvkm_device_func *func;
17 	const struct nvkm_device_quirk *quirk;
18 	struct device *dev;
19 	enum nvkm_device_type type;
20 	u64 handle;
21 	const char *name;
22 	const char *cfgopt;
23 	const char *dbgopt;
24 
25 	struct list_head head;
26 	struct mutex mutex;
27 	int refcount;
28 
29 	void __iomem *pri;
30 
31 	u32 debug;
32 
33 	const struct nvkm_device_chip *chip;
34 	enum {
35 		NV_04    = 0x04,
36 		NV_10    = 0x10,
37 		NV_11    = 0x11,
38 		NV_20    = 0x20,
39 		NV_30    = 0x30,
40 		NV_40    = 0x40,
41 		NV_50    = 0x50,
42 		NV_C0    = 0xc0,
43 		NV_E0    = 0xe0,
44 		GM100    = 0x110,
45 		GP100    = 0x130,
46 		GV100    = 0x140,
47 		TU100    = 0x160,
48 		GA100    = 0x170,
49 	} card_type;
50 	u32 chipset;
51 	u8  chiprev;
52 	u32 crystal;
53 
54 	struct {
55 		struct notifier_block nb;
56 	} acpi;
57 
58 #define NVKM_LAYOUT_ONCE(type,data,ptr) data *ptr;
59 #define NVKM_LAYOUT_INST(type,data,ptr,cnt) data *ptr[cnt];
60 #include <core/layout.h>
61 #undef NVKM_LAYOUT_INST
62 #undef NVKM_LAYOUT_ONCE
63 	struct list_head subdev;
64 
65 	struct {
66 		struct list_head intr;
67 		struct list_head prio[NVKM_INTR_PRIO_NR];
68 		spinlock_t lock;
69 		int irq;
70 		bool alloc;
71 		bool armed;
72 		bool legacy_done;
73 	} intr;
74 };
75 
76 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int type, int inst);
77 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int type, int inst);
78 
79 struct nvkm_device_func {
80 	struct nvkm_device_pci *(*pci)(struct nvkm_device *);
81 	struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
82 	void *(*dtor)(struct nvkm_device *);
83 	int (*preinit)(struct nvkm_device *);
84 	int (*init)(struct nvkm_device *);
85 	void (*fini)(struct nvkm_device *, bool suspend);
86 	int (*irq)(struct nvkm_device *);
87 	resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
88 	resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
89 	bool cpu_coherent;
90 };
91 
92 struct nvkm_device_quirk {
93 	u8 tv_pin_mask;
94 	u8 tv_gpio;
95 };
96 
97 struct nvkm_device_chip {
98 	const char *name;
99 #define NVKM_LAYOUT_ONCE(type,data,ptr,...)                                                  \
100 	struct {                                                                             \
101 		u32 inst;                                                                    \
102 		int (*ctor)(struct nvkm_device *, enum nvkm_subdev_type, int inst, data **); \
103 	} ptr;
104 #define NVKM_LAYOUT_INST(A...) NVKM_LAYOUT_ONCE(A)
105 #include <core/layout.h>
106 #undef NVKM_LAYOUT_INST
107 #undef NVKM_LAYOUT_ONCE
108 };
109 
110 struct nvkm_device *nvkm_device_find(u64 name);
111 int nvkm_device_list(u64 *name, int size);
112 
113 /* privileged register interface accessor macros */
114 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
115 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
116 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
117 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
118 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
119 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
120 #define nvkm_mask(d,a,m,v) ({                                                  \
121 	struct nvkm_device *_device = (d);                                     \
122 	u32 _addr = (a), _temp = nvkm_rd32(_device, _addr);                    \
123 	nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v));                       \
124 	_temp;                                                                 \
125 })
126 
127 void nvkm_device_del(struct nvkm_device **);
128 
129 struct nvkm_device_oclass {
130 	int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
131 		    void *data, u32 size, struct nvkm_object **);
132 	struct nvkm_sclass base;
133 };
134 
135 extern const struct nvkm_sclass nvkm_udevice_sclass;
136 
137 /* device logging */
138 #define nvdev_printk_(d,l,p,f,a...) do {                                       \
139 	const struct nvkm_device *_device = (d);                               \
140 	if (_device->debug >= (l))                                             \
141 		dev_##p(_device->dev, f, ##a);                                 \
142 } while(0)
143 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
144 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL,   crit, f, ##a)
145 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR,    err, f, ##a)
146 #define nvdev_warn(d,f,a...)  nvdev_printk((d),  WARN, notice, f, ##a)
147 #define nvdev_info(d,f,a...)  nvdev_printk((d),  INFO,   info, f, ##a)
148 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG,   info, f, ##a)
149 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE,   info, f, ##a)
150 #define nvdev_spam(d,f,a...)  nvdev_printk((d),  SPAM,    dbg, f, ##a)
151 #endif
152