Lines Matching +full:cfg +full:- +full:space

1 // SPDX-License-Identifier: GPL-2.0
32 /* Enable/Disable Debugging Configuration Space Access */
108 struct grpci1_priv *priv = dev->bus->sysdata; in grpci1_map_irq()
113 pin = ((pin - 1) + irq_group) & 0x3; in grpci1_map_irq()
115 return priv->irq_map[pin]; in grpci1_map_irq()
121 u32 *pci_conf, tmp, cfg; in grpci1_cfg_r32() local
124 return -EINVAL; in grpci1_cfg_r32()
134 cfg = REGLOAD(priv->regs->cfg_stat); in grpci1_cfg_r32()
135 REGSTORE(priv->regs->cfg_stat, (cfg & ~(0xf << 23)) | (bus << 23)); in grpci1_cfg_r32()
138 pci_conf = (u32 *) (priv->pci_conf | (devfn << 8) | (where & 0xfc)); in grpci1_cfg_r32()
142 if (REGLOAD(priv->regs->cfg_stat) & CFGSTAT_CTO) { in grpci1_cfg_r32()
144 /* Clear Master abort bit in PCI cfg space (is set) */ in grpci1_cfg_r32()
145 tmp = REGLOAD(priv->regs->stat_cmd); in grpci1_cfg_r32()
148 /* Bus always little endian (unaffected by byte-swapping) */ in grpci1_cfg_r32()
162 return -EINVAL; in grpci1_cfg_r16()
184 u32 cfg; in grpci1_cfg_w32() local
187 return -EINVAL; in grpci1_cfg_w32()
197 cfg = REGLOAD(priv->regs->cfg_stat); in grpci1_cfg_w32()
198 REGSTORE(priv->regs->cfg_stat, (cfg & ~(0xf << 23)) | (bus << 23)); in grpci1_cfg_w32()
200 pci_conf = (unsigned int *) (priv->pci_conf | in grpci1_cfg_w32()
214 return -EINVAL; in grpci1_cfg_w16()
237 /* Read from Configuration Space. When entering here the PCI layer has taken
244 unsigned int busno = bus->number; in grpci1_read_config()
263 ret = -EINVAL; in grpci1_read_config()
276 /* Write to Configuration Space. When entering here the PCI layer has taken
283 unsigned int busno = bus->number; in grpci1_write_config()
296 return -EINVAL; in grpci1_write_config()
321 irqidx = (u32)data->chip_data - 1; in grpci1_mask_irq()
326 REGSTORE(priv->regs->irq, REGLOAD(priv->regs->irq) & ~(1 << irqidx)); in grpci1_mask_irq()
334 irqidx = (u32)data->chip_data - 1; in grpci1_unmask_irq()
339 REGSTORE(priv->regs->irq, REGLOAD(priv->regs->irq) | (1 << irqidx)); in grpci1_unmask_irq()
368 irqreg = REGLOAD(priv->regs->irq); in grpci1_pci_flow_irq()
373 generic_handle_irq(priv->irq_err); in grpci1_pci_flow_irq()
382 generic_handle_irq(priv->irq_map[i]); in grpci1_pci_flow_irq()
388 * Call "first level" IRQ chip end-of-irq handler. It will ACK LEON IRQ in grpci1_pci_flow_irq()
393 desc->irq_data.chip->irq_eoi(&desc->irq_data); in grpci1_pci_flow_irq()
415 * Initialize mappings AMBA<->PCI, clear IRQ state, setup PCI interface
425 struct grpci1_regs __iomem *regs = priv->regs; in grpci1_hw_init()
427 /* set 1:1 mapping between AHB -> PCI memory space */ in grpci1_hw_init()
428 REGSTORE(regs->cfg_stat, priv->pci_area & 0xf0000000); in grpci1_hw_init()
432 REGSTORE(regs->page1, ahbadr); in grpci1_hw_init()
434 /* translate I/O accesses to 0, I/O Space always @ PCI low 64Kbytes */ in grpci1_hw_init()
435 REGSTORE(regs->iomap, REGLOAD(regs->iomap) & 0x0000ffff); in grpci1_hw_init()
438 REGSTORE(regs->irq, 0); in grpci1_hw_init()
446 pciadr = priv->pci_area - bar_sz; in grpci1_hw_init()
472 dev_err(priv->dev, "Jump IRQ happened\n"); in grpci1_jump_interrupt()
483 status &= priv->pci_err_mask; in grpci1_err_interrupt()
489 dev_err(priv->dev, "Data Parity Error\n"); in grpci1_err_interrupt()
492 dev_err(priv->dev, "Signalled Target Abort\n"); in grpci1_err_interrupt()
495 dev_err(priv->dev, "Received Target Abort\n"); in grpci1_err_interrupt()
498 dev_err(priv->dev, "Received Master Abort\n"); in grpci1_err_interrupt()
501 dev_err(priv->dev, "Signalled System Error\n"); in grpci1_err_interrupt()
504 dev_err(priv->dev, "Parity Error\n"); in grpci1_err_interrupt()
518 u32 cfg, size, err_mask; in grpci1_of_probe() local
522 dev_err(&ofdev->dev, "only one GRPCI1 supported\n"); in grpci1_of_probe()
523 return -ENODEV; in grpci1_of_probe()
526 if (ofdev->num_resources < 3) { in grpci1_of_probe()
527 dev_err(&ofdev->dev, "not enough APB/AHB resources\n"); in grpci1_of_probe()
528 return -EIO; in grpci1_of_probe()
531 priv = devm_kzalloc(&ofdev->dev, sizeof(*priv), GFP_KERNEL); in grpci1_of_probe()
533 dev_err(&ofdev->dev, "memory allocation failed\n"); in grpci1_of_probe()
534 return -ENOMEM; in grpci1_of_probe()
537 priv->dev = &ofdev->dev; in grpci1_of_probe()
541 regs = devm_ioremap_resource(&ofdev->dev, res); in grpci1_of_probe()
549 cfg = REGLOAD(regs->cfg_stat); in grpci1_of_probe()
550 if ((cfg & CFGSTAT_HOST) == 0) { in grpci1_of_probe()
551 dev_err(&ofdev->dev, "not in host system slot\n"); in grpci1_of_probe()
552 return -EIO; in grpci1_of_probe()
555 /* check that BAR1 support 256 MByte so that we can map kernel space */ in grpci1_of_probe()
556 REGSTORE(regs->page1, 0xffffffff); in grpci1_of_probe()
557 size = ~REGLOAD(regs->page1) + 1; in grpci1_of_probe()
559 dev_err(&ofdev->dev, "BAR1 must be at least 256MByte\n"); in grpci1_of_probe()
560 return -EIO; in grpci1_of_probe()
563 /* hardware must support little-endian PCI (byte-twisting) */ in grpci1_of_probe()
564 if ((REGLOAD(regs->page0) & PAGE0_BTEN) == 0) { in grpci1_of_probe()
565 dev_err(&ofdev->dev, "byte-twisting is required\n"); in grpci1_of_probe()
566 return -EIO; in grpci1_of_probe()
569 priv->regs = regs; in grpci1_of_probe()
570 priv->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); in grpci1_of_probe()
571 dev_info(&ofdev->dev, "host found at 0x%p, irq%d\n", regs, priv->irq); in grpci1_of_probe()
573 /* Find PCI Memory, I/O and Configuration Space Windows */ in grpci1_of_probe()
574 priv->pci_area = ofdev->resource[1].start; in grpci1_of_probe()
575 priv->pci_area_end = ofdev->resource[1].end+1; in grpci1_of_probe()
576 priv->pci_io = ofdev->resource[2].start; in grpci1_of_probe()
577 priv->pci_conf = ofdev->resource[2].start + 0x10000; in grpci1_of_probe()
578 priv->pci_conf_end = priv->pci_conf + 0x10000; in grpci1_of_probe()
579 priv->pci_io_va = (unsigned long)ioremap(priv->pci_io, 0x10000); in grpci1_of_probe()
580 if (!priv->pci_io_va) { in grpci1_of_probe()
581 dev_err(&ofdev->dev, "unable to map PCI I/O area\n"); in grpci1_of_probe()
582 return -EIO; in grpci1_of_probe()
586 "GRPCI1: MEMORY SPACE [0x%08lx - 0x%08lx]\n" in grpci1_of_probe()
587 " I/O SPACE [0x%08lx - 0x%08lx]\n" in grpci1_of_probe()
588 " CONFIG SPACE [0x%08lx - 0x%08lx]\n", in grpci1_of_probe()
589 priv->pci_area, priv->pci_area_end-1, in grpci1_of_probe()
590 priv->pci_io, priv->pci_conf-1, in grpci1_of_probe()
591 priv->pci_conf, priv->pci_conf_end-1); in grpci1_of_probe()
594 * I/O Space resources in I/O Window mapped into Virtual Adr Space in grpci1_of_probe()
598 priv->info.io_space.name = "GRPCI1 PCI I/O Space"; in grpci1_of_probe()
599 priv->info.io_space.start = priv->pci_io_va + 0x1000; in grpci1_of_probe()
600 priv->info.io_space.end = priv->pci_io_va + 0x10000 - 1; in grpci1_of_probe()
601 priv->info.io_space.flags = IORESOURCE_IO; in grpci1_of_probe()
605 * non-prefetchable memory in grpci1_of_probe()
607 priv->info.mem_space.name = "GRPCI1 PCI MEM Space"; in grpci1_of_probe()
608 priv->info.mem_space.start = priv->pci_area; in grpci1_of_probe()
609 priv->info.mem_space.end = priv->pci_area_end - 1; in grpci1_of_probe()
610 priv->info.mem_space.flags = IORESOURCE_MEM; in grpci1_of_probe()
612 if (request_resource(&iomem_resource, &priv->info.mem_space) < 0) { in grpci1_of_probe()
613 dev_err(&ofdev->dev, "unable to request PCI memory area\n"); in grpci1_of_probe()
614 err = -ENOMEM; in grpci1_of_probe()
618 if (request_resource(&ioport_resource, &priv->info.io_space) < 0) { in grpci1_of_probe()
619 dev_err(&ofdev->dev, "unable to request PCI I/O area\n"); in grpci1_of_probe()
620 err = -ENOMEM; in grpci1_of_probe()
625 priv->info.busn.name = "GRPCI1 busn"; in grpci1_of_probe()
626 priv->info.busn.start = 0; in grpci1_of_probe()
627 priv->info.busn.end = 15; in grpci1_of_probe()
636 * Error IRQ. All PCI and PCI-Error interrupts are shared using the in grpci1_of_probe()
639 leon_update_virq_handling(priv->irq, grpci1_pci_flow_irq, "pcilvl", 0); in grpci1_of_probe()
641 priv->irq_map[0] = grpci1_build_device_irq(1); in grpci1_of_probe()
642 priv->irq_map[1] = grpci1_build_device_irq(2); in grpci1_of_probe()
643 priv->irq_map[2] = grpci1_build_device_irq(3); in grpci1_of_probe()
644 priv->irq_map[3] = grpci1_build_device_irq(4); in grpci1_of_probe()
645 priv->irq_err = grpci1_build_device_irq(5); in grpci1_of_probe()
648 priv->irq_map[0], priv->irq_map[1], priv->irq_map[2], in grpci1_of_probe()
649 priv->irq_map[3]); in grpci1_of_probe()
652 err = devm_request_irq(&ofdev->dev, priv->irq, grpci1_jump_interrupt, 0, in grpci1_of_probe()
655 dev_err(&ofdev->dev, "ERR IRQ request failed: %d\n", err); in grpci1_of_probe()
660 err = devm_request_irq(&ofdev->dev, priv->irq_err, in grpci1_of_probe()
664 dev_err(&ofdev->dev, "ERR VIRQ request failed: %d\n", err); in grpci1_of_probe()
668 tmp = of_get_property(ofdev->dev.of_node, "all_pci_errors", &len); in grpci1_of_probe()
670 priv->pci_err_mask = ALL_PCI_ERRORS; in grpci1_of_probe()
673 priv->pci_err_mask = DEF_PCI_ERRORS; in grpci1_of_probe()
681 REGSTORE(regs->irq, err_mask); in grpci1_of_probe()
684 priv->info.ops = &grpci1_ops; in grpci1_of_probe()
685 priv->info.map_irq = grpci1_map_irq; in grpci1_of_probe()
686 leon_pci_init(ofdev, &priv->info); in grpci1_of_probe()
691 release_resource(&priv->info.io_space); in grpci1_of_probe()
693 release_resource(&priv->info.mem_space); in grpci1_of_probe()
695 iounmap((void __iomem *)priv->pci_io_va); in grpci1_of_probe()