1 /******************************************************************************
3 * Module Name: aslmapenter - Build resource descriptor/device maps
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acapps.h>
47 #include <contrib/dev/acpica/compiler/aslcompiler.h>
49 /* This module used for application-level code only */
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("aslmapenter")
54 /* Local prototypes */
56 static ACPI_GPIO_INFO *
61 static ACPI_SERIAL_INFO *
67 /*******************************************************************************
69 * FUNCTION: MpSaveGpioInfo
71 * PARAMETERS: Resource - GPIO resource descriptor
72 * PinCount - From GPIO descriptor
73 * PinList - From GPIO descriptor
74 * DeviceName - The "ResourceSource" name
78 * DESCRIPTION: External Interface.
79 * Save GPIO resource descriptor information.
80 * Creates new GPIO info blocks, one for each pin defined by the
83 ******************************************************************************/
87 ACPI_PARSE_OBJECT *Op,
88 AML_RESOURCE *Resource,
97 /* Mapfile option enabled? */
104 /* Create an info block for each pin defined in the descriptor */
106 for (i = 0; i < PinCount; i++)
108 Info = MpCreateGpioInfo (PinList[i], DeviceName);
111 Info->DeviceName = DeviceName;
112 Info->PinCount = PinCount;
114 Info->PinNumber = PinList[i];
115 Info->Type = Resource->Gpio.ConnectionType;
116 Info->Direction = (UINT8) (Resource->Gpio.IntFlags & 0x0003); /* _IOR, for IO descriptor */
117 Info->Polarity = (UINT8) ((Resource->Gpio.IntFlags >> 1) & 0x0003); /* _POL, for INT descriptor */
122 /*******************************************************************************
124 * FUNCTION: MpSaveSerialInfo
126 * PARAMETERS: Resource - A Serial resource descriptor
127 * DeviceName - The "ResourceSource" name.
131 * DESCRIPTION: External Interface.
132 * Save serial resource descriptor information.
133 * Creates a new serial info block.
135 ******************************************************************************/
139 ACPI_PARSE_OBJECT *Op,
140 AML_RESOURCE *Resource,
143 ACPI_SERIAL_INFO *Info;
148 /* Mapfile option enabled? */
150 if (!Gbl_MapfileFlag)
155 if (Resource->DescriptorType != ACPI_RESOURCE_NAME_SERIAL_BUS)
160 /* Extract address and speed from the resource descriptor */
162 switch (Resource->CommonSerialBus.Type)
164 case AML_RESOURCE_I2C_SERIALBUSTYPE:
166 Address = Resource->I2cSerialBus.SlaveAddress;
167 Speed = Resource->I2cSerialBus.ConnectionSpeed;
170 case AML_RESOURCE_SPI_SERIALBUSTYPE:
172 Address = Resource->SpiSerialBus.DeviceSelection;
173 Speed = Resource->SpiSerialBus.ConnectionSpeed;
176 case AML_RESOURCE_UART_SERIALBUSTYPE:
179 Speed = Resource->UartSerialBus.DefaultBaudRate;
182 default: /* Invalid bus subtype */
186 Info = MpCreateSerialInfo (DeviceName, Address);
189 Info->DeviceName = DeviceName;
190 Info->Resource = Resource;
191 Info->Address = Address;
196 /*******************************************************************************
198 * FUNCTION: MpCreateGpioInfo
200 * PARAMETERS: PinNumber - GPIO pin number
201 * DeviceName - The "ResourceSource" name
203 * RETURN: New GPIO info block.
205 * DESCRIPTION: Create a new GPIO info block and place it on the global list.
206 * The list is sorted by GPIO device names first, and pin numbers
209 ******************************************************************************/
211 static ACPI_GPIO_INFO *
216 ACPI_GPIO_INFO *Info;
217 ACPI_GPIO_INFO *NextGpio;
218 ACPI_GPIO_INFO *PrevGpio;
223 * Allocate a new info block and insert it into the global GPIO list
224 * sorted by both source device name and then the pin number. There is
227 Buffer = UtStringCacheCalloc (sizeof (ACPI_GPIO_INFO));
228 Info = ACPI_CAST_PTR (ACPI_GPIO_INFO, Buffer);
230 NextGpio = Gbl_GpioList;
239 /* Sort on source DeviceName first */
242 (ACPI_STRCMP (DeviceName, NextGpio->DeviceName) > 0))
245 NextGpio = NextGpio->Next;
248 /* Now sort on the PinNumber */
251 (NextGpio->PinNumber < PinNumber) &&
252 !ACPI_STRCMP (DeviceName, NextGpio->DeviceName))
255 NextGpio = NextGpio->Next;
258 /* Finish the list insertion */
262 PrevGpio->Next = Info;
269 Info->Next = NextGpio;
274 /*******************************************************************************
276 * FUNCTION: MpCreateSerialInfo
278 * PARAMETERS: DeviceName - The "ResourceSource" name.
279 * Address - Physical address for the device
281 * RETURN: New Serial info block.
283 * DESCRIPTION: Create a new Serial info block and place it on the global list.
284 * The list is sorted by Serial device names first, and addresses
287 ******************************************************************************/
289 static ACPI_SERIAL_INFO *
294 ACPI_SERIAL_INFO *Info;
295 ACPI_SERIAL_INFO *NextSerial;
296 ACPI_SERIAL_INFO *PrevSerial;
301 * Allocate a new info block and insert it into the global Serial list
302 * sorted by both source device name and then the address.
304 Buffer = UtStringCacheCalloc (sizeof (ACPI_SERIAL_INFO));
305 Info = ACPI_CAST_PTR (ACPI_SERIAL_INFO, Buffer);
307 NextSerial = Gbl_SerialList;
311 Gbl_SerialList = Info;
316 /* Sort on source DeviceName */
319 (ACPI_STRCMP (DeviceName, NextSerial->DeviceName) > 0))
321 PrevSerial = NextSerial;
322 NextSerial = NextSerial->Next;
325 /* Now sort on the Address */
328 (NextSerial->Address < Address) &&
329 !ACPI_STRCMP (DeviceName, NextSerial->DeviceName))
331 PrevSerial = NextSerial;
332 NextSerial = NextSerial->Next;
335 /* Finish the list insertion */
339 PrevSerial->Next = Info;
343 Gbl_SerialList = Info;
346 Info->Next = NextSerial;