Skip to content

Commit

Permalink
ACPICA: ACPI 6.2: Add support for PinFunction() resource
Browse files Browse the repository at this point in the history
ACPICA commit 6bbc6357f7061f1243601adde0ea45f7a89274e0

ACPI 6.2 introduced a new resource that is used to describe how certain
pins are muxed for a device. The ASL syntax of this new resource looks
like below:

  PinFunction(Shared, PinConfig, FunctionNumber, ResourceSource,
              ResourceSourceIndex, ResourceUsage, DescriptorName,
              VendorData) {Pin List}

Which is pretty similar to GpioIo()/GpioInt() resources.

Teach ACPICA about this new resource.

Link: acpica/acpica@6bbc6357
Signed-off-by: Mika Westerberg <[email protected]>
Signed-off-by: Lv Zheng <[email protected]>
Signed-off-by: Bob Moore <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
westeri authored and rafaeljw committed Jun 12, 2017
1 parent c7a1dfb commit 2b72693
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 4 deletions.
1 change: 1 addition & 0 deletions drivers/acpi/acpica/aclocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ struct acpi_port_info {
#define ACPI_RESOURCE_NAME_ADDRESS64 0x8A
#define ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64 0x8B
#define ACPI_RESOURCE_NAME_GPIO 0x8C
#define ACPI_RESOURCE_NAME_PIN_FUNCTION 0x8D
#define ACPI_RESOURCE_NAME_SERIAL_BUS 0x8E
#define ACPI_RESOURCE_NAME_LARGE_MAX 0x8E

Expand Down
2 changes: 2 additions & 0 deletions drivers/acpi/acpica/acresrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ extern struct acpi_rsconvert_info acpi_rs_convert_fixed_dma[];
extern struct acpi_rsconvert_info acpi_rs_convert_i2c_serial_bus[];
extern struct acpi_rsconvert_info acpi_rs_convert_spi_serial_bus[];
extern struct acpi_rsconvert_info acpi_rs_convert_uart_serial_bus[];
extern struct acpi_rsconvert_info acpi_rs_convert_pin_function[];

/* These resources require separate get/set tables */

Expand Down Expand Up @@ -372,6 +373,7 @@ extern struct acpi_rsdump_info acpi_rs_dump_ext_address64[];
extern struct acpi_rsdump_info acpi_rs_dump_ext_irq[];
extern struct acpi_rsdump_info acpi_rs_dump_generic_reg[];
extern struct acpi_rsdump_info acpi_rs_dump_gpio[];
extern struct acpi_rsdump_info acpi_rs_dump_pin_function[];
extern struct acpi_rsdump_info acpi_rs_dump_fixed_dma[];
extern struct acpi_rsdump_info acpi_rs_dump_common_serial_bus[];
extern struct acpi_rsdump_info acpi_rs_dump_i2c_serial_bus[];
Expand Down
22 changes: 22 additions & 0 deletions drivers/acpi/acpica/amlresrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define ACPI_RESTAG_DRIVESTRENGTH "_DRS"
#define ACPI_RESTAG_ENDIANNESS "_END"
#define ACPI_RESTAG_FLOWCONTROL "_FLC"
#define ACPI_RESTAG_FUNCTION "_FUN"
#define ACPI_RESTAG_GRANULARITY "_GRA"
#define ACPI_RESTAG_INTERRUPT "_INT"
#define ACPI_RESTAG_INTERRUPTLEVEL "_LL_" /* active_lo(1), active_hi(0) */
Expand Down Expand Up @@ -404,6 +405,26 @@ struct aml_resource_uart_serialbus {
#define AML_RESOURCE_UART_TYPE_REVISION 1 /* ACPI 5.0 */
#define AML_RESOURCE_UART_MIN_DATA_LEN 10

struct aml_resource_pin_function {
AML_RESOURCE_LARGE_HEADER_COMMON u8 revision_id;
u16 flags;
u8 pin_config;
u16 function_number;
u16 pin_table_offset;
u8 res_source_index;
u16 res_source_offset;
u16 vendor_offset;
u16 vendor_length;
/*
* Optional fields follow immediately:
* 1) PIN list (Words)
* 2) Resource Source String
* 3) Vendor Data bytes
*/
};

#define AML_RESOURCE_PIN_FUNCTION_REVISION 1 /* ACPI 6.2 */

/* restore default alignment */

#pragma pack()
Expand Down Expand Up @@ -446,6 +467,7 @@ union aml_resource {
struct aml_resource_spi_serialbus spi_serial_bus;
struct aml_resource_uart_serialbus uart_serial_bus;
struct aml_resource_common_serialbus common_serial_bus;
struct aml_resource_pin_function pin_function;

/* Utility overlays */

Expand Down
34 changes: 34 additions & 0 deletions drivers/acpi/acpica/rscalc.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ acpi_rs_get_aml_length(struct acpi_resource *resource,

break;

case ACPI_RESOURCE_TYPE_PIN_FUNCTION:

total_size = (acpi_rs_length)(total_size +
(resource->data.
pin_function.
pin_table_length * 2) +
resource->data.
pin_function.
resource_source.
string_length +
resource->data.
pin_function.
vendor_length);

break;

case ACPI_RESOURCE_TYPE_SERIAL_BUS:

total_size =
Expand Down Expand Up @@ -537,6 +553,24 @@ acpi_rs_get_list_length(u8 *aml_buffer,
}
break;

case ACPI_RESOURCE_NAME_PIN_FUNCTION:

/* Vendor data is optional */

if (aml_resource->pin_function.vendor_length) {
extra_struct_bytes +=
aml_resource->pin_function.vendor_offset -
aml_resource->pin_function.
pin_table_offset +
aml_resource->pin_function.vendor_length;
} else {
extra_struct_bytes +=
aml_resource->large_header.resource_length +
sizeof(struct aml_resource_large_header) -
aml_resource->pin_function.pin_table_offset;
}
break;

case ACPI_RESOURCE_NAME_SERIAL_BUS:

minimum_aml_resource_length =
Expand Down
23 changes: 23 additions & 0 deletions drivers/acpi/acpica/rsdumpinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,29 @@ struct acpi_rsdump_info acpi_rs_dump_gpio[16] = {
NULL},
};

struct acpi_rsdump_info acpi_rs_dump_pin_function[10] = {
{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_pin_function),
"PinFunction", NULL},
{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_function.revision_id),
"RevisionId", NULL},
{ACPI_RSD_UINT8, ACPI_RSD_OFFSET(pin_function.pin_config), "PinConfig",
acpi_gbl_ppc_decode},
{ACPI_RSD_1BITFLAG, ACPI_RSD_OFFSET(pin_function.sharable), "Sharing",
acpi_gbl_shr_decode},
{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_function.function_number),
"FunctionNumber", NULL},
{ACPI_RSD_SOURCE, ACPI_RSD_OFFSET(pin_function.resource_source),
"ResourceSource", NULL},
{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_function.pin_table_length),
"PinTableLength", NULL},
{ACPI_RSD_WORDLIST, ACPI_RSD_OFFSET(pin_function.pin_table), "PinTable",
NULL},
{ACPI_RSD_UINT16, ACPI_RSD_OFFSET(pin_function.vendor_length),
"VendorLength", NULL},
{ACPI_RSD_SHORTLISTX, ACPI_RSD_OFFSET(pin_function.vendor_data),
"VendorData", NULL},
};

