OsdHardware.c revision 67760
1/*-
2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *	$FreeBSD: head/sys/dev/acpica/Osd/OsdHardware.c 67760 2000-10-28 06:56:15Z msmith $
28 */
29
30/*
31 * 6.7 : Hardware Abstraction
32 */
33
34#include "acpi.h"
35
36#include <machine/bus_pio.h>
37#include <machine/bus.h>
38#include <machine/pci_cfgreg.h>
39
40/*
41 * ACPICA's rather gung-ho approach to hardware resource ownership is a little
42 * troublesome insofar as there is no easy way for us to know in advance
43 * exactly which I/O resources it's going to want to use.
44 *
45 * In order to deal with this, we ignore resource ownership entirely, and simply
46 * use the native I/O space accessor functionality.  This is Evil, but it works.
47 *
48 * XXX use an intermediate #define for the tag/handle
49 */
50
51#define ACPI_BUS_SPACE_IO	I386_BUS_SPACE_IO
52#define ACPI_BUS_HANDLE		0
53
54UINT8
55AcpiOsIn8(ACPI_IO_ADDRESS InPort)
56{
57    return(bus_space_read_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort));
58}
59
60UINT16
61AcpiOsIn16(ACPI_IO_ADDRESS InPort)
62{
63    return(bus_space_read_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort));
64}
65
66UINT32
67AcpiOsIn32(ACPI_IO_ADDRESS InPort)
68{
69    return(bus_space_read_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort));
70}
71
72void
73AcpiOsOut8(ACPI_IO_ADDRESS OutPort, UINT8 Value)
74{
75    bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
76}
77
78void
79AcpiOsOut16(ACPI_IO_ADDRESS OutPort, UINT16 Value)
80{
81    bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
82}
83
84void
85AcpiOsOut32(ACPI_IO_ADDRESS OutPort, UINT32 Value)
86{
87    bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
88}
89
90ACPI_STATUS
91AcpiOsReadPciCfgByte (UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT8 *Value)
92{
93    u_int32_t	result;
94
95    if (!pci_cfgregopen())
96	return(AE_NOT_EXIST);
97    result = pci_cfgregread(Bus, DeviceFunction >> 16, DeviceFunction & 0xff, Register, 1);
98    *Value = (UINT8)result;
99    return(AE_OK);
100}
101
102ACPI_STATUS
103AcpiOsReadPciCfgWord (UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT16 *Value)
104{
105    u_int32_t	result;
106
107    if (!pci_cfgregopen())
108	return(AE_NOT_EXIST);
109    result = pci_cfgregread(Bus, DeviceFunction >> 16, DeviceFunction & 0xff, Register, 2);
110    *Value = (UINT16)result;
111    return(AE_OK);
112}
113
114ACPI_STATUS
115AcpiOsReadPciCfgDword (UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT32 *Value)
116{
117    if (!pci_cfgregopen())
118	return(AE_NOT_EXIST);
119    *Value = pci_cfgregread(Bus, DeviceFunction >> 16, DeviceFunction & 0xff, Register, 4);
120    return(AE_OK);
121}
122
123ACPI_STATUS
124AcpiOsWritePciCfgByte (UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT8 Value)
125{
126    if (!pci_cfgregopen())
127	return(AE_NOT_EXIST);
128    pci_cfgregwrite(Bus, DeviceFunction >> 16, DeviceFunction & 0xff, Register, (u_int32_t)Value, 1);
129    return(AE_OK);
130}
131
132ACPI_STATUS
133AcpiOsWritePciCfgWord (UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT16 Value)
134{
135    if (!pci_cfgregopen())
136	return(AE_NOT_EXIST);
137    pci_cfgregwrite(Bus, DeviceFunction >> 16, DeviceFunction & 0xff, Register, (u_int32_t)Value, 2);
138    return(AE_OK);
139}
140
141ACPI_STATUS
142AcpiOsWritePciCfgDword (UINT32 Bus, UINT32 DeviceFunction, UINT32 Register, UINT32 Value)
143{
144    if (!pci_cfgregopen())
145	return(AE_NOT_EXIST);
146    pci_cfgregwrite(Bus, DeviceFunction >> 16, DeviceFunction & 0xff, Register, (u_int32_t)Value, 4);
147    return(AE_OK);
148}
149