1 /* 2 * BeOS kernel compatibility layer 3 * 4 * The contents of this file are subject to the Mozilla Public License 5 * Version 1.0 (the "License"); you may not use this file except in 6 * compliance with the License. You may obtain a copy of the License 7 * at http://www.mozilla.org/MPL/ 8 * 9 * Software distributed under the License is distributed on an "AS IS" 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 * the License for the specific language governing rights and 12 * limitations under the License. 13 * 14 * The initial developer of the original code is David A. Hinds 15 * <dhinds@hyper.stanford.edu>. Portions created by David A. Hinds 16 * are Copyright (C) 1998 David A. Hinds. All Rights Reserved. 17 */ 18 19 #ifndef _BE_K_COMPAT_H 20 #define _BE_K_COMPAT_H 21 22 #include <KernelExport.h> 23 #include <ISA.h> 24 #include <PCI.h> 25 #include <Drivers.h> 26 #include <ByteOrder.h> 27 #include <SupportDefs.h> 28 #include <stdio.h> 29 #include <string.h> 30 31 #define u32 uint32 32 #define u16 uint16 33 #define u8 uint8 34 35 #define __KERNEL__ 36 #define __init 37 #define __exit 38 39 /* IO port access */ 40 #define inb(p) (isa->read_io_8)(p) 41 #define inw(p) (isa->read_io_16)(p) 42 #define inl(p) (isa->read_io_32)(p) 43 #define outb(d,p) (isa->write_io_8)(p,d) 44 #define outw(d,p) (isa->write_io_16)(p,d) 45 #define outl(d,p) (isa->write_io_32)(p,d) 46 47 /* Memory-mapped IO access: unlike Linux, BeOS allows dereferencing 48 pointers to mapped devices */ 49 #define readb(p) (*(volatile u_char *)(p)) 50 #define readw(p) (*(volatile u_short *)(p)) 51 #define readl(p) (*(volatile u_int *)(p)) 52 #define writeb(b, p) (*(volatile u_char *)(p) = (b)) 53 #define writew(w, p) (*(volatile u_short *)(p) = (w)) 54 #define writel(l, p) (*(volatile u_int *)(p) = (l)) 55 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c)) 56 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c)) 57 58 /* Byte swapping */ 59 #define le16_to_cpu B_LENDIAN_TO_HOST_INT16 60 #define le32_to_cpu B_LENDIAN_TO_HOST_INT32 61 #define cpu_to_le16 B_HOST_TO_LENDIAN_INT16 62 #define cpu_to_le32 B_HOST_TO_LENDIAN_INT32 63 #define writew_ns writew 64 #define readw_ns readw 65 66 /* Copying data between kernel and user space: BeOS can directly 67 dereference user pointers in kernel mode */ 68 #define get_user(x, p) ((x) = *(p)) 69 #define put_user(x, p) (*(p) = (x)) 70 #define copy_from_user memcpy 71 #define copy_to_user memcpy 72 73 /* Virtual memory mapping: this is somewhat inelegant, but lets us 74 use drop-in replacements for the Linux equivalents */ 75 // #define PAGE_SIZE (0x1000) 76 static inline void *ioremap(u_long base, u_long size) 77 { 78 char tag[B_OS_NAME_LENGTH]; 79 area_id id; 80 void *virt; 81 sprintf(tag, "pccard %08lx", base); 82 id = map_physical_memory(tag, (phys_addr_t)base, 83 size, B_ANY_KERNEL_ADDRESS, 84 B_READ_AREA | B_WRITE_AREA, &virt); 85 return (id < 0) ? NULL : virt; 86 } 87 static inline void iounmap(void *virt) 88 { 89 area_id id = area_for(virt); 90 if (id >= 0) delete_area(id); 91 } 92 93 /* Resource management: use helper functions from the PCMCIA resource 94 manager module. RSRC_MGR needs to be defined appropriately if the 95 calls are via a module_info structure. */ 96 #define request_region(base, num, name) \ 97 (RSRC_MGR register_resource(B_IO_PORT_RESOURCE, (base), (num))) 98 #define vacate_region release_region 99 #define vacate_mem_region release_mem_region 100 #define release_region(base, num) \ 101 (RSRC_MGR release_resource(B_IO_PORT_RESOURCE, (base), (num))) 102 #define check_region(base, num) \ 103 (RSRC_MGR check_resource(B_IO_PORT_RESOURCE, (base), (num))) 104 #define request_mem_region(base, num, name) \ 105 (RSRC_MGR register_resource(B_MEMORY_RESOURCE, (base), (num))) 106 #define release_mem_region(base, num) \ 107 (RSRC_MGR release_resource(B_MEMORY_RESOURCE, (base), (num))) 108 #define check_mem_region(base, num) \ 109 (RSRC_MGR check_resource(B_MEMORY_RESOURCE, (base), (num))) 110 #define register_irq(irq) \ 111 (RSRC_MGR register_resource(B_IRQ_RESOURCE, (irq), 0)) 112 #define release_irq(irq) \ 113 (RSRC_MGR release_resource(B_IRQ_RESOURCE, (irq), 0)) 114 #define check_irq(irq) \ 115 (RSRC_MGR check_resource(B_IRQ_RESOURCE, (irq), 0)) 116 #define ACQUIRE_RESOURCE_LOCK \ 117 do { module_info *m; \ 118 get_module(B_CONFIG_MANAGER_FOR_DRIVER_MODULE_NAME, &m); } while (0) 119 #define RELEASE_RESOURCE_LOCK \ 120 put_module(B_CONFIG_MANAGER_FOR_DRIVER_MODULE_NAME) 121 122 /* Memory allocation. BeOS doesn't have an atomic malloc. */ 123 #define kmalloc(s,f) malloc(s) 124 #define kfree(p) free(p) 125 #define kfree_s(p,s) free(p) 126 void *malloc(); 127 void free(void *); 128 129 /* PCI configuration register access */ 130 #define pcibios_present() (1) 131 #define pcibios_read_config_byte(b,df,o,v) \ 132 ((*(v) = pci->read_pci_config(b,(df)>>3,((df)&7),o,1)),0) 133 #define pcibios_read_config_word(b,df,o,v) \ 134 ((*(v) = pci->read_pci_config(b,(df)>>3,((df)&7),o,2)),0) 135 #define pcibios_read_config_dword(b,df,o,v) \ 136 ((*(v) = pci->read_pci_config(b,(df)>>3,((df)&7),o,4)),0) 137 #define pcibios_write_config_byte(b,df,o,v) \ 138 (pci->write_pci_config(b,(df)>>3,((df)&7),o,1,v),0) 139 #define pcibios_write_config_word(b,df,o,v) \ 140 (pci->write_pci_config(b,(df)>>3,((df)&7),o,2,v),0) 141 #define pcibios_write_config_dword(b,df,o,v) \ 142 (pci->write_pci_config(b,(df)>>3,((df)&7),o,4,v),0) 143 #define PCI_VENDOR_ID PCI_vendor_id 144 #define PCI_DEVICE_ID PCI_device_id 145 #define PCI_COMMAND PCI_command 146 #define PCI_COMMAND_IO PCI_command_io 147 #define PCI_COMMAND_MEMORY PCI_command_memory 148 #define PCI_COMMAND_MASTER PCI_command_master 149 #define PCI_COMMAND_WAIT PCI_command_address_step 150 #define PCI_STATUS PCI_status 151 #define PCI_CLASS_REVISION PCI_revision 152 #define PCI_CACHE_LINE_SIZE PCI_line_size 153 #define PCI_LATENCY_TIMER PCI_latency 154 #define PCI_INTERRUPT_LINE PCI_interrupt_line 155 #define PCI_INTERRUPT_PIN PCI_interrupt_pin 156 #define PCI_HEADER_TYPE PCI_header_type 157 #define PCI_BASE_ADDRESS_0 PCI_base_registers 158 #define PCI_BASE_ADDRESS_SPACE PCI_address_space 159 #define PCI_BASE_ADDRESS_MEM_MASK PCI_address_memory_32_mask 160 #define PCI_BASE_ADDRESS_IO_MASK PCI_address_io_mask 161 #define PCI_BASE_ADDRESS_MEM_PREFETCH PCI_address_prefetchable 162 #define PCI_FUNC(devfn) ((devfn)&7) 163 #define PCI_SLOT(devfn) ((devfn)>>3) 164 #define PCI_DEVFN(dev,fn) (((dev)<<3)|((fn)&7)) 165 #define PCI_CLASS_BRIDGE_PCMCIA 0x0605 166 #define PCI_CLASS_BRIDGE_CARDBUS 0x0607 167 168 /* Atomic test-and-set */ 169 #define test_and_set_bit(b,p) (((atomic_or(p,(1<<(b))))>>(b))&1) 170 171 /* Spin locks */ 172 #define __SMP__ 173 #define spinlock_t spinlock 174 #define USE_SPIN_LOCKS 175 #define SPIN_LOCK_UNLOCKED 0 176 #define spin_lock_irqsave(l,f) \ 177 do { f = disable_interrupts(); acquire_spinlock(l); } while (0) 178 #define spin_unlock_irqrestore(l,f) \ 179 do { release_spinlock(l); restore_interrupts(f); } while (0) 180 181 /* Interrupt handling */ 182 #define request_irq(i,h,f,n,d) install_io_interrupt_handler(i,h,d,0) 183 #define free_irq(i,h) remove_io_interrupt(i,h) 184 //#define REQUEST_IRQ(i,h,f,n,d) install_io_interrupt_handler(i,h,d,0) 185 //#define FREE_IRQ(i,h,d) remove_io_interrupt(i,h) 186 //#define IRQ(i,d,r) (d) 187 #define IRQ(i,d,r) 188 #define DEV_ID dev_id 189 #define NR_IRQS 16 190 #define SA_SHIRQ 1 191 192 #define init_waitqueue(w) memset((w), 0, sizeof(*w)) 193 #define init_waitqueue_head(w) memset((w), 0, sizeof(*w)) 194 #define signal_pending(a) has_signals_pending(NULL) 195 196 /* Miscellaneous services */ 197 typedef long long k_time_t; 198 #define schedule_timeout(x) snooze(x) 199 #define udelay(d) spin(d) 200 #define mdelay(d) \ 201 do { int i; for (i=0;i<d;i++) spin(1000); } while (0) 202 #define printk dprintf 203 #define KERN_ERR "" 204 #define KERN_NOTICE "" 205 #define KERN_INFO "" 206 #define KERN_WARNING "" 207 #define KERN_DEBUG "" 208 209 #ifndef ENODATA 210 #define ENODATA ENOSPC 211 #endif 212 213 #include <pcmcia/cs_timer.h> 214 #define add_timer my_add_timer 215 #define del_timer my_del_timer 216 217 /* Module handling stuff */ 218 #define MODULE_AUTHOR(x) 219 #define MODULE_DESCRIPTION(x) 220 #define MODULE_LICENSE(x) 221 #define MODULE_PARM(a,b) extern int __dummy_decl 222 #define MOD_INC_USE_COUNT 223 #define MOD_DEC_USE_COUNT 224 225 #endif /* _BE_K_COMPAT_H */ 226