Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libio / io.c
1 /*-
2  * Copyright (c) 1998 Doug Rabson
3  * 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  *
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
24  * SUCH DAMAGE.
25  *
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 $
28  */
29
30 #include <sys/types.h>
31 #include <sys/sysctl.h>
32 #include <err.h>
33 #include "io.h"
34
35 static struct io_ops *ops;
36
37 int
38 ioperm(unsigned long from, unsigned long num, int on)
39 {
40     int error;
41     int bwx;
42     size_t len = sizeof(bwx);
43
44     if ((error = sysctlbyname("hw.chipset.bwx", &bwx, &len, 0, 0)) < 0)
45         return error;
46     if (bwx)
47         ops = &bwx_io_ops;
48     else
49         ops = &swiz_io_ops;
50
51     return ops->ioperm(from, num, on);
52 }
53
54 u_int8_t
55 inb(u_int32_t port)
56 {
57     return ops->inb(port);
58 }
59
60 u_int16_t
61 inw(u_int32_t port)
62 {
63     return ops->inw(port);
64 }
65
66 u_int32_t
67 inl(u_int32_t port)
68 {
69     return ops->inl(port);
70 }
71
72 void
73 outb(u_int32_t port, u_int8_t val)
74 {
75     ops->outb(port, val);
76 }
77
78 void
79 outw(u_int32_t port, u_int16_t val)
80 {
81     ops->outw(port, val);
82 }
83
84 void
85 outl(u_int32_t port, u_int32_t val)
86 {
87     ops->outl(port, val);
88 }
89
90 void *
91 map_memory(u_int32_t address, u_int32_t size)
92 {
93     return ops->map_memory(address, size);
94 }
95
96 void
97 unmap_memory(void *handle, u_int32_t size)
98 {
99     ops->unmap_memory(handle, size);
100 }
101
102 u_int8_t
103 readb(void *handle, u_int32_t offset)
104 {
105     return ops->readb(handle, offset);
106 }
107
108 u_int16_t
109 readw(void *handle, u_int32_t offset)
110 {
111     return ops->readw(handle, offset);
112 }
113
114 u_int32_t
115 readl(void *handle, u_int32_t offset)
116 {
117     return ops->readl(handle, offset);
118 }
119
120 void
121 writeb(void *handle, u_int32_t offset, u_int8_t val)
122 {
123     ops->writeb(handle, offset, val);
124     __asm__ __volatile__ ("mb");
125 }
126
127 void
128 writew(void *handle, u_int32_t offset, u_int16_t val)
129 {
130     ops->writew(handle, offset, val);
131     __asm__ __volatile__ ("mb");
132 }
133
134 void
135 writel(void *handle, u_int32_t offset, u_int32_t val)
136 {
137     ops->writel(handle, offset, val);
138     __asm__ __volatile__ ("mb");
139 }
140
141 void
142 writeb_nb(void *handle, u_int32_t offset, u_int8_t val)
143 {
144     return ops->writeb(handle, offset, val);
145 }
146
147 void
148 writew_nb(void *handle, u_int32_t offset, u_int16_t val)
149 {
150     return ops->writew(handle, offset, val);
151 }
152
153 void
154 writel_nb(void *handle, u_int32_t offset, u_int32_t val)
155 {
156     return ops->writel(handle, offset, val);
157 }
158
159 u_int64_t
160 dense_base(void)
161 {
162     static u_int64_t base = 0;
163
164     if (base == 0) {
165         size_t len = sizeof(base);
166         int error;
167         if ((error = sysctlbyname("hw.chipset.dense", &base, &len,
168                                   0, 0)) < 0)
169             err(1, "hw.chipset.dense");
170     }
171
172     return base;
173 }