xref: /freebsd/sys/dev/drm2/drm_os_freebsd.h (revision 01addd846c64fc2c8be610d83bfdc84ddb57f2ec)
1 /**
2  * \file drm_os_freebsd.h
3  * OS abstraction macros.
4  */
5 
6 #include <sys/cdefs.h>
7 #ifndef _DRM_OS_FREEBSD_H_
8 #define	_DRM_OS_FREEBSD_H_
9 
10 #include <sys/fbio.h>
11 #include <sys/smp.h>
12 
13 #if _BYTE_ORDER == _BIG_ENDIAN
14 #define	__BIG_ENDIAN 4321
15 #else
16 #define	__LITTLE_ENDIAN 1234
17 #endif
18 
19 #ifdef __LP64__
20 #define	BITS_PER_LONG	64
21 #else
22 #define	BITS_PER_LONG	32
23 #endif
24 
25 #ifndef __user
26 #define	__user
27 #endif
28 #ifndef __iomem
29 #define	__iomem
30 #endif
31 #ifndef __always_unused
32 #define	__always_unused
33 #endif
34 #ifndef __must_check
35 #define	__must_check
36 #endif
37 #ifndef __force
38 #define	__force
39 #endif
40 #ifndef uninitialized_var
41 #define	uninitialized_var(x) x
42 #endif
43 
44 #define	cpu_to_le16(x)	htole16(x)
45 #define	le16_to_cpu(x)	le16toh(x)
46 #define	cpu_to_le32(x)	htole32(x)
47 #define	le32_to_cpu(x)	le32toh(x)
48 
49 #define	cpu_to_be16(x)	htobe16(x)
50 #define	be16_to_cpu(x)	be16toh(x)
51 #define	cpu_to_be32(x)	htobe32(x)
52 #define	be32_to_cpu(x)	be32toh(x)
53 #define	be32_to_cpup(x)	be32toh(*x)
54 
55 typedef vm_paddr_t dma_addr_t;
56 typedef vm_paddr_t resource_size_t;
57 #define	wait_queue_head_t atomic_t
58 
59 typedef uint64_t u64;
60 typedef uint32_t u32;
61 typedef uint16_t u16;
62 typedef uint8_t  u8;
63 typedef int64_t s64;
64 typedef int32_t s32;
65 typedef int16_t s16;
66 typedef int8_t  s8;
67 typedef uint16_t __le16;
68 typedef uint32_t __le32;
69 typedef uint64_t __le64;
70 typedef uint16_t __be16;
71 typedef uint32_t __be32;
72 typedef uint64_t __be64;
73 
74 #define	DRM_IRQ_ARGS		void *arg
75 typedef void			irqreturn_t;
76 #define	IRQ_HANDLED		/* nothing */
77 #define	IRQ_NONE		/* nothing */
78 
79 #define	__init
80 #define	__exit
81 
82 #define	BUILD_BUG_ON(x)		CTASSERT(!(x))
83 #define	BUILD_BUG_ON_NOT_POWER_OF_2(x)
84 
85 #ifndef WARN
86 #define WARN(condition, format, ...) ({				\
87 	int __ret_warn_on = !!(condition);			\
88 	if (unlikely(__ret_warn_on))				\
89 	DRM_ERROR(format, ##__VA_ARGS__);			\
90 	unlikely(__ret_warn_on);				\
91 })
92 #endif
93 #define	WARN_ONCE(condition, format, ...)			\
94 	WARN(condition, format, ##__VA_ARGS__)
95 #define	WARN_ON(cond)		WARN(cond, "WARN ON: " #cond)
96 #define	WARN_ON_SMP(cond)	WARN_ON(cond)
97 #define	BUG()			panic("BUG")
98 #define	BUG_ON(cond)		KASSERT(!(cond), ("BUG ON: " #cond " -> 0x%jx", (uintmax_t)(cond)))
99 #define	unlikely(x)            __builtin_expect(!!(x), 0)
100 #define	likely(x)              __builtin_expect(!!(x), 1)
101 #define	container_of(ptr, type, member) ({			\
102 	__typeof( ((type *)0)->member ) *__mptr = (ptr);	\
103 	(type *)( (char *)__mptr - offsetof(type,member) );})
104 
105 #define	KHZ2PICOS(a)	(1000000000UL/(a))
106 
107 #define ARRAY_SIZE(x)		(sizeof(x)/sizeof(x[0]))
108 
109 #define	HZ			hz
110 #define	DRM_HZ			hz
111 #define	DRM_CURRENTPID		curthread->td_proc->p_pid
112 #define	DRM_SUSER(p)		(priv_check(p, PRIV_DRIVER) == 0)
113 #define	udelay(usecs)		DELAY(usecs)
114 #define	mdelay(msecs)		do { int loops = (msecs);		\
115 				  while (loops--) DELAY(1000);		\
116 				} while (0)
117 #define	DRM_UDELAY(udelay)	DELAY(udelay)
118 #define	drm_msleep(x, msg)	pause((msg), ((int64_t)(x)) * hz / 1000)
119 #define	DRM_MSLEEP(msecs)	drm_msleep((msecs), "drm_msleep")
120 #define	get_seconds()		time_second
121 
122 #define ioread8(addr)		*(volatile uint8_t *)((char *)addr)
123 #define ioread16(addr)		*(volatile uint16_t *)((char *)addr)
124 #define ioread32(addr)		*(volatile uint32_t *)((char *)addr)
125 
126 #define iowrite8(data, addr)	*(volatile uint8_t *)((char *)addr) = data;
127 #define iowrite16(data, addr)	*(volatile uint16_t *)((char *)addr) = data;
128 #define iowrite32(data, addr)	*(volatile uint32_t *)((char *)addr) = data;
129 
130 #define	DRM_READ8(map, offset)						\
131 	*(volatile u_int8_t *)(((vm_offset_t)(map)->handle) +		\
132 	    (vm_offset_t)(offset))
133 #define	DRM_READ16(map, offset)						\
134 	le16toh(*(volatile u_int16_t *)(((vm_offset_t)(map)->handle) +	\
135 	    (vm_offset_t)(offset)))
136 #define	DRM_READ32(map, offset)						\
137 	le32toh(*(volatile u_int32_t *)(((vm_offset_t)(map)->handle) +	\
138 	    (vm_offset_t)(offset)))
139 #define	DRM_READ64(map, offset)						\
140 	le64toh(*(volatile u_int64_t *)(((vm_offset_t)(map)->handle) +	\
141 	    (vm_offset_t)(offset)))
142 #define	DRM_WRITE8(map, offset, val)					\
143 	*(volatile u_int8_t *)(((vm_offset_t)(map)->handle) +		\
144 	    (vm_offset_t)(offset)) = val
145 #define	DRM_WRITE16(map, offset, val)					\
146 	*(volatile u_int16_t *)(((vm_offset_t)(map)->handle) +		\
147 	    (vm_offset_t)(offset)) = htole16(val)
148 #define	DRM_WRITE32(map, offset, val)					\
149 	*(volatile u_int32_t *)(((vm_offset_t)(map)->handle) +		\
150 	    (vm_offset_t)(offset)) = htole32(val)
151 #define	DRM_WRITE64(map, offset, val)					\
152 	*(volatile u_int64_t *)(((vm_offset_t)(map)->handle) +		\
153 	    (vm_offset_t)(offset)) = htole64(val)
154 
155 #if !defined(__arm__)
156 #if defined(__i386__) || defined(__amd64__) || defined(__powerpc__) || defined(__aarch64__)
157 #define DRM_MSG "WARNING! drm2 module is deprecated.  Install the graphics/drm-kmod pkg\n"
158 #else
159 #define DRM_MSG "WARNING! drm2 module is deprecated.\n"
160 #endif
161 #define DRM_OBSOLETE(dev)	gone_in_dev(dev, 13, DRM_MSG)
162 #endif /* __arm__ */
163 
164 /* DRM_READMEMORYBARRIER() prevents reordering of reads.
165  * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
166  * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
167  */
168 #define	DRM_READMEMORYBARRIER()		rmb()
169 #define	DRM_WRITEMEMORYBARRIER()	wmb()
170 #define	DRM_MEMORYBARRIER()		mb()
171 #define	smp_rmb()			rmb()
172 #define	smp_wmb()			wmb()
173 #define	smp_mb__before_atomic_inc()	mb()
174 #define	smp_mb__after_atomic_inc()	mb()
175 #define	barrier()			__compiler_membar()
176 
177 #define	do_div(a, b)		((a) /= (b))
178 #define	div64_u64(a, b)		((a) / (b))
179 #define	lower_32_bits(n)	((u32)(n))
180 #define	upper_32_bits(n)	((u32)(((n) >> 16) >> 16))
181 
182 #define	__set_bit(n, s)		set_bit((n), (s))
183 #define	__clear_bit(n, s)	clear_bit((n), (s))
184 
185 #define min_t(type, x, y) ({			\
186 	type __min1 = (x);			\
187 	type __min2 = (y);			\
188 	__min1 < __min2 ? __min1 : __min2; })
189 
190 #define max_t(type, x, y) ({			\
191 	type __max1 = (x);			\
192 	type __max2 = (y);			\
193 	__max1 > __max2 ? __max1 : __max2; })
194 
195 #define	memset_io(a, b, c)	memset((a), (b), (c))
196 #define	memcpy_fromio(a, b, c)	memcpy((a), (b), (c))
197 #define	memcpy_toio(a, b, c)	memcpy((a), (b), (c))
198 
199 #define	VERIFY_READ	VM_PROT_READ
200 #define	VERIFY_WRITE	VM_PROT_WRITE
201 #define	access_ok(prot, p, l)	useracc((p), (l), (prot))
202 
203 /* XXXKIB what is the right code for the FreeBSD ? */
204 /* kib@ used ENXIO here -- dumbbell@ */
205 #define	EREMOTEIO	EIO
206 #define	ERESTARTSYS	512 /* Same value as Linux. */
207 
208 #define	KTR_DRM		KTR_DEV
209 #define	KTR_DRM_REG	KTR_SPARE3
210 
211 #define	DRM_AGP_KERN	struct agp_info
212 #define	DRM_AGP_MEM	void
213 
214 #define	PCI_VENDOR_ID_APPLE		0x106b
215 #define	PCI_VENDOR_ID_ASUSTEK		0x1043
216 #define	PCI_VENDOR_ID_ATI		0x1002
217 #define	PCI_VENDOR_ID_DELL		0x1028
218 #define	PCI_VENDOR_ID_HP		0x103c
219 #define	PCI_VENDOR_ID_IBM		0x1014
220 #define	PCI_VENDOR_ID_INTEL		0x8086
221 #define	PCI_VENDOR_ID_SERVERWORKS	0x1166
222 #define	PCI_VENDOR_ID_SONY		0x104d
223 #define	PCI_VENDOR_ID_VIA		0x1106
224 
225 #define DIV_ROUND_UP(n,d) 	(((n) + (d) - 1) / (d))
226 #define	DIV_ROUND_CLOSEST(n,d)	(((n) + (d) / 2) / (d))
227 #define	div_u64(n, d)		((n) / (d))
228 #define	hweight32(i)		bitcount32(i)
229 
230 /**
231  * ror32 - rotate a 32-bit value right
232  * @word: value to rotate
233  * @shift: bits to roll
234  *
235  * Source: include/linux/bitops.h
236  */
237 static inline uint32_t
ror32(uint32_t word,unsigned int shift)238 ror32(uint32_t word, unsigned int shift)
239 {
240 
241 	return (word >> shift) | (word << (32 - shift));
242 }
243 
244 #define	IS_ALIGNED(x, y)	(((x) & ((y) - 1)) == 0)
245 #define	round_down(x, y)	rounddown2((x), (y))
246 #define	round_up(x, y)		roundup2((x), (y))
247 #define	get_unaligned(ptr)                                              \
248 	({ __typeof__(*(ptr)) __tmp;                                    \
249 	  memcpy(&__tmp, (ptr), sizeof(*(ptr))); __tmp; })
250 
251 #if _BYTE_ORDER == _LITTLE_ENDIAN
252 /* Taken from linux/include/linux/unaligned/le_struct.h. */
253 struct __una_u32 { u32 x; } __packed;
254 
255 static inline u32
__get_unaligned_cpu32(const void * p)256 __get_unaligned_cpu32(const void *p)
257 {
258 	const struct __una_u32 *ptr = (const struct __una_u32 *)p;
259 
260 	return (ptr->x);
261 }
262 
263 static inline u32
get_unaligned_le32(const void * p)264 get_unaligned_le32(const void *p)
265 {
266 
267 	return (__get_unaligned_cpu32((const u8 *)p));
268 }
269 #else
270 /* Taken from linux/include/linux/unaligned/le_byteshift.h. */
271 static inline u32
__get_unaligned_le32(const u8 * p)272 __get_unaligned_le32(const u8 *p)
273 {
274 
275 	return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24);
276 }
277 
278 static inline u32
get_unaligned_le32(const void * p)279 get_unaligned_le32(const void *p)
280 {
281 
282 	return (__get_unaligned_le32((const u8 *)p));
283 }
284 #endif
285 
286 int64_t		timeval_to_ns(const struct timeval *tv);
287 struct timeval	ns_to_timeval(const int64_t nsec);
288 
289 #define	PAGE_ALIGN(addr) round_page(addr)
290 #define	page_to_phys(x) VM_PAGE_TO_PHYS(x)
291 #define	offset_in_page(x) ((x) & PAGE_MASK)
292 
293 #define	drm_get_device_from_kdev(_kdev)	(((struct drm_minor *)(_kdev)->si_drv1)->dev)
294 
295 #define DRM_IOC_VOID		IOC_VOID
296 #define DRM_IOC_READ		IOC_OUT
297 #define DRM_IOC_WRITE		IOC_IN
298 #define DRM_IOC_READWRITE	IOC_INOUT
299 #define DRM_IOC(dir, group, nr, size) _IOC(dir, group, nr, size)
300 
301 static inline long
__copy_to_user(void __user * to,const void * from,unsigned long n)302 __copy_to_user(void __user *to, const void *from, unsigned long n)
303 {
304 	return (copyout(from, to, n) != 0 ? n : 0);
305 }
306 #define	copy_to_user(to, from, n) __copy_to_user((to), (from), (n))
307 
308 static inline int
__put_user(size_t size,void * ptr,void * x)309 __put_user(size_t size, void *ptr, void *x)
310 {
311 
312 	size = copy_to_user(ptr, x, size);
313 
314 	return (size ? -EFAULT : size);
315 }
316 #define	put_user(x, ptr) __put_user(sizeof(*ptr), (ptr), &(x))
317 
318 static inline unsigned long
__copy_from_user(void * to,const void __user * from,unsigned long n)319 __copy_from_user(void *to, const void __user *from, unsigned long n)
320 {
321 	return ((copyin(__DECONST(void *, from), to, n) != 0 ? n : 0));
322 }
323 #define	copy_from_user(to, from, n) __copy_from_user((to), (from), (n))
324 
325 static inline int
__get_user(size_t size,const void * ptr,void * x)326 __get_user(size_t size, const void *ptr, void *x)
327 {
328 
329 	size = copy_from_user(x, ptr, size);
330 
331 	return (size ? -EFAULT : size);
332 }
333 #define	get_user(x, ptr) __get_user(sizeof(*ptr), (ptr), &(x))
334 
335 static inline int
__copy_to_user_inatomic(void __user * to,const void * from,unsigned n)336 __copy_to_user_inatomic(void __user *to, const void *from, unsigned n)
337 {
338 
339 	return (copyout_nofault(from, to, n) != 0 ? n : 0);
340 }
341 #define	__copy_to_user_inatomic_nocache(to, from, n) \
342     __copy_to_user_inatomic((to), (from), (n))
343 
344 static inline unsigned long
__copy_from_user_inatomic(void * to,const void __user * from,unsigned long n)345 __copy_from_user_inatomic(void *to, const void __user *from,
346     unsigned long n)
347 {
348 
349 	/*
350 	 * XXXKIB.  Equivalent Linux function is implemented using
351 	 * MOVNTI for aligned moves.  For unaligned head and tail,
352 	 * normal move is performed.  As such, it is not incorrect, if
353 	 * only somewhat slower, to use normal copyin.  All uses
354 	 * except shmem_pwrite_fast() have the destination mapped WC.
355 	 */
356 	return ((copyin_nofault(__DECONST(void *, from), to, n) != 0 ? n : 0));
357 }
358 #define	__copy_from_user_inatomic_nocache(to, from, n) \
359     __copy_from_user_inatomic((to), (from), (n))
360 
361 static inline int
fault_in_multipages_readable(const char __user * uaddr,int size)362 fault_in_multipages_readable(const char __user *uaddr, int size)
363 {
364 	char c;
365 	int ret = 0;
366 	const char __user *end = uaddr + size - 1;
367 
368 	if (unlikely(size == 0))
369 		return ret;
370 
371 	while (uaddr <= end) {
372 		ret = -copyin(uaddr, &c, 1);
373 		if (ret != 0)
374 			return -EFAULT;
375 		uaddr += PAGE_SIZE;
376 	}
377 
378 	/* Check whether the range spilled into the next page. */
379 	if (((unsigned long)uaddr & ~PAGE_MASK) ==
380 			((unsigned long)end & ~PAGE_MASK)) {
381 		ret = -copyin(end, &c, 1);
382 	}
383 
384 	return ret;
385 }
386 
387 static inline int
fault_in_multipages_writeable(char __user * uaddr,int size)388 fault_in_multipages_writeable(char __user *uaddr, int size)
389 {
390 	int ret = 0;
391 	char __user *end = uaddr + size - 1;
392 
393 	if (unlikely(size == 0))
394 		return ret;
395 
396 	/*
397 	 * Writing zeroes into userspace here is OK, because we know that if
398 	 * the zero gets there, we'll be overwriting it.
399 	 */
400 	while (uaddr <= end) {
401 		ret = subyte(uaddr, 0);
402 		if (ret != 0)
403 			return -EFAULT;
404 		uaddr += PAGE_SIZE;
405 	}
406 
407 	/* Check whether the range spilled into the next page. */
408 	if (((unsigned long)uaddr & ~PAGE_MASK) ==
409 			((unsigned long)end & ~PAGE_MASK))
410 		ret = subyte(end, 0);
411 
412 	return ret;
413 }
414 
415 enum __drm_capabilities {
416 	CAP_SYS_ADMIN
417 };
418 
419 static inline bool
capable(enum __drm_capabilities cap)420 capable(enum __drm_capabilities cap)
421 {
422 
423 	switch (cap) {
424 	case CAP_SYS_ADMIN:
425 		return DRM_SUSER(curthread);
426 	default:
427 		panic("%s: unhandled capability: %0x", __func__, cap);
428 		return (false);
429 	}
430 }
431 
432 #define	to_user_ptr(x)		((void *)(uintptr_t)(x))
433 #define	sigemptyset(set)	SIGEMPTYSET(set)
434 #define	sigaddset(set, sig)	SIGADDSET(set, sig)
435 
436 #define DRM_LOCK(dev)		sx_xlock(&(dev)->dev_struct_lock)
437 #define DRM_UNLOCK(dev) 	sx_xunlock(&(dev)->dev_struct_lock)
438 
439 extern unsigned long drm_linux_timer_hz_mask;
440 #define jiffies			ticks
441 #define	jiffies_to_msecs(x)	(((int64_t)(x)) * 1000 / hz)
442 #define	msecs_to_jiffies(x)	(((int64_t)(x)) * hz / 1000)
443 #define	time_after(a,b)		((long)(b) - (long)(a) < 0)
444 #define	time_after_eq(a,b)	((long)(b) - (long)(a) <= 0)
445 #define	round_jiffies(j)	((unsigned long)(((j) + drm_linux_timer_hz_mask) & ~drm_linux_timer_hz_mask))
446 #define	round_jiffies_up(j)		round_jiffies(j) /* TODO */
447 #define	round_jiffies_up_relative(j)	round_jiffies_up(j) /* TODO */
448 
449 #define	getrawmonotonic(ts)	getnanouptime(ts)
450 
451 #define	wake_up(queue)				wakeup_one((void *)queue)
452 #define	wake_up_interruptible(queue)		wakeup_one((void *)queue)
453 #define	wake_up_all(queue)			wakeup((void *)queue)
454 #define	wake_up_interruptible_all(queue)	wakeup((void *)queue)
455 
456 struct completion {
457 	unsigned int done;
458 	struct mtx lock;
459 };
460 
461 #define	INIT_COMPLETION(c) ((c).done = 0);
462 
463 static inline void
init_completion(struct completion * c)464 init_completion(struct completion *c)
465 {
466 
467 	mtx_init(&c->lock, "drmcompl", NULL, MTX_DEF);
468 	c->done = 0;
469 }
470 
471 static inline void
free_completion(struct completion * c)472 free_completion(struct completion *c)
473 {
474 
475 	mtx_destroy(&c->lock);
476 }
477 
478 static inline void
complete_all(struct completion * c)479 complete_all(struct completion *c)
480 {
481 
482 	mtx_lock(&c->lock);
483 	c->done++;
484 	mtx_unlock(&c->lock);
485 	wakeup(c);
486 }
487 
488 static inline long
wait_for_completion_interruptible_timeout(struct completion * c,unsigned long timeout)489 wait_for_completion_interruptible_timeout(struct completion *c,
490     unsigned long timeout)
491 {
492 	unsigned long start_jiffies, elapsed_jiffies;
493 	bool timeout_expired = false, awakened = false;
494 	long ret = timeout;
495 
496 	start_jiffies = ticks;
497 
498 	mtx_lock(&c->lock);
499 	while (c->done == 0 && !timeout_expired) {
500 		ret = -msleep(c, &c->lock, PCATCH, "drmwco", timeout);
501 		switch(ret) {
502 		case -EWOULDBLOCK:
503 			timeout_expired = true;
504 			ret = 0;
505 			break;
506 		case -EINTR:
507 		case -ERESTART:
508 			ret = -ERESTARTSYS;
509 			break;
510 		case 0:
511 			awakened = true;
512 			break;
513 		}
514 	}
515 	mtx_unlock(&c->lock);
516 
517 	if (awakened) {
518 		elapsed_jiffies = ticks - start_jiffies;
519 		ret = timeout > elapsed_jiffies ? timeout - elapsed_jiffies : 1;
520 	}
521 
522 	return (ret);
523 }
524 
525 MALLOC_DECLARE(DRM_MEM_DMA);
526 MALLOC_DECLARE(DRM_MEM_SAREA);
527 MALLOC_DECLARE(DRM_MEM_DRIVER);
528 MALLOC_DECLARE(DRM_MEM_MAGIC);
529 MALLOC_DECLARE(DRM_MEM_MINOR);
530 MALLOC_DECLARE(DRM_MEM_IOCTLS);
531 MALLOC_DECLARE(DRM_MEM_MAPS);
532 MALLOC_DECLARE(DRM_MEM_BUFS);
533 MALLOC_DECLARE(DRM_MEM_SEGS);
534 MALLOC_DECLARE(DRM_MEM_PAGES);
535 MALLOC_DECLARE(DRM_MEM_FILES);
536 MALLOC_DECLARE(DRM_MEM_QUEUES);
537 MALLOC_DECLARE(DRM_MEM_CMDS);
538 MALLOC_DECLARE(DRM_MEM_MAPPINGS);
539 MALLOC_DECLARE(DRM_MEM_BUFLISTS);
540 MALLOC_DECLARE(DRM_MEM_AGPLISTS);
541 MALLOC_DECLARE(DRM_MEM_CTXBITMAP);
542 MALLOC_DECLARE(DRM_MEM_SGLISTS);
543 MALLOC_DECLARE(DRM_MEM_MM);
544 MALLOC_DECLARE(DRM_MEM_HASHTAB);
545 MALLOC_DECLARE(DRM_MEM_KMS);
546 MALLOC_DECLARE(DRM_MEM_VBLANK);
547 
548 #define	simple_strtol(a, b, c)			strtol((a), (b), (c))
549 
550 typedef struct drm_pci_id_list
551 {
552 	int vendor;
553 	int device;
554 	long driver_private;
555 	char *name;
556 } drm_pci_id_list_t;
557 
558 #ifdef __i386__
559 #define	CONFIG_X86	1
560 #endif
561 #ifdef __amd64__
562 #define	CONFIG_X86	1
563 #define	CONFIG_X86_64	1
564 #endif
565 #ifdef __ia64__
566 #define	CONFIG_IA64	1
567 #endif
568 
569 #if defined(__i386__) || defined(__amd64__)
570 #define	CONFIG_ACPI
571 #define	CONFIG_DRM_I915_KMS
572 #undef	CONFIG_INTEL_IOMMU
573 #endif
574 
575 #ifdef COMPAT_FREEBSD32
576 #define	CONFIG_COMPAT
577 #endif
578 
579 #ifndef __arm__
580 #define	CONFIG_AGP	1
581 #define	CONFIG_MTRR	1
582 #endif
583 
584 #define	CONFIG_FB	1
585 extern const char *fb_mode_option;
586 
587 #undef	CONFIG_DEBUG_FS
588 #undef	CONFIG_VGA_CONSOLE
589 
590 #define	EXPORT_SYMBOL(x)
591 #define	EXPORT_SYMBOL_GPL(x)
592 #define	MODULE_AUTHOR(author)
593 #define	MODULE_DESCRIPTION(desc)
594 #define	MODULE_LICENSE(license)
595 #define	MODULE_PARM_DESC(name, desc)
596 #define	MODULE_DEVICE_TABLE(name, list)
597 #define	module_param_named(name, var, type, perm)
598 
599 #define	printk		printf
600 #define	pr_err		DRM_ERROR
601 #define	pr_warn		DRM_WARNING
602 #define	pr_warn_once	DRM_WARNING
603 #define	KERN_DEBUG	""
604 
605 /* I2C compatibility. */
606 #define	I2C_M_RD	IIC_M_RD
607 #define	I2C_M_WR	IIC_M_WR
608 #define	I2C_M_NOSTART	IIC_M_NOSTART
609 
610 struct fb_info *	framebuffer_alloc(void);
611 void			framebuffer_release(struct fb_info *info);
612 
613 #define	console_lock()
614 #define	console_unlock()
615 #define	console_trylock()	true
616 
617 #define	PM_EVENT_SUSPEND	0x0002
618 #define	PM_EVENT_QUIESCE	0x0008
619 #define	PM_EVENT_PRETHAW	PM_EVENT_QUIESCE
620 
621 typedef struct pm_message {
622 	int event;
623 } pm_message_t;
624 
625 static inline int
pci_read_config_byte(device_t kdev,int where,u8 * val)626 pci_read_config_byte(device_t kdev, int where, u8 *val)
627 {
628 
629 	*val = (u8)pci_read_config(kdev, where, 1);
630 	return (0);
631 }
632 
633 static inline int
pci_write_config_byte(device_t kdev,int where,u8 val)634 pci_write_config_byte(device_t kdev, int where, u8 val)
635 {
636 
637 	pci_write_config(kdev, where, val, 1);
638 	return (0);
639 }
640 
641 static inline int
pci_read_config_word(device_t kdev,int where,uint16_t * val)642 pci_read_config_word(device_t kdev, int where, uint16_t *val)
643 {
644 
645 	*val = (uint16_t)pci_read_config(kdev, where, 2);
646 	return (0);
647 }
648 
649 static inline int
pci_write_config_word(device_t kdev,int where,uint16_t val)650 pci_write_config_word(device_t kdev, int where, uint16_t val)
651 {
652 
653 	pci_write_config(kdev, where, val, 2);
654 	return (0);
655 }
656 
657 static inline int
pci_read_config_dword(device_t kdev,int where,uint32_t * val)658 pci_read_config_dword(device_t kdev, int where, uint32_t *val)
659 {
660 
661 	*val = (uint32_t)pci_read_config(kdev, where, 4);
662 	return (0);
663 }
664 
665 static inline int
pci_write_config_dword(device_t kdev,int where,uint32_t val)666 pci_write_config_dword(device_t kdev, int where, uint32_t val)
667 {
668 
669 	pci_write_config(kdev, where, val, 4);
670 	return (0);
671 }
672 
673 static inline void
on_each_cpu(void callback (void * data),void * data,int wait)674 on_each_cpu(void callback(void *data), void *data, int wait)
675 {
676 
677 	smp_rendezvous(NULL, callback, NULL, data);
678 }
679 
680 void	hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
681 	    int groupsize, char *linebuf, size_t linebuflen, bool ascii);
682 
683 #define KIB_NOTYET()							\
684 do {									\
685 	if (drm_debug && drm_notyet)					\
686 		printf("NOTYET: %s at %s:%d\n", __func__, __FILE__, __LINE__); \
687 } while (0)
688 
689 #endif /* _DRM_OS_FREEBSD_H_ */
690