xref: /freebsd/sys/dev/hptmv/mvOs.h (revision 77a1348b3c1cfe8547be49a121b56299a1e18b69)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2004-2005 HighPoint Technologies, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 #ifndef __INCmvOsBsdh
31 #define __INCmvOsBsdh
32 
33 #ifdef DEBUG
34 #define MV_DEBUG_LOG
35 #endif
36 
37 #define ENABLE_READ_AHEAD
38 #define ENABLE_WRITE_CACHE
39 
40 /* Typedefs    */
41 /*#define HPTLIBAPI __attribute__((regparm(0))) */
42 #define HPTLIBAPI
43 #define FAR
44 #define SS_SEG
45 #ifdef FASTCALL
46 #undef FASTCALL
47 #endif
48 #define FASTCALL HPTLIBAPI
49 #define PASCAL HPTLIBAPI
50 
51 typedef unsigned short USHORT;
52 typedef unsigned char  UCHAR;
53 typedef unsigned char *PUCHAR;
54 typedef unsigned short *PUSHORT;
55 typedef unsigned char  BOOLEAN;
56 typedef unsigned short WORD;
57 typedef unsigned int   UINT, BOOL;
58 typedef unsigned char  BYTE;
59 typedef void *PVOID, *LPVOID;
60 typedef void *ADDRESS;
61 
62 typedef int  LONG;
63 typedef unsigned int ULONG, *PULONG;
64 typedef unsigned int DWORD, *LPDWORD, *PDWORD;
65 typedef unsigned long ULONG_PTR, UINT_PTR, BUS_ADDR;
66 typedef unsigned long long HPT_U64, LBA_T;
67 
68 typedef enum mvBoolean{MV_FALSE, MV_TRUE} MV_BOOLEAN;
69 
70 #define FALSE 0
71 #define TRUE  1
72 
73 #ifndef NULL
74 #define NULL  0
75 #endif
76 
77 /* System dependent typedefs */
78 typedef void			MV_VOID;
79 typedef unsigned int 	MV_U32;
80 typedef unsigned short	MV_U16;
81 typedef unsigned char	MV_U8;
82 typedef void			*MV_VOID_PTR;
83 typedef MV_U32			*MV_U32_PTR;
84 typedef MV_U16 			*MV_U16_PTR;
85 typedef MV_U8			*MV_U8_PTR;
86 typedef char			*MV_CHAR_PTR;
87 typedef void			*MV_BUS_ADDR_T;
88 
89 /* System dependent macro for flushing CPU write cache */
90 #define MV_CPU_WRITE_BUFFER_FLUSH()
91 
92 /* System dependent little endian from / to CPU conversions */
93 #define MV_CPU_TO_LE16(x)	(x)
94 #define MV_CPU_TO_LE32(x)	(x)
95 
96 #define MV_LE16_TO_CPU(x)	(x)
97 #define MV_LE32_TO_CPU(x)	(x)
98 
99 /* System dependent register read / write in byte/word/dword variants */
100 extern void HPTLIBAPI MV_REG_WRITE_BYTE(MV_BUS_ADDR_T base, MV_U32 offset, MV_U8 val);
101 extern void HPTLIBAPI MV_REG_WRITE_WORD(MV_BUS_ADDR_T base, MV_U32 offset, MV_U16 val);
102 extern void HPTLIBAPI MV_REG_WRITE_DWORD(MV_BUS_ADDR_T base, MV_U32 offset, MV_U32 val);
103 extern MV_U8  HPTLIBAPI MV_REG_READ_BYTE(MV_BUS_ADDR_T base, MV_U32 offset);
104 extern MV_U16 HPTLIBAPI MV_REG_READ_WORD(MV_BUS_ADDR_T base, MV_U32 offset);
105 extern MV_U32 HPTLIBAPI MV_REG_READ_DWORD(MV_BUS_ADDR_T base, MV_U32 offset);
106 
107 /* System dependent structure */
108 typedef struct mvOsSemaphore
109 {
110 	int notused;
111 } MV_OS_SEMAPHORE;
112 
113 /* Functions (User implemented)*/
114 ULONG_PTR HPTLIBAPI fOsPhysicalAddress(void *addr);
115 
116 /* Semaphore init, take and release */
117 #define mvOsSemInit(p)		(MV_TRUE)
118 #define mvOsSemTake(p)		(MV_TRUE)
119 #define mvOsSemRelease(p)	(MV_TRUE)
120 
121 /* Delay function in micro seconds resolution */
122 void HPTLIBAPI mvMicroSecondsDelay(MV_U32);
123 
124 /* System logging function */
125 #ifdef MV_DEBUG_LOG
126 int mvLogMsg(MV_U8, MV_CHAR_PTR, ...);
127 #define _mvLogMsg(x) mvLogMsg x
128 #else
129 #define mvLogMsg(x...)
130 #define _mvLogMsg(x)
131 #endif
132 
133 /*************************************************************************
134  * Debug support
135  *************************************************************************/
136 #ifdef DEBUG
137 #define HPT_ASSERT(x) do { if (!(x)) { \
138 						printf("ASSERT fail at %s line %d", __FILE__, __LINE__); \
139 						while (1); \
140 					  }} while (0)
141 extern int hpt_dbg_level;
142 #define KdPrintI(_x_) do{ if (hpt_dbg_level>2) printf _x_; }while(0)
143 #define KdPrintW(_x_) do{ if (hpt_dbg_level>1) printf _x_; }while(0)
144 #define KdPrintE(_x_) do{ if (hpt_dbg_level>0) printf _x_; }while(0)
145 #define KdPrint(x) KdPrintI(x)
146 #else
147 #define HPT_ASSERT(x)
148 #define KdPrint(x)
149 #define KdPrintI(x)
150 #define KdPrintW(x)
151 #define KdPrintE(x)
152 #endif
153 
154 #endif
155