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