18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2003 Christoph Hellwig (hch@lst.de) 48c2ecf20Sopenharmony_ci * Copyright (C) 1999, 2000, 04 Ralf Baechle (ralf@linux-mips.org) 58c2ecf20Sopenharmony_ci * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#include <linux/kernel.h> 88c2ecf20Sopenharmony_ci#include <linux/export.h> 98c2ecf20Sopenharmony_ci#include <linux/pci.h> 108c2ecf20Sopenharmony_ci#include <linux/smp.h> 118c2ecf20Sopenharmony_ci#include <linux/dma-direct.h> 128c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 138c2ecf20Sopenharmony_ci#include <linux/platform_data/xtalk-bridge.h> 148c2ecf20Sopenharmony_ci#include <linux/nvmem-consumer.h> 158c2ecf20Sopenharmony_ci#include <linux/crc16.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <asm/pci/bridge.h> 188c2ecf20Sopenharmony_ci#include <asm/paccess.h> 198c2ecf20Sopenharmony_ci#include <asm/sn/irq_alloc.h> 208c2ecf20Sopenharmony_ci#include <asm/sn/ioc3.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define CRC16_INIT 0 238c2ecf20Sopenharmony_ci#define CRC16_VALID 0xb001 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * Common phys<->dma mapping for platforms using pci xtalk bridge 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_cidma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci struct pci_dev *pdev = to_pci_dev(dev); 318c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(pdev->bus); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci return bc->baddr + paddr; 348c2ecf20Sopenharmony_ci} 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciphys_addr_t dma_to_phys(struct device *dev, dma_addr_t dma_addr) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci return dma_addr & ~(0xffUL << 56); 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * Most of the IOC3 PCI config register aren't present 438c2ecf20Sopenharmony_ci * we emulate what is needed for a normal PCI enumeration 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_cistatic int ioc3_cfg_rd(void *addr, int where, int size, u32 *value, u32 sid) 468c2ecf20Sopenharmony_ci{ 478c2ecf20Sopenharmony_ci u32 cf, shift, mask; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci switch (where & ~3) { 508c2ecf20Sopenharmony_ci case 0x00 ... 0x10: 518c2ecf20Sopenharmony_ci case 0x40 ... 0x44: 528c2ecf20Sopenharmony_ci if (get_dbe(cf, (u32 *)addr)) 538c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 548c2ecf20Sopenharmony_ci break; 558c2ecf20Sopenharmony_ci case 0x2c: 568c2ecf20Sopenharmony_ci cf = sid; 578c2ecf20Sopenharmony_ci break; 588c2ecf20Sopenharmony_ci case 0x3c: 598c2ecf20Sopenharmony_ci /* emulate sane interrupt pin value */ 608c2ecf20Sopenharmony_ci cf = 0x00000100; 618c2ecf20Sopenharmony_ci break; 628c2ecf20Sopenharmony_ci default: 638c2ecf20Sopenharmony_ci cf = 0; 648c2ecf20Sopenharmony_ci break; 658c2ecf20Sopenharmony_ci } 668c2ecf20Sopenharmony_ci shift = (where & 3) << 3; 678c2ecf20Sopenharmony_ci mask = 0xffffffffU >> ((4 - size) << 3); 688c2ecf20Sopenharmony_ci *value = (cf >> shift) & mask; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic int ioc3_cfg_wr(void *addr, int where, int size, u32 value) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci u32 cf, shift, mask, smask; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci if ((where >= 0x14 && where < 0x40) || (where >= 0x48)) 788c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci if (get_dbe(cf, (u32 *)addr)) 818c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci shift = ((where & 3) << 3); 848c2ecf20Sopenharmony_ci mask = (0xffffffffU >> ((4 - size) << 3)); 858c2ecf20Sopenharmony_ci smask = mask << shift; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci cf = (cf & ~smask) | ((value & mask) << shift); 888c2ecf20Sopenharmony_ci if (put_dbe(cf, (u32 *)addr)) 898c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 928c2ecf20Sopenharmony_ci} 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_cistatic void bridge_disable_swapping(struct pci_dev *dev) 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus); 978c2ecf20Sopenharmony_ci int slot = PCI_SLOT(dev->devfn); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci /* Turn off byte swapping */ 1008c2ecf20Sopenharmony_ci bridge_clr(bc, b_device[slot].reg, BRIDGE_DEV_SWAP_DIR); 1018c2ecf20Sopenharmony_ci bridge_read(bc, b_widget.w_tflush); /* Flush */ 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ciDECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_IOC3, 1058c2ecf20Sopenharmony_ci bridge_disable_swapping); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* 1098c2ecf20Sopenharmony_ci * The Bridge ASIC supports both type 0 and type 1 access. Type 1 is 1108c2ecf20Sopenharmony_ci * not really documented, so right now I can't write code which uses it. 1118c2ecf20Sopenharmony_ci * Therefore we use type 0 accesses for now even though they won't work 1128c2ecf20Sopenharmony_ci * correctly for PCI-to-PCI bridges. 1138c2ecf20Sopenharmony_ci * 1148c2ecf20Sopenharmony_ci * The function is complicated by the ultimate brokenness of the IOC3 chip 1158c2ecf20Sopenharmony_ci * which is used in SGI systems. The IOC3 can only handle 32-bit PCI 1168c2ecf20Sopenharmony_ci * accesses and does only decode parts of it's address space. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_cistatic int pci_conf0_read_config(struct pci_bus *bus, unsigned int devfn, 1198c2ecf20Sopenharmony_ci int where, int size, u32 *value) 1208c2ecf20Sopenharmony_ci{ 1218c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(bus); 1228c2ecf20Sopenharmony_ci struct bridge_regs *bridge = bc->base; 1238c2ecf20Sopenharmony_ci int slot = PCI_SLOT(devfn); 1248c2ecf20Sopenharmony_ci int fn = PCI_FUNC(devfn); 1258c2ecf20Sopenharmony_ci void *addr; 1268c2ecf20Sopenharmony_ci u32 cf; 1278c2ecf20Sopenharmony_ci int res; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[PCI_VENDOR_ID]; 1308c2ecf20Sopenharmony_ci if (get_dbe(cf, (u32 *)addr)) 1318c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* 1348c2ecf20Sopenharmony_ci * IOC3 is broken beyond belief ... Don't even give the 1358c2ecf20Sopenharmony_ci * generic PCI code a chance to look at it for real ... 1368c2ecf20Sopenharmony_ci */ 1378c2ecf20Sopenharmony_ci if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16))) { 1388c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2]; 1398c2ecf20Sopenharmony_ci return ioc3_cfg_rd(addr, where, size, value, 1408c2ecf20Sopenharmony_ci bc->ioc3_sid[slot]); 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[where ^ (4 - size)]; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci if (size == 1) 1468c2ecf20Sopenharmony_ci res = get_dbe(*value, (u8 *)addr); 1478c2ecf20Sopenharmony_ci else if (size == 2) 1488c2ecf20Sopenharmony_ci res = get_dbe(*value, (u16 *)addr); 1498c2ecf20Sopenharmony_ci else 1508c2ecf20Sopenharmony_ci res = get_dbe(*value, (u32 *)addr); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci return res ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL; 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic int pci_conf1_read_config(struct pci_bus *bus, unsigned int devfn, 1568c2ecf20Sopenharmony_ci int where, int size, u32 *value) 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(bus); 1598c2ecf20Sopenharmony_ci struct bridge_regs *bridge = bc->base; 1608c2ecf20Sopenharmony_ci int busno = bus->number; 1618c2ecf20Sopenharmony_ci int slot = PCI_SLOT(devfn); 1628c2ecf20Sopenharmony_ci int fn = PCI_FUNC(devfn); 1638c2ecf20Sopenharmony_ci void *addr; 1648c2ecf20Sopenharmony_ci u32 cf; 1658c2ecf20Sopenharmony_ci int res; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci bridge_write(bc, b_pci_cfg, (busno << 16) | (slot << 11)); 1688c2ecf20Sopenharmony_ci addr = &bridge->b_type1_cfg.c[(fn << 8) | PCI_VENDOR_ID]; 1698c2ecf20Sopenharmony_ci if (get_dbe(cf, (u32 *)addr)) 1708c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci /* 1738c2ecf20Sopenharmony_ci * IOC3 is broken beyond belief ... Don't even give the 1748c2ecf20Sopenharmony_ci * generic PCI code a chance to look at it for real ... 1758c2ecf20Sopenharmony_ci */ 1768c2ecf20Sopenharmony_ci if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16))) { 1778c2ecf20Sopenharmony_ci addr = &bridge->b_type1_cfg.c[(fn << 8) | (where & ~3)]; 1788c2ecf20Sopenharmony_ci return ioc3_cfg_rd(addr, where, size, value, 1798c2ecf20Sopenharmony_ci bc->ioc3_sid[slot]); 1808c2ecf20Sopenharmony_ci } 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci addr = &bridge->b_type1_cfg.c[(fn << 8) | (where ^ (4 - size))]; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci if (size == 1) 1858c2ecf20Sopenharmony_ci res = get_dbe(*value, (u8 *)addr); 1868c2ecf20Sopenharmony_ci else if (size == 2) 1878c2ecf20Sopenharmony_ci res = get_dbe(*value, (u16 *)addr); 1888c2ecf20Sopenharmony_ci else 1898c2ecf20Sopenharmony_ci res = get_dbe(*value, (u32 *)addr); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci return res ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL; 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic int pci_read_config(struct pci_bus *bus, unsigned int devfn, 1958c2ecf20Sopenharmony_ci int where, int size, u32 *value) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci if (!pci_is_root_bus(bus)) 1988c2ecf20Sopenharmony_ci return pci_conf1_read_config(bus, devfn, where, size, value); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci return pci_conf0_read_config(bus, devfn, where, size, value); 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic int pci_conf0_write_config(struct pci_bus *bus, unsigned int devfn, 2048c2ecf20Sopenharmony_ci int where, int size, u32 value) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(bus); 2078c2ecf20Sopenharmony_ci struct bridge_regs *bridge = bc->base; 2088c2ecf20Sopenharmony_ci int slot = PCI_SLOT(devfn); 2098c2ecf20Sopenharmony_ci int fn = PCI_FUNC(devfn); 2108c2ecf20Sopenharmony_ci void *addr; 2118c2ecf20Sopenharmony_ci u32 cf; 2128c2ecf20Sopenharmony_ci int res; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[PCI_VENDOR_ID]; 2158c2ecf20Sopenharmony_ci if (get_dbe(cf, (u32 *)addr)) 2168c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci /* 2198c2ecf20Sopenharmony_ci * IOC3 is broken beyond belief ... Don't even give the 2208c2ecf20Sopenharmony_ci * generic PCI code a chance to look at it for real ... 2218c2ecf20Sopenharmony_ci */ 2228c2ecf20Sopenharmony_ci if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16))) { 2238c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2]; 2248c2ecf20Sopenharmony_ci return ioc3_cfg_wr(addr, where, size, value); 2258c2ecf20Sopenharmony_ci } 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].c[where ^ (4 - size)]; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci if (size == 1) 2308c2ecf20Sopenharmony_ci res = put_dbe(value, (u8 *)addr); 2318c2ecf20Sopenharmony_ci else if (size == 2) 2328c2ecf20Sopenharmony_ci res = put_dbe(value, (u16 *)addr); 2338c2ecf20Sopenharmony_ci else 2348c2ecf20Sopenharmony_ci res = put_dbe(value, (u32 *)addr); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci if (res) 2378c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 2408c2ecf20Sopenharmony_ci} 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistatic int pci_conf1_write_config(struct pci_bus *bus, unsigned int devfn, 2438c2ecf20Sopenharmony_ci int where, int size, u32 value) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(bus); 2468c2ecf20Sopenharmony_ci struct bridge_regs *bridge = bc->base; 2478c2ecf20Sopenharmony_ci int slot = PCI_SLOT(devfn); 2488c2ecf20Sopenharmony_ci int fn = PCI_FUNC(devfn); 2498c2ecf20Sopenharmony_ci int busno = bus->number; 2508c2ecf20Sopenharmony_ci void *addr; 2518c2ecf20Sopenharmony_ci u32 cf; 2528c2ecf20Sopenharmony_ci int res; 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci bridge_write(bc, b_pci_cfg, (busno << 16) | (slot << 11)); 2558c2ecf20Sopenharmony_ci addr = &bridge->b_type1_cfg.c[(fn << 8) | PCI_VENDOR_ID]; 2568c2ecf20Sopenharmony_ci if (get_dbe(cf, (u32 *)addr)) 2578c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci /* 2608c2ecf20Sopenharmony_ci * IOC3 is broken beyond belief ... Don't even give the 2618c2ecf20Sopenharmony_ci * generic PCI code a chance to look at it for real ... 2628c2ecf20Sopenharmony_ci */ 2638c2ecf20Sopenharmony_ci if (cf == (PCI_VENDOR_ID_SGI | (PCI_DEVICE_ID_SGI_IOC3 << 16))) { 2648c2ecf20Sopenharmony_ci addr = &bridge->b_type0_cfg_dev[slot].f[fn].l[where >> 2]; 2658c2ecf20Sopenharmony_ci return ioc3_cfg_wr(addr, where, size, value); 2668c2ecf20Sopenharmony_ci } 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci addr = &bridge->b_type1_cfg.c[(fn << 8) | (where ^ (4 - size))]; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci if (size == 1) 2718c2ecf20Sopenharmony_ci res = put_dbe(value, (u8 *)addr); 2728c2ecf20Sopenharmony_ci else if (size == 2) 2738c2ecf20Sopenharmony_ci res = put_dbe(value, (u16 *)addr); 2748c2ecf20Sopenharmony_ci else 2758c2ecf20Sopenharmony_ci res = put_dbe(value, (u32 *)addr); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci if (res) 2788c2ecf20Sopenharmony_ci return PCIBIOS_DEVICE_NOT_FOUND; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci return PCIBIOS_SUCCESSFUL; 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic int pci_write_config(struct pci_bus *bus, unsigned int devfn, 2848c2ecf20Sopenharmony_ci int where, int size, u32 value) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci if (!pci_is_root_bus(bus)) 2878c2ecf20Sopenharmony_ci return pci_conf1_write_config(bus, devfn, where, size, value); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci return pci_conf0_write_config(bus, devfn, where, size, value); 2908c2ecf20Sopenharmony_ci} 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_cistatic struct pci_ops bridge_pci_ops = { 2938c2ecf20Sopenharmony_ci .read = pci_read_config, 2948c2ecf20Sopenharmony_ci .write = pci_write_config, 2958c2ecf20Sopenharmony_ci}; 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_cistruct bridge_irq_chip_data { 2988c2ecf20Sopenharmony_ci struct bridge_controller *bc; 2998c2ecf20Sopenharmony_ci nasid_t nasid; 3008c2ecf20Sopenharmony_ci}; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_cistatic int bridge_set_affinity(struct irq_data *d, const struct cpumask *mask, 3038c2ecf20Sopenharmony_ci bool force) 3048c2ecf20Sopenharmony_ci{ 3058c2ecf20Sopenharmony_ci#ifdef CONFIG_NUMA 3068c2ecf20Sopenharmony_ci struct bridge_irq_chip_data *data = d->chip_data; 3078c2ecf20Sopenharmony_ci int bit = d->parent_data->hwirq; 3088c2ecf20Sopenharmony_ci int pin = d->hwirq; 3098c2ecf20Sopenharmony_ci int ret, cpu; 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci ret = irq_chip_set_affinity_parent(d, mask, force); 3128c2ecf20Sopenharmony_ci if (ret >= 0) { 3138c2ecf20Sopenharmony_ci cpu = cpumask_first_and(mask, cpu_online_mask); 3148c2ecf20Sopenharmony_ci data->nasid = cpu_to_node(cpu); 3158c2ecf20Sopenharmony_ci bridge_write(data->bc, b_int_addr[pin].addr, 3168c2ecf20Sopenharmony_ci (((data->bc->intr_addr >> 30) & 0x30000) | 3178c2ecf20Sopenharmony_ci bit | (data->nasid << 8))); 3188c2ecf20Sopenharmony_ci bridge_read(data->bc, b_wid_tflush); 3198c2ecf20Sopenharmony_ci } 3208c2ecf20Sopenharmony_ci return ret; 3218c2ecf20Sopenharmony_ci#else 3228c2ecf20Sopenharmony_ci return irq_chip_set_affinity_parent(d, mask, force); 3238c2ecf20Sopenharmony_ci#endif 3248c2ecf20Sopenharmony_ci} 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_cistruct irq_chip bridge_irq_chip = { 3278c2ecf20Sopenharmony_ci .name = "BRIDGE", 3288c2ecf20Sopenharmony_ci .irq_mask = irq_chip_mask_parent, 3298c2ecf20Sopenharmony_ci .irq_unmask = irq_chip_unmask_parent, 3308c2ecf20Sopenharmony_ci .irq_set_affinity = bridge_set_affinity 3318c2ecf20Sopenharmony_ci}; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_cistatic int bridge_domain_alloc(struct irq_domain *domain, unsigned int virq, 3348c2ecf20Sopenharmony_ci unsigned int nr_irqs, void *arg) 3358c2ecf20Sopenharmony_ci{ 3368c2ecf20Sopenharmony_ci struct bridge_irq_chip_data *data; 3378c2ecf20Sopenharmony_ci struct irq_alloc_info *info = arg; 3388c2ecf20Sopenharmony_ci int ret; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci if (nr_irqs > 1 || !info) 3418c2ecf20Sopenharmony_ci return -EINVAL; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci data = kzalloc(sizeof(*data), GFP_KERNEL); 3448c2ecf20Sopenharmony_ci if (!data) 3458c2ecf20Sopenharmony_ci return -ENOMEM; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, arg); 3488c2ecf20Sopenharmony_ci if (ret >= 0) { 3498c2ecf20Sopenharmony_ci data->bc = info->ctrl; 3508c2ecf20Sopenharmony_ci data->nasid = info->nasid; 3518c2ecf20Sopenharmony_ci irq_domain_set_info(domain, virq, info->pin, &bridge_irq_chip, 3528c2ecf20Sopenharmony_ci data, handle_level_irq, NULL, NULL); 3538c2ecf20Sopenharmony_ci } else { 3548c2ecf20Sopenharmony_ci kfree(data); 3558c2ecf20Sopenharmony_ci } 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci return ret; 3588c2ecf20Sopenharmony_ci} 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_cistatic void bridge_domain_free(struct irq_domain *domain, unsigned int virq, 3618c2ecf20Sopenharmony_ci unsigned int nr_irqs) 3628c2ecf20Sopenharmony_ci{ 3638c2ecf20Sopenharmony_ci struct irq_data *irqd = irq_domain_get_irq_data(domain, virq); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci if (nr_irqs) 3668c2ecf20Sopenharmony_ci return; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci kfree(irqd->chip_data); 3698c2ecf20Sopenharmony_ci irq_domain_free_irqs_top(domain, virq, nr_irqs); 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistatic int bridge_domain_activate(struct irq_domain *domain, 3738c2ecf20Sopenharmony_ci struct irq_data *irqd, bool reserve) 3748c2ecf20Sopenharmony_ci{ 3758c2ecf20Sopenharmony_ci struct bridge_irq_chip_data *data = irqd->chip_data; 3768c2ecf20Sopenharmony_ci struct bridge_controller *bc = data->bc; 3778c2ecf20Sopenharmony_ci int bit = irqd->parent_data->hwirq; 3788c2ecf20Sopenharmony_ci int pin = irqd->hwirq; 3798c2ecf20Sopenharmony_ci u32 device; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci bridge_write(bc, b_int_addr[pin].addr, 3828c2ecf20Sopenharmony_ci (((bc->intr_addr >> 30) & 0x30000) | 3838c2ecf20Sopenharmony_ci bit | (data->nasid << 8))); 3848c2ecf20Sopenharmony_ci bridge_set(bc, b_int_enable, (1 << pin)); 3858c2ecf20Sopenharmony_ci bridge_set(bc, b_int_enable, 0x7ffffe00); /* more stuff in int_enable */ 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci /* 3888c2ecf20Sopenharmony_ci * Enable sending of an interrupt clear packt to the hub on a high to 3898c2ecf20Sopenharmony_ci * low transition of the interrupt pin. 3908c2ecf20Sopenharmony_ci * 3918c2ecf20Sopenharmony_ci * IRIX sets additional bits in the address which are documented as 3928c2ecf20Sopenharmony_ci * reserved in the bridge docs. 3938c2ecf20Sopenharmony_ci */ 3948c2ecf20Sopenharmony_ci bridge_set(bc, b_int_mode, (1UL << pin)); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci /* 3978c2ecf20Sopenharmony_ci * We assume the bridge to have a 1:1 mapping between devices 3988c2ecf20Sopenharmony_ci * (slots) and intr pins. 3998c2ecf20Sopenharmony_ci */ 4008c2ecf20Sopenharmony_ci device = bridge_read(bc, b_int_device); 4018c2ecf20Sopenharmony_ci device &= ~(7 << (pin*3)); 4028c2ecf20Sopenharmony_ci device |= (pin << (pin*3)); 4038c2ecf20Sopenharmony_ci bridge_write(bc, b_int_device, device); 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci bridge_read(bc, b_wid_tflush); 4068c2ecf20Sopenharmony_ci return 0; 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic void bridge_domain_deactivate(struct irq_domain *domain, 4108c2ecf20Sopenharmony_ci struct irq_data *irqd) 4118c2ecf20Sopenharmony_ci{ 4128c2ecf20Sopenharmony_ci struct bridge_irq_chip_data *data = irqd->chip_data; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci bridge_clr(data->bc, b_int_enable, (1 << irqd->hwirq)); 4158c2ecf20Sopenharmony_ci bridge_read(data->bc, b_wid_tflush); 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_cistatic const struct irq_domain_ops bridge_domain_ops = { 4198c2ecf20Sopenharmony_ci .alloc = bridge_domain_alloc, 4208c2ecf20Sopenharmony_ci .free = bridge_domain_free, 4218c2ecf20Sopenharmony_ci .activate = bridge_domain_activate, 4228c2ecf20Sopenharmony_ci .deactivate = bridge_domain_deactivate 4238c2ecf20Sopenharmony_ci}; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci/* 4268c2ecf20Sopenharmony_ci * All observed requests have pin == 1. We could have a global here, that 4278c2ecf20Sopenharmony_ci * gets incremented and returned every time - unfortunately, pci_map_irq 4288c2ecf20Sopenharmony_ci * may be called on the same device over and over, and need to return the 4298c2ecf20Sopenharmony_ci * same value. On O2000, pin can be 0 or 1, and PCI slots can be [0..7]. 4308c2ecf20Sopenharmony_ci * 4318c2ecf20Sopenharmony_ci * A given PCI device, in general, should be able to intr any of the cpus 4328c2ecf20Sopenharmony_ci * on any one of the hubs connected to its xbow. 4338c2ecf20Sopenharmony_ci */ 4348c2ecf20Sopenharmony_cistatic int bridge_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(dev->bus); 4378c2ecf20Sopenharmony_ci struct irq_alloc_info info; 4388c2ecf20Sopenharmony_ci int irq; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci switch (pin) { 4418c2ecf20Sopenharmony_ci case PCI_INTERRUPT_UNKNOWN: 4428c2ecf20Sopenharmony_ci case PCI_INTERRUPT_INTA: 4438c2ecf20Sopenharmony_ci case PCI_INTERRUPT_INTC: 4448c2ecf20Sopenharmony_ci pin = 0; 4458c2ecf20Sopenharmony_ci break; 4468c2ecf20Sopenharmony_ci case PCI_INTERRUPT_INTB: 4478c2ecf20Sopenharmony_ci case PCI_INTERRUPT_INTD: 4488c2ecf20Sopenharmony_ci pin = 1; 4498c2ecf20Sopenharmony_ci } 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci irq = bc->pci_int[slot][pin]; 4528c2ecf20Sopenharmony_ci if (irq == -1) { 4538c2ecf20Sopenharmony_ci info.ctrl = bc; 4548c2ecf20Sopenharmony_ci info.nasid = bc->nasid; 4558c2ecf20Sopenharmony_ci info.pin = bc->int_mapping[slot][pin]; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci irq = irq_domain_alloc_irqs(bc->domain, 1, bc->nasid, &info); 4588c2ecf20Sopenharmony_ci if (irq < 0) 4598c2ecf20Sopenharmony_ci return irq; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci bc->pci_int[slot][pin] = irq; 4628c2ecf20Sopenharmony_ci } 4638c2ecf20Sopenharmony_ci return irq; 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci#define IOC3_SID(sid) (PCI_VENDOR_ID_SGI | ((sid) << 16)) 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_cistatic void bridge_setup_ip27_baseio6g(struct bridge_controller *bc) 4698c2ecf20Sopenharmony_ci{ 4708c2ecf20Sopenharmony_ci bc->ioc3_sid[2] = IOC3_SID(IOC3_SUBSYS_IP27_BASEIO6G); 4718c2ecf20Sopenharmony_ci bc->ioc3_sid[6] = IOC3_SID(IOC3_SUBSYS_IP27_MIO); 4728c2ecf20Sopenharmony_ci bc->int_mapping[2][1] = 4; 4738c2ecf20Sopenharmony_ci bc->int_mapping[6][1] = 6; 4748c2ecf20Sopenharmony_ci} 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_cistatic void bridge_setup_ip27_baseio(struct bridge_controller *bc) 4778c2ecf20Sopenharmony_ci{ 4788c2ecf20Sopenharmony_ci bc->ioc3_sid[2] = IOC3_SID(IOC3_SUBSYS_IP27_BASEIO); 4798c2ecf20Sopenharmony_ci bc->int_mapping[2][1] = 4; 4808c2ecf20Sopenharmony_ci} 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_cistatic void bridge_setup_ip29_baseio(struct bridge_controller *bc) 4838c2ecf20Sopenharmony_ci{ 4848c2ecf20Sopenharmony_ci bc->ioc3_sid[2] = IOC3_SID(IOC3_SUBSYS_IP29_SYSBOARD); 4858c2ecf20Sopenharmony_ci bc->int_mapping[2][1] = 3; 4868c2ecf20Sopenharmony_ci} 4878c2ecf20Sopenharmony_ci 4888c2ecf20Sopenharmony_cistatic void bridge_setup_ip30_sysboard(struct bridge_controller *bc) 4898c2ecf20Sopenharmony_ci{ 4908c2ecf20Sopenharmony_ci bc->ioc3_sid[2] = IOC3_SID(IOC3_SUBSYS_IP30_SYSBOARD); 4918c2ecf20Sopenharmony_ci bc->int_mapping[2][1] = 4; 4928c2ecf20Sopenharmony_ci} 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_cistatic void bridge_setup_menet(struct bridge_controller *bc) 4958c2ecf20Sopenharmony_ci{ 4968c2ecf20Sopenharmony_ci bc->ioc3_sid[0] = IOC3_SID(IOC3_SUBSYS_MENET); 4978c2ecf20Sopenharmony_ci bc->ioc3_sid[1] = IOC3_SID(IOC3_SUBSYS_MENET); 4988c2ecf20Sopenharmony_ci bc->ioc3_sid[2] = IOC3_SID(IOC3_SUBSYS_MENET); 4998c2ecf20Sopenharmony_ci bc->ioc3_sid[3] = IOC3_SID(IOC3_SUBSYS_MENET4); 5008c2ecf20Sopenharmony_ci} 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistatic void bridge_setup_io7(struct bridge_controller *bc) 5038c2ecf20Sopenharmony_ci{ 5048c2ecf20Sopenharmony_ci bc->ioc3_sid[4] = IOC3_SID(IOC3_SUBSYS_IO7); 5058c2ecf20Sopenharmony_ci} 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_cistatic void bridge_setup_io8(struct bridge_controller *bc) 5088c2ecf20Sopenharmony_ci{ 5098c2ecf20Sopenharmony_ci bc->ioc3_sid[4] = IOC3_SID(IOC3_SUBSYS_IO8); 5108c2ecf20Sopenharmony_ci} 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_cistatic void bridge_setup_io9(struct bridge_controller *bc) 5138c2ecf20Sopenharmony_ci{ 5148c2ecf20Sopenharmony_ci bc->ioc3_sid[1] = IOC3_SID(IOC3_SUBSYS_IO9); 5158c2ecf20Sopenharmony_ci} 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_cistatic void bridge_setup_ip34_fuel_sysboard(struct bridge_controller *bc) 5188c2ecf20Sopenharmony_ci{ 5198c2ecf20Sopenharmony_ci bc->ioc3_sid[4] = IOC3_SID(IOC3_SUBSYS_IP34_SYSBOARD); 5208c2ecf20Sopenharmony_ci} 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci#define BRIDGE_BOARD_SETUP(_partno, _setup) \ 5238c2ecf20Sopenharmony_ci { .match = _partno, .setup = _setup } 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_cistatic const struct { 5268c2ecf20Sopenharmony_ci char *match; 5278c2ecf20Sopenharmony_ci void (*setup)(struct bridge_controller *bc); 5288c2ecf20Sopenharmony_ci} bridge_ioc3_devid[] = { 5298c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-0734-", bridge_setup_ip27_baseio6g), 5308c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-0880-", bridge_setup_ip27_baseio6g), 5318c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1023-", bridge_setup_ip27_baseio), 5328c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1124-", bridge_setup_ip27_baseio), 5338c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1025-", bridge_setup_ip29_baseio), 5348c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1244-", bridge_setup_ip29_baseio), 5358c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1389-", bridge_setup_ip29_baseio), 5368c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-0887-", bridge_setup_ip30_sysboard), 5378c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1467-", bridge_setup_ip30_sysboard), 5388c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-0873-", bridge_setup_menet), 5398c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1557-", bridge_setup_io7), 5408c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1673-", bridge_setup_io8), 5418c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1771-", bridge_setup_io9), 5428c2ecf20Sopenharmony_ci BRIDGE_BOARD_SETUP("030-1707-", bridge_setup_ip34_fuel_sysboard), 5438c2ecf20Sopenharmony_ci}; 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_cistatic void bridge_setup_board(struct bridge_controller *bc, char *partnum) 5468c2ecf20Sopenharmony_ci{ 5478c2ecf20Sopenharmony_ci int i; 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(bridge_ioc3_devid); i++) 5508c2ecf20Sopenharmony_ci if (!strncmp(partnum, bridge_ioc3_devid[i].match, 5518c2ecf20Sopenharmony_ci strlen(bridge_ioc3_devid[i].match))) { 5528c2ecf20Sopenharmony_ci bridge_ioc3_devid[i].setup(bc); 5538c2ecf20Sopenharmony_ci } 5548c2ecf20Sopenharmony_ci} 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_cistatic int bridge_nvmem_match(struct device *dev, const void *data) 5578c2ecf20Sopenharmony_ci{ 5588c2ecf20Sopenharmony_ci const char *name = dev_name(dev); 5598c2ecf20Sopenharmony_ci const char *prefix = data; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci if (strlen(name) < strlen(prefix)) 5628c2ecf20Sopenharmony_ci return 0; 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci return memcmp(prefix, dev_name(dev), strlen(prefix)) == 0; 5658c2ecf20Sopenharmony_ci} 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_cistatic int bridge_get_partnum(u64 baddr, char *partnum) 5688c2ecf20Sopenharmony_ci{ 5698c2ecf20Sopenharmony_ci struct nvmem_device *nvmem; 5708c2ecf20Sopenharmony_ci char prefix[24]; 5718c2ecf20Sopenharmony_ci u8 prom[64]; 5728c2ecf20Sopenharmony_ci int i, j; 5738c2ecf20Sopenharmony_ci int ret; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci snprintf(prefix, sizeof(prefix), "bridge-%012llx-0b-", baddr); 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci nvmem = nvmem_device_find(prefix, bridge_nvmem_match); 5788c2ecf20Sopenharmony_ci if (IS_ERR(nvmem)) 5798c2ecf20Sopenharmony_ci return PTR_ERR(nvmem); 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci ret = nvmem_device_read(nvmem, 0, 64, prom); 5828c2ecf20Sopenharmony_ci nvmem_device_put(nvmem); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci if (ret != 64) 5858c2ecf20Sopenharmony_ci return ret; 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci if (crc16(CRC16_INIT, prom, 32) != CRC16_VALID || 5888c2ecf20Sopenharmony_ci crc16(CRC16_INIT, prom + 32, 32) != CRC16_VALID) 5898c2ecf20Sopenharmony_ci return -EINVAL; 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci /* Assemble part number */ 5928c2ecf20Sopenharmony_ci j = 0; 5938c2ecf20Sopenharmony_ci for (i = 0; i < 19; i++) 5948c2ecf20Sopenharmony_ci if (prom[i + 11] != ' ') 5958c2ecf20Sopenharmony_ci partnum[j++] = prom[i + 11]; 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci for (i = 0; i < 6; i++) 5988c2ecf20Sopenharmony_ci if (prom[i + 32] != ' ') 5998c2ecf20Sopenharmony_ci partnum[j++] = prom[i + 32]; 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci partnum[j] = 0; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci return 0; 6048c2ecf20Sopenharmony_ci} 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_cistatic int bridge_probe(struct platform_device *pdev) 6078c2ecf20Sopenharmony_ci{ 6088c2ecf20Sopenharmony_ci struct xtalk_bridge_platform_data *bd = dev_get_platdata(&pdev->dev); 6098c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 6108c2ecf20Sopenharmony_ci struct bridge_controller *bc; 6118c2ecf20Sopenharmony_ci struct pci_host_bridge *host; 6128c2ecf20Sopenharmony_ci struct irq_domain *domain, *parent; 6138c2ecf20Sopenharmony_ci struct fwnode_handle *fn; 6148c2ecf20Sopenharmony_ci char partnum[26]; 6158c2ecf20Sopenharmony_ci int slot; 6168c2ecf20Sopenharmony_ci int err; 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci /* get part number from one wire prom */ 6198c2ecf20Sopenharmony_ci if (bridge_get_partnum(virt_to_phys((void *)bd->bridge_addr), partnum)) 6208c2ecf20Sopenharmony_ci return -EPROBE_DEFER; /* not available yet */ 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci parent = irq_get_default_host(); 6238c2ecf20Sopenharmony_ci if (!parent) 6248c2ecf20Sopenharmony_ci return -ENODEV; 6258c2ecf20Sopenharmony_ci fn = irq_domain_alloc_named_fwnode("BRIDGE"); 6268c2ecf20Sopenharmony_ci if (!fn) 6278c2ecf20Sopenharmony_ci return -ENOMEM; 6288c2ecf20Sopenharmony_ci domain = irq_domain_create_hierarchy(parent, 0, 8, fn, 6298c2ecf20Sopenharmony_ci &bridge_domain_ops, NULL); 6308c2ecf20Sopenharmony_ci if (!domain) { 6318c2ecf20Sopenharmony_ci irq_domain_free_fwnode(fn); 6328c2ecf20Sopenharmony_ci return -ENOMEM; 6338c2ecf20Sopenharmony_ci } 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci pci_set_flags(PCI_PROBE_ONLY); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci host = devm_pci_alloc_host_bridge(dev, sizeof(*bc)); 6388c2ecf20Sopenharmony_ci if (!host) { 6398c2ecf20Sopenharmony_ci err = -ENOMEM; 6408c2ecf20Sopenharmony_ci goto err_remove_domain; 6418c2ecf20Sopenharmony_ci } 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci bc = pci_host_bridge_priv(host); 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci bc->busn.name = "Bridge PCI busn"; 6468c2ecf20Sopenharmony_ci bc->busn.start = 0; 6478c2ecf20Sopenharmony_ci bc->busn.end = 0xff; 6488c2ecf20Sopenharmony_ci bc->busn.flags = IORESOURCE_BUS; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci bc->domain = domain; 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci pci_add_resource_offset(&host->windows, &bd->mem, bd->mem_offset); 6538c2ecf20Sopenharmony_ci pci_add_resource_offset(&host->windows, &bd->io, bd->io_offset); 6548c2ecf20Sopenharmony_ci pci_add_resource(&host->windows, &bc->busn); 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci err = devm_request_pci_bus_resources(dev, &host->windows); 6578c2ecf20Sopenharmony_ci if (err < 0) 6588c2ecf20Sopenharmony_ci goto err_free_resource; 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci bc->nasid = bd->nasid; 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci bc->baddr = (u64)bd->masterwid << 60 | PCI64_ATTR_BAR; 6638c2ecf20Sopenharmony_ci bc->base = (struct bridge_regs *)bd->bridge_addr; 6648c2ecf20Sopenharmony_ci bc->intr_addr = bd->intr_addr; 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci /* 6678c2ecf20Sopenharmony_ci * Clear all pending interrupts. 6688c2ecf20Sopenharmony_ci */ 6698c2ecf20Sopenharmony_ci bridge_write(bc, b_int_rst_stat, BRIDGE_IRR_ALL_CLR); 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci /* 6728c2ecf20Sopenharmony_ci * Until otherwise set up, assume all interrupts are from slot 0 6738c2ecf20Sopenharmony_ci */ 6748c2ecf20Sopenharmony_ci bridge_write(bc, b_int_device, 0x0); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci /* 6778c2ecf20Sopenharmony_ci * disable swapping for big windows 6788c2ecf20Sopenharmony_ci */ 6798c2ecf20Sopenharmony_ci bridge_clr(bc, b_wid_control, 6808c2ecf20Sopenharmony_ci BRIDGE_CTRL_IO_SWAP | BRIDGE_CTRL_MEM_SWAP); 6818c2ecf20Sopenharmony_ci#ifdef CONFIG_PAGE_SIZE_4KB 6828c2ecf20Sopenharmony_ci bridge_clr(bc, b_wid_control, BRIDGE_CTRL_PAGE_SIZE); 6838c2ecf20Sopenharmony_ci#else /* 16kB or larger */ 6848c2ecf20Sopenharmony_ci bridge_set(bc, b_wid_control, BRIDGE_CTRL_PAGE_SIZE); 6858c2ecf20Sopenharmony_ci#endif 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_ci /* 6888c2ecf20Sopenharmony_ci * Hmm... IRIX sets additional bits in the address which 6898c2ecf20Sopenharmony_ci * are documented as reserved in the bridge docs. 6908c2ecf20Sopenharmony_ci */ 6918c2ecf20Sopenharmony_ci bridge_write(bc, b_wid_int_upper, 6928c2ecf20Sopenharmony_ci ((bc->intr_addr >> 32) & 0xffff) | (bd->masterwid << 16)); 6938c2ecf20Sopenharmony_ci bridge_write(bc, b_wid_int_lower, bc->intr_addr & 0xffffffff); 6948c2ecf20Sopenharmony_ci bridge_write(bc, b_dir_map, (bd->masterwid << 20)); /* DMA */ 6958c2ecf20Sopenharmony_ci bridge_write(bc, b_int_enable, 0); 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci for (slot = 0; slot < 8; slot++) { 6988c2ecf20Sopenharmony_ci bridge_set(bc, b_device[slot].reg, BRIDGE_DEV_SWAP_DIR); 6998c2ecf20Sopenharmony_ci bc->pci_int[slot][0] = -1; 7008c2ecf20Sopenharmony_ci bc->pci_int[slot][1] = -1; 7018c2ecf20Sopenharmony_ci /* default interrupt pin mapping */ 7028c2ecf20Sopenharmony_ci bc->int_mapping[slot][0] = slot; 7038c2ecf20Sopenharmony_ci bc->int_mapping[slot][1] = slot ^ 4; 7048c2ecf20Sopenharmony_ci } 7058c2ecf20Sopenharmony_ci bridge_read(bc, b_wid_tflush); /* wait until Bridge PIO complete */ 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci bridge_setup_board(bc, partnum); 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci host->dev.parent = dev; 7108c2ecf20Sopenharmony_ci host->sysdata = bc; 7118c2ecf20Sopenharmony_ci host->busnr = 0; 7128c2ecf20Sopenharmony_ci host->ops = &bridge_pci_ops; 7138c2ecf20Sopenharmony_ci host->map_irq = bridge_map_irq; 7148c2ecf20Sopenharmony_ci host->swizzle_irq = pci_common_swizzle; 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci err = pci_scan_root_bus_bridge(host); 7178c2ecf20Sopenharmony_ci if (err < 0) 7188c2ecf20Sopenharmony_ci goto err_free_resource; 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci pci_bus_claim_resources(host->bus); 7218c2ecf20Sopenharmony_ci pci_bus_add_devices(host->bus); 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, host->bus); 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci return 0; 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_cierr_free_resource: 7288c2ecf20Sopenharmony_ci pci_free_resource_list(&host->windows); 7298c2ecf20Sopenharmony_cierr_remove_domain: 7308c2ecf20Sopenharmony_ci irq_domain_remove(domain); 7318c2ecf20Sopenharmony_ci irq_domain_free_fwnode(fn); 7328c2ecf20Sopenharmony_ci return err; 7338c2ecf20Sopenharmony_ci} 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_cistatic int bridge_remove(struct platform_device *pdev) 7368c2ecf20Sopenharmony_ci{ 7378c2ecf20Sopenharmony_ci struct pci_bus *bus = platform_get_drvdata(pdev); 7388c2ecf20Sopenharmony_ci struct bridge_controller *bc = BRIDGE_CONTROLLER(bus); 7398c2ecf20Sopenharmony_ci struct fwnode_handle *fn = bc->domain->fwnode; 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci irq_domain_remove(bc->domain); 7428c2ecf20Sopenharmony_ci irq_domain_free_fwnode(fn); 7438c2ecf20Sopenharmony_ci pci_lock_rescan_remove(); 7448c2ecf20Sopenharmony_ci pci_stop_root_bus(bus); 7458c2ecf20Sopenharmony_ci pci_remove_root_bus(bus); 7468c2ecf20Sopenharmony_ci pci_unlock_rescan_remove(); 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci return 0; 7498c2ecf20Sopenharmony_ci} 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_cistatic struct platform_driver bridge_driver = { 7528c2ecf20Sopenharmony_ci .probe = bridge_probe, 7538c2ecf20Sopenharmony_ci .remove = bridge_remove, 7548c2ecf20Sopenharmony_ci .driver = { 7558c2ecf20Sopenharmony_ci .name = "xtalk-bridge", 7568c2ecf20Sopenharmony_ci } 7578c2ecf20Sopenharmony_ci}; 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_cibuiltin_platform_driver(bridge_driver); 760