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 $
29 #include <sys/types.h>
30 #include <sys/sysctl.h>
34 static struct io_ops *ops;
37 ioperm(unsigned long from, unsigned long num, int on)
41 size_t len = sizeof(bwx);
43 if ((error = sysctlbyname("hw.chipset.bwx", &bwx, &len, 0, 0)) < 0)
50 return ops->ioperm(from, num, on);
56 return ops->inb(port);
62 return ops->inw(port);
68 return ops->inl(port);
72 outb(u_int32_t port, u_int8_t val)
78 outw(u_int32_t port, u_int16_t val)
84 outl(u_int32_t port, u_int32_t val)
90 map_memory(u_int32_t address, u_int32_t size)
92 return ops->map_memory(address, size);
96 unmap_memory(void *handle, u_int32_t size)
98 ops->unmap_memory(handle, size);
102 readb(void *handle, u_int32_t offset)
104 return ops->readb(handle, offset);
108 readw(void *handle, u_int32_t offset)
110 return ops->readw(handle, offset);
114 readl(void *handle, u_int32_t offset)
116 return ops->readl(handle, offset);
120 writeb(void *handle, u_int32_t offset, u_int8_t val)
122 ops->writeb(handle, offset, val);
123 __asm__ __volatile__ ("mb");
127 writew(void *handle, u_int32_t offset, u_int16_t val)
129 ops->writew(handle, offset, val);
130 __asm__ __volatile__ ("mb");
134 writel(void *handle, u_int32_t offset, u_int32_t val)
136 ops->writel(handle, offset, val);
137 __asm__ __volatile__ ("mb");
141 writeb_nb(void *handle, u_int32_t offset, u_int8_t val)
143 return ops->writeb(handle, offset, val);
147 writew_nb(void *handle, u_int32_t offset, u_int16_t val)
149 return ops->writew(handle, offset, val);
153 writel_nb(void *handle, u_int32_t offset, u_int32_t val)
155 return ops->writel(handle, offset, val);
161 static u_int64_t base = 0;
164 size_t len = sizeof(base);
166 if ((error = sysctlbyname("hw.chipset.dense", &base, &len,
168 err(1, "hw.chipset.dense");