xref: /freebsd/sys/dev/acpica/Osd/OsdHardware.c (revision 9d839ea8e4a9327a06de07eb9427eec4357a93e3)
1fd660059SMike Smith /*-
29d839ea8SMike Smith  * Copyright (c) 2000, 2001 Michael Smith
3fd660059SMike Smith  * Copyright (c) 2000 BSDi
4fd660059SMike Smith  * All rights reserved.
5fd660059SMike Smith  *
6fd660059SMike Smith  * Redistribution and use in source and binary forms, with or without
7fd660059SMike Smith  * modification, are permitted provided that the following conditions
8fd660059SMike Smith  * are met:
9fd660059SMike Smith  * 1. Redistributions of source code must retain the above copyright
10fd660059SMike Smith  *    notice, this list of conditions and the following disclaimer.
11fd660059SMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
12fd660059SMike Smith  *    notice, this list of conditions and the following disclaimer in the
13fd660059SMike Smith  *    documentation and/or other materials provided with the distribution.
14fd660059SMike Smith  *
15fd660059SMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16fd660059SMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17fd660059SMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18fd660059SMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19fd660059SMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20fd660059SMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21fd660059SMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22fd660059SMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23fd660059SMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24fd660059SMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25fd660059SMike Smith  * SUCH DAMAGE.
26fd660059SMike Smith  *
27fd660059SMike Smith  *	$FreeBSD$
28fd660059SMike Smith  */
29fd660059SMike Smith 
30fd660059SMike Smith /*
31fd660059SMike Smith  * 6.7 : Hardware Abstraction
32fd660059SMike Smith  */
33fd660059SMike Smith 
34fd660059SMike Smith #include "acpi.h"
35fd660059SMike Smith 
36fd660059SMike Smith #include <machine/bus_pio.h>
37fd660059SMike Smith #include <machine/bus.h>
38fd660059SMike Smith #include <machine/pci_cfgreg.h>
39fd660059SMike Smith 
40fd660059SMike Smith /*
41fd660059SMike Smith  * ACPICA's rather gung-ho approach to hardware resource ownership is a little
42fd660059SMike Smith  * troublesome insofar as there is no easy way for us to know in advance
43fd660059SMike Smith  * exactly which I/O resources it's going to want to use.
44fd660059SMike Smith  *
45fd660059SMike Smith  * In order to deal with this, we ignore resource ownership entirely, and simply
46fd660059SMike Smith  * use the native I/O space accessor functionality.  This is Evil, but it works.
47fd660059SMike Smith  *
48fd660059SMike Smith  * XXX use an intermediate #define for the tag/handle
49fd660059SMike Smith  */
50fd660059SMike Smith 
51fd660059SMike Smith #define ACPI_BUS_SPACE_IO	I386_BUS_SPACE_IO
52fd660059SMike Smith #define ACPI_BUS_HANDLE		0
53fd660059SMike Smith 
549d839ea8SMike Smith ACPI_STATUS
559d839ea8SMike Smith AcpiOsReadPort (
569d839ea8SMike Smith     ACPI_IO_ADDRESS	InPort,
579d839ea8SMike Smith     void		*Value,
589d839ea8SMike Smith     UINT32		Width)
59fd660059SMike Smith {
609d839ea8SMike Smith     switch (Width) {
619d839ea8SMike Smith     case 8:
629d839ea8SMike Smith         *(u_int8_t *)Value = bus_space_read_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
639d839ea8SMike Smith         break;
649d839ea8SMike Smith     case 16:
659d839ea8SMike Smith         *(u_int16_t *)Value = bus_space_read_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
669d839ea8SMike Smith         break;
679d839ea8SMike Smith     case 32:
689d839ea8SMike Smith         *(u_int32_t *)Value = bus_space_read_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, InPort);
699d839ea8SMike Smith         break;
709d839ea8SMike Smith     default:
719d839ea8SMike Smith         /* debug trap goes here */
72fd660059SMike Smith     }
73fd660059SMike Smith 
749d839ea8SMike Smith     return(AE_OK);
75fd660059SMike Smith }
76fd660059SMike Smith 
779d839ea8SMike Smith ACPI_STATUS
789d839ea8SMike Smith AcpiOsWritePort (
799d839ea8SMike Smith     ACPI_IO_ADDRESS	OutPort,
809d839ea8SMike Smith     NATIVE_UINT		Value,
819d839ea8SMike Smith     UINT32		Width)
82fd660059SMike Smith {
839d839ea8SMike Smith     switch (Width) {
849d839ea8SMike Smith     case 8:
85fd660059SMike Smith         bus_space_write_1(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
869d839ea8SMike Smith         break;
879d839ea8SMike Smith     case 16:
88fd660059SMike Smith         bus_space_write_2(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
899d839ea8SMike Smith         break;
909d839ea8SMike Smith     case 32:
91fd660059SMike Smith         bus_space_write_4(ACPI_BUS_SPACE_IO, ACPI_BUS_HANDLE, OutPort, Value);
929d839ea8SMike Smith         break;
939d839ea8SMike Smith     default:
949d839ea8SMike Smith         /* debug trap goes here */
95fd660059SMike Smith     }
96fd660059SMike Smith 
97fd660059SMike Smith     return(AE_OK);
98fd660059SMike Smith }
99fd660059SMike Smith 
100fd660059SMike Smith ACPI_STATUS
1019d839ea8SMike Smith AcpiOsReadPciConfiguration (
1029d839ea8SMike Smith     ACPI_PCI_ID		*PciId,
1039d839ea8SMike Smith     UINT32		Register,
1049d839ea8SMike Smith     void		*Value,
1059d839ea8SMike Smith     UINT32		Width)
106fd660059SMike Smith {
1079d839ea8SMike Smith     u_int32_t	byte_width = Width / 8;
1089d839ea8SMike Smith     u_int32_t	val;
109fd660059SMike Smith 
110fd660059SMike Smith     if (!pci_cfgregopen())
111fd660059SMike Smith         return(AE_NOT_EXIST);
1129d839ea8SMike Smith 
1139d839ea8SMike Smith     val = pci_cfgregread(PciId->Bus, PciId->Device, PciId->Function, Register, byte_width);
1149d839ea8SMike Smith     switch (Width) {
1159d839ea8SMike Smith     case 8:
1169d839ea8SMike Smith 	*(u_int8_t *)Value = val & 0xff;
1179d839ea8SMike Smith 	break;
1189d839ea8SMike Smith     case 16:
1199d839ea8SMike Smith 	*(u_int16_t *)Value = val & 0xffff;
1209d839ea8SMike Smith 	break;
1219d839ea8SMike Smith     case 32:
1229d839ea8SMike Smith 	*(u_int32_t *)Value = val;
1239d839ea8SMike Smith 	break;
1249d839ea8SMike Smith     default:
1259d839ea8SMike Smith 	/* debug trap goes here */
1269d839ea8SMike Smith     }
1279d839ea8SMike Smith 
1289d839ea8SMike Smith 
129fd660059SMike Smith     return(AE_OK);
130fd660059SMike Smith }
131fd660059SMike Smith 
132fd660059SMike Smith 
133fd660059SMike Smith ACPI_STATUS
1349d839ea8SMike Smith AcpiOsWritePciConfiguration (
1359d839ea8SMike Smith     ACPI_PCI_ID		*PciId,
1369d839ea8SMike Smith     UINT32		Register,
1379d839ea8SMike Smith     NATIVE_UINT		Value,
1389d839ea8SMike Smith     UINT32		Width)
139fd660059SMike Smith {
1409d839ea8SMike Smith     u_int32_t	byte_width = Width / 8;
141fd660059SMike Smith 
142fd660059SMike Smith     if (!pci_cfgregopen())
143fd660059SMike Smith     	return(AE_NOT_EXIST);
144fd660059SMike Smith 
1459d839ea8SMike Smith     pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register, Value, byte_width);
1469d839ea8SMike Smith 
147fd660059SMike Smith     return(AE_OK);
148fd660059SMike Smith }
149