1 #ifndef __NOUVEAU_DEVICE_H__
2 #define __NOUVEAU_DEVICE_H__
4 #include <core/object.h>
5 #include <core/subdev.h>
6 #include <core/engine.h>
7 #include <core/event.h>
13 /* All subdevs from DEVINIT to DEVINIT_LAST will be created before
14 * *any* of them are initialised. This subdev category is used
15 * for any subdevs that the VBIOS init table parsing may call out
21 NVDEV_SUBDEV_DEVINIT_LAST = NVDEV_SUBDEV_I2C,
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.
43 NVDEV_ENGINE_DMAOBJ = NVDEV_ENGINE_FIRST,
65 struct nouveau_device {
66 struct nouveau_engine base;
67 struct list_head head;
70 struct platform_device *platformdev;
73 struct nvkm_event event;
96 struct nouveau_oclass *oclass[NVDEV_SUBDEV_NR];
97 struct nouveau_object *subdev[NVDEV_SUBDEV_NR];
100 struct notifier_block nb;
104 static inline struct nouveau_device *
107 struct nouveau_object *object = nv_object(obj);
108 struct nouveau_object *device = object;
111 device = device->engine;
113 device = device->parent;
115 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
116 if (unlikely(!nv_iclass(device, NV_SUBDEV_CLASS) ||
117 (nv_hclass(device) & 0xff) != NVDEV_ENGINE_DEVICE)) {
118 nv_assert("BAD CAST -> NvDevice, 0x%08x 0x%08x",
119 nv_hclass(object), nv_hclass(device));
123 return (void *)device;
126 static inline struct nouveau_subdev *
127 nouveau_subdev(void *obj, int sub)
129 if (nv_device(obj)->subdev[sub])
130 return nv_subdev(nv_device(obj)->subdev[sub]);
134 static inline struct nouveau_engine *
135 nouveau_engine(void *obj, int sub)
137 struct nouveau_subdev *subdev = nouveau_subdev(obj, sub);
138 if (subdev && nv_iclass(subdev, NV_ENGINE_CLASS))
139 return nv_engine(subdev);
144 nv_device_match(struct nouveau_object *object, u16 dev, u16 ven, u16 sub)
146 struct nouveau_device *device = nv_device(object);
147 return device->pdev->device == dev &&
148 device->pdev->subsystem_vendor == ven &&
149 device->pdev->subsystem_device == sub;
153 nv_device_is_pci(struct nouveau_device *device)
155 return device->pdev != NULL;
158 static inline struct device *
159 nv_device_base(struct nouveau_device *device)
161 return nv_device_is_pci(device) ? &device->pdev->dev :
162 &device->platformdev->dev;
166 nv_device_resource_start(struct nouveau_device *device, unsigned int bar);
169 nv_device_resource_len(struct nouveau_device *device, unsigned int bar);
172 nv_device_get_irq(struct nouveau_device *device, bool stall);