Angel Pons | c80e350 | 2020-04-03 01:21:49 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 2 | |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 3 | #include <string.h> |
| 4 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 6 | #include <device/device.h> |
Elyes HAOUAS | 2782048 | 2019-12-22 14:20:45 +0100 | [diff] [blame] | 7 | |
Vladimir Serbinenko | 0e64617 | 2014-08-31 00:27:05 +0200 | [diff] [blame] | 8 | #include "mainboard.h" |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 9 | |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 10 | static long acpi_create_ecdt(acpi_ecdt_t * ecdt) |
| 11 | { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 12 | /* Attention: Make sure these match the values from |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 13 | * the DSDT's ec.asl |
| 14 | */ |
| 15 | static const char ec_id[] = "\\_SB.PCI0.LPCB.EC0"; |
| 16 | int ecdt_len = sizeof(acpi_ecdt_t) + strlen(ec_id) + 1; |
| 17 | |
| 18 | acpi_header_t *header = &(ecdt->header); |
| 19 | |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 20 | memset((void *)ecdt, 0, ecdt_len); |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 21 | |
| 22 | /* fill out header fields */ |
| 23 | memcpy(header->signature, "ECDT", 4); |
| 24 | memcpy(header->oem_id, OEM_ID, 6); |
| 25 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 26 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 27 | |
| 28 | header->length = ecdt_len; |
| 29 | header->revision = 1; |
| 30 | |
| 31 | /* Location of the two EC registers */ |
| 32 | ecdt->ec_control.space_id = ACPI_ADDRESS_SPACE_IO; |
| 33 | ecdt->ec_control.bit_width = 8; |
| 34 | ecdt->ec_control.bit_offset = 0; |
| 35 | ecdt->ec_control.addrl = 0x66; |
| 36 | ecdt->ec_control.addrh = 0; |
| 37 | |
Elyes HAOUAS | 28db21c | 2020-07-19 11:04:08 +0200 | [diff] [blame] | 38 | ecdt->ec_data.space_id = ACPI_ADDRESS_SPACE_IO; |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 39 | ecdt->ec_data.bit_width = 8; |
| 40 | ecdt->ec_data.bit_offset = 0; |
| 41 | ecdt->ec_data.addrl = 0x62; |
| 42 | ecdt->ec_data.addrh = 0; |
| 43 | |
| 44 | ecdt->uid = 1; // Must match _UID of the EC0 node. |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 45 | |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 46 | ecdt->gpe_bit = 23; // SCI interrupt within GPEx_STS |
| 47 | |
Jacob Garber | 0db6e75 | 2019-07-16 15:48:28 -0600 | [diff] [blame] | 48 | memcpy(ecdt->ec_id, ec_id, sizeof(ec_id)); |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 49 | |
| 50 | header->checksum = |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 51 | acpi_checksum((void *)ecdt, ecdt_len); |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 52 | |
| 53 | return header->length; |
| 54 | } |
| 55 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 56 | unsigned long mainboard_write_acpi_tables(const struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 57 | unsigned long start, |
| 58 | acpi_rsdp_t *rsdp) |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 59 | { |
| 60 | unsigned long current; |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 61 | acpi_header_t *ecdt; |
| 62 | |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 63 | current = start; |
| 64 | |
| 65 | /* Align ACPI tables to 16byte */ |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 66 | current = acpi_align_current(current); |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 67 | |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 68 | printk(BIOS_DEBUG, "ACPI: * ECDT\n"); |
| 69 | ecdt = (acpi_header_t *)current; |
| 70 | current += acpi_create_ecdt((acpi_ecdt_t *)current); |
Aaron Durbin | 07a1b28 | 2015-12-10 17:07:38 -0600 | [diff] [blame] | 71 | current = acpi_align_current(current); |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 72 | acpi_add_table(rsdp, ecdt); |
| 73 | |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "current = %lx\n", current); |
Stefan Reinauer | 7cfa7f9 | 2010-05-16 14:24:41 +0000 | [diff] [blame] | 75 | return current; |
| 76 | } |