xref: /freebsd-src/sys/dev/hptrr/osm.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4b063a422SScott Long  * Copyright (c) HighPoint Technologies, Inc.
5b063a422SScott Long  * All rights reserved.
6b063a422SScott Long  *
7b063a422SScott Long  * Redistribution and use in source and binary forms, with or without
8b063a422SScott Long  * modification, are permitted provided that the following conditions
9b063a422SScott Long  * are met:
10b063a422SScott Long  * 1. Redistributions of source code must retain the above copyright
11b063a422SScott Long  *    notice, this list of conditions and the following disclaimer.
12b063a422SScott Long  * 2. Redistributions in binary form must reproduce the above copyright
13b063a422SScott Long  *    notice, this list of conditions and the following disclaimer in the
14b063a422SScott Long  *    documentation and/or other materials provided with the distribution.
15b063a422SScott Long  *
16b063a422SScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17b063a422SScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18b063a422SScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19b063a422SScott Long  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20b063a422SScott Long  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21b063a422SScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22b063a422SScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23b063a422SScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24b063a422SScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25b063a422SScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26b063a422SScott Long  * SUCH DAMAGE.
27b063a422SScott Long  */
28b063a422SScott Long #include <dev/hptrr/hptrr_config.h>
29b063a422SScott Long /*
304fdb276aSScott Long  * $Id: osm.h,v 1.7 2007/12/10 02:13:52 xxj Exp $
31b063a422SScott Long  * Copyright (C) 2005 HighPoint Technologies, Inc. All rights reserved.
32b063a422SScott Long  */
33b063a422SScott Long #ifndef _HPT_OSM_H_
34b063a422SScott Long #define _HPT_OSM_H_
35b063a422SScott Long 
364fdb276aSScott Long #define VERMAGIC_OSM 6
37b063a422SScott Long 
38b063a422SScott Long #define os_max_queue_comm 32
39b063a422SScott Long #define os_max_sg_descriptors 18
40b063a422SScott Long 
41b063a422SScott Long 
424fdb276aSScott Long extern int os_max_cache_size;
434fdb276aSScott Long 
444fdb276aSScott Long 
45b063a422SScott Long #define DMAPOOL_PAGE_SIZE 0x1000 /* PAGE_SIZE (i386/x86_64) */
46b063a422SScott Long #define os_max_cache_pages (os_max_cache_size/DMAPOOL_PAGE_SIZE)
47b063a422SScott Long 
48b063a422SScott Long /* data types */
49b063a422SScott Long typedef unsigned int HPT_UINT, HPT_U32;
50b063a422SScott Long typedef unsigned long HPT_UPTR;
51b063a422SScott Long typedef unsigned short HPT_U16;
52b063a422SScott Long typedef unsigned char HPT_U8;
53b063a422SScott Long typedef unsigned long HPT_TIME;
54b063a422SScott Long typedef unsigned long long HPT_U64;
55b063a422SScott Long 
56b063a422SScott Long #define CPU_TO_LE64(x) (x)
57b063a422SScott Long #define CPU_TO_LE32(x) (x)
58b063a422SScott Long #define CPU_TO_LE16(x) (x)
59b063a422SScott Long #define LE32_TO_CPU(x) (x)
60b063a422SScott Long #define LE16_TO_CPU(x) (x)
61b063a422SScott Long #define LE64_TO_CPU(x) (x)
62b063a422SScott Long 
63b063a422SScott Long #define FAR
64b063a422SScott Long #define EXTERN_C
65b063a422SScott Long 
66b063a422SScott Long typedef void * HPT_PTR;
67b063a422SScott Long 
68b063a422SScott Long typedef HPT_U64 HPT_LBA;
694fdb276aSScott Long typedef HPT_U64 HPT_RAW_LBA;
70b063a422SScott Long #define MAX_LBA_VALUE 0xffffffffffffffffull
714fdb276aSScott Long #define MAX_RAW_LBA_VALUE MAX_LBA_VALUE
724fdb276aSScott Long #define RAW_LBA(x) (x)
73b063a422SScott Long #define LO_LBA(x) ((HPT_U32)(x))
74b063a422SScott Long #define HI_LBA(x) (sizeof(HPT_LBA)>4? (HPT_U32)((x)>>32) : 0)
75b063a422SScott Long #define LBA_FORMAT_STR "0x%llX"
76b063a422SScott Long 
77b063a422SScott Long typedef HPT_U64 BUS_ADDRESS;
78b063a422SScott Long #define LO_BUSADDR(x) ((HPT_U32)(x))
79b063a422SScott Long #define HI_BUSADDR(x) (sizeof(BUS_ADDRESS)>4? (x)>>32 : 0)
80b063a422SScott Long 
81b063a422SScott Long typedef unsigned char HPT_BOOL;
82b063a422SScott Long #define HPT_TRUE  1
83b063a422SScott Long #define HPT_FALSE 0
84b063a422SScott Long 
85b063a422SScott Long typedef struct _TIME_RECORD {
86b063a422SScott Long    HPT_U32        seconds:6;      /* 0 - 59 */
87b063a422SScott Long    HPT_U32        minutes:6;      /* 0 - 59 */
88b063a422SScott Long    HPT_U32        month:4;        /* 1 - 12 */
89b063a422SScott Long    HPT_U32        hours:6;        /* 0 - 59 */
90b063a422SScott Long    HPT_U32        day:5;          /* 1 - 31 */
91b063a422SScott Long    HPT_U32        year:5;         /* 0=2000, 31=2031 */
92b063a422SScott Long } TIME_RECORD;
93b063a422SScott Long 
94b063a422SScott Long /* hardware access */
95b063a422SScott Long HPT_U8   os_inb  (void *port);
96b063a422SScott Long HPT_U16  os_inw  (void *port);
97b063a422SScott Long HPT_U32  os_inl  (void *port);
98b063a422SScott Long void     os_outb (void *port, HPT_U8 value);
99b063a422SScott Long void     os_outw (void *port, HPT_U16 value);
100b063a422SScott Long void     os_outl (void *port, HPT_U32 value);
101b063a422SScott Long void     os_insw (void *port, HPT_U16 *buffer, HPT_U32 count);
102b063a422SScott Long void     os_outsw(void *port, HPT_U16 *buffer, HPT_U32 count);
103b063a422SScott Long 
104b063a422SScott Long extern HPT_U32 __dummy_reg; /* to avoid the compiler warning */
105b063a422SScott Long 
106b063a422SScott Long #define os_readb(addr) (*(HPT_U8 *)&__dummy_reg = *(volatile HPT_U8 *)(addr))
107b063a422SScott Long #define os_readw(addr) (*(HPT_U16 *)&__dummy_reg = *(volatile HPT_U16 *)(addr))
108b063a422SScott Long #define os_readl(addr) (*(HPT_U32 *)&__dummy_reg = *(volatile HPT_U32 *)(addr))
109b063a422SScott Long 
110b063a422SScott Long #define os_writeb(addr, val) *(volatile HPT_U8 *)(addr) = (HPT_U8)(val)
111b063a422SScott Long #define os_writew(addr, val) *(volatile HPT_U16 *)(addr) = (HPT_U16)(val)
112b063a422SScott Long #define os_writel(addr, val) *(volatile HPT_U32 *)(addr) = (HPT_U32)(val)
113b063a422SScott Long 
114b063a422SScott Long /* PCI configuration space for specified device*/
115b063a422SScott Long HPT_U8   os_pci_readb (void *osext, HPT_U8 offset);
116b063a422SScott Long HPT_U16  os_pci_readw (void *osext, HPT_U8 offset);
117b063a422SScott Long HPT_U32  os_pci_readl (void *osext, HPT_U8 offset);
118b063a422SScott Long void     os_pci_writeb(void *osext, HPT_U8 offset, HPT_U8 value);
119b063a422SScott Long void     os_pci_writew(void *osext, HPT_U8 offset, HPT_U16 value);
120b063a422SScott Long void     os_pci_writel(void *osext, HPT_U8 offset, HPT_U32 value);
121b063a422SScott Long 
122b063a422SScott Long /* obsolute interface */
123b063a422SScott Long #define MAX_PCI_BUS_NUMBER 0xff
124b063a422SScott Long #define MAX_PCI_DEVICE_NUMBER 32
125b063a422SScott Long #define MAX_PCI_FUNC_NUMBER 8
126b063a422SScott Long #define pcicfg_read_dword(bus, dev, fn, reg) 0xffff
127b063a422SScott Long 
128b063a422SScott Long 
129b063a422SScott Long void *os_map_pci_bar(
130b063a422SScott Long 	void *osext,
131b063a422SScott Long 	int index,
132b063a422SScott Long 	HPT_U32 offset,
133b063a422SScott Long 	HPT_U32 length
134b063a422SScott Long );
135b063a422SScott Long 
136b063a422SScott Long 
137b063a422SScott Long void os_unmap_pci_bar(void *osext, void *base);
138b063a422SScott Long 
139b063a422SScott Long #define os_kmap_sgptr(psg) (psg->addr._logical)
140b063a422SScott Long #define os_kunmap_sgptr(ptr)
141b063a422SScott Long #define os_set_sgptr(psg, ptr) (psg)->addr._logical = (ptr)
142b063a422SScott Long 
143b063a422SScott Long /* timer */
144b063a422SScott Long void *os_add_timer(void *osext, HPT_U32 microseconds, void (*proc)(void *), void *arg);
145b063a422SScott Long void  os_del_timer(void *handle);
146b063a422SScott Long void  os_request_timer(void * osext, HPT_U32 interval);
147b063a422SScott Long HPT_TIME os_query_time(void);
148b063a422SScott Long 
149b063a422SScott Long /* task */
150b063a422SScott Long #define OS_SUPPORT_TASK
151b063a422SScott Long 
152b063a422SScott Long typedef struct _OSM_TASK {
153b063a422SScott Long 	struct _OSM_TASK *next;
154b063a422SScott Long 	void (*func)(void *vbus, void *data);
155b063a422SScott Long 	void *data;
156b063a422SScott Long }
157b063a422SScott Long OSM_TASK;
158b063a422SScott Long 
159b063a422SScott Long void os_schedule_task(void *osext, OSM_TASK *task);
160b063a422SScott Long 
161b063a422SScott Long /* misc */
162b063a422SScott Long HPT_U32 os_get_stamp(void);
163b063a422SScott Long void os_stallexec(HPT_U32 microseconds);
164b063a422SScott Long 
165b063a422SScott Long #ifndef _SYS_LIBKERN_H_
166b063a422SScott Long #define memcpy(dst, src, size) __builtin_memcpy((dst), (src), (size))
167b063a422SScott Long #define memcmp(dst, src, size) __builtin_memcmp((dst), (src), (size))
168b063a422SScott Long #define strcpy(dst, src) __builtin_strcpy((dst), (src))
memset(void * dst,int c,unsigned long size)169b063a422SScott Long static __inline void * memset(void *dst, int c, unsigned long size)
170b063a422SScott Long {
171b063a422SScott Long 	char *p;
172b063a422SScott Long 	for (p=(char*)dst; size; size--,p++) *p = c;
173b063a422SScott Long 	return dst;
174b063a422SScott Long }
175b063a422SScott Long #endif
176b063a422SScott Long 
177b063a422SScott Long #define farMemoryCopy(a,b,c) memcpy((char *)(a), (char *)(b), (HPT_U32)c)
178b063a422SScott Long 
179b063a422SScott Long 
180b063a422SScott Long #define os_register_device(osext, target_id)
181b063a422SScott Long #define os_unregister_device(osext, target_id)
182b063a422SScott Long int os_query_remove_device(void *osext, int target_id);
183b063a422SScott Long int os_revalidate_device(void *osext, int target_id);
184b063a422SScott Long 
185b063a422SScott Long HPT_U8 os_get_vbus_seq(void *osext);
186b063a422SScott Long 
187b063a422SScott Long /* debug support */
188b063a422SScott Long int  os_printk(char *fmt, ...);
189b063a422SScott Long 
1909d6a74ebSScott Long #if DBG
191b204a4e7SScott Long extern int hptrr_dbg_level;
192b204a4e7SScott Long #define KdPrint(x)  do { if (hptrr_dbg_level) os_printk x; } while (0)
193b063a422SScott Long void __os_dbgbreak(const char *file, int line);
194b063a422SScott Long #define os_dbgbreak() __os_dbgbreak(__FILE__, __LINE__)
195b063a422SScott Long #define HPT_ASSERT(x) do { if (!(x)) os_dbgbreak(); } while (0)
196b063a422SScott Long void os_check_stack(const char *location, int size);
197b063a422SScott Long #define HPT_CHECK_STACK(size) os_check_stack(__FUNCTION__, (size))
198b063a422SScott Long #else
199b063a422SScott Long #define KdPrint(x)
200b063a422SScott Long #define HPT_ASSERT(x)
201b063a422SScott Long #define HPT_CHECK_STACK(size)
202b063a422SScott Long #endif
203b063a422SScott Long 
204b063a422SScott Long #define OsPrint(x) do { os_printk x; } while (0)
205b063a422SScott Long 
206b063a422SScott Long #endif
207