Linux Audio

Check our new training course

Loading...
v6.13.7
  1/* SPDX-License-Identifier: MIT */
  2#ifndef __NVIF_OBJECT_H__
  3#define __NVIF_OBJECT_H__
 
  4#include <nvif/os.h>
  5
  6struct nvif_sclass {
  7	s32 oclass;
  8	int minver;
  9	int maxver;
 10};
 11
 12struct nvif_object {
 13	struct nvif_parent *parent;
 14	struct nvif_client *client;
 15	const char *name;
 16	u32 handle;
 17	s32 oclass;
 18	void *priv; /*XXX: hack */
 19	struct {
 20		void __iomem *ptr;
 21		u64 size;
 22	} map;
 23};
 24
 25static inline bool
 26nvif_object_constructed(struct nvif_object *object)
 27{
 28	return object->client != NULL;
 29}
 30
 31int  nvif_object_ctor(struct nvif_object *, const char *name, u32 handle,
 32		      s32 oclass, void *, u32, struct nvif_object *);
 33void nvif_object_dtor(struct nvif_object *);
 34int  nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
 35int  nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **);
 36void nvif_object_sclass_put(struct nvif_sclass **);
 
 
 37int  nvif_object_mthd(struct nvif_object *, u32, void *, u32);
 38int  nvif_object_map_handle(struct nvif_object *, void *, u32,
 39			    u64 *handle, u64 *length);
 40void nvif_object_unmap_handle(struct nvif_object *);
 41int  nvif_object_map(struct nvif_object *, void *, u32);
 42void nvif_object_unmap(struct nvif_object *);
 43
 44#define nvif_handle(a) (unsigned long)(void *)(a)
 45#define nvif_object(a) (a)->object
 46
 47#define nvif_rd(a,f,b,c) ({                                                    \
 48	u32 _data = f((u8 __iomem *)(a)->map.ptr + (c));                       \
 
 
 
 
 
 49	_data;                                                                 \
 50})
 51#define nvif_wr(a,f,b,c,d) ({                                                  \
 52	f((d), (u8 __iomem *)(a)->map.ptr + (c));                              \
 
 
 
 
 53})
 54#define nvif_rd08(a,b) ({ ((u8)nvif_rd((a), ioread8, 1, (b))); })
 55#define nvif_rd16(a,b) ({ ((u16)nvif_rd((a), ioread16_native, 2, (b))); })
 56#define nvif_rd32(a,b) ({ ((u32)nvif_rd((a), ioread32_native, 4, (b))); })
 57#define nvif_wr08(a,b,c) nvif_wr((a), iowrite8, 1, (b), (u8)(c))
 58#define nvif_wr16(a,b,c) nvif_wr((a), iowrite16_native, 2, (b), (u16)(c))
 59#define nvif_wr32(a,b,c) nvif_wr((a), iowrite32_native, 4, (b), (u32)(c))
 60#define nvif_mask(a,b,c,d) ({                                                  \
 61	typeof(a) __object = (a);                                              \
 62	u32 _addr = (b), _data = nvif_rd32(__object, _addr);                   \
 63	nvif_wr32(__object, _addr, (_data & ~(c)) | (d));                      \
 64	_data;                                                                 \
 65})
 66
 67#define nvif_mthd(a,b,c,d) nvif_object_mthd((a), (b), (c), (d))
 68
 69struct nvif_mclass {
 70	s32 oclass;
 71	int version;
 72};
 73
 74#define nvif_mclass(o,m) ({                                                    \
 75	struct nvif_object *object = (o);                                      \
 76	struct nvif_sclass *sclass;                                            \
 77	typeof(m[0]) *mclass = (m);                                            \
 78	int ret = -ENODEV;                                                     \
 79	int cnt, i, j;                                                         \
 80                                                                               \
 81	cnt = nvif_object_sclass_get(object, &sclass);                         \
 82	if (cnt >= 0) {                                                        \
 83		for (i = 0; ret < 0 && mclass[i].oclass; i++) {                \
 84			for (j = 0; j < cnt; j++) {                            \
 85				if (mclass[i].oclass  == sclass[j].oclass &&   \
 86				    mclass[i].version >= sclass[j].minver &&   \
 87				    mclass[i].version <= sclass[j].maxver) {   \
 88					ret = i;                               \
 89					break;                                 \
 90				}                                              \
 91			}                                                      \
 92		}                                                              \
 93		nvif_object_sclass_put(&sclass);                               \
 94	}                                                                      \
 95	ret;                                                                   \
 96})
 97
 98#define nvif_sclass(o,m,u) ({                                                  \
 99	const typeof(m[0]) *_mclass = (m);                                     \
