0001
0002 #ifndef __NVKM_DEVICE_H__
0003 #define __NVKM_DEVICE_H__
0004 #include <core/oclass.h>
0005 enum nvkm_subdev_type;
0006
0007 enum nvkm_device_type {
0008 NVKM_DEVICE_PCI,
0009 NVKM_DEVICE_AGP,
0010 NVKM_DEVICE_PCIE,
0011 NVKM_DEVICE_TEGRA,
0012 };
0013
0014 struct nvkm_device {
0015 const struct nvkm_device_func *func;
0016 const struct nvkm_device_quirk *quirk;
0017 struct device *dev;
0018 enum nvkm_device_type type;
0019 u64 handle;
0020 const char *name;
0021 const char *cfgopt;
0022 const char *dbgopt;
0023
0024 struct list_head head;
0025 struct mutex mutex;
0026 int refcount;
0027
0028 void __iomem *pri;
0029
0030 u32 debug;
0031
0032 const struct nvkm_device_chip *chip;
0033 enum {
0034 NV_04 = 0x04,
0035 NV_10 = 0x10,
0036 NV_11 = 0x11,
0037 NV_20 = 0x20,
0038 NV_30 = 0x30,
0039 NV_40 = 0x40,
0040 NV_50 = 0x50,
0041 NV_C0 = 0xc0,
0042 NV_E0 = 0xe0,
0043 GM100 = 0x110,
0044 GP100 = 0x130,
0045 GV100 = 0x140,
0046 TU100 = 0x160,
0047 GA100 = 0x170,
0048 } card_type;
0049 u32 chipset;
0050 u8 chiprev;
0051 u32 crystal;
0052
0053 struct {
0054 struct notifier_block nb;
0055 } acpi;
0056
0057 #define NVKM_LAYOUT_ONCE(type,data,ptr) data *ptr;
0058 #define NVKM_LAYOUT_INST(type,data,ptr,cnt) data *ptr[cnt];
0059 #include <core/layout.h>
0060 #undef NVKM_LAYOUT_INST
0061 #undef NVKM_LAYOUT_ONCE
0062 struct list_head subdev;
0063 };
0064
0065 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int type, int inst);
0066 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int type, int inst);
0067
0068 struct nvkm_device_func {
0069 struct nvkm_device_pci *(*pci)(struct nvkm_device *);
0070 struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
0071 void *(*dtor)(struct nvkm_device *);
0072 int (*preinit)(struct nvkm_device *);
0073 int (*init)(struct nvkm_device *);
0074 void (*fini)(struct nvkm_device *, bool suspend);
0075 resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
0076 resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
0077 bool cpu_coherent;
0078 };
0079
0080 struct nvkm_device_quirk {
0081 u8 tv_pin_mask;
0082 u8 tv_gpio;
0083 };
0084
0085 struct nvkm_device_chip {
0086 const char *name;
0087 #define NVKM_LAYOUT_ONCE(type,data,ptr,...) \
0088 struct { \
0089 u32 inst; \
0090 int (*ctor)(struct nvkm_device *, enum nvkm_subdev_type, int inst, data **); \
0091 } ptr;
0092 #define NVKM_LAYOUT_INST(A...) NVKM_LAYOUT_ONCE(A)
0093 #include <core/layout.h>
0094 #undef NVKM_LAYOUT_INST
0095 #undef NVKM_LAYOUT_ONCE
0096 };
0097
0098 struct nvkm_device *nvkm_device_find(u64 name);
0099 int nvkm_device_list(u64 *name, int size);
0100
0101
0102 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
0103 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
0104 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
0105 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
0106 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
0107 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
0108 #define nvkm_mask(d,a,m,v) ({ \
0109 struct nvkm_device *_device = (d); \
0110 u32 _addr = (a), _temp = nvkm_rd32(_device, _addr); \
0111 nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v)); \
0112 _temp; \
0113 })
0114
0115 void nvkm_device_del(struct nvkm_device **);
0116
0117 struct nvkm_device_oclass {
0118 int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
0119 void *data, u32 size, struct nvkm_object **);
0120 struct nvkm_sclass base;
0121 };
0122
0123 extern const struct nvkm_sclass nvkm_udevice_sclass;
0124
0125
0126 #define nvdev_printk_(d,l,p,f,a...) do { \
0127 const struct nvkm_device *_device = (d); \
0128 if (_device->debug >= (l)) \
0129 dev_##p(_device->dev, f, ##a); \
0130 } while(0)
0131 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
0132 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL, crit, f, ##a)
0133 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR, err, f, ##a)
0134 #define nvdev_warn(d,f,a...) nvdev_printk((d), WARN, notice, f, ##a)
0135 #define nvdev_info(d,f,a...) nvdev_printk((d), INFO, info, f, ##a)
0136 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG, info, f, ##a)
0137 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE, info, f, ##a)
0138 #define nvdev_spam(d,f,a...) nvdev_printk((d), SPAM, dbg, f, ##a)
0139 #endif