| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/pci.h> |
| 5 |
#include <device/pci_ops.h> |
| 6 |
#include <intelblocks/itss.h> |
| 7 |
#include <intelblocks/lpc_lib.h> |
| 8 |
#include <intelblocks/pcr.h> |
| 9 |
#include <soc/irq.h> |
| 10 |
#include <soc/pcr_ids.h> |
| 11 |
|
| 12 |
#include <acpi/acpigen.h> |
| 13 |
#include <acpi/acpigen_pci.h> |
| 14 |
|
| 15 |
void lpc_soc_fill_ssdt(const struct device *dev) |
| 16 |
{ |
| 17 |
const char *scope = acpi_device_scope(dev); |
| 18 |
const char *name = acpi_device_name(dev); |
| 19 |
|
| 20 |
if (!scope || !name) { |
| 21 |
printk(BIOS_ERR, "%s: Missing ACPI path/scope\n", dev_path(dev)); |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
acpigen_write_scope(scope); |
| 27 |
acpigen_write_device(name); |
| 28 |
|
| 29 |
printk(BIOS_DEBUG, "%s.%s: %s\n", scope, name, dev_path(dev)); |
| 30 |
acpigen_write_ADR_pci_device(dev); |
| 31 |
|
| 32 |
acpigen_write_device_end(); |
| 33 |
acpigen_write_scope_end(); |
| 34 |
} |
| 35 |
|
| 36 |
uint32_t itss_soc_get_on_chip_dev_pir(const struct device *dev) |
| 37 |
{ |
| 38 |
assert(is_pci(dev)); |
| 39 |
return PCI_ITSS_PIR(PCI_SLOT(dev->path.pci.devfn)); |
| 40 |
} |
| 41 |
|
| 42 |
static void soc_itss_route_irq(const struct device *irq_dev, uint8_t int_pin) |
| 43 |
{ |
| 44 |
uint8_t pirq = itss_get_on_chip_dev_pirq(irq_dev, int_pin); |
| 45 |
if (pirq == PIRQ_INVALID) |
| 46 |
return; |
| 47 |
|
| 48 |
uint8_t pirq_rout = pcr_read8(PID_ITSS, |
| 49 |
PCR_ITSS_PIRQA_ROUT + pirq_idx(pirq)); |
| 50 |
uint8_t int_line = (pirq_rout & 0x80) ? pirq_idx(pirq) + PCH_IRQ16 : pirq_rout & 0xf; |
| 51 |
|
| 52 |
printk(BIOS_SPEW, "routing irq: dev %s, pin %d, pirq %d, intline %d\n", |
| 53 |
dev_path(irq_dev), int_pin, pirq, int_line); |
| 54 |
pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line); |
| 55 |
} |
| 56 |
|
| 57 |
static void soc_pch_pirq_init(void) |
| 58 |
{ |
| 59 |
|
| 60 |
size_t pirq_routes; |
| 61 |
const uint8_t *pirq_routing_legacy = lpc_get_pic_pirq_routing(&pirq_routes); |
| 62 |
|
| 63 |
itss_irq_init(pirq_routing_legacy); |
| 64 |
for (int i = 0; i < PIRQ_COUNT; i++) |
| 65 |
itss_set_irq_polarity(pirq_routing_legacy[i], 1); |
| 66 |
|
| 67 |
|
| 68 |
struct device *domain = NULL; |
| 69 |
while ((domain = dev_find_path(domain, DEVICE_PATH_DOMAIN))) { |
| 70 |
struct device *irq_dev = NULL; |
| 71 |
while ((irq_dev = dev_bus_each_child(domain->downstream, irq_dev))) { |
| 72 |
if (!is_enabled_pci(irq_dev)) |
| 73 |
continue; |
| 74 |
uint8_t int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN); |
| 75 |
if (int_pin < PCI_INT_A || int_pin > PCI_INT_D) |
| 76 |
continue; |
| 77 |
|
| 78 |
soc_itss_route_irq(irq_dev, int_pin); |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
void lpc_soc_init(struct device *dev) |
| 84 |
{ |
| 85 |
printk(BIOS_SPEW, "pch: lpc_init\n"); |
| 86 |
|
| 87 |
soc_pch_pirq_init(); |
| 88 |
} |