18bf1194jhibbits/*-
28bf1194jhibbits * Copyright (c) 2011 Semihalf.
38bf1194jhibbits * All rights reserved.
48bf1194jhibbits *
58bf1194jhibbits * Redistribution and use in source and binary forms, with or without
68bf1194jhibbits * modification, are permitted provided that the following conditions
78bf1194jhibbits * are met:
88bf1194jhibbits * 1. Redistributions of source code must retain the above copyright
98bf1194jhibbits *    notice, this list of conditions and the following disclaimer.
108bf1194jhibbits * 2. Redistributions in binary form must reproduce the above copyright
118bf1194jhibbits *    notice, this list of conditions and the following disclaimer in the
128bf1194jhibbits *    documentation and/or other materials provided with the distribution.
138bf1194jhibbits *
148bf1194jhibbits * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
158bf1194jhibbits * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
168bf1194jhibbits * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
178bf1194jhibbits * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
188bf1194jhibbits * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
198bf1194jhibbits * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
208bf1194jhibbits * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
218bf1194jhibbits * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
228bf1194jhibbits * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
238bf1194jhibbits * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
248bf1194jhibbits * SUCH DAMAGE.
258bf1194jhibbits */
268bf1194jhibbits
278bf1194jhibbits#ifndef TYPES_FREEBSD_H_
288bf1194jhibbits#define TYPES_FREEBSD_H_
298bf1194jhibbits
308bf1194jhibbits#include <sys/param.h>
318bf1194jhibbits#include <sys/kernel.h>
328bf1194jhibbits#include <sys/libkern.h>
338bf1194jhibbits#include <sys/stddef.h>
348bf1194jhibbits#include <sys/types.h>
358bf1194jhibbits
368bf1194jhibbits#include <machine/pio.h>
378bf1194jhibbits
388bf1194jhibbits#if !defined(__bool_true_false_are_defined)
398bf1194jhibbitstypedef	boolean_t	bool;
408bf1194jhibbits#endif
418bf1194jhibbits#define	TRUE		1
428bf1194jhibbits#define	FALSE		0
438bf1194jhibbits
448bf1194jhibbitstypedef vm_paddr_t	physAddress_t;
458bf1194jhibbits
468bf1194jhibbits#define	_Packed
478bf1194jhibbits#define	_PackedType	__attribute__ ((packed))
488bf1194jhibbits
498bf1194jhibbits/**
508bf1194jhibbits * Accessor defines.
518bf1194jhibbits * TODO: These are only stubs and have to be redefined (use bus_space
528bf1194jhibbits * facilities).
538bf1194jhibbits */
548bf1194jhibbits#define GET_UINT32(arg)			in32(&(arg))
558bf1194jhibbits#define GET_UINT64(arg)			in64(&(arg))
568bf1194jhibbits
578bf1194jhibbits#define _WRITE_UINT32(arg, data)	out32(&(arg), (data))
588bf1194jhibbits#define _WRITE_UINT64(arg, data)	out64(&(arg), (data))
598bf1194jhibbits
608bf1194jhibbits#ifndef QE_32_BIT_ACCESS_RESTRICTION
618bf1194jhibbits
628bf1194jhibbits#define GET_UINT8(arg)			in8(&(arg))
638bf1194jhibbits#define GET_UINT16(arg)			in16(&(arg))
648bf1194jhibbits
658bf1194jhibbits#define _WRITE_UINT8(arg, data)		out8(&(arg), (data))
668bf1194jhibbits#define _WRITE_UINT16(arg, data)	out16(&(arg), (data))
678bf1194jhibbits
688bf1194jhibbits#else  /* QE_32_BIT_ACCESS_RESTRICTION */
698bf1194jhibbits
708bf1194jhibbits#define QE_32_BIT_ADDR(_arg)        (uint32_t)((uint32_t)&(_arg) & 0xFFFFFFFC)
718bf1194jhibbits#define QE_32_BIT_SHIFT8(__arg)     (uint32_t)((3 - ((uint32_t)&(__arg) & 0x3)) * 8)
728bf1194jhibbits#define QE_32_BIT_SHIFT16(__arg)    (uint32_t)((2 - ((uint32_t)&(__arg) & 0x3)) * 8)
738bf1194jhibbits
748bf1194jhibbits#define GET_UINT8(arg)              (uint8_t)(in32(QE_32_BIT_ADDR(arg)) >> QE_32_BIT_SHIFT8(arg))
758bf1194jhibbits#define GET_UINT16(arg)             (uint16_t)(in32(QE_32_BIT_ADDR(arg)) >> QE_32_BIT_SHIFT16(arg))
768bf1194jhibbits
778bf1194jhibbits#define _WRITE_UINT8(arg, data)                                                                         \
788bf1194jhibbits    do                                                                                                  \
798bf1194jhibbits    {                                                                                                   \
808bf1194jhibbits        uint32_t addr = QE_32_BIT_ADDR(arg);                                                            \
818bf1194jhibbits        uint32_t shift = QE_32_BIT_SHIFT8(arg);                                                         \
828bf1194jhibbits        uint32_t tmp = in32(addr);                                                                      \
838bf1194jhibbits        tmp = (uint32_t)((tmp & ~(0x000000FF << shift)) | ((uint32_t)(data & 0x000000FF) << shift));    \
848bf1194jhibbits        out32(addr, tmp);                                                                               \
858bf1194jhibbits    } while (0)
868bf1194jhibbits
878bf1194jhibbits#define _WRITE_UINT16(arg, data)                                                                        \
888bf1194jhibbits    do                                                                                                  \
898bf1194jhibbits    {                                                                                                   \
908bf1194jhibbits        uint32_t addr = QE_32_BIT_ADDR(arg);                                                            \
918bf1194jhibbits        uint32_t shift = QE_32_BIT_SHIFT16(arg);                                                        \
928bf1194jhibbits        uint32_t tmp = in32(addr);                                                                      \
938bf1194jhibbits        tmp = (uint32_t)((tmp & ~(0x0000FFFF << shift)) | ((uint32_t)(data & 0x0000FFFF) << shift));    \
948bf1194jhibbits        out32(addr, tmp);                                                                               \
958bf1194jhibbits    } while (0)
968bf1194jhibbits
978bf1194jhibbits#endif /* QE_32_BIT_ACCESS_RESTRICTION */
988bf1194jhibbits
998bf1194jhibbits#define WRITE_UINT8                 _WRITE_UINT8
1008bf1194jhibbits#define WRITE_UINT16                _WRITE_UINT16
1018bf1194jhibbits#define WRITE_UINT32                _WRITE_UINT32
1028bf1194jhibbits#define WRITE_UINT64                _WRITE_UINT64
1038bf1194jhibbits
1048bf1194jhibbits#endif /* TYPES_FREEBSD_H_ */
105