xref: /freebsd/sys/dev/acpica/Osd/OsdHardware.c (revision 2ba1d4970a06a1660b46f6fd99351d154b295683)
1 /*-
2  * Copyright (c) 2000, 2001 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 
28 /*
29  * 6.7 : Hardware Abstraction
30  */
31 
32 #include <sys/cdefs.h>
33 #include <contrib/dev/acpica/include/acpi.h>
34 
35 #include <machine/iodev.h>
36 #include <machine/pci_cfgreg.h>
37 
38 extern int	acpi_susp_bounce;
39 
40 ACPI_STATUS
41 AcpiOsEnterSleep(UINT8 SleepState, UINT32 RegaValue, UINT32 RegbValue)
42 {
43 
44 	/* If testing device suspend only, back out of everything here. */
45 	if (acpi_susp_bounce)
46 		return (AE_CTRL_TERMINATE);
47 
48 	return (AE_OK);
49 }
50 
51 /*
52  * ACPICA's rather gung-ho approach to hardware resource ownership is a little
53  * troublesome insofar as there is no easy way for us to know in advance
54  * exactly which I/O resources it's going to want to use.
55  *
56  * In order to deal with this, we ignore resource ownership entirely, and simply
57  * use the native I/O space accessor functionality.  This is Evil, but it works.
58  */
59 
60 ACPI_STATUS
61 AcpiOsReadPort(ACPI_IO_ADDRESS InPort, UINT32 *Value, UINT32 Width)
62 {
63 
64     switch (Width) {
65     case 8:
66 	*Value = iodev_read_1(InPort);
67 	break;
68     case 16:
69 	*Value = iodev_read_2(InPort);
70 	break;
71     case 32:
72 	*Value = iodev_read_4(InPort);
73 	break;
74     }
75 
76     return (AE_OK);
77 }
78 
79 ACPI_STATUS
80 AcpiOsWritePort(ACPI_IO_ADDRESS OutPort, UINT32	Value, UINT32 Width)
81 {
82 
83     switch (Width) {
84     case 8:
85 	iodev_write_1(OutPort, Value);
86 	break;
87     case 16:
88 	iodev_write_2(OutPort, Value);
89 	break;
90     case 32:
91 	iodev_write_4(OutPort, Value);
92 	break;
93     }
94 
95     return (AE_OK);
96 }
97 
98 ACPI_STATUS
99 AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value,
100     UINT32 Width)
101 {
102 
103 #ifdef __aarch64__
104     /* ARM64TODO: Add pci support */
105     return (AE_SUPPORT);
106 #else
107     if (Width == 64)
108 	return (AE_SUPPORT);
109 
110     if (!pci_cfgregopen())
111 	return (AE_NOT_EXIST);
112 
113     *(UINT64 *)Value = pci_cfgregread(PciId->Bus, PciId->Device,
114 	PciId->Function, Register, Width / 8);
115 
116     return (AE_OK);
117 #endif
118 }
119 
120 ACPI_STATUS
121 AcpiOsWritePciConfiguration (ACPI_PCI_ID *PciId, UINT32 Register,
122     UINT64 Value, UINT32 Width)
123 {
124 
125 #ifdef __aarch64__
126     /* ARM64TODO: Add pci support */
127     return (AE_SUPPORT);
128 #else
129     if (Width == 64)
130 	return (AE_SUPPORT);
131 
132     if (!pci_cfgregopen())
133     	return (AE_NOT_EXIST);
134 
135     pci_cfgregwrite(PciId->Bus, PciId->Device, PciId->Function, Register,
136 	Value, Width / 8);
137 
138     return (AE_OK);
139 #endif
140 }
141