• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __NOUVEAU_DEVICE_H__
2 #define __NOUVEAU_DEVICE_H__
3 
4 #include <core/object.h>
5 #include <core/subdev.h>
6 #include <core/engine.h>
7 
8 enum nv_subdev_type {
9 	NVDEV_ENGINE_DEVICE,
10 	NVDEV_SUBDEV_VBIOS,
11 
12 	/* All subdevs from DEVINIT to DEVINIT_LAST will be created before
13 	 * *any* of them are initialised.  This subdev category is used
14 	 * for any subdevs that the VBIOS init table parsing may call out
15 	 * to during POST.
16 	 */
17 	NVDEV_SUBDEV_DEVINIT,
18 	NVDEV_SUBDEV_GPIO,
19 	NVDEV_SUBDEV_I2C,
20 	NVDEV_SUBDEV_CLOCK,
21 	NVDEV_SUBDEV_DEVINIT_LAST = NVDEV_SUBDEV_CLOCK,
22 
23 	/* This grouping of subdevs are initialised right after they've
24 	 * been created, and are allowed to assume any subdevs in the
25 	 * list above them exist and have been initialised.
26 	 */
27 	NVDEV_SUBDEV_MXM,
28 	NVDEV_SUBDEV_MC,
29 	NVDEV_SUBDEV_BUS,
30 	NVDEV_SUBDEV_TIMER,
31 	NVDEV_SUBDEV_FB,
32 	NVDEV_SUBDEV_LTCG,
33 	NVDEV_SUBDEV_IBUS,
34 	NVDEV_SUBDEV_INSTMEM,
35 	NVDEV_SUBDEV_VM,
36 	NVDEV_SUBDEV_BAR,
37 	NVDEV_SUBDEV_VOLT,
38 	NVDEV_SUBDEV_THERM,
39 
40 	NVDEV_ENGINE_DMAOBJ,
41 	NVDEV_ENGINE_FIFO,
42 	NVDEV_ENGINE_SW,
43 	NVDEV_ENGINE_GR,
44 	NVDEV_ENGINE_MPEG,
45 	NVDEV_ENGINE_ME,
46 	NVDEV_ENGINE_VP,
47 	NVDEV_ENGINE_CRYPT,
48 	NVDEV_ENGINE_BSP,
49 	NVDEV_ENGINE_PPP,
50 	NVDEV_ENGINE_COPY0,
51 	NVDEV_ENGINE_COPY1,
52 	NVDEV_ENGINE_UNK1C1,
53 	NVDEV_ENGINE_VENC,
54 	NVDEV_ENGINE_DISP,
55 
56 	NVDEV_SUBDEV_NR,
57 };
58 
59 struct nouveau_device {
60 	struct nouveau_engine base;
61 	struct list_head head;
62 
63 	struct pci_dev *pdev;
64 	u64 handle;
65 
66 	const char *cfgopt;
67 	const char *dbgopt;
68 	const char *name;
69 	const char *cname;
70 
71 	enum {
72 		NV_04    = 0x04,
73 		NV_10    = 0x10,
74 		NV_20    = 0x20,
75 		NV_30    = 0x30,
76 		NV_40    = 0x40,
77 		NV_50    = 0x50,
78 		NV_C0    = 0xc0,
79 		NV_D0    = 0xd0,
80 		NV_E0    = 0xe0,
81 	} card_type;
82 	u32 chipset;
83 	u32 crystal;
84 
85 	struct nouveau_oclass *oclass[NVDEV_SUBDEV_NR];
86 	struct nouveau_object *subdev[NVDEV_SUBDEV_NR];
87 };
88 
89 static inline struct nouveau_device *
nv_device(void * obj)90 nv_device(void *obj)
91 {
92 	struct nouveau_object *object = nv_object(obj);
93 	struct nouveau_object *device = object;
94 
95 	if (device->engine)
96 		device = device->engine;
97 	if (device->parent)
98 		device = device->parent;
99 
100 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
101 	if (unlikely(!nv_iclass(device, NV_SUBDEV_CLASS) ||
102 		     (nv_hclass(device) & 0xff) != NVDEV_ENGINE_DEVICE)) {
103 		nv_assert("BAD CAST -> NvDevice, 0x%08x 0x%08x",
104 			  nv_hclass(object), nv_hclass(device));
105 	}
106 #endif
107 
108 	return (void *)device;
109 }
110 
111 static inline struct nouveau_subdev *
nouveau_subdev(void * obj,int sub)112 nouveau_subdev(void *obj, int sub)
113 {
114 	if (nv_device(obj)->subdev[sub])
115 		return nv_subdev(nv_device(obj)->subdev[sub]);
116 	return NULL;
117 }
118 
119 static inline struct nouveau_engine *
nouveau_engine(void * obj,int sub)120 nouveau_engine(void *obj, int sub)
121 {
122 	struct nouveau_subdev *subdev = nouveau_subdev(obj, sub);
123 	if (subdev && nv_iclass(subdev, NV_ENGINE_CLASS))
124 		return nv_engine(subdev);
125 	return NULL;
126 }
127 
128 static inline bool
nv_device_match(struct nouveau_object * object,u16 dev,u16 ven,u16 sub)129 nv_device_match(struct nouveau_object *object, u16 dev, u16 ven, u16 sub)
130 {
131 	struct nouveau_device *device = nv_device(object);
132 	return device->pdev->device == dev &&
133 	       device->pdev->subsystem_vendor == ven &&
134 	       device->pdev->subsystem_device == sub;
135 }
136 
137 #endif
138