Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Common routines for Tundra Semiconductor TSI108 host bridge. |
| 4 | * |
| 5 | * 2004-2005 (c) Tundra Semiconductor Corp. |
| 6 | * Author: Alex Bounine (alexandreb@tundra.com) |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 7 | * Author: Roy Zang (tie-fei.zang@freescale.com) |
| 8 | * Add pci interrupt router host |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/pci.h> |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 14 | #include <linux/irq.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 17 | #include <asm/byteorder.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/irq.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 20 | #include <linux/uaccess.h> |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 21 | #include <asm/machdep.h> |
| 22 | #include <asm/pci-bridge.h> |
| 23 | #include <asm/tsi108.h> |
Josh Boyer | 08390db | 2007-05-08 07:25:22 +1000 | [diff] [blame] | 24 | #include <asm/tsi108_pci.h> |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 25 | #include <asm/tsi108_irq.h> |
| 26 | #include <asm/prom.h> |
| 27 | |
| 28 | #undef DEBUG |
| 29 | #ifdef DEBUG |
| 30 | #define DBG(x...) printk(x) |
| 31 | #else |
| 32 | #define DBG(x...) |
| 33 | #endif |
| 34 | |
| 35 | #define tsi_mk_config_addr(bus, devfunc, offset) \ |
| 36 | ((((bus)<<16) | ((devfunc)<<8) | (offset & 0xfc)) + tsi108_pci_cfg_base) |
| 37 | |
| 38 | u32 tsi108_pci_cfg_base; |
Josh Boyer | 05ad6a9 | 2007-05-08 07:27:15 +1000 | [diff] [blame] | 39 | static u32 tsi108_pci_cfg_phys; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 40 | u32 tsi108_csr_vir_base; |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 41 | static struct irq_domain *pci_irq_host; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 42 | |
| 43 | extern u32 get_vir_csrbase(void); |
| 44 | extern u32 tsi108_read_reg(u32 reg_offset); |
| 45 | extern void tsi108_write_reg(u32 reg_offset, u32 val); |
| 46 | |
| 47 | int |
| 48 | tsi108_direct_write_config(struct pci_bus *bus, unsigned int devfunc, |
| 49 | int offset, int len, u32 val) |
| 50 | { |
| 51 | volatile unsigned char *cfg_addr; |
Kumar Gala | bccd6f7 | 2009-04-30 03:10:12 +0000 | [diff] [blame] | 52 | struct pci_controller *hose = pci_bus_to_host(bus); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 53 | |
| 54 | if (ppc_md.pci_exclude_device) |
Kumar Gala | 7d52c7b | 2007-06-22 00:23:57 -0500 | [diff] [blame] | 55 | if (ppc_md.pci_exclude_device(hose, bus->number, devfunc)) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 56 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 57 | |
| 58 | cfg_addr = (unsigned char *)(tsi_mk_config_addr(bus->number, |
| 59 | devfunc, offset) | |
| 60 | (offset & 0x03)); |
| 61 | |
| 62 | #ifdef DEBUG |
| 63 | printk("PCI CFG write : "); |
| 64 | printk("%d:0x%x:0x%x ", bus->number, devfunc, offset); |
| 65 | printk("%d ADDR=0x%08x ", len, (uint) cfg_addr); |
| 66 | printk("data = 0x%08x\n", val); |
| 67 | #endif |
| 68 | |
| 69 | switch (len) { |
| 70 | case 1: |
| 71 | out_8((u8 *) cfg_addr, val); |
| 72 | break; |
| 73 | case 2: |
| 74 | out_le16((u16 *) cfg_addr, val); |
| 75 | break; |
| 76 | default: |
| 77 | out_le32((u32 *) cfg_addr, val); |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | return PCIBIOS_SUCCESSFUL; |
| 82 | } |
| 83 | |
| 84 | void tsi108_clear_pci_error(u32 pci_cfg_base) |
| 85 | { |
| 86 | u32 err_stat, err_addr, pci_stat; |
| 87 | |
| 88 | /* |
| 89 | * Quietly clear PB and PCI error flags set as result |
| 90 | * of PCI/X configuration read requests. |
| 91 | */ |
| 92 | |
| 93 | /* Read PB Error Log Registers */ |
| 94 | |
| 95 | err_stat = tsi108_read_reg(TSI108_PB_OFFSET + TSI108_PB_ERRCS); |
| 96 | err_addr = tsi108_read_reg(TSI108_PB_OFFSET + TSI108_PB_AERR); |
| 97 | |
| 98 | if (err_stat & TSI108_PB_ERRCS_ES) { |
| 99 | /* Clear error flag */ |
| 100 | tsi108_write_reg(TSI108_PB_OFFSET + TSI108_PB_ERRCS, |
| 101 | TSI108_PB_ERRCS_ES); |
| 102 | |
| 103 | /* Clear read error reported in PB_ISR */ |
| 104 | tsi108_write_reg(TSI108_PB_OFFSET + TSI108_PB_ISR, |
| 105 | TSI108_PB_ISR_PBS_RD_ERR); |
| 106 | |
| 107 | /* Clear PCI/X bus cfg errors if applicable */ |
| 108 | if ((err_addr & 0xFF000000) == pci_cfg_base) { |
| 109 | pci_stat = |
| 110 | tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_CSR); |
| 111 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_CSR, |
| 112 | pci_stat); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | #define __tsi108_read_pci_config(x, addr, op) \ |
| 120 | __asm__ __volatile__( \ |
| 121 | " "op" %0,0,%1\n" \ |
| 122 | "1: eieio\n" \ |
| 123 | "2:\n" \ |
| 124 | ".section .fixup,\"ax\"\n" \ |
| 125 | "3: li %0,-1\n" \ |
| 126 | " b 2b\n" \ |
Nicholas Piggin | 24bfa6a | 2016-10-13 16:42:53 +1100 | [diff] [blame] | 127 | ".previous\n" \ |
| 128 | EX_TABLE(1b, 3b) \ |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 129 | : "=r"(x) : "r"(addr)) |
| 130 | |
| 131 | int |
| 132 | tsi108_direct_read_config(struct pci_bus *bus, unsigned int devfn, int offset, |
| 133 | int len, u32 * val) |
| 134 | { |
| 135 | volatile unsigned char *cfg_addr; |
Kumar Gala | bccd6f7 | 2009-04-30 03:10:12 +0000 | [diff] [blame] | 136 | struct pci_controller *hose = pci_bus_to_host(bus); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 137 | u32 temp; |
| 138 | |
| 139 | if (ppc_md.pci_exclude_device) |
Kumar Gala | 7d52c7b | 2007-06-22 00:23:57 -0500 | [diff] [blame] | 140 | if (ppc_md.pci_exclude_device(hose, bus->number, devfn)) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 141 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 142 | |
| 143 | cfg_addr = (unsigned char *)(tsi_mk_config_addr(bus->number, |
| 144 | devfn, |
| 145 | offset) | (offset & |
| 146 | 0x03)); |
| 147 | |
| 148 | switch (len) { |
| 149 | case 1: |
| 150 | __tsi108_read_pci_config(temp, cfg_addr, "lbzx"); |
| 151 | break; |
| 152 | case 2: |
| 153 | __tsi108_read_pci_config(temp, cfg_addr, "lhbrx"); |
| 154 | break; |
| 155 | default: |
| 156 | __tsi108_read_pci_config(temp, cfg_addr, "lwbrx"); |
| 157 | break; |
| 158 | } |
| 159 | |
| 160 | *val = temp; |
| 161 | |
| 162 | #ifdef DEBUG |
| 163 | if ((0xFFFFFFFF != temp) && (0xFFFF != temp) && (0xFF != temp)) { |
| 164 | printk("PCI CFG read : "); |
| 165 | printk("%d:0x%x:0x%x ", bus->number, devfn, offset); |
| 166 | printk("%d ADDR=0x%08x ", len, (uint) cfg_addr); |
| 167 | printk("data = 0x%x\n", *val); |
| 168 | } |
| 169 | #endif |
| 170 | return PCIBIOS_SUCCESSFUL; |
| 171 | } |
| 172 | |
| 173 | void tsi108_clear_pci_cfg_error(void) |
| 174 | { |
Josh Boyer | 05ad6a9 | 2007-05-08 07:27:15 +1000 | [diff] [blame] | 175 | tsi108_clear_pci_error(tsi108_pci_cfg_phys); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static struct pci_ops tsi108_direct_pci_ops = { |
Nathan Lynch | 8935fa0 | 2007-08-10 05:18:46 +1000 | [diff] [blame] | 179 | .read = tsi108_direct_read_config, |
| 180 | .write = tsi108_direct_write_config, |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 181 | }; |
| 182 | |
Josh Boyer | 05ad6a9 | 2007-05-08 07:27:15 +1000 | [diff] [blame] | 183 | int __init tsi108_setup_pci(struct device_node *dev, u32 cfg_phys, int primary) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 184 | { |
| 185 | int len; |
| 186 | struct pci_controller *hose; |
| 187 | struct resource rsrc; |
Jeremy Kerr | 88c8059 | 2006-07-12 15:41:52 +1000 | [diff] [blame] | 188 | const int *bus_range; |
Josh Boyer | 05ad6a9 | 2007-05-08 07:27:15 +1000 | [diff] [blame] | 189 | int has_address = 0; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 190 | |
| 191 | /* PCI Config mapping */ |
Josh Boyer | 05ad6a9 | 2007-05-08 07:27:15 +1000 | [diff] [blame] | 192 | tsi108_pci_cfg_base = (u32)ioremap(cfg_phys, TSI108_PCI_CFG_SIZE); |
| 193 | tsi108_pci_cfg_phys = cfg_phys; |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 194 | DBG("TSI_PCI: %s tsi108_pci_cfg_base=0x%x\n", __func__, |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 195 | tsi108_pci_cfg_base); |
| 196 | |
| 197 | /* Fetch host bridge registers address */ |
| 198 | has_address = (of_address_to_resource(dev, 0, &rsrc) == 0); |
| 199 | |
| 200 | /* Get bus range if any */ |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 201 | bus_range = of_get_property(dev, "bus-range", &len); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 202 | if (bus_range == NULL || len < 2 * sizeof(int)) { |
Rob Herring | b7c670d | 2017-08-21 10:16:47 -0500 | [diff] [blame] | 203 | printk(KERN_WARNING "Can't get bus-range for %pOF, assume" |
| 204 | " bus 0\n", dev); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Kumar Gala | dbf8471 | 2007-06-27 01:56:50 -0500 | [diff] [blame] | 207 | hose = pcibios_alloc_controller(dev); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 208 | |
| 209 | if (!hose) { |
| 210 | printk("PCI Host bridge init failed\n"); |
| 211 | return -ENOMEM; |
| 212 | } |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 213 | |
| 214 | hose->first_busno = bus_range ? bus_range[0] : 0; |
| 215 | hose->last_busno = bus_range ? bus_range[1] : 0xff; |
| 216 | |
| 217 | (hose)->ops = &tsi108_direct_pci_ops; |
| 218 | |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 219 | printk(KERN_INFO "Found tsi108 PCI host bridge at 0x%08x. " |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 220 | "Firmware bus number: %d->%d\n", |
| 221 | rsrc.start, hose->first_busno, hose->last_busno); |
| 222 | |
| 223 | /* Interpret the "ranges" property */ |
| 224 | /* This also maps the I/O region and sets isa_io/mem_base */ |
| 225 | pci_process_bridge_OF_ranges(hose, dev, primary); |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * Low level utility functions |
| 231 | */ |
| 232 | |
| 233 | static void tsi108_pci_int_mask(u_int irq) |
| 234 | { |
| 235 | u_int irp_cfg; |
| 236 | int int_line = (irq - IRQ_PCI_INTAD_BASE); |
| 237 | |
| 238 | irp_cfg = tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL); |
| 239 | mb(); |
| 240 | irp_cfg |= (1 << int_line); /* INTx_DIR = output */ |
| 241 | irp_cfg &= ~(3 << (8 + (int_line * 2))); /* INTx_TYPE = unused */ |
| 242 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL, irp_cfg); |
| 243 | mb(); |
| 244 | irp_cfg = tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL); |
| 245 | } |
| 246 | |
| 247 | static void tsi108_pci_int_unmask(u_int irq) |
| 248 | { |
| 249 | u_int irp_cfg; |
| 250 | int int_line = (irq - IRQ_PCI_INTAD_BASE); |
| 251 | |
| 252 | irp_cfg = tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL); |
| 253 | mb(); |
| 254 | irp_cfg &= ~(1 << int_line); |
| 255 | irp_cfg |= (3 << (8 + (int_line * 2))); |
| 256 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL, irp_cfg); |
| 257 | mb(); |
| 258 | } |
| 259 | |
| 260 | static void init_pci_source(void) |
| 261 | { |
| 262 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL, |
| 263 | 0x0000ff00); |
| 264 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_ENABLE, |
| 265 | TSI108_PCI_IRP_ENABLE_P_INT); |
| 266 | mb(); |
| 267 | } |
| 268 | |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 269 | static inline unsigned int get_pci_source(void) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 270 | { |
| 271 | u_int temp = 0; |
| 272 | int irq = -1; |
| 273 | int i; |
| 274 | u_int pci_irp_stat; |
| 275 | static int mask = 0; |
| 276 | |
| 277 | /* Read PCI/X block interrupt status register */ |
| 278 | pci_irp_stat = tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_STAT); |
| 279 | mb(); |
| 280 | |
| 281 | if (pci_irp_stat & TSI108_PCI_IRP_STAT_P_INT) { |
| 282 | /* Process Interrupt from PCI bus INTA# - INTD# lines */ |
| 283 | temp = |
| 284 | tsi108_read_reg(TSI108_PCI_OFFSET + |
| 285 | TSI108_PCI_IRP_INTAD) & 0xf; |
| 286 | mb(); |
| 287 | for (i = 0; i < 4; i++, mask++) { |
| 288 | if (temp & (1 << mask % 4)) { |
| 289 | irq = IRQ_PCI_INTA + mask % 4; |
| 290 | mask++; |
| 291 | break; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /* Disable interrupts from PCI block */ |
| 296 | temp = tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_ENABLE); |
| 297 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_ENABLE, |
| 298 | temp & ~TSI108_PCI_IRP_ENABLE_P_INT); |
| 299 | mb(); |
| 300 | (void)tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_ENABLE); |
| 301 | mb(); |
| 302 | } |
| 303 | #ifdef DEBUG |
| 304 | else { |
| 305 | printk("TSI108_PIC: error in TSI108_PCI_IRP_STAT\n"); |
| 306 | pci_irp_stat = |
| 307 | tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_STAT); |
| 308 | temp = |
| 309 | tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_INTAD); |
| 310 | mb(); |
| 311 | printk(">> stat=0x%08x intad=0x%08x ", pci_irp_stat, temp); |
| 312 | temp = |
| 313 | tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_CFG_CTL); |
| 314 | mb(); |
| 315 | printk("cfg_ctl=0x%08x ", temp); |
| 316 | temp = |
| 317 | tsi108_read_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_ENABLE); |
| 318 | mb(); |
| 319 | printk("irp_enable=0x%08x\n", temp); |
| 320 | } |
| 321 | #endif /* end of DEBUG */ |
| 322 | |
| 323 | return irq; |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /* |
| 328 | * Linux descriptor level callbacks |
| 329 | */ |
| 330 | |
Lennert Buytenhek | 11afe2b | 2011-03-07 14:00:12 +0000 | [diff] [blame] | 331 | static void tsi108_pci_irq_unmask(struct irq_data *d) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 332 | { |
Lennert Buytenhek | 11afe2b | 2011-03-07 14:00:12 +0000 | [diff] [blame] | 333 | tsi108_pci_int_unmask(d->irq); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 334 | |
| 335 | /* Enable interrupts from PCI block */ |
| 336 | tsi108_write_reg(TSI108_PCI_OFFSET + TSI108_PCI_IRP_ENABLE, |
| 337 | tsi108_read_reg(TSI108_PCI_OFFSET + |
| 338 | TSI108_PCI_IRP_ENABLE) | |
| 339 | TSI108_PCI_IRP_ENABLE_P_INT); |
| 340 | mb(); |
| 341 | } |
| 342 | |
Lennert Buytenhek | 11afe2b | 2011-03-07 14:00:12 +0000 | [diff] [blame] | 343 | static void tsi108_pci_irq_mask(struct irq_data *d) |
| 344 | { |
| 345 | tsi108_pci_int_mask(d->irq); |
| 346 | } |
| 347 | |
| 348 | static void tsi108_pci_irq_ack(struct irq_data *d) |
| 349 | { |
| 350 | tsi108_pci_int_mask(d->irq); |
| 351 | } |
| 352 | |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 353 | /* |
| 354 | * Interrupt controller descriptor for cascaded PCI interrupt controller. |
| 355 | */ |
| 356 | |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 357 | static struct irq_chip tsi108_pci_irq = { |
Thomas Gleixner | b27df67 | 2009-11-18 23:44:21 +0000 | [diff] [blame] | 358 | .name = "tsi108_PCI_int", |
Lennert Buytenhek | 11afe2b | 2011-03-07 14:00:12 +0000 | [diff] [blame] | 359 | .irq_mask = tsi108_pci_irq_mask, |
| 360 | .irq_ack = tsi108_pci_irq_ack, |
| 361 | .irq_unmask = tsi108_pci_irq_unmask, |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 362 | }; |
| 363 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 364 | static int pci_irq_host_xlate(struct irq_domain *h, struct device_node *ct, |
Roman Fietze | 40d50cf | 2009-12-08 02:39:50 +0000 | [diff] [blame] | 365 | const u32 *intspec, unsigned int intsize, |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 366 | irq_hw_number_t *out_hwirq, unsigned int *out_flags) |
| 367 | { |
| 368 | *out_hwirq = intspec[0]; |
| 369 | *out_flags = IRQ_TYPE_LEVEL_HIGH; |
| 370 | return 0; |
| 371 | } |
| 372 | |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 373 | static int pci_irq_host_map(struct irq_domain *h, unsigned int virq, |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 374 | irq_hw_number_t hw) |
| 375 | { unsigned int irq; |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 376 | DBG("%s(%d, 0x%lx)\n", __func__, virq, hw); |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 377 | if ((virq >= 1) && (virq <= 4)){ |
| 378 | irq = virq + IRQ_PCI_INTAD_BASE - 1; |
Thomas Gleixner | 98488db | 2011-03-25 15:43:57 +0100 | [diff] [blame] | 379 | irq_set_status_flags(irq, IRQ_LEVEL); |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 380 | irq_set_chip(irq, &tsi108_pci_irq); |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 381 | } |
| 382 | return 0; |
| 383 | } |
| 384 | |
Krzysztof Kozlowski | 202648a | 2015-04-27 21:48:47 +0900 | [diff] [blame] | 385 | static const struct irq_domain_ops pci_irq_domain_ops = { |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 386 | .map = pci_irq_host_map, |
| 387 | .xlate = pci_irq_host_xlate, |
| 388 | }; |
| 389 | |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 390 | /* |
| 391 | * Exported functions |
| 392 | */ |
| 393 | |
| 394 | /* |
| 395 | * The Tsi108 PCI interrupts initialization routine. |
| 396 | * |
| 397 | * The INTA# - INTD# interrupts on the PCI bus are reported by the PCI block |
| 398 | * to the MPIC using single interrupt source (IRQ_TSI108_PCI). Therefore the |
| 399 | * PCI block has to be treated as a cascaded interrupt controller connected |
| 400 | * to the MPIC. |
| 401 | */ |
| 402 | |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 403 | void __init tsi108_pci_int_init(struct device_node *node) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 404 | { |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 405 | DBG("Tsi108_pci_int_init: initializing PCI interrupts\n"); |
| 406 | |
Grant Likely | 1bc04f2 | 2012-02-14 14:06:55 -0700 | [diff] [blame] | 407 | pci_irq_host = irq_domain_add_legacy_isa(node, &pci_irq_domain_ops, NULL); |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 408 | if (pci_irq_host == NULL) { |
Grant Likely | bae1d8f | 2012-02-14 14:06:50 -0700 | [diff] [blame] | 409 | printk(KERN_ERR "pci_irq_host: failed to allocate irq domain!\n"); |
Zang Roy-r61911 | 5873c9b | 2006-11-14 14:31:50 +0800 | [diff] [blame] | 410 | return; |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | init_pci_source(); |
| 414 | } |
| 415 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 416 | void tsi108_irq_cascade(struct irq_desc *desc) |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 417 | { |
Thomas Gleixner | ec775d0 | 2011-03-25 16:45:20 +0100 | [diff] [blame] | 418 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Zang Roy-r61911 | c4342ff | 2006-08-23 10:19:50 +0800 | [diff] [blame] | 419 | unsigned int cascade_irq = get_pci_source(); |
Lennert Buytenhek | 11afe2b | 2011-03-07 14:00:12 +0000 | [diff] [blame] | 420 | |
Michael Ellerman | ef24ba7 | 2016-09-06 21:53:24 +1000 | [diff] [blame] | 421 | if (cascade_irq) |
Olof Johansson | 49f19ce | 2006-10-05 20:31:10 -0500 | [diff] [blame] | 422 | generic_handle_irq(cascade_irq); |
Lennert Buytenhek | 11afe2b | 2011-03-07 14:00:12 +0000 | [diff] [blame] | 423 | |
| 424 | chip->irq_eoi(&desc->irq_data); |
Zang Roy-r61911 | 2b9d746 | 2006-06-13 15:07:23 +0800 | [diff] [blame] | 425 | } |