1#ifndef __NOUVEAU_SUBDEV_H__ 2#define __NOUVEAU_SUBDEV_H__ 3 4#include <core/object.h> 5 6#define NV_SUBDEV_(sub,var) (NV_SUBDEV_CLASS | ((var) << 8) | (sub)) 7#define NV_SUBDEV(name,var) NV_SUBDEV_(NVDEV_SUBDEV_##name, (var)) 8 9struct nouveau_subdev { 10 struct nouveau_object base; 11 struct mutex mutex; 12 const char *name; 13 void __iomem *mmio; 14 u32 debug; 15 u32 unit; 16 17 void (*intr)(struct nouveau_subdev *); 18}; 19 20static inline struct nouveau_subdev * 21nv_subdev(void *obj) 22{ 23#if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA 24 if (unlikely(!nv_iclass(obj, NV_SUBDEV_CLASS))) 25 nv_assert("BAD CAST -> NvSubDev, %08x", nv_hclass(obj)); 26#endif 27 return obj; 28} 29 30static inline int 31nv_subidx(struct nouveau_object *object) 32{ 33 return nv_hclass(nv_subdev(object)) & 0xff; 34} 35 36#define nouveau_subdev_create(p,e,o,v,s,f,d) \ 37 nouveau_subdev_create_((p), (e), (o), (v), (s), (f), \ 38 sizeof(**d),(void **)d) 39 40int nouveau_subdev_create_(struct nouveau_object *, struct nouveau_object *, 41 struct nouveau_oclass *, u32 pclass, 42 const char *sname, const char *fname, 43 int size, void **); 44void nouveau_subdev_destroy(struct nouveau_subdev *); 45int nouveau_subdev_init(struct nouveau_subdev *); 46int nouveau_subdev_fini(struct nouveau_subdev *, bool suspend); 47void nouveau_subdev_reset(struct nouveau_object *); 48 49void _nouveau_subdev_dtor(struct nouveau_object *); 50int _nouveau_subdev_init(struct nouveau_object *); 51int _nouveau_subdev_fini(struct nouveau_object *, bool suspend); 52 53#define s_printk(s,l,f,a...) do { \ 54 if ((s)->debug >= OS_DBG_##l) { \ 55 nv_printk((s)->base.parent, (s)->name, l, f, ##a); \ 56 } \ 57} while(0) 58 59static inline u8 60nv_rd08(void *obj, u32 addr) 61{ 62 struct nouveau_subdev *subdev = nv_subdev(obj); 63 u8 data = ioread8(subdev->mmio + addr); 64 nv_spam(subdev, "nv_rd08 0x%06x 0x%02x\n", addr, data); 65 return data; 66} 67 68static inline u16 69nv_rd16(void *obj, u32 addr) 70{ 71 struct nouveau_subdev *subdev = nv_subdev(obj); 72 u16 data = ioread16_native(subdev->mmio + addr); 73 nv_spam(subdev, "nv_rd16 0x%06x 0x%04x\n", addr, data); 74 return data; 75} 76 77static inline u32 78nv_rd32(void *obj, u32 addr) 79{ 80 struct nouveau_subdev *subdev = nv_subdev(obj); 81 u32 data = ioread32_native(subdev->mmio + addr); 82 nv_spam(subdev, "nv_rd32 0x%06x 0x%08x\n", addr, data); 83 return data; 84} 85 86static inline void 87nv_wr08(void *obj, u32 addr, u8 data) 88{ 89 struct nouveau_subdev *subdev = nv_subdev(obj); 90 nv_spam(subdev, "nv_wr08 0x%06x 0x%02x\n", addr, data); 91 iowrite8(data, subdev->mmio + addr); 92} 93 94static inline void 95nv_wr16(void *obj, u32 addr, u16 data) 96{ 97 struct nouveau_subdev *subdev = nv_subdev(obj); 98 nv_spam(subdev, "nv_wr16 0x%06x 0x%04x\n", addr, data); 99 iowrite16_native(data, subdev->mmio + addr); 100} 101 102static inline void 103nv_wr32(void *obj, u32 addr, u32 data) 104{ 105 struct nouveau_subdev *subdev = nv_subdev(obj); 106 nv_spam(subdev, "nv_wr32 0x%06x 0x%08x\n", addr, data); 107 iowrite32_native(data, subdev->mmio + addr); 108} 109 110static inline u32 111nv_mask(void *obj, u32 addr, u32 mask, u32 data) 112{ 113 u32 temp = nv_rd32(obj, addr); 114 nv_wr32(obj, addr, (temp & ~mask) | data); 115 return temp; 116} 117 118#endif 119