2 * Copyright (c) 1998 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/lib/libio/io.c,v 1.3 2000/02/12 14:57:01 dfr Exp $
27 * $DragonFly: src/lib/libio/Attic/io.c,v 1.2 2003/06/17 04:26:49 dillon Exp $
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
35 static struct io_ops *ops;
38 ioperm(unsigned long from, unsigned long num, int on)
42 size_t len = sizeof(bwx);
44 if ((error = sysctlbyname("hw.chipset.bwx", &bwx, &len, 0, 0)) < 0)
51 return ops->ioperm(from, num, on);
57 return ops->inb(port);
63 return ops->inw(port);
69 return ops->inl(port);
73 outb(u_int32_t port, u_int8_t val)
79 outw(u_int32_t port, u_int16_t val)
85 outl(u_int32_t port, u_int32_t val)
91 map_memory(u_int32_t address, u_int32_t size)
93 return ops->map_memory(address, size);
97 unmap_memory(void *handle, u_int32_t size)
99 ops->unmap_memory(handle, size);
103 readb(void *handle, u_int32_t offset)
105 return ops->readb(handle, offset);
109 readw(void *handle, u_int32_t offset)
111 return ops->readw(handle, offset);
115 readl(void *handle, u_int32_t offset)
117 return ops->readl(handle, offset);
121 writeb(void *handle, u_int32_t offset, u_int8_t val)
123 ops->writeb(handle, offset, val);
124 __asm__ __volatile__ ("mb");
128 writew(void *handle, u_int32_t offset, u_int16_t val)
130 ops->writew(handle, offset, val);
131 __asm__ __volatile__ ("mb");
135 writel(void *handle, u_int32_t offset, u_int32_t val)
137 ops->writel(handle, offset, val);
138 __asm__ __volatile__ ("mb");
142 writeb_nb(void *handle, u_int32_t offset, u_int8_t val)
144 return ops->writeb(handle, offset, val);
148 writew_nb(void *handle, u_int32_t offset, u_int16_t val)
150 return ops->writew(handle, offset, val);
154 writel_nb(void *handle, u_int32_t offset, u_int32_t val)
156 return ops->writel(handle, offset, val);
162 static u_int64_t base = 0;
165 size_t len = sizeof(base);
167 if ((error = sysctlbyname("hw.chipset.dense", &base, &len,
169 err(1, "hw.chipset.dense");