coreboot-kgpe-d16/src/acpi/acpi_pld.c
Furquan Shaikh 6cc1e9e81e acpi: Move ACPI table support out of arch/x86 (1/5)
This change moves all ACPI table support in coreboot currently living
under arch/x86 into common code to make it architecture
independent. ACPI table generation is not really tied to any
architecture and hence it makes sense to move this to its own directory.

In order to make it easier to review, this change is being split into
multiple CLs. This is change 1/5 which moves .c files from arch/x86 to
acpi/.

The only acpi files that are still retained under arch/x86 are:
a. acpi_s3.c: This doesn't really deal with ACPI tables. Also, there
are some assumptions in there about SMM which will have to be resolved
if this file needs to be moved to common code.

b. acpi_bert_storage.c/bert_storage.h: This file is currently written
specifically with x86 in mind. So, not moving the file for now.

Motivation for this change: Not all stages on Picasso SoC are targeted
for the same architecture. For example, verstage (if runs before
bootblock) will be targeted for non-x86. This makes it difficult to
add device tree to verstage which would be required to get to SoC
configs from the tree. This is because the device tree on x86
platforms currently contains a lot of devices that require ACPI
related enums and structs (like acpi_gpio, acpi_pld, acpi_dp and so
on). Hence, this change removes all ACPI table support out of
arch/x86.

BUG=b:155428745

Change-Id: Icc6b793c52c86483a8c52e0555619e36869a869e
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/40930
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
2020-05-02 18:39:40 +00:00

160 lines
3.7 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */
#include <stdint.h>
#include <string.h>
#include <arch/acpi.h>
#include <arch/acpi_pld.h>
int acpi_pld_fill_usb(struct acpi_pld *pld, enum acpi_upc_type type,
struct acpi_pld_group *group)
{
if (!pld)
return -1;
memset(pld, 0, sizeof(struct acpi_pld));
/* Set defaults */
pld->ignore_color = 1;
pld->panel = PLD_PANEL_UNKNOWN;
pld->vertical_position = PLD_VERTICAL_POSITION_CENTER;
pld->horizontal_position = PLD_HORIZONTAL_POSITION_CENTER;
pld->rotation = PLD_ROTATE_0;
pld->visible = 1;
pld->group.token = group->token;
pld->group.position = group->position;
/* Set the shape based on port type */
switch (type) {
case UPC_TYPE_A:
case UPC_TYPE_USB3_A:
case UPC_TYPE_USB3_POWER_B:
pld->shape = PLD_SHAPE_HORIZONTAL_RECTANGLE;
break;
case UPC_TYPE_MINI_AB:
case UPC_TYPE_USB3_B:
pld->shape = PLD_SHAPE_CHAMFERED;
break;
case UPC_TYPE_USB3_MICRO_B:
case UPC_TYPE_USB3_MICRO_AB:
pld->shape = PLD_SHAPE_HORIZONTAL_TRAPEZOID;
break;
case UPC_TYPE_C_USB2_ONLY:
case UPC_TYPE_C_USB2_SS_SWITCH:
case UPC_TYPE_C_USB2_SS:
pld->shape = PLD_SHAPE_OVAL;
break;
case UPC_TYPE_INTERNAL:
default:
pld->shape = PLD_SHAPE_UNKNOWN;
pld->visible = 0;
break;
}
return 0;
}
int acpi_pld_to_buffer(const struct acpi_pld *pld, uint8_t *buf, int buf_len)
{
if (!pld || !buf)
return -1;
memset(buf, 0, buf_len);
/* [0] Revision (=2) */
buf[0] = 0x2;
if (pld->ignore_color) {
/* [1] Ignore Color */
buf[0] |= 0x80;
} else {
/* [15:8] Red Color */
buf[1] = pld->color_red;
/* [23:16] Green Color */
buf[2] = pld->color_green;
/* [31:24] Blue Color */
buf[3] = pld->color_blue;
}
/* [47:32] Width */
buf[4] = pld->width & 0xff;
buf[5] = pld->width >> 8;
/* [63:48] Height */
buf[6] = pld->height & 0xff;
buf[7] = pld->height >> 8;
/* [64] User Visible */
buf[8] |= (pld->visible & 0x1);
/* [65] Dock */
buf[8] |= (pld->dock & 0x1) << 1;
/* [66] Lid */
buf[8] |= (pld->lid & 0x1) << 2;
/* [69:67] Panel */
buf[8] |= (pld->panel & 0x7) << 3;
/* [71:70] Vertical Position */
buf[8] |= (pld->vertical_position & 0x3) << 6;
/* [73:72] Horizontal Position */
buf[9] |= (pld->horizontal_position & 0x3);
/* [77:74] Shape */
buf[9] |= (pld->shape & 0xf) << 2;
/* [78] Orientation */
buf[9] |= (pld->orientation & 0x1) << 6;
/* [86:79] Group Token (incorrectly defined as 1 bit in ACPI 6.2A) */
buf[9] |= (pld->group.token & 0x1) << 7;
buf[10] |= (pld->group.token >> 0x1) & 0x7f;
/* [94:87] Group Position */
buf[10] |= (pld->group.position & 0x1) << 7;
buf[11] |= (pld->group.position >> 0x1) & 0x7f;
/* [95] Bay */
buf[11] |= (pld->bay & 0x1) << 7;
/* [96] Ejectable */
buf[12] |= (pld->ejectable & 0x1);
/* [97] Ejectable with OSPM help */
buf[12] |= (pld->ejectable_ospm & 0x1) << 1;
/* [105:98] Cabinet Number */
buf[12] |= (pld->cabinet_number & 0x3f) << 2;
buf[13] |= (pld->cabinet_number >> 6) & 0x3;
/* [113:106] Card Cage Number */
buf[13] |= (pld->card_cage_number & 0x3f) << 2;
buf[14] |= (pld->card_cage_number >> 6) & 0x3;
/* [114] PLD is a Reference Shape */
buf[14] |= (pld->reference_shape & 0x1) << 2;
/* [118:115] Rotation */
buf[14] |= (pld->rotation & 0xf) << 3;
/* [123:119] Draw Order */
buf[14] |= (pld->draw_order & 0x1) << 7;
buf[15] |= (pld->draw_order >> 1) & 0xf;
/* [127:124] Reserved */
/* Both 16 byte and 20 byte buffers are supported by the spec */
if (buf_len == 20) {
/* [143:128] Vertical Offset */
buf[16] = pld->vertical_offset & 0xff;
buf[17] = pld->vertical_offset >> 8;
/* [159:144] Horizontal Offset */
buf[18] = pld->horizontal_offset & 0xff;
buf[19] = pld->horizontal_offset >> 8;
}
return 0;
}