1 /*- 2 * Copyright (c) 2011 Semihalf. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef TYPES_FREEBSD_H_ 28 #define TYPES_FREEBSD_H_ 29 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> 35 36 #include <machine/pio.h> 37 38 #if !defined(__bool_true_false_are_defined) 39 typedef boolean_t bool; 40 #endif 41 #define TRUE 1 42 #define FALSE 0 43 44 typedef vm_paddr_t physAddress_t; 45 46 #define _Packed 47 #define _PackedType __attribute__ ((packed)) 48 49 /** 50 * Accessor defines. 51 * TODO: These are only stubs and have to be redefined (use bus_space 52 * facilities). 53 */ 54 #define GET_UINT32(arg) in32(&(arg)) 55 #define GET_UINT64(arg) in64(&(arg)) 56 57 #define _WRITE_UINT32(arg, data) out32(&(arg), (data)) 58 #define _WRITE_UINT64(arg, data) out64(&(arg), (data)) 59 60 #ifndef QE_32_BIT_ACCESS_RESTRICTION 61 62 #define GET_UINT8(arg) in8(&(arg)) 63 #define GET_UINT16(arg) in16(&(arg)) 64 65 #define _WRITE_UINT8(arg, data) out8(&(arg), (data)) 66 #define _WRITE_UINT16(arg, data) out16(&(arg), (data)) 67 68 #else /* QE_32_BIT_ACCESS_RESTRICTION */ 69 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) 73 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)) 76 77 #define _WRITE_UINT8(arg, data) \ 78 do \ 79 { \ 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)); \ 84 out32(addr, tmp); \ 85 } while (0) 86 87 #define _WRITE_UINT16(arg, data) \ 88 do \ 89 { \ 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)); \ 94 out32(addr, tmp); \ 95 } while (0) 96 97 #endif /* QE_32_BIT_ACCESS_RESTRICTION */ 98 99 #define WRITE_UINT8 _WRITE_UINT8 100 #define WRITE_UINT16 _WRITE_UINT16 101 #define WRITE_UINT32 _WRITE_UINT32 102 #define WRITE_UINT64 _WRITE_UINT64 103 104 #endif /* TYPES_FREEBSD_H_ */ 105