subr_hal.c revision 124574
1/* 2 * Copyright (c) 2003 3 * Bill Paul <wpaul@windriver.com>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Bill Paul. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> 34__FBSDID("$FreeBSD: head/sys/compat/ndis/subr_hal.c 124574 2004-01-15 19:34:56Z obrien $"); 35 36#include <sys/param.h> 37#include <sys/types.h> 38#include <sys/errno.h> 39 40#include <sys/callout.h> 41#include <sys/kernel.h> 42#include <sys/lock.h> 43#include <sys/mutex.h> 44 45#include <sys/systm.h> 46#include <machine/clock.h> 47#include <machine/bus_memio.h> 48#include <machine/bus_pio.h> 49#include <machine/bus.h> 50 51#include <sys/bus.h> 52#include <sys/rman.h> 53 54#include <compat/ndis/pe_var.h> 55#include <compat/ndis/hal_var.h> 56#include <compat/ndis/ntoskrnl_var.h> 57 58#define FUNC void(*)(void) 59 60__stdcall static void hal_stall_exec_cpu(uint32_t); 61__stdcall static void hal_writeport_buf_ulong(uint32_t *, 62 uint32_t *, uint32_t); 63__stdcall static void hal_writeport_buf_ushort(uint16_t *, 64 uint16_t *, uint32_t); 65__stdcall static void hal_writeport_buf_uchar(uint8_t *, 66 uint8_t *, uint32_t); 67__stdcall static void hal_writeport_ulong(uint32_t *, uint32_t); 68__stdcall static void hal_writeport_ushort(uint16_t *, uint16_t); 69__stdcall static void hal_writeport_uchar(uint8_t *, uint8_t); 70__stdcall static uint32_t hal_readport_ulong(uint32_t *); 71__stdcall static uint16_t hal_readport_ushort(uint16_t *); 72__stdcall static uint8_t hal_readport_uchar(uint8_t *); 73__stdcall static void hal_readport_buf_ulong(uint32_t *, 74 uint32_t *, uint32_t); 75__stdcall static void hal_readport_buf_ushort(uint16_t *, 76 uint16_t *, uint32_t); 77__stdcall static void hal_readport_buf_uchar(uint8_t *, 78 uint8_t *, uint32_t); 79__stdcall static uint8_t hal_lock(/*kspin_lock * */void); 80__stdcall static void hal_unlock(/*kspin_lock *, uint8_t*/void); 81__stdcall static uint8_t hal_irql(void); 82__stdcall static void dummy (void); 83 84extern struct mtx_pool *ndis_mtxpool; 85 86__stdcall static void 87hal_stall_exec_cpu(usecs) 88 uint32_t usecs; 89{ 90 DELAY(usecs); 91 return; 92} 93 94__stdcall static void 95hal_writeport_ulong(port, val) 96 uint32_t *port; 97 uint32_t val; 98{ 99 bus_space_write_4(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port, val); 100 return; 101} 102 103__stdcall static void 104hal_writeport_ushort(port, val) 105 uint16_t *port; 106 uint16_t val; 107{ 108 bus_space_write_2(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port, val); 109 return; 110} 111 112__stdcall static void 113hal_writeport_uchar(port, val) 114 uint8_t *port; 115 uint8_t val; 116{ 117 bus_space_write_1(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port, val); 118 return; 119} 120 121__stdcall static void 122hal_writeport_buf_ulong(port, val, cnt) 123 uint32_t *port; 124 uint32_t *val; 125 uint32_t cnt; 126{ 127 bus_space_write_multi_4(NDIS_BUS_SPACE_IO, 0x0, 128 (bus_size_t)port, val, cnt); 129 return; 130} 131 132__stdcall static void 133hal_writeport_buf_ushort(port, val, cnt) 134 uint16_t *port; 135 uint16_t *val; 136 uint32_t cnt; 137{ 138 bus_space_write_multi_2(NDIS_BUS_SPACE_IO, 0x0, 139 (bus_size_t)port, val, cnt); 140 return; 141} 142 143__stdcall static void 144hal_writeport_buf_uchar(port, val, cnt) 145 uint8_t *port; 146 uint8_t *val; 147 uint32_t cnt; 148{ 149 bus_space_write_multi_1(NDIS_BUS_SPACE_IO, 0x0, 150 (bus_size_t)port, val, cnt); 151 return; 152} 153 154__stdcall static uint16_t 155hal_readport_ushort(port) 156 uint16_t *port; 157{ 158 return(bus_space_read_2(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port)); 159} 160 161__stdcall static uint32_t 162hal_readport_ulong(port) 163 uint32_t *port; 164{ 165 return(bus_space_read_4(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port)); 166} 167 168__stdcall static uint8_t 169hal_readport_uchar(port) 170 uint8_t *port; 171{ 172 return(bus_space_read_1(NDIS_BUS_SPACE_IO, 0x0, (bus_size_t)port)); 173} 174 175__stdcall static void 176hal_readport_buf_ulong(port, val, cnt) 177 uint32_t *port; 178 uint32_t *val; 179 uint32_t cnt; 180{ 181 bus_space_read_multi_4(NDIS_BUS_SPACE_IO, 0x0, 182 (bus_size_t)port, val, cnt); 183 return; 184} 185 186__stdcall static void 187hal_readport_buf_ushort(port, val, cnt) 188 uint16_t *port; 189 uint16_t *val; 190 uint32_t cnt; 191{ 192 bus_space_read_multi_2(NDIS_BUS_SPACE_IO, 0x0, 193 (bus_size_t)port, val, cnt); 194 return; 195} 196 197__stdcall static void 198hal_readport_buf_uchar(port, val, cnt) 199 uint8_t *port; 200 uint8_t *val; 201 uint32_t cnt; 202{ 203 bus_space_read_multi_1(NDIS_BUS_SPACE_IO, 0x0, 204 (bus_size_t)port, val, cnt); 205 return; 206} 207 208__stdcall static uint8_t 209hal_lock(/*lock*/void) 210{ 211 kspin_lock *lock; 212 213 __asm__ __volatile__ ("" : "=c" (lock)); 214 215 mtx_pool_lock(ndis_mtxpool, (struct mtx *)*lock); 216 return(0); 217} 218 219__stdcall static void 220hal_unlock(/*lock, newirql*/void) 221{ 222 kspin_lock *lock; 223 uint8_t newiqrl; 224 225 __asm__ __volatile__ ("" : "=c" (lock), "=d" (newiqrl)); 226 227 mtx_pool_unlock(ndis_mtxpool, (struct mtx *)*lock); 228 return; 229} 230 231__stdcall static uint8_t 232hal_irql(void) 233{ 234 return(0); 235} 236 237__stdcall 238static void dummy() 239{ 240 printf ("hal dummy called...\n"); 241 return; 242} 243 244image_patch_table hal_functbl[] = { 245 { "KeStallExecutionProcessor", (FUNC)hal_stall_exec_cpu }, 246 { "WRITE_PORT_ULONG", (FUNC)hal_writeport_ulong }, 247 { "WRITE_PORT_USHORT", (FUNC)hal_writeport_ushort }, 248 { "WRITE_PORT_UCHAR", (FUNC)hal_writeport_uchar }, 249 { "WRITE_PORT_BUFFER_ULONG", (FUNC)hal_writeport_buf_ulong }, 250 { "WRITE_PORT_BUFFER_USHORT", (FUNC)hal_writeport_buf_ushort }, 251 { "WRITE_PORT_BUFFER_UCHAR", (FUNC)hal_writeport_buf_uchar }, 252 { "READ_PORT_ULONG", (FUNC)hal_readport_ulong }, 253 { "READ_PORT_USHORT", (FUNC)hal_readport_ushort }, 254 { "READ_PORT_UCHAR", (FUNC)hal_readport_uchar }, 255 { "READ_PORT_BUFFER_ULONG", (FUNC)hal_readport_buf_ulong }, 256 { "READ_PORT_BUFFER_USHORT", (FUNC)hal_readport_buf_ushort }, 257 { "READ_PORT_BUFFER_UCHAR", (FUNC)hal_readport_buf_uchar }, 258 { "KfAcquireSpinLock", (FUNC)hal_lock }, 259 { "KfReleaseSpinLock", (FUNC)hal_unlock }, 260 { "KeGetCurrentIrql", (FUNC)hal_irql }, 261 262 /* 263 * This last entry is a catch-all for any function we haven't 264 * implemented yet. The PE import list patching routine will 265 * use it for any function that doesn't have an explicit match 266 * in this table. 267 */ 268 269 { NULL, (FUNC)dummy }, 270 271 /* End of list. */ 272 273 { NULL, NULL }, 274}; 275