]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/server/src/acpi_osl.cc
adb6a0a8b9a5c708ff94dddbc9499182deec44f7
[l4.git] / l4 / pkg / io / server / src / acpi_osl.cc
1 /*
2  * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #include <l4/sys/compiler.h>
10 #include <l4/sigma0/sigma0.h>
11
12 __BEGIN_DECLS
13 #include "acpi.h"
14 #include "acpiosxf.h"
15 __END_DECLS
16
17 #include <cstdio>
18
19 #include "pci.h"
20 #include "res.h"
21
22 #if defined(ARCH_amd64) || defined(ARCH_x86)
23
24 #include <l4/util/port_io.h>
25 #define DEBUG_OSL_PORT_IO 0
26 /*
27  * Platform and hardware-independent I/O interfaces
28  */
29 ACPI_STATUS
30 AcpiOsReadPort (
31         ACPI_IO_ADDRESS                 address,
32         UINT32                         *value,
33         UINT32                          width)
34 {
35   if(0 && DEBUG_OSL_PORT_IO)
36     printf("IN: adr=0x%x, width=%i\n", address, width);
37
38   if (address == 0x80)
39     return AE_OK;
40
41   switch(width)
42     {
43     case 8:
44       if (res_get_ioport(address, 0) < 0)
45         return AE_BAD_PARAMETER;
46       *value = l4util_in8((l4_uint16_t)address);
47       break;
48     case 16:
49       if (res_get_ioport(address, 1) < 0)
50         return AE_BAD_PARAMETER;
51       *value = l4util_in16((l4_uint16_t)address);
52       break;
53     case 32:
54       if (res_get_ioport(address, 2) < 0)
55         return AE_BAD_PARAMETER;
56       *value = l4util_in32((l4_uint16_t)address);
57       break;
58     default :
59       return AE_BAD_PARAMETER;
60     }
61   if(DEBUG_OSL_PORT_IO)
62     printf("\tport(0x%x)=>0x%x\n",address,*value);
63   return AE_OK;
64 }
65
66 ACPI_STATUS
67 AcpiOsWritePort (
68         ACPI_IO_ADDRESS                 address,
69         UINT32                          value,
70         UINT32                          width)
71 {
72   if(DEBUG_OSL_PORT_IO)
73     printf("\tport(0x%x)<=0x%x\n",address,value);
74
75   if (address == 0x80)
76     return AE_OK;
77
78   switch(width)
79     {
80     case 8:
81       if (res_get_ioport(address, 0) < 0)
82         return AE_BAD_PARAMETER;
83       l4util_out8((l4_uint8_t)value,(l4_uint16_t)address);
84       break;
85     case 16:
86       if (res_get_ioport(address, 1) < 0)
87         return AE_BAD_PARAMETER;
88       l4util_out16((l4_uint16_t)value,(l4_uint16_t)address);
89       break;
90     case 32:
91       if (res_get_ioport(address, 2) < 0)
92         return AE_BAD_PARAMETER;
93       l4util_out32((l4_uint32_t)value,(l4_uint32_t)address);
94       break;
95     default :
96       return AE_BAD_PARAMETER;
97     }
98   return AE_OK;
99 }
100 #else
101
102 ACPI_STATUS
103 AcpiOsReadPort (
104         ACPI_IO_ADDRESS                 /*address*/,
105         UINT32                        * /*value*/,
106         UINT32                        /*width*/)
107 {
108   return AE_NO_MEMORY;
109 }
110
111 ACPI_STATUS
112 AcpiOsWritePort (
113         ACPI_IO_ADDRESS                 /*address*/,
114         UINT32                        /*value*/,
115         UINT32                        /*width*/)
116 {
117   return AE_NO_MEMORY;
118 }
119 #endif
120
121 void *
122 AcpiOsMapMemory (
123         ACPI_PHYSICAL_ADDRESS           where,
124         ACPI_SIZE                       length)
125 {
126   void *virt = (void*)res_map_iomem(where, length);
127
128   printf("%s(%x, %x) = %lx\n", __func__, where, length, (unsigned long)virt);
129
130   return virt;
131 }
132
133 void
134 AcpiOsUnmapMemory (
135         void                            *logical_address,
136         ACPI_SIZE                       size)
137 {
138   (void)logical_address;
139   (void)size;
140 //  l4io_release_iomem((l4_addr_t)logical_address, size);
141   return;
142 }
143
144
145
146 /******************************************************************************
147  *
148  * FUNCTION:    AcpiOsReadPciConfiguration
149  *
150  * PARAMETERS:  PciId               Seg/Bus/Dev
151  *              Register            Device Register
152  *              Value               Buffer where value is placed
153  *              Width               Number of bits
154  *
155  * RETURN:      Status
156  *
157  * DESCRIPTION: Read data from PCI configuration space
158  *
159  *****************************************************************************/
160
161 extern inline
162 l4_uint32_t
163 pci_conf_addr(l4_uint32_t bus, l4_uint32_t dev, l4_uint32_t fn, l4_uint32_t reg)
164 { return 0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3); }
165
166 ACPI_STATUS
167 AcpiOsReadPciConfiguration (
168     ACPI_PCI_ID             *PciId,
169     UINT32                  Register,
170     void                    *Value,
171     UINT32                  Width)
172 {
173   //printf("%s: ...\n", __func__);
174   Pci_root_bridge *rb = pci_root_bridge(PciId->Segment);
175   if (!rb)
176     return AE_BAD_PARAMETER;
177
178   int r = rb->cfg_read(PciId->Bus, (PciId->Device << 16) | PciId->Function,
179       Register, (l4_uint32_t *)Value, Hw::Pci::cfg_w_to_o(Width));
180
181   if (r < 0)
182     return AE_BAD_PARAMETER;
183
184   return AE_OK;
185 }
186
187
188 /******************************************************************************
189  *
190  * FUNCTION:    AcpiOsWritePciConfiguration
191  *
192  * PARAMETERS:  PciId               Seg/Bus/Dev
193  *              Register            Device Register
194  *              Value               Value to be written
195  *              Width               Number of bits
196  *
197  * RETURN:      Status.
198  *
199  * DESCRIPTION: Write data to PCI configuration space
200  *
201  *****************************************************************************/
202
203 ACPI_STATUS
204 AcpiOsWritePciConfiguration (
205     ACPI_PCI_ID             *PciId,
206     UINT32                  Register,
207     ACPI_INTEGER            Value,
208     UINT32                  Width)
209 {
210   //printf("%s: ...\n", __func__);
211   Pci_root_bridge *rb = pci_root_bridge(PciId->Segment);
212   if (!rb)
213     return AE_BAD_PARAMETER;
214
215   int r = rb->cfg_write(PciId->Bus, (PciId->Device << 16) | PciId->Function,
216       Register, Value, Hw::Pci::cfg_w_to_o(Width));
217
218   if (r < 0)
219     return AE_BAD_PARAMETER;
220
221   return AE_OK;
222
223   return (AE_OK);
224 }
225