struct acpi_rsdump_info acpi_rs_dump_fixed_dma[4] = {
{ACPI_RSD_TITLE, ACPI_RSD_TABLE_SIZE(acpi_rs_dump_fixed_dma),
"FixedDma", NULL},
Expand Down
6 changes: 5 additions & 1 deletion drivers/acpi/acpica/rsinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ struct acpi_rsconvert_info *acpi_gbl_set_resource_dispatch[] = {
acpi_rs_convert_gpio, /* 0x11, ACPI_RESOURCE_TYPE_GPIO */
acpi_rs_convert_fixed_dma, /* 0x12, ACPI_RESOURCE_TYPE_FIXED_DMA */
NULL, /* 0x13, ACPI_RESOURCE_TYPE_SERIAL_BUS - Use subtype table below */
acpi_rs_convert_pin_function, /* 0x14, ACPI_RESOURCE_TYPE_PIN_FUNCTION */
};

/* Dispatch tables for AML-to-resource (Get Resource) conversion functions */
Expand Down Expand Up @@ -119,7 +120,7 @@ struct acpi_rsconvert_info *acpi_gbl_get_resource_dispatch[] = {
acpi_rs_convert_address64, /* 0x0A, ACPI_RESOURCE_NAME_ADDRESS64 */
acpi_rs_convert_ext_address64, /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64 */
acpi_rs_convert_gpio, /* 0x0C, ACPI_RESOURCE_NAME_GPIO */
NULL, /* 0x0D, Reserved */
acpi_rs_convert_pin_function, /* 0x0D, ACPI_RESOURCE_NAME_PIN_FUNCTION */
NULL, /* 0x0E, ACPI_RESOURCE_NAME_SERIAL_BUS - Use subtype table below */
};

Expand Down Expand Up @@ -157,6 +158,7 @@ struct acpi_rsdump_info *acpi_gbl_dump_resource_dispatch[] = {
acpi_rs_dump_gpio, /* ACPI_RESOURCE_TYPE_GPIO */
acpi_rs_dump_fixed_dma, /* ACPI_RESOURCE_TYPE_FIXED_DMA */
NULL, /* ACPI_RESOURCE_TYPE_SERIAL_BUS */
acpi_rs_dump_pin_function, /* ACPI_RESOURCE_TYPE_PIN_FUNCTION */
};

struct acpi_rsdump_info *acpi_gbl_dump_serial_bus_dispatch[] = {
Expand Down Expand Up @@ -193,6 +195,7 @@ const u8 acpi_gbl_aml_resource_sizes[] = {
sizeof(struct aml_resource_gpio), /* ACPI_RESOURCE_TYPE_GPIO */
sizeof(struct aml_resource_fixed_dma), /* ACPI_RESOURCE_TYPE_FIXED_DMA */
sizeof(struct aml_resource_common_serialbus), /* ACPI_RESOURCE_TYPE_SERIAL_BUS */
sizeof(struct aml_resource_pin_function), /* ACPI_RESOURCE_TYPE_PIN_FUNCTION */
};

const u8 acpi_gbl_resource_struct_sizes[] = {
Expand Down Expand Up @@ -230,6 +233,7 @@ const u8 acpi_gbl_resource_struct_sizes[] = {
ACPI_RS_SIZE(struct acpi_resource_address64),
ACPI_RS_SIZE(struct acpi_resource_extended_address64),
ACPI_RS_SIZE(struct acpi_resource_gpio),
ACPI_RS_SIZE(struct acpi_resource_pin_function),
ACPI_RS_SIZE(struct acpi_resource_common_serialbus)
};

Expand Down
76 changes: 76 additions & 0 deletions drivers/acpi/acpica/rsserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,82 @@ struct acpi_rsconvert_info acpi_rs_convert_gpio[18] = {
0},
};

/*******************************************************************************
*
* acpi_rs_convert_pinfunction
*
******************************************************************************/

struct acpi_rsconvert_info acpi_rs_convert_pin_function[13] = {
{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_PIN_FUNCTION,
ACPI_RS_SIZE(struct acpi_resource_pin_function),
ACPI_RSC_TABLE_SIZE(acpi_rs_convert_pin_function)},

{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_PIN_FUNCTION,
sizeof(struct aml_resource_pin_function),
0},

{ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.pin_function.revision_id),
AML_OFFSET(pin_function.revision_id),
1},

{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.pin_function.sharable),
AML_OFFSET(pin_function.flags),
0},

{ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.pin_function.pin_config),
AML_OFFSET(pin_function.pin_config),
1},

{ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.pin_function.function_number),
AML_OFFSET(pin_function.function_number),
2},

/* Pin Table */

/*
* It is OK to use GPIO operations here because none of them refer GPIO
* structures directly but instead use offsets given here.
*/

{ACPI_RSC_COUNT_GPIO_PIN,
ACPI_RS_OFFSET(data.pin_function.pin_table_length),
AML_OFFSET(pin_function.pin_table_offset),
AML_OFFSET(pin_function.res_source_offset)},

{ACPI_RSC_MOVE_GPIO_PIN, ACPI_RS_OFFSET(data.pin_function.pin_table),
AML_OFFSET(pin_function.pin_table_offset),
0},

/* Resource Source */

{ACPI_RSC_MOVE8,
ACPI_RS_OFFSET(data.pin_function.resource_source.index),
AML_OFFSET(pin_function.res_source_index),
1},

{ACPI_RSC_COUNT_GPIO_RES,
ACPI_RS_OFFSET(data.pin_function.resource_source.string_length),
AML_OFFSET(pin_function.res_source_offset),
AML_OFFSET(pin_function.vendor_offset)},

{ACPI_RSC_MOVE_GPIO_RES,
ACPI_RS_OFFSET(data.pin_function.resource_source.string_ptr),
AML_OFFSET(pin_function.res_source_offset),
0},