100	s32 _oclass = (u);                                                     \
101	int _cid;                                                              \
102	if (_oclass) {                                                         \
103		for (_cid = 0; _mclass[_cid].oclass; _cid++) {                 \
104			if (_mclass[_cid].oclass == _oclass)                   \
105				break;                                         \
106		}                                                              \
107		_cid = _mclass[_cid].oclass ? _cid : -ENOSYS;                  \
108	} else {                                                               \
109		_cid = nvif_mclass((o), _mclass);                              \
110	}                                                                      \
111	_cid;                                                                  \
112})
113
114#define NVIF_RD32_(p,o,dr)   nvif_rd32((p), (o) + (dr))
115#define NVIF_WR32_(p,o,dr,f) nvif_wr32((p), (o) + (dr), (f))
116#define NVIF_RD32(p,A...) DRF_RD(NVIF_RD32_,                  (p), 0, ##A)
117#define NVIF_RV32(p,A...) DRF_RV(NVIF_RD32_,                  (p), 0, ##A)
118#define NVIF_TV32(p,A...) DRF_TV(NVIF_RD32_,                  (p), 0, ##A)
119#define NVIF_TD32(p,A...) DRF_TD(NVIF_RD32_,                  (p), 0, ##A)
120#define NVIF_WR32(p,A...) DRF_WR(            NVIF_WR32_,      (p), 0, ##A)
121#define NVIF_WV32(p,A...) DRF_WV(            NVIF_WR32_,      (p), 0, ##A)
122#define NVIF_WD32(p,A...) DRF_WD(            NVIF_WR32_,      (p), 0, ##A)
123#define NVIF_MR32(p,A...) DRF_MR(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
124#define NVIF_MV32(p,A...) DRF_MV(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
125#define NVIF_MD32(p,A...) DRF_MD(NVIF_RD32_, NVIF_WR32_, u32, (p), 0, ##A)
126#endif
v4.17
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __NVIF_OBJECT_H__
  3#define __NVIF_OBJECT_H__
  4
  5#include <nvif/os.h>
  6
  7struct nvif_sclass {
  8	s32 oclass;
  9	int minver;
 10	int maxver;
 11};
 12
 13struct nvif_object {
 
 14	struct nvif_client *client;
 
 15	u32 handle;
 16	s32 oclass;
 17	void *priv; /*XXX: hack */
 18	struct {
 19		void __iomem *ptr;
 20		u64 size;
 21	} map;
 22};
 23
 24int  nvif_object_init(struct nvif_object *, u32 handle, s32 oclass, void *, u32,
 25		      struct nvif_object *);
 26void nvif_object_fini(struct nvif_object *);
 
 
 
 
 
 
 27int  nvif_object_ioctl(struct nvif_object *, void *, u32, void **);
 28int  nvif_object_sclass_get(struct nvif_object *, struct nvif_sclass **);
 29void nvif_object_sclass_put(struct nvif_sclass **);
 30u32  nvif_object_rd(struct nvif_object *, int, u64);
 31void nvif_object_wr(struct nvif_object *, int, u64, u32);
 32int  nvif_object_mthd(struct nvif_object *, u32, void *, u32);
 33int  nvif_object_map_handle(struct nvif_object *, void *, u32,
 34			    u64 *handle, u64 *length);
 35void nvif_object_unmap_handle(struct nvif_object *);
 36int  nvif_object_map(struct nvif_object *, void *, u32);
 37void nvif_object_unmap(struct nvif_object *);
 38
 39#define nvif_handle(a) (unsigned long)(void *)(a)
 40#define nvif_object(a) (a)->object
 41
 42#define nvif_rd(a,f,b,c) ({                                                    \
 43	struct nvif_object *_object = (a);                                     \
 44	u32 _data;                                                             \
 45	if (likely(_object->map.ptr))                                          \
 46		_data = f((u8 __iomem *)_object->map.ptr + (c));               \
 47	else                                                                   \
 48		_data = nvif_object_rd(_object, (b), (c));                     \
 49	_data;                                                                 \
 50})
 51#define nvif_wr(a,f,b,c,d) ({                                                  \
 52	struct nvif_object *_object = (a);                                     \
 53	if (likely(_object->map.ptr))                                          \
 54		f((d), (u8 __iomem *)_object->map.ptr + (c));                  \
 55	else                                                                   \
 56		nvif_object_wr(_object, (b), (c), (d));                        \
 57})
 58#define nvif_rd08(a,b) ({ ((u8)nvif_rd((a), ioread8, 1, (b))); })
 59#define nvif_rd16(a,b) ({ ((u16)nvif_rd((a), ioread16_native, 2, (b))); })
 60#define nvif_rd32(a,b) ({ ((u32)nvif_rd((a), ioread32_native, 4, (b))); })
 61#define nvif_wr08(a,b,c) nvif_wr((a), iowrite8, 1, (b), (u8)(c))
 62#define nvif_wr16(a,b,c) nvif_wr((a), iowrite16_native, 2, (b), (u16)(c))
 63#define nvif_wr32(a,b,c) nvif_wr((a), iowrite32_native, 4, (b), (u32)(c))
 64#define nvif_mask(a,b,c,d) ({                                                  \
 65	struct nvif_object *__object = (a);                                    \
 66	u32 _addr = (b), _data = nvif_rd32(__object, _addr);                   \
 67	nvif_wr32(__object, _addr, (_data & ~(c)) | (d));                      \
 68	_data;                                                                 \
 69})
 70
 71#define nvif_mthd(a,b,c,d) nvif_object_mthd((a), (b), (c), (d))
 72
 73struct nvif_mclass {
 74	s32 oclass;
 75	int version;
 76};
 77
 78#define nvif_mclass(o,m) ({                                                    \
 79	struct nvif_object *object = (o);                                      \
 80	struct nvif_sclass *sclass;                                            \
 81	const typeof(m[0]) *mclass = (m);                                      \
 82	int ret = -ENODEV;                                                     \
 83	int cnt, i, j;                                                         \
 84                                                                               \
 85	cnt = nvif_object_sclass_get(object, &sclass);                         \
 86	if (cnt >= 0) {                                                        \
 87		for (i = 0; ret < 0 && mclass[i].oclass; i++) {                \
 88			for (j = 0; j < cnt; j++) {                            \
 89				if (mclass[i].oclass  == sclass[j].oclass &&   \
 90				    mclass[i].version >= sclass[j].minver &&   \
 91				    mclass[i].version <= sclass[j].maxver) {   \
 92					ret = i;                               \
 93					break;                                 \
 94				}                                              \
 95			}                                                      \
 96		}                                                              \
 97		nvif_object_sclass_put(&sclass);                               \
 98	}                                                                      \
 99	ret;                                                                   \
100})
101
102/*XXX*/
103#include <core/object.h>
104#define nvxx_object(a) ({                                                      \
105	struct nvif_object *_object = (a);                                     \
106	(struct nvkm_object *)_object->priv;                                   \
 
 
 
 
 
 
 
 
 
107})
 
 
 
 
 
 
 
 
 
 
 
 
 
108#endif