1718cf2ccSPedro F. Giffuni /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4d2bd3ab9SScott Long * Copyright (c) 2004-2005 HighPoint Technologies, Inc. 51713e81bSScott Long * All rights reserved. 61713e81bSScott Long * 71713e81bSScott Long * Redistribution and use in source and binary forms, with or without 81713e81bSScott Long * modification, are permitted provided that the following conditions 91713e81bSScott Long * are met: 101713e81bSScott Long * 1. Redistributions of source code must retain the above copyright 111713e81bSScott Long * notice, this list of conditions and the following disclaimer. 121713e81bSScott Long * 2. Redistributions in binary form must reproduce the above copyright 131713e81bSScott Long * notice, this list of conditions and the following disclaimer in the 141713e81bSScott Long * documentation and/or other materials provided with the distribution. 151713e81bSScott Long * 161713e81bSScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 171713e81bSScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181713e81bSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191713e81bSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 201713e81bSScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211713e81bSScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221713e81bSScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231713e81bSScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241713e81bSScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251713e81bSScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261713e81bSScott Long * SUCH DAMAGE. 271713e81bSScott Long */ 281713e81bSScott Long #ifndef __INCmvOsBsdh 291713e81bSScott Long #define __INCmvOsBsdh 301713e81bSScott Long 3164470755SXin LI #ifdef DEBUG 321713e81bSScott Long #define MV_DEBUG_LOG 331713e81bSScott Long #endif 341713e81bSScott Long 351713e81bSScott Long #define ENABLE_READ_AHEAD 361713e81bSScott Long #define ENABLE_WRITE_CACHE 371713e81bSScott Long 381713e81bSScott Long /* Typedefs */ 39d2bd3ab9SScott Long /*#define HPTLIBAPI __attribute__((regparm(0))) */ 40d2bd3ab9SScott Long #define HPTLIBAPI 411713e81bSScott Long #define FAR 42d2bd3ab9SScott Long #define SS_SEG 431713e81bSScott Long #ifdef FASTCALL 441713e81bSScott Long #undef FASTCALL 451713e81bSScott Long #endif 461713e81bSScott Long #define FASTCALL HPTLIBAPI 471713e81bSScott Long #define PASCAL HPTLIBAPI 481713e81bSScott Long 49d2bd3ab9SScott Long typedef unsigned short USHORT; 50d2bd3ab9SScott Long typedef unsigned char UCHAR; 51d2bd3ab9SScott Long typedef unsigned char *PUCHAR; 52d2bd3ab9SScott Long typedef unsigned short *PUSHORT; 53d2bd3ab9SScott Long typedef unsigned char BOOLEAN; 54d2bd3ab9SScott Long typedef unsigned short WORD; 55d2bd3ab9SScott Long typedef unsigned int UINT, BOOL; 56d2bd3ab9SScott Long typedef unsigned char BYTE; 571713e81bSScott Long typedef void *PVOID, *LPVOID; 581713e81bSScott Long typedef void *ADDRESS; 591713e81bSScott Long 601713e81bSScott Long typedef int LONG; 6164470755SXin LI typedef unsigned int ULONG, *PULONG; 621713e81bSScott Long typedef unsigned int DWORD, *LPDWORD, *PDWORD; 631713e81bSScott Long typedef unsigned long ULONG_PTR, UINT_PTR, BUS_ADDR; 6464470755SXin LI typedef unsigned long long HPT_U64, LBA_T; 651713e81bSScott Long 661713e81bSScott Long typedef enum mvBoolean{MV_FALSE, MV_TRUE} MV_BOOLEAN; 671713e81bSScott Long 681713e81bSScott Long #define FALSE 0 691713e81bSScott Long #define TRUE 1 701713e81bSScott Long 71d2bd3ab9SScott Long #ifndef NULL 72d2bd3ab9SScott Long #define NULL 0 73d2bd3ab9SScott Long #endif 74d2bd3ab9SScott Long 75453130d9SPedro F. Giffuni /* System dependent typedefs */ 761713e81bSScott Long typedef void MV_VOID; 77d2bd3ab9SScott Long typedef unsigned int MV_U32; 78d2bd3ab9SScott Long typedef unsigned short MV_U16; 79d2bd3ab9SScott Long typedef unsigned char MV_U8; 801713e81bSScott Long typedef void *MV_VOID_PTR; 811713e81bSScott Long typedef MV_U32 *MV_U32_PTR; 821713e81bSScott Long typedef MV_U16 *MV_U16_PTR; 831713e81bSScott Long typedef MV_U8 *MV_U8_PTR; 841713e81bSScott Long typedef char *MV_CHAR_PTR; 851713e81bSScott Long typedef void *MV_BUS_ADDR_T; 861713e81bSScott Long 871713e81bSScott Long /* System dependent macro for flushing CPU write cache */ 881713e81bSScott Long #define MV_CPU_WRITE_BUFFER_FLUSH() 891713e81bSScott Long 901713e81bSScott Long /* System dependent little endian from / to CPU conversions */ 911713e81bSScott Long #define MV_CPU_TO_LE16(x) (x) 921713e81bSScott Long #define MV_CPU_TO_LE32(x) (x) 931713e81bSScott Long 941713e81bSScott Long #define MV_LE16_TO_CPU(x) (x) 951713e81bSScott Long #define MV_LE32_TO_CPU(x) (x) 961713e81bSScott Long 971713e81bSScott Long /* System dependent register read / write in byte/word/dword variants */ 98d2bd3ab9SScott Long extern void HPTLIBAPI MV_REG_WRITE_BYTE(MV_BUS_ADDR_T base, MV_U32 offset, MV_U8 val); 99d2bd3ab9SScott Long extern void HPTLIBAPI MV_REG_WRITE_WORD(MV_BUS_ADDR_T base, MV_U32 offset, MV_U16 val); 100d2bd3ab9SScott Long extern void HPTLIBAPI MV_REG_WRITE_DWORD(MV_BUS_ADDR_T base, MV_U32 offset, MV_U32 val); 1011713e81bSScott Long extern MV_U8 HPTLIBAPI MV_REG_READ_BYTE(MV_BUS_ADDR_T base, MV_U32 offset); 1021713e81bSScott Long extern MV_U16 HPTLIBAPI MV_REG_READ_WORD(MV_BUS_ADDR_T base, MV_U32 offset); 1031713e81bSScott Long extern MV_U32 HPTLIBAPI MV_REG_READ_DWORD(MV_BUS_ADDR_T base, MV_U32 offset); 1041713e81bSScott Long 1051713e81bSScott Long /* System dependent structure */ 1061713e81bSScott Long typedef struct mvOsSemaphore 1071713e81bSScott Long { 1081713e81bSScott Long int notused; 1091713e81bSScott Long } MV_OS_SEMAPHORE; 1101713e81bSScott Long 1111713e81bSScott Long /* Functions (User implemented)*/ 1121713e81bSScott Long ULONG_PTR HPTLIBAPI fOsPhysicalAddress(void *addr); 1131713e81bSScott Long 1141713e81bSScott Long /* Semaphore init, take and release */ 115d2bd3ab9SScott Long #define mvOsSemInit(p) (MV_TRUE) 116d2bd3ab9SScott Long #define mvOsSemTake(p) (MV_TRUE) 117d2bd3ab9SScott Long #define mvOsSemRelease(p) (MV_TRUE) 1181713e81bSScott Long 1191713e81bSScott Long /* Delay function in micro seconds resolution */ 1201713e81bSScott Long void HPTLIBAPI mvMicroSecondsDelay(MV_U32); 1211713e81bSScott Long 1221713e81bSScott Long /* System logging function */ 1231713e81bSScott Long #ifdef MV_DEBUG_LOG 1241713e81bSScott Long int mvLogMsg(MV_U8, MV_CHAR_PTR, ...); 1251713e81bSScott Long #define _mvLogMsg(x) mvLogMsg x 1261713e81bSScott Long #else 1271713e81bSScott Long #define mvLogMsg(x...) 1281713e81bSScott Long #define _mvLogMsg(x) 1291713e81bSScott Long #endif 1301713e81bSScott Long 1311713e81bSScott Long /************************************************************************* 1321713e81bSScott Long * Debug support 1331713e81bSScott Long *************************************************************************/ 134f4e98881SRuslan Ermilov #ifdef DEBUG 135d2bd3ab9SScott Long #define HPT_ASSERT(x) do { if (!(x)) { \ 136d2bd3ab9SScott Long printf("ASSERT fail at %s line %d", __FILE__, __LINE__); \ 137d2bd3ab9SScott Long while (1); \ 138d2bd3ab9SScott Long }} while (0) 1391713e81bSScott Long extern int hpt_dbg_level; 1401713e81bSScott Long #define KdPrintI(_x_) do{ if (hpt_dbg_level>2) printf _x_; }while(0) 1411713e81bSScott Long #define KdPrintW(_x_) do{ if (hpt_dbg_level>1) printf _x_; }while(0) 1421713e81bSScott Long #define KdPrintE(_x_) do{ if (hpt_dbg_level>0) printf _x_; }while(0) 1431713e81bSScott Long #define KdPrint(x) KdPrintI(x) 1441713e81bSScott Long #else 1451713e81bSScott Long #define HPT_ASSERT(x) 1461713e81bSScott Long #define KdPrint(x) 1471713e81bSScott Long #define KdPrintI(x) 1481713e81bSScott Long #define KdPrintW(x) 1491713e81bSScott Long #define KdPrintE(x) 1501713e81bSScott Long #endif 1511713e81bSScott Long 152d2bd3ab9SScott Long #endif 153