/* Vendor Data */

{ACPI_RSC_COUNT_GPIO_VEN,
ACPI_RS_OFFSET(data.pin_function.vendor_length),
AML_OFFSET(pin_function.vendor_length),
1},

{ACPI_RSC_MOVE_GPIO_RES, ACPI_RS_OFFSET(data.pin_function.vendor_data),
AML_OFFSET(pin_function.vendor_offset),
0},
};

/*******************************************************************************
*
* acpi_rs_convert_i2c_serial_bus
Expand Down
4 changes: 2 additions & 2 deletions drivers/acpi/acpica/utresrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ const u8 acpi_gbl_resource_aml_sizes[] = {
ACPI_AML_SIZE_LARGE(struct aml_resource_address64),
ACPI_AML_SIZE_LARGE(struct aml_resource_extended_address64),
ACPI_AML_SIZE_LARGE(struct aml_resource_gpio),
0,
ACPI_AML_SIZE_LARGE(struct aml_resource_pin_function),
ACPI_AML_SIZE_LARGE(struct aml_resource_common_serialbus),
};

Expand Down Expand Up @@ -384,7 +384,7 @@ static const u8 acpi_gbl_resource_types[] = {
ACPI_VARIABLE_LENGTH, /* 0A Qword* address */
ACPI_FIXED_LENGTH, /* 0B Extended* address */
ACPI_VARIABLE_LENGTH, /* 0C Gpio* */
0,
ACPI_VARIABLE_LENGTH, /* 0D pin_function */
ACPI_VARIABLE_LENGTH /* 0E *serial_bus */
};

Expand Down
16 changes: 15 additions & 1 deletion include/acpi/acrestyp.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,18 @@ struct acpi_resource_uart_serialbus {
#define ACPI_UART_CLEAR_TO_SEND (1<<6)
#define ACPI_UART_REQUEST_TO_SEND (1<<7)

struct acpi_resource_pin_function {
u8 revision_id;
u8 pin_config;
u8 sharable; /* For values, see Interrupt Attributes above */
u16 function_number;
u16 pin_table_length;
u16 vendor_length;
struct acpi_resource_source resource_source;
u16 *pin_table;
u8 *vendor_data;
};

/* ACPI_RESOURCE_TYPEs */

#define ACPI_RESOURCE_TYPE_IRQ 0
Expand All @@ -556,7 +568,8 @@ struct acpi_resource_uart_serialbus {
#define ACPI_RESOURCE_TYPE_GPIO 17 /* ACPI 5.0 */
#define ACPI_RESOURCE_TYPE_FIXED_DMA 18 /* ACPI 5.0 */
#define ACPI_RESOURCE_TYPE_SERIAL_BUS 19 /* ACPI 5.0 */
#define ACPI_RESOURCE_TYPE_MAX 19
#define ACPI_RESOURCE_TYPE_PIN_FUNCTION 20 /* ACPI 6.2 */
#define ACPI_RESOURCE_TYPE_MAX 20

/* Master union for resource descriptors */

Expand Down Expand Up @@ -584,6 +597,7 @@ union acpi_resource_data {
struct acpi_resource_spi_serialbus spi_serial_bus;
struct acpi_resource_uart_serialbus uart_serial_bus;
struct acpi_resource_common_serialbus common_serial_bus;
struct acpi_resource_pin_function pin_function;

/* Common fields */

Expand Down

0 comments on commit 2b72693

Please sign in to comment.