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