2 * Copyright (c) 2011 Semihalf.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #ifndef TYPES_FREEBSD_H_
28 #define TYPES_FREEBSD_H_
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/libkern.h>
33 #include <sys/stddef.h>
34 #include <sys/types.h>
36 #include <machine/pio.h>
38 #if !defined(__bool_true_false_are_defined)
39 typedef boolean_t bool;
44 typedef vm_paddr_t physAddress_t;
47 #define _PackedType __attribute__ ((packed))
51 * TODO: These are only stubs and have to be redefined (use bus_space
54 #define GET_UINT32(arg) in32(&(arg))
55 #define GET_UINT64(arg) in64(&(arg))
57 #define _WRITE_UINT32(arg, data) out32(&(arg), (data))
58 #define _WRITE_UINT64(arg, data) out64(&(arg), (data))
60 #ifndef QE_32_BIT_ACCESS_RESTRICTION
62 #define GET_UINT8(arg) in8(&(arg))
63 #define GET_UINT16(arg) in16(&(arg))
65 #define _WRITE_UINT8(arg, data) out8(&(arg), (data))
66 #define _WRITE_UINT16(arg, data) out16(&(arg), (data))
68 #else /* QE_32_BIT_ACCESS_RESTRICTION */
70 #define QE_32_BIT_ADDR(_arg) (uint32_t)((uint32_t)&(_arg) & 0xFFFFFFFC)
71 #define QE_32_BIT_SHIFT8(__arg) (uint32_t)((3 - ((uint32_t)&(__arg) & 0x3)) * 8)
72 #define QE_32_BIT_SHIFT16(__arg) (uint32_t)((2 - ((uint32_t)&(__arg) & 0x3)) * 8)
74 #define GET_UINT8(arg) (uint8_t)(in32(QE_32_BIT_ADDR(arg)) >> QE_32_BIT_SHIFT8(arg))
75 #define GET_UINT16(arg) (uint16_t)(in32(QE_32_BIT_ADDR(arg)) >> QE_32_BIT_SHIFT16(arg))
77 #define _WRITE_UINT8(arg, data) \
80 uint32_t addr = QE_32_BIT_ADDR(arg); \
81 uint32_t shift = QE_32_BIT_SHIFT8(arg); \
82 uint32_t tmp = in32(addr); \
83 tmp = (uint32_t)((tmp & ~(0x000000FF << shift)) | ((uint32_t)(data & 0x000000FF) << shift)); \
87 #define _WRITE_UINT16(arg, data) \
90 uint32_t addr = QE_32_BIT_ADDR(arg); \
91 uint32_t shift = QE_32_BIT_SHIFT16(arg); \
92 uint32_t tmp = in32(addr); \
93 tmp = (uint32_t)((tmp & ~(0x0000FFFF << shift)) | ((uint32_t)(data & 0x0000FFFF) << shift)); \
97 #endif /* QE_32_BIT_ACCESS_RESTRICTION */
99 #define WRITE_UINT8 _WRITE_UINT8
100 #define WRITE_UINT16 _WRITE_UINT16
101 #define WRITE_UINT32 _WRITE_UINT32
102 #define WRITE_UINT64 _WRITE_UINT64
104 #endif /* TYPES_FREEBSD_H_ */