Debian Codegraph @

src/soc/intel/common/block/itss/itss.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <stdint.h>
4 #include <commonlib/helpers.h>
5 #include <console/console.h>
6 #include <intelblocks/itss.h>
7 #include <intelblocks/pcr.h>
8 #include <soc/pcr_ids.h>
9 #include <southbridge/intel/common/acpi_pirq_gen.h>
10
11 void itss_irq_init(const uint8_t pch_interrupt_routing[PIRQ_COUNT])
12 {
13 uint32_t regs[PIRQ_COUNT/sizeof(uint32_t)] = {0};
14 uint8_t index, byte;
15
16 /* Fill in all the PIRx routes into one array. */
17 for (index = 0; index < ARRAY_SIZE(regs); index++) {
18 for (byte = 0; byte < sizeof(uint32_t); byte++) {
19 uint8_t val = pch_interrupt_routing[index *
20 sizeof(uint32_t) + byte];
21 uint8_t irq = val & 0xf;
22
23 if ((irq <= 2) || (irq == 8) || (irq == 13))
24 regs[index] |= (0x80 << (8 * byte));
25 else
26 regs[index] |= (val << (8 * byte));
27 }
28 /* Access the routing register in 32 bit mode to make this
29 function suitable for both IOSF 1.0 (where only 32 bit access
30 is supported) and later versions of the interface. */
31 pcr_write32(PID_ITSS,
32 PCR_ITSS_PIRQA_ROUT + (index * sizeof(uint32_t)),
33 regs[index]);
34 }
35 }
36
37 void itss_clock_gate_8254(void)
38 {
39 const uint32_t cge8254_mask = (1 << 2);
40
41 pcr_rmw32(PID_ITSS, PCR_ITSS_ITSSPRC, ~cge8254_mask, cge8254_mask);
42 }
43
44 void itss_set_irq_polarity(int irq, int active_low)
45 {
46 uint32_t mask;
47 uint16_t reg;
48 const uint16_t port = PID_ITSS;
49
50 if (irq < 0 || irq > ITSS_MAX_IRQ)
51 return;
52
53 reg = PCR_ITSS_IPC0_CONF + sizeof(uint32_t) * (irq / IRQS_PER_IPC);
54 mask = 1 << (irq % IRQS_PER_IPC);
55
56 pcr_rmw32(port, reg, ~mask, (active_low ? mask : 0));
57 }
58
59 static uint32_t irq_snapshot[NUM_IPC_REGS];
60
61 void itss_snapshot_irq_polarities(int start, int end)
62 {
63 int i;
64 int reg_start;
65 int reg_end;
66 const uint16_t port = PID_ITSS;
67
68 if (start < 0 || start > ITSS_MAX_IRQ ||
69 end < 0 || end > ITSS_MAX_IRQ || end < start)
70 return;
71
72 reg_start = start / IRQS_PER_IPC;
73 reg_end = (end + IRQS_PER_IPC - 1) / IRQS_PER_IPC;
74
75 for (i = reg_start; i < reg_end; i++) {
76 uint16_t reg = PCR_ITSS_IPC0_CONF + sizeof(uint32_t) * i;
77 irq_snapshot[i] = pcr_read32(port, reg);
78 }
79 }
80
81 static void show_irq_polarities(const char *msg)
82 {
83 int i;
84 const uint16_t port = PID_ITSS;
85
86 printk(BIOS_INFO, "ITSS IRQ Polarities %s:\n", msg);
87 for (i = 0; i < NUM_IPC_REGS; i++) {
88 uint16_t reg = PCR_ITSS_IPC0_CONF + sizeof(uint32_t) * i;
89 printk(BIOS_INFO, "IPC%d: 0x%08x\n", i, pcr_read32(port, reg));
90 }
91 }
92
93 void itss_restore_irq_polarities(int start, int end)
94 {
95 int i;
96 int reg_start;
97 int reg_end;
98 const uint16_t port = PID_ITSS;
99
100 if (start < 0 || start > ITSS_MAX_IRQ ||
101 end < 0 || end > ITSS_MAX_IRQ || end < start)
102 return;
103
104 show_irq_polarities("Before");
105
106 reg_start = start / IRQS_PER_IPC;
107 reg_end = (end + IRQS_PER_IPC - 1) / IRQS_PER_IPC;
108
109 for (i = reg_start; i < reg_end; i++) {
110 uint32_t mask;
111 uint16_t reg;
112 int irq_start;
113 int irq_end;
114
115 irq_start = i * IRQS_PER_IPC;
116 irq_end = MIN(irq_start + IRQS_PER_IPC - 1, ITSS_MAX_IRQ);
117
118 if (start > irq_end)
119 continue;
120 if (end < irq_start)
121 break;
122
123 /* Track bits within the bounds of the register. */
124 irq_start = MAX(start, irq_start) % IRQS_PER_IPC;
125 irq_end = MIN(end, irq_end) % IRQS_PER_IPC;
126
127 /* Create bitmask of the inclusive range of start and end. */
128 mask = (((1U << irq_end) - 1) | (1U << irq_end));
129 mask &= ~((1U << irq_start) - 1);
130
131 reg = PCR_ITSS_IPC0_CONF + sizeof(uint32_t) * i;
132 pcr_rmw32(port, reg, ~mask, (mask & irq_snapshot[i]));
133 }
134
135 show_irq_polarities("After");
136 }
137
138 enum pirq itss_get_on_chip_dev_pirq(const struct device *dev, enum pci_pin pin)
139 {
140 /* Check if device is on chip. */
141 if (dev->upstream->dev->path.type != DEVICE_PATH_DOMAIN)
142 return PIRQ_INVALID;
143
144 uint16_t pir = pcr_read16(PID_ITSS, itss_soc_get_on_chip_dev_pir(dev));
145
146 /* The lower 3 bits of every 4 bits indicates which PIRQ is connect to INT. */
147 unsigned int pir_shift = (pin - PCI_INT_A) * 4;
148 unsigned int pir_mask = 0x07;
149 return ((pir >> pir_shift) & pir_mask) + PIRQ_A;
150 }