xref: /freebsd/sys/dev/acpica/Osd/OsdHardware.c (revision 1587a9db92c03c738bb3f0fc5874b43c961e7c99)
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 
28fd660059SMike Smith /*
29fd660059SMike Smith  * 6.7 : Hardware Abstraction
30fd660059SMike Smith  */
31fd660059SMike Smith 
32a3ab9d1eSNate Lawson #include <sys/cdefs.h>
33129d3046SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
34fd660059SMike Smith 
3569496408SJung-uk Kim #include <machine/iodev.h>
36fd660059SMike Smith #include <machine/pci_cfgreg.h>
37fd660059SMike Smith 
38e787342eSJung-uk Kim extern int	acpi_susp_bounce;
39e787342eSJung-uk Kim 
4028482948SJung-uk Kim ACPI_STATUS
AcpiOsEnterSleep(UINT8 SleepState,UINT32 RegaValue,UINT32 RegbValue)4128482948SJung-uk Kim AcpiOsEnterSleep(UINT8 SleepState, UINT32 RegaValue, UINT32 RegbValue)
4228482948SJung-uk Kim {
4328482948SJung-uk Kim 
44e787342eSJung-uk Kim 	/* If testing device suspend only, back out of everything here. */
45e787342eSJung-uk Kim 	if (acpi_susp_bounce)
46e787342eSJung-uk Kim 		return (AE_CTRL_TERMINATE);
47e787342eSJung-uk Kim 
4828482948SJung-uk Kim 	return (AE_OK);
4928482948SJung-uk Kim }
5028482948SJung-uk Kim 
51fd660059SMike Smith /*
52fd660059SMike Smith  * ACPICA's rather gung-ho approach to hardware resource ownership is a little
53fd660059SMike Smith  * troublesome insofar as there is no easy way for us to know in advance
54fd660059SMike Smith  * exactly which I/O resources it's going to want to use.
55fd660059SMike Smith  *
56fd660059SMike Smith  * In order to deal with this, we ignore resource ownership entirely, and simply
57fd660059SMike Smith  * use the native I/O space accessor functionality.  This is Evil, but it works.
58fd660059SMike Smith  */
59fd660059SMike Smith 
609d839ea8SMike Smith ACPI_STATUS
AcpiOsReadPort(ACPI_IO_ADDRESS InPort,UINT32 * Value,UINT32 Width)61c871a6daSNate Lawson AcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width)
62fd660059SMike Smith {
63dbcb35ffSNate Lawson 
649d839ea8SMike Smith     switch (Width) {
659d839ea8SMike Smith     case 8:
6669496408SJung-uk Kim 	*Value = iodev_read_1(InPort);
679d839ea8SMike Smith 	break;
689d839ea8SMike Smith     case 16:
6969496408SJung-uk Kim 	*Value = iodev_read_2(InPort);
709d839ea8SMike Smith 	break;
719d839ea8SMike Smith     case 32:
7269496408SJung-uk Kim 	*Value = iodev_read_4(InPort);
739d839ea8SMike Smith 	break;
74fd660059SMike Smith     }
75fd660059SMike Smith 
769d839ea8SMike Smith     return (AE_OK);
77fd660059SMike Smith }
78fd660059SMike Smith 
799d839ea8SMike Smith ACPI_STATUS
AcpiOsWritePort(ACPI_IO_ADDRESS OutPort,UINT32 Value,UINT32 Width)80c871a6daSNate Lawson AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32	Value, UINT32 Width)
81fd660059SMike Smith {
82dbcb35ffSNate Lawson 
839d839ea8SMike Smith     switch (Width) {
849d839ea8SMike Smith     case 8:
8569496408SJung-uk Kim 	iodev_write_1(OutPort, Value);
869d839ea8SMike Smith 	break;
879d839ea8SMike Smith     case 16:
8869496408SJung-uk Kim 	iodev_write_2(OutPort, Value);
899d839ea8SMike Smith 	break;
909d839ea8SMike Smith     case 32:
9169496408SJung-uk Kim 	iodev_write_4(OutPort, Value);
929d839ea8SMike Smith 	break;
93fd660059SMike Smith     }
94fd660059SMike Smith 
95fd660059SMike Smith     return (AE_OK);
96fd660059SMike Smith }
97fd660059SMike Smith 
98fd660059SMike Smith ACPI_STATUS
AcpiOsReadPciConfiguration(ACPI_PCI_ID * PciId,UINT32 Register,UINT64 * Value,UINT32 Width)99709fac06SJung-uk Kim AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value,
1009d839ea8SMike Smith     UINT32 Width)
101fd660059SMike Smith {
1026e766102SJung-uk Kim 
103617994efSAndrew Turner #ifdef __aarch64__
104617994efSAndrew Turner     /* ARM64TODO: Add pci support */
105617994efSAndrew Turner     return (AE_SUPPORT);
106617994efSAndrew Turner #else
1076e766102SJung-uk Kim     if (Width == 64)
1086e766102SJung-uk Kim 	return (AE_SUPPORT);
109fd660059SMike Smith 
110fd660059SMike Smith     if (!pci_cfgregopen())
111fd660059SMike Smith 	return (AE_NOT_EXIST);
1129d839ea8SMike Smith 
113*1587a9dbSJohn Baldwin     *(UINT64 *)Value = pci_cfgregread(PciId->Segment, PciId->Bus, PciId->Device,
1146e766102SJung-uk Kim 	PciId->Function, Register, Width / 8);
1159d839ea8SMike Smith 
116fd660059SMike Smith     return (AE_OK);
117617994efSAndrew Turner #endif
118fd660059SMike Smith }
119fd660059SMike Smith 
120fd660059SMike Smith ACPI_STATUS
AcpiOsWritePciConfiguration(ACPI_PCI_ID * PciId,UINT32 Register,UINT64 Value,UINT32 Width)121c871a6daSNate Lawson AcpiOsWritePciConfiguration (ACPI_PCI_ID *PciId, UINT32 Register,
1229a179dd8SJung-uk Kim     UINT64 Value, UINT32 Width)
123fd660059SMike Smith {
1246e766102SJung-uk Kim 
125617994efSAndrew Turner #ifdef __aarch64__
126617994efSAndrew Turner     /* ARM64TODO: Add pci support */
127617994efSAndrew Turner     return (AE_SUPPORT);
128617994efSAndrew Turner #else
1296e766102SJung-uk Kim     if (Width == 64)
1306e766102SJung-uk Kim 	return (AE_SUPPORT);
131fd660059SMike Smith 
132fd660059SMike Smith     if (!pci_cfgregopen())
133fd660059SMike Smith     	return (AE_NOT_EXIST);
134fd660059SMike Smith 
135*1587a9dbSJohn Baldwin     pci_cfgregwrite(PciId->Segment, PciId->Bus, PciId->Device, PciId->Function,
136*1587a9dbSJohn Baldwin 	Register, Value, Width / 8);
1379d839ea8SMike Smith 
138fd660059SMike Smith     return (AE_OK);
139617994efSAndrew Turner #endif
140fd660059SMike Smith }
141