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