summaryrefslogtreecommitdiffstats
path: root/sys/i386/include/acpica_osd.h
blob: 9255e74cac6a77b4b7ea9ab6346e6f7c1956074d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*-
 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
 * Copyright (c) 2000 Munehiro Matsuda <haro@tk.kubota.co.jp>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	$Id: acpica_osd.h,v 1.3 2000/08/09 14:47:48 iwasaki Exp $
 *	$FreeBSD$
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <machine/acpi_machdep.h>
#include <machine/vmparam.h>
#include <sys/acpi.h>
#include <vm/vm.h>
#include <vm/pmap.h>

#include "pcib_if.h"

/*
 * ACPICA compatibility
 */

static UINT32	OsdInX(ACPI_IO_ADDRESS, int);
static void	OsdOutX(ACPI_IO_ADDRESS, UINT32, int);

/*
 * New-bus dependent code
 */

static device_t	get_pcib_device(void);

static __inline device_t
get_pcib_device()
{
	device_t	nexus, pcib;

	if ((nexus = device_find_child(root_bus, "nexus", 0)) == NULL) {
		return (NULL);
	}
	if ((pcib = device_find_child(nexus, "pcib", 0)) == NULL) {
		return (NULL);
	}

	return (pcib);
}

/*
 * Platform/Hardware independent I/O interfaces
 */

static __inline UINT32
OsdInX(ACPI_IO_ADDRESS InPort, int bytes)
{
	bus_space_tag_t		bst;
	bus_space_handle_t	bsh;
	UINT32			retval;

	bst = ACPI_BUS_SPACE_IO;
	bsh = InPort;
	switch (bytes) {
	case 1:
		retval = bus_space_read_1(bst, bsh, 0);
		break;
	case 2:
		retval = bus_space_read_2(bst, bsh, 0);
		break;
	case 4:
		retval = bus_space_read_4(bst, bsh, 0);
		break;
	default:
		printf("OsdInX: wrong length to read\n");
		retval = 0;
	}
	return (retval);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
UINT8
OsdIn8(ACPI_IO_ADDRESS InPort)
{
	return (OsdInX(InPort, 1) & 0xff);
}
 
#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
UINT16
OsdIn16(ACPI_IO_ADDRESS InPort)
{
	return (OsdInX(InPort, 2) & 0xffff);
}
 
#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
UINT32
OsdIn32(ACPI_IO_ADDRESS InPort)
{
	return (OsdInX(InPort, 4));
}

static __inline void
OsdOutX(ACPI_IO_ADDRESS OutPort, UINT32 Value, int bytes)
{
	bus_space_tag_t		bst;
	bus_space_handle_t	bsh;

	bst = ACPI_BUS_SPACE_IO;
	bsh = OutPort;
	switch (bytes) {
	case 1:
		bus_space_write_1(bst, bsh, 0, Value & 0xff);
		break;
	case 2:
		bus_space_write_2(bst, bsh, 0, Value & 0xffff);
		break;
	case 4:
		bus_space_write_4(bst, bsh, 0, Value);
		break;
	default:
		printf("OsdOutX: wrong length to write\n");
	}
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
void
OsdOut8(ACPI_IO_ADDRESS OutPort, UINT8 Value)
{
	OsdOutX(OutPort, Value, 1);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
void    
OsdOut16(ACPI_IO_ADDRESS OutPort, UINT16 Value)
{
	OsdOutX(OutPort, Value, 2);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
void
OsdOut32(ACPI_IO_ADDRESS OutPort, UINT32 Value)
{
	OsdOutX(OutPort, Value, 4);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdMapMemory(void *PhysicalAddress, UINT32 Length, void **LogicalAddress)
{
	vm_offset_t	PhysicalEnd;
	vm_offset_t	PhysicalOffs;

	PhysicalEnd = (vm_offset_t)PhysicalAddress + Length;
	if (PhysicalEnd < 1024 * 1024) {
		/*
		 * The first 1Mb is mapped at KERNBASE.
		 */
		*LogicalAddress = (void *)(uintptr_t)
				  (KERNBASE + (vm_offset_t)PhysicalAddress);
	} else {
		PhysicalOffs = (vm_offset_t)PhysicalAddress -
			       trunc_page((vm_offset_t)PhysicalAddress);
		*LogicalAddress = (caddr_t)
		    pmap_mapdev((vm_offset_t)PhysicalAddress - PhysicalOffs,
				Length + PhysicalOffs) +
		    PhysicalOffs;
	}

	return (AE_OK);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
void    
OsdUnMapMemory(void *LogicalAddress, UINT32 Length)
{

	if ((vm_offset_t)LogicalAddress + Length - KERNBASE >= 1024 * 1024) {
		pmap_unmapdev((vm_offset_t)LogicalAddress, Length);
	}
}

/*
 * Standard access to PCI configuration space
 */

static __inline ACPI_STATUS
OsdReadPciCfg(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT32 *Value, int bytes)
{
	static device_t	pcib = NULL;

	if (pcib == NULL && (pcib = get_pcib_device()) == NULL) {
		return (AE_ERROR);
	}

	*Value = PCIB_READ_CONFIG(pcib, Bus, (DeviceFunction >> 16) & 0xff,
	    DeviceFunction & 0xff, Register, bytes);

	return (AE_OK);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdReadPciCfgByte(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT8 *Value)
{
	ACPI_STATUS	status;
	UINT32		tmp;

	status = OsdReadPciCfg(Bus, DeviceFunction, Register, &tmp, 1);
	*Value = tmp & 0xff;
	return (status);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdReadPciCfgWord(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT16 *Value)
{
	ACPI_STATUS	status;
	UINT32		tmp;

	status = OsdReadPciCfg(Bus, DeviceFunction, Register, &tmp, 2);
	*Value = tmp & 0xffff;
	return (status);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdReadPciCfgDword(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT32 *Value)
{
	ACPI_STATUS	status;
	UINT32		tmp;

	status = OsdReadPciCfg(Bus, DeviceFunction, Register, &tmp, 2);
	*Value = tmp;
	return (status);
}

static __inline ACPI_STATUS
OsdWritePciCfg(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT32 Value, int bytes)
{
	static device_t	pcib = NULL;

	if (pcib == NULL && (pcib = get_pcib_device()) == NULL) {
		return (AE_ERROR);
	}

	PCIB_WRITE_CONFIG(pcib, Bus, (DeviceFunction >> 16) & 0xff,
	    DeviceFunction & 0xff, Register, Value, bytes);

	return (AE_OK);
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdWritePciCfgByte(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT8 Value)
{
	return (OsdWritePciCfg(Bus, DeviceFunction, Register, (UINT32) Value, 1));
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdWritePciCfgWord(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT16 Value)
{
	return (OsdWritePciCfg(Bus, DeviceFunction, Register, (UINT32) Value, 2));
}

#ifndef ACPI_NO_OSDFUNC_INLINE
static __inline
#endif
ACPI_STATUS
OsdWritePciCfgDword(UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT32 Value)
{
	return (OsdWritePciCfg(Bus, DeviceFunction, Register, Value, 4));
}
OpenPOWER on IntegriCloud