1174604Sscottl/* 2174604Sscottl * Copyright (c) HighPoint Technologies, Inc. 3174604Sscottl * All rights reserved. 4174604Sscottl * 5174604Sscottl * Redistribution and use in source and binary forms, with or without 6174604Sscottl * modification, are permitted provided that the following conditions 7174604Sscottl * are met: 8174604Sscottl * 1. Redistributions of source code must retain the above copyright 9174604Sscottl * notice, this list of conditions and the following disclaimer. 10174604Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11174604Sscottl * notice, this list of conditions and the following disclaimer in the 12174604Sscottl * documentation and/or other materials provided with the distribution. 13174604Sscottl * 14174604Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15174604Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16174604Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17174604Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18174604Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19174604Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20174604Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21174604Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22174604Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23174604Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24174604Sscottl * SUCH DAMAGE. 25174604Sscottl * 26174604Sscottl * $FreeBSD$ 27174604Sscottl */ 28174604Sscottl#include <dev/hptrr/hptrr_config.h> 29174604Sscottl/* 30176018Sscottl * $Id: osm.h,v 1.7 2007/12/10 02:13:52 xxj Exp $ 31174604Sscottl * Copyright (C) 2005 HighPoint Technologies, Inc. All rights reserved. 32174604Sscottl */ 33174604Sscottl#ifndef _HPT_OSM_H_ 34174604Sscottl#define _HPT_OSM_H_ 35174604Sscottl 36176018Sscottl#define VERMAGIC_OSM 6 37174604Sscottl 38174604Sscottl#define os_max_queue_comm 32 39174604Sscottl#define os_max_sg_descriptors 18 40174604Sscottl 41174604Sscottl 42176018Sscottlextern int os_max_cache_size; 43176018Sscottl 44176018Sscottl 45174604Sscottl#define DMAPOOL_PAGE_SIZE 0x1000 /* PAGE_SIZE (i386/x86_64) */ 46174604Sscottl#define os_max_cache_pages (os_max_cache_size/DMAPOOL_PAGE_SIZE) 47174604Sscottl 48174604Sscottl/* data types */ 49174604Sscottltypedef unsigned int HPT_UINT, HPT_U32; 50174604Sscottltypedef unsigned long HPT_UPTR; 51174604Sscottltypedef unsigned short HPT_U16; 52174604Sscottltypedef unsigned char HPT_U8; 53174604Sscottltypedef unsigned long HPT_TIME; 54174604Sscottltypedef unsigned long long HPT_U64; 55174604Sscottl 56174604Sscottl#define CPU_TO_LE64(x) (x) 57174604Sscottl#define CPU_TO_LE32(x) (x) 58174604Sscottl#define CPU_TO_LE16(x) (x) 59174604Sscottl#define LE32_TO_CPU(x) (x) 60174604Sscottl#define LE16_TO_CPU(x) (x) 61174604Sscottl#define LE64_TO_CPU(x) (x) 62174604Sscottl 63174604Sscottl#define FAR 64174604Sscottl#define EXTERN_C 65174604Sscottl 66174604Sscottltypedef void * HPT_PTR; 67174604Sscottl 68174604Sscottltypedef HPT_U64 HPT_LBA; 69176018Sscottltypedef HPT_U64 HPT_RAW_LBA; 70174604Sscottl#define MAX_LBA_VALUE 0xffffffffffffffffull 71176018Sscottl#define MAX_RAW_LBA_VALUE MAX_LBA_VALUE 72176018Sscottl#define RAW_LBA(x) (x) 73174604Sscottl#define LO_LBA(x) ((HPT_U32)(x)) 74174604Sscottl#define HI_LBA(x) (sizeof(HPT_LBA)>4? (HPT_U32)((x)>>32) : 0) 75174604Sscottl#define LBA_FORMAT_STR "0x%llX" 76174604Sscottl 77174604Sscottltypedef HPT_U64 BUS_ADDRESS; 78174604Sscottl#define LO_BUSADDR(x) ((HPT_U32)(x)) 79174604Sscottl#define HI_BUSADDR(x) (sizeof(BUS_ADDRESS)>4? (x)>>32 : 0) 80174604Sscottl 81174604Sscottltypedef unsigned char HPT_BOOL; 82174604Sscottl#define HPT_TRUE 1 83174604Sscottl#define HPT_FALSE 0 84174604Sscottl 85174604Sscottltypedef struct _TIME_RECORD { 86174604Sscottl HPT_U32 seconds:6; /* 0 - 59 */ 87174604Sscottl HPT_U32 minutes:6; /* 0 - 59 */ 88174604Sscottl HPT_U32 month:4; /* 1 - 12 */ 89174604Sscottl HPT_U32 hours:6; /* 0 - 59 */ 90174604Sscottl HPT_U32 day:5; /* 1 - 31 */ 91174604Sscottl HPT_U32 year:5; /* 0=2000, 31=2031 */ 92174604Sscottl} TIME_RECORD; 93174604Sscottl 94174604Sscottl/* hardware access */ 95174604SscottlHPT_U8 os_inb (void *port); 96174604SscottlHPT_U16 os_inw (void *port); 97174604SscottlHPT_U32 os_inl (void *port); 98174604Sscottlvoid os_outb (void *port, HPT_U8 value); 99174604Sscottlvoid os_outw (void *port, HPT_U16 value); 100174604Sscottlvoid os_outl (void *port, HPT_U32 value); 101174604Sscottlvoid os_insw (void *port, HPT_U16 *buffer, HPT_U32 count); 102174604Sscottlvoid os_outsw(void *port, HPT_U16 *buffer, HPT_U32 count); 103174604Sscottl 104174604Sscottlextern HPT_U32 __dummy_reg; /* to avoid the compiler warning */ 105174604Sscottl 106174604Sscottl#define os_readb(addr) (*(HPT_U8 *)&__dummy_reg = *(volatile HPT_U8 *)(addr)) 107174604Sscottl#define os_readw(addr) (*(HPT_U16 *)&__dummy_reg = *(volatile HPT_U16 *)(addr)) 108174604Sscottl#define os_readl(addr) (*(HPT_U32 *)&__dummy_reg = *(volatile HPT_U32 *)(addr)) 109174604Sscottl 110174604Sscottl#define os_writeb(addr, val) *(volatile HPT_U8 *)(addr) = (HPT_U8)(val) 111174604Sscottl#define os_writew(addr, val) *(volatile HPT_U16 *)(addr) = (HPT_U16)(val) 112174604Sscottl#define os_writel(addr, val) *(volatile HPT_U32 *)(addr) = (HPT_U32)(val) 113174604Sscottl 114174604Sscottl/* PCI configuration space for specified device*/ 115174604SscottlHPT_U8 os_pci_readb (void *osext, HPT_U8 offset); 116174604SscottlHPT_U16 os_pci_readw (void *osext, HPT_U8 offset); 117174604SscottlHPT_U32 os_pci_readl (void *osext, HPT_U8 offset); 118174604Sscottlvoid os_pci_writeb(void *osext, HPT_U8 offset, HPT_U8 value); 119174604Sscottlvoid os_pci_writew(void *osext, HPT_U8 offset, HPT_U16 value); 120174604Sscottlvoid os_pci_writel(void *osext, HPT_U8 offset, HPT_U32 value); 121174604Sscottl 122174604Sscottl/* obsolute interface */ 123174604Sscottl#define MAX_PCI_BUS_NUMBER 0xff 124174604Sscottl#define MAX_PCI_DEVICE_NUMBER 32 125174604Sscottl#define MAX_PCI_FUNC_NUMBER 8 126174604Sscottl#define pcicfg_read_dword(bus, dev, fn, reg) 0xffff 127174604Sscottl 128174604Sscottl 129174604Sscottlvoid *os_map_pci_bar( 130174604Sscottl void *osext, 131174604Sscottl int index, 132174604Sscottl HPT_U32 offset, 133174604Sscottl HPT_U32 length 134174604Sscottl); 135174604Sscottl 136174604Sscottl 137174604Sscottlvoid os_unmap_pci_bar(void *osext, void *base); 138174604Sscottl 139174604Sscottl#define os_kmap_sgptr(psg) (psg->addr._logical) 140174604Sscottl#define os_kunmap_sgptr(ptr) 141174604Sscottl#define os_set_sgptr(psg, ptr) (psg)->addr._logical = (ptr) 142174604Sscottl 143174604Sscottl/* timer */ 144174604Sscottlvoid *os_add_timer(void *osext, HPT_U32 microseconds, void (*proc)(void *), void *arg); 145174604Sscottlvoid os_del_timer(void *handle); 146174604Sscottlvoid os_request_timer(void * osext, HPT_U32 interval); 147174604SscottlHPT_TIME os_query_time(void); 148174604Sscottl 149174604Sscottl/* task */ 150174604Sscottl#define OS_SUPPORT_TASK 151174604Sscottl 152174604Sscottltypedef struct _OSM_TASK { 153174604Sscottl struct _OSM_TASK *next; 154174604Sscottl void (*func)(void *vbus, void *data); 155174604Sscottl void *data; 156174604Sscottl} 157174604SscottlOSM_TASK; 158174604Sscottl 159174604Sscottlvoid os_schedule_task(void *osext, OSM_TASK *task); 160174604Sscottl 161174604Sscottl/* misc */ 162174604SscottlHPT_U32 os_get_stamp(void); 163174604Sscottlvoid os_stallexec(HPT_U32 microseconds); 164174604Sscottl 165174604Sscottl#ifndef _SYS_LIBKERN_H_ 166174604Sscottl#define memcpy(dst, src, size) __builtin_memcpy((dst), (src), (size)) 167174604Sscottl#define memcmp(dst, src, size) __builtin_memcmp((dst), (src), (size)) 168174604Sscottl#define strcpy(dst, src) __builtin_strcpy((dst), (src)) 169174604Sscottlstatic __inline void * memset(void *dst, int c, unsigned long size) 170174604Sscottl{ 171174604Sscottl char *p; 172174604Sscottl for (p=(char*)dst; size; size--,p++) *p = c; 173174604Sscottl return dst; 174174604Sscottl} 175174604Sscottl#endif 176174604Sscottl 177174604Sscottl#define farMemoryCopy(a,b,c) memcpy((char *)(a), (char *)(b), (HPT_U32)c) 178174604Sscottl 179174604Sscottl 180174604Sscottl#define os_register_device(osext, target_id) 181174604Sscottl#define os_unregister_device(osext, target_id) 182174604Sscottlint os_query_remove_device(void *osext, int target_id); 183174604Sscottlint os_revalidate_device(void *osext, int target_id); 184174604Sscottl 185174604SscottlHPT_U8 os_get_vbus_seq(void *osext); 186174604Sscottl 187174604Sscottl/* debug support */ 188174604Sscottlint os_printk(char *fmt, ...); 189174604Sscottl 190176939Sscottl#if DBG 191176031Sscottlextern int hptrr_dbg_level; 192176031Sscottl#define KdPrint(x) do { if (hptrr_dbg_level) os_printk x; } while (0) 193174604Sscottlvoid __os_dbgbreak(const char *file, int line); 194174604Sscottl#define os_dbgbreak() __os_dbgbreak(__FILE__, __LINE__) 195174604Sscottl#define HPT_ASSERT(x) do { if (!(x)) os_dbgbreak(); } while (0) 196174604Sscottlvoid os_check_stack(const char *location, int size); 197174604Sscottl#define HPT_CHECK_STACK(size) os_check_stack(__FUNCTION__, (size)) 198174604Sscottl#else 199174604Sscottl#define KdPrint(x) 200174604Sscottl#define HPT_ASSERT(x) 201174604Sscottl#define HPT_CHECK_STACK(size) 202174604Sscottl#endif 203174604Sscottl 204174604Sscottl#define OsPrint(x) do { os_printk x; } while (0) 205174604Sscottl 206174604Sscottl#endif 207