xref: /freebsd/sys/dev/acpica/Osd/OsdHardware.c (revision 617994efc71862e5b33df01711b8c26d124b8010)
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>
33a3ab9d1eSNate Lawson __FBSDID("$FreeBSD$");
34a3ab9d1eSNate Lawson 
35129d3046SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
36fd660059SMike Smith 
3769496408SJung-uk Kim #include <machine/iodev.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 
499d839ea8SMike Smith ACPI_STATUS
50c871a6daSNate Lawson AcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width)
51fd660059SMike Smith {
52dbcb35ffSNate Lawson 
539d839ea8SMike Smith     switch (Width) {
549d839ea8SMike Smith     case 8:
5569496408SJung-uk Kim 	*Value = iodev_read_1(InPort);
569d839ea8SMike Smith 	break;
579d839ea8SMike Smith     case 16:
5869496408SJung-uk Kim 	*Value = iodev_read_2(InPort);
599d839ea8SMike Smith 	break;
609d839ea8SMike Smith     case 32:
6169496408SJung-uk Kim 	*Value = iodev_read_4(InPort);
629d839ea8SMike Smith 	break;
63fd660059SMike Smith     }
64fd660059SMike Smith 
659d839ea8SMike Smith     return (AE_OK);
66fd660059SMike Smith }
67fd660059SMike Smith 
689d839ea8SMike Smith ACPI_STATUS
69c871a6daSNate Lawson AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32	Value, UINT32 Width)
70fd660059SMike Smith {
71dbcb35ffSNate Lawson 
729d839ea8SMike Smith     switch (Width) {
739d839ea8SMike Smith     case 8:
7469496408SJung-uk Kim 	iodev_write_1(OutPort, Value);
759d839ea8SMike Smith 	break;
769d839ea8SMike Smith     case 16:
7769496408SJung-uk Kim 	iodev_write_2(OutPort, Value);
789d839ea8SMike Smith 	break;
799d839ea8SMike Smith     case 32:
8069496408SJung-uk Kim 	iodev_write_4(OutPort, Value);
819d839ea8SMike Smith 	break;
82fd660059SMike Smith     }
83fd660059SMike Smith 
84fd660059SMike Smith     return (AE_OK);
85fd660059SMike Smith }
86fd660059SMike Smith 
87fd660059SMike Smith ACPI_STATUS
88709fac06SJung-uk Kim AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value,
899d839ea8SMike Smith     UINT32 Width)
90fd660059SMike Smith {
916e766102SJung-uk Kim 
92*617994efSAndrew Turner #ifdef __aarch64__
93*617994efSAndrew Turner     /* ARM64TODO: Add pci support */
94*617994efSAndrew Turner     return (AE_SUPPORT);
95*617994efSAndrew Turner #else
966e766102SJung-uk Kim     if (Width == 64)
976e766102SJung-uk Kim 	return (AE_SUPPORT);
98fd660059SMike Smith 
99fd660059SMike Smith     if (!pci_cfgregopen())
100fd660059SMike Smith 	return (AE_NOT_EXIST);
1019d839ea8SMike Smith 
1026e766102SJung-uk Kim     *(UINT64 *)Value = pci_cfgregread(PciId->Bus, PciId->Device,
1036e766102SJung-uk Kim 	PciId->Function, Register, Width / 8);
1049d839ea8SMike Smith 
105fd660059SMike Smith     return (AE_OK);
106*617994efSAndrew Turner #endif
107fd660059SMike Smith }
108fd660059SMike Smith 
109fd660059SMike Smith 
110fd660059SMike Smith ACPI_STATUS
111c871a6daSNate Lawson AcpiOsWritePciConfiguration (ACPI_PCI_ID *PciId, UINT32 Register,
1129a179dd8SJung-uk Kim     UINT64 Value, UINT32 Width)
113fd660059SMike Smith {
1146e766102SJung-uk Kim 
115*617994efSAndrew Turner #ifdef __aarch64__
116*617994efSAndrew Turner     /* ARM64TODO: Add pci support */
117*617994efSAndrew Turner     return (AE_SUPPORT);
118*617994efSAndrew Turner #else
1196e766102SJung-uk Kim     if (Width == 64)
1206e766102SJung-uk Kim 	return (AE_SUPPORT);
121fd660059SMike Smith 
122fd660059SMike Smith     if (!pci_cfgregopen())
123fd660059SMike Smith     	return (AE_NOT_EXIST);
124fd660059SMike Smith 
125c871a6daSNate Lawson     pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register,
1266e766102SJung-uk Kim 	Value, Width / 8);
1279d839ea8SMike Smith 
128fd660059SMike Smith     return (AE_OK);
129*617994efSAndrew Turner #endif
130fd660059SMike Smith }
131