xref: /freebsd/sys/dev/hptrr/osm.h (revision 535af610)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 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 #include <dev/hptrr/hptrr_config.h>
31 /*
32  * $Id: osm.h,v 1.7 2007/12/10 02:13:52 xxj Exp $
33  * Copyright (C) 2005 HighPoint Technologies, Inc. All rights reserved.
34  */
35 #ifndef _HPT_OSM_H_
36 #define _HPT_OSM_H_
37 
38 #define VERMAGIC_OSM 6
39 
40 #define os_max_queue_comm 32
41 #define os_max_sg_descriptors 18
42 
43 
44 extern int os_max_cache_size;
45 
46 
47 #define DMAPOOL_PAGE_SIZE 0x1000 /* PAGE_SIZE (i386/x86_64) */
48 #define os_max_cache_pages (os_max_cache_size/DMAPOOL_PAGE_SIZE)
49 
50 /* data types */
51 typedef unsigned int HPT_UINT, HPT_U32;
52 typedef unsigned long HPT_UPTR;
53 typedef unsigned short HPT_U16;
54 typedef unsigned char HPT_U8;
55 typedef unsigned long HPT_TIME;
56 typedef unsigned long long HPT_U64;
57 
58 #define CPU_TO_LE64(x) (x)
59 #define CPU_TO_LE32(x) (x)
60 #define CPU_TO_LE16(x) (x)
61 #define LE32_TO_CPU(x) (x)
62 #define LE16_TO_CPU(x) (x)
63 #define LE64_TO_CPU(x) (x)
64 
65 #define FAR
66 #define EXTERN_C
67 
68 typedef void * HPT_PTR;
69 
70 typedef HPT_U64 HPT_LBA;
71 typedef HPT_U64 HPT_RAW_LBA;
72 #define MAX_LBA_VALUE 0xffffffffffffffffull
73 #define MAX_RAW_LBA_VALUE MAX_LBA_VALUE
74 #define RAW_LBA(x) (x)
75 #define LO_LBA(x) ((HPT_U32)(x))
76 #define HI_LBA(x) (sizeof(HPT_LBA)>4? (HPT_U32)((x)>>32) : 0)
77 #define LBA_FORMAT_STR "0x%llX"
78 
79 typedef HPT_U64 BUS_ADDRESS;
80 #define LO_BUSADDR(x) ((HPT_U32)(x))
81 #define HI_BUSADDR(x) (sizeof(BUS_ADDRESS)>4? (x)>>32 : 0)
82 
83 typedef unsigned char HPT_BOOL;
84 #define HPT_TRUE  1
85 #define HPT_FALSE 0
86 
87 typedef struct _TIME_RECORD {
88    HPT_U32        seconds:6;      /* 0 - 59 */
89    HPT_U32        minutes:6;      /* 0 - 59 */
90    HPT_U32        month:4;        /* 1 - 12 */
91    HPT_U32        hours:6;        /* 0 - 59 */
92    HPT_U32        day:5;          /* 1 - 31 */
93    HPT_U32        year:5;         /* 0=2000, 31=2031 */
94 } TIME_RECORD;
95 
96 /* hardware access */
97 HPT_U8   os_inb  (void *port);
98 HPT_U16  os_inw  (void *port);
99 HPT_U32  os_inl  (void *port);
100 void     os_outb (void *port, HPT_U8 value);
101 void     os_outw (void *port, HPT_U16 value);
102 void     os_outl (void *port, HPT_U32 value);
103 void     os_insw (void *port, HPT_U16 *buffer, HPT_U32 count);
104 void     os_outsw(void *port, HPT_U16 *buffer, HPT_U32 count);
105 
106 extern HPT_U32 __dummy_reg; /* to avoid the compiler warning */
107 
108 #define os_readb(addr) (*(HPT_U8 *)&__dummy_reg = *(volatile HPT_U8 *)(addr))
109 #define os_readw(addr) (*(HPT_U16 *)&__dummy_reg = *(volatile HPT_U16 *)(addr))
110 #define os_readl(addr) (*(HPT_U32 *)&__dummy_reg = *(volatile HPT_U32 *)(addr))
111 
112 #define os_writeb(addr, val) *(volatile HPT_U8 *)(addr) = (HPT_U8)(val)
113 #define os_writew(addr, val) *(volatile HPT_U16 *)(addr) = (HPT_U16)(val)
114 #define os_writel(addr, val) *(volatile HPT_U32 *)(addr) = (HPT_U32)(val)
115 
116 /* PCI configuration space for specified device*/
117 HPT_U8   os_pci_readb (void *osext, HPT_U8 offset);
118 HPT_U16  os_pci_readw (void *osext, HPT_U8 offset);
119 HPT_U32  os_pci_readl (void *osext, HPT_U8 offset);
120 void     os_pci_writeb(void *osext, HPT_U8 offset, HPT_U8 value);
121 void     os_pci_writew(void *osext, HPT_U8 offset, HPT_U16 value);
122 void     os_pci_writel(void *osext, HPT_U8 offset, HPT_U32 value);
123 
124 /* obsolute interface */
125 #define MAX_PCI_BUS_NUMBER 0xff
126 #define MAX_PCI_DEVICE_NUMBER 32
127 #define MAX_PCI_FUNC_NUMBER 8
128 #define pcicfg_read_dword(bus, dev, fn, reg) 0xffff
129 
130 
131 void *os_map_pci_bar(
132 	void *osext,
133 	int index,
134 	HPT_U32 offset,
135 	HPT_U32 length
136 );
137 
138 
139 void os_unmap_pci_bar(void *osext, void *base);
140 
141 #define os_kmap_sgptr(psg) (psg->addr._logical)
142 #define os_kunmap_sgptr(ptr)
143 #define os_set_sgptr(psg, ptr) (psg)->addr._logical = (ptr)
144 
145 /* timer */
146 void *os_add_timer(void *osext, HPT_U32 microseconds, void (*proc)(void *), void *arg);
147 void  os_del_timer(void *handle);
148 void  os_request_timer(void * osext, HPT_U32 interval);
149 HPT_TIME os_query_time(void);
150 
151 /* task */
152 #define OS_SUPPORT_TASK
153 
154 typedef struct _OSM_TASK {
155 	struct _OSM_TASK *next;
156 	void (*func)(void *vbus, void *data);
157 	void *data;
158 }
159 OSM_TASK;
160 
161 void os_schedule_task(void *osext, OSM_TASK *task);
162 
163 /* misc */
164 HPT_U32 os_get_stamp(void);
165 void os_stallexec(HPT_U32 microseconds);
166 
167 #ifndef _SYS_LIBKERN_H_
168 #define memcpy(dst, src, size) __builtin_memcpy((dst), (src), (size))
169 #define memcmp(dst, src, size) __builtin_memcmp((dst), (src), (size))
170 #define strcpy(dst, src) __builtin_strcpy((dst), (src))
171 static __inline void * memset(void *dst, int c, unsigned long size)
172 {
173 	char *p;
174 	for (p=(char*)dst; size; size--,p++) *p = c;
175 	return dst;
176 }
177 #endif
178 
179 #define farMemoryCopy(a,b,c) memcpy((char *)(a), (char *)(b), (HPT_U32)c)
180 
181 
182 #define os_register_device(osext, target_id)
183 #define os_unregister_device(osext, target_id)
184 int os_query_remove_device(void *osext, int target_id);
185 int os_revalidate_device(void *osext, int target_id);
186 
187 HPT_U8 os_get_vbus_seq(void *osext);
188 
189 /* debug support */
190 int  os_printk(char *fmt, ...);
191 
192 #if DBG
193 extern int hptrr_dbg_level;
194 #define KdPrint(x)  do { if (hptrr_dbg_level) os_printk x; } while (0)
195 void __os_dbgbreak(const char *file, int line);
196 #define os_dbgbreak() __os_dbgbreak(__FILE__, __LINE__)
197 #define HPT_ASSERT(x) do { if (!(x)) os_dbgbreak(); } while (0)
198 void os_check_stack(const char *location, int size);
199 #define HPT_CHECK_STACK(size) os_check_stack(__FUNCTION__, (size))
200 #else
201 #define KdPrint(x)
202 #define HPT_ASSERT(x)
203 #define HPT_CHECK_STACK(size)
204 #endif
205 
206 #define OsPrint(x) do { os_printk x; } while (0)
207 
208 #endif
209