1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_OS_H__
3 #define __NVKM_OS_H__
4 #include <nvif/os.h>
5 
6 #ifdef __BIG_ENDIAN
7 #define ioread16_native ioread16be
8 #define iowrite16_native iowrite16be
9 #define ioread32_native  ioread32be
10 #define iowrite32_native iowrite32be
11 #else
12 #define ioread16_native ioread16
13 #define iowrite16_native iowrite16
14 #define ioread32_native  ioread32
15 #define iowrite32_native iowrite32
16 #endif
17 
18 #define iowrite64_native(v,p) do {                                             \
19 	u32 __iomem *_p = (u32 __iomem *)(p);				       \
20 	u64 _v = (v);							       \
21 	iowrite32_native(lower_32_bits(_v), &_p[0]);			       \
22 	iowrite32_native(upper_32_bits(_v), &_p[1]);			       \
23 } while(0)
24 
25 struct nvkm_blob {
26 	void *data;
27 	u32 size;
28 };
29 
30 static inline void
nvkm_blob_dtor(struct nvkm_blob * blob)31 nvkm_blob_dtor(struct nvkm_blob *blob)
32 {
33 	kfree(blob->data);
34 	blob->data = NULL;
35 	blob->size = 0;
36 }
37 
38 #define nvkm_list_find_next(p,h,m,c) ({                                                      \
39 	typeof(p) _p = NULL;                                                                 \
40 	list_for_each_entry_continue(p, (h), m) {                                            \
41 		if (c) {                                                                     \
42 			_p = p;                                                              \
43 			break;                                                               \
44 		}                                                                            \
45 	}                                                                                    \
46 	_p;                                                                                  \
47 })
48 #define nvkm_list_find(p,h,m,c)                                                              \
49 	(p = container_of((h), typeof(*p), m), nvkm_list_find_next(p, (h), m, (c)))
50 #define nvkm_list_foreach(p,h,m,c)                                                           \
51 	for (p = nvkm_list_find(p, (h), m, (c)); p; p = nvkm_list_find_next(p, (h), m, (c)))
52 #endif
53