dino.c
来自「linux 内核源代码」· C语言 代码 · 共 1,071 行 · 第 1/3 页
C
1,071 行
.enable = dino_enable_irq, .disable = dino_disable_irq, .ack = no_ack_irq, .end = no_end_irq,};/* * Handle a Processor interrupt generated by Dino. * * ilr_loop counter is a kluge to prevent a "stuck" IRQ line from * wedging the CPU. Could be removed or made optional at some point. */static irqreturn_t dino_isr(int irq, void *intr_dev){ struct dino_device *dino_dev = intr_dev; u32 mask; int ilr_loop = 100; /* read and acknowledge pending interrupts */#ifdef DINO_DEBUG dino_dev->dino_irr0 =#endif mask = __raw_readl(dino_dev->hba.base_addr+DINO_IRR0) & DINO_IRR_MASK; if (mask == 0) return IRQ_NONE;ilr_again: do { int local_irq = __ffs(mask); int irq = dino_dev->global_irq[local_irq]; DBG(KERN_DEBUG "%s(%d, %p) mask 0x%x\n", __FUNCTION__, irq, intr_dev, mask); __do_IRQ(irq); mask &= ~(1 << local_irq); } while (mask); /* Support for level triggered IRQ lines. ** ** Dropping this support would make this routine *much* faster. ** But since PCI requires level triggered IRQ line to share lines... ** device drivers may assume lines are level triggered (and not ** edge triggered like EISA/ISA can be). */ mask = __raw_readl(dino_dev->hba.base_addr+DINO_ILR) & dino_dev->imr; if (mask) { if (--ilr_loop > 0) goto ilr_again; printk(KERN_ERR "Dino 0x%p: stuck interrupt %d\n", dino_dev->hba.base_addr, mask); return IRQ_NONE; } return IRQ_HANDLED;}static void dino_assign_irq(struct dino_device *dino, int local_irq, int *irqp){ int irq = gsc_assign_irq(&dino_interrupt_type, dino); if (irq == NO_IRQ) return; *irqp = irq; dino->global_irq[local_irq] = irq;}static void dino_choose_irq(struct parisc_device *dev, void *ctrl){ int irq; struct dino_device *dino = ctrl; switch (dev->id.sversion) { case 0x00084: irq = 8; break; /* PS/2 */ case 0x0008c: irq = 10; break; /* RS232 */ case 0x00096: irq = 8; break; /* PS/2 */ default: return; /* Unknown */ } dino_assign_irq(dino, irq, &dev->irq);}/* * Cirrus 6832 Cardbus reports wrong irq on RDI Tadpole PARISC Laptop (deller@gmx.de) * (the irqs are off-by-one, not sure yet if this is a cirrus, dino-hardware or dino-driver problem...) */static void __devinit quirk_cirrus_cardbus(struct pci_dev *dev){ u8 new_irq = dev->irq - 1; printk(KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d\n", pci_name(dev), dev->irq, new_irq); dev->irq = new_irq;}DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6832, quirk_cirrus_cardbus );static void __initdino_bios_init(void){ DBG("dino_bios_init\n");}/* * dino_card_setup - Set up the memory space for a Dino in card mode. * @bus: the bus under this dino * * Claim an 8MB chunk of unused IO space and call the generic PCI routines * to set up the addresses of the devices on this bus. */#define _8MB 0x00800000ULstatic void __initdino_card_setup(struct pci_bus *bus, void __iomem *base_addr){ int i; struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge)); struct resource *res; char name[128]; int size; res = &dino_dev->hba.lmmio_space; res->flags = IORESOURCE_MEM; size = scnprintf(name, sizeof(name), "Dino LMMIO (%s)", bus->bridge->bus_id); res->name = kmalloc(size+1, GFP_KERNEL); if(res->name) strcpy((char *)res->name, name); else res->name = dino_dev->hba.lmmio_space.name; if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB, F_EXTEND(0xf0000000UL) | _8MB, F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) { struct list_head *ln, *tmp_ln; printk(KERN_ERR "Dino: cannot attach bus %s\n", bus->bridge->bus_id); /* kill the bus, we can't do anything with it */ list_for_each_safe(ln, tmp_ln, &bus->devices) { struct pci_dev *dev = pci_dev_b(ln); list_del(&dev->global_list); list_del(&dev->bus_list); } return; } bus->resource[1] = res; bus->resource[0] = &(dino_dev->hba.io_space); /* Now tell dino what range it has */ for (i = 1; i < 31; i++) { if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB))) break; } DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %p\n", i, res->start, base_addr + DINO_IO_ADDR_EN); __raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN);}static void __initdino_card_fixup(struct pci_dev *dev){ u32 irq_pin; /* ** REVISIT: card-mode PCI-PCI expansion chassis do exist. ** Not sure they were ever productized. ** Die here since we'll die later in dino_inb() anyway. */ if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { panic("Card-Mode Dino: PCI-PCI Bridge not supported\n"); } /* ** Set Latency Timer to 0xff (not a shared bus) ** Set CACHELINE_SIZE. */ dino_cfg_write(dev->bus, dev->devfn, PCI_CACHE_LINE_SIZE, 2, 0xff00 | L1_CACHE_BYTES/4); /* ** Program INT_LINE for card-mode devices. ** The cards are hardwired according to this algorithm. ** And it doesn't matter if PPB's are present or not since ** the IRQ lines bypass the PPB. ** ** "-1" converts INTA-D (1-4) to PCIINTA-D (0-3) range. ** The additional "-1" adjusts for skewing the IRQ<->slot. */ dino_cfg_read(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 1, &irq_pin); dev->irq = (irq_pin + PCI_SLOT(dev->devfn) - 1) % 4 ; /* Shouldn't really need to do this but it's in case someone tries ** to bypass PCI services and look at the card themselves. */ dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, dev->irq); }/* The alignment contraints for PCI bridges under dino */#define DINO_BRIDGE_ALIGN 0x100000static void __initdino_fixup_bus(struct pci_bus *bus){ struct list_head *ln; struct pci_dev *dev; struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge)); int port_base = HBA_PORT_BASE(dino_dev->hba.hba_num); DBG(KERN_WARNING "%s(0x%p) bus %d platform_data 0x%p\n", __FUNCTION__, bus, bus->secondary, bus->bridge->platform_data); /* Firmware doesn't set up card-mode dino, so we have to */ if (is_card_dino(&dino_dev->hba.dev->id)) { dino_card_setup(bus, dino_dev->hba.base_addr); } else if(bus->parent == NULL) { /* must have a dino above it, reparent the resources * into the dino window */ int i; struct resource *res = &dino_dev->hba.lmmio_space; bus->resource[0] = &(dino_dev->hba.io_space); for(i = 0; i < DINO_MAX_LMMIO_RESOURCES; i++) { if(res[i].flags == 0) break; bus->resource[i+1] = &res[i]; } } else if(bus->self) { int i; pci_read_bridge_bases(bus); for(i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) { if((bus->self->resource[i].flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0) continue; if(bus->self->resource[i].flags & IORESOURCE_MEM) { /* There's a quirk to alignment of * bridge memory resources: the start * is the alignment and start-end is * the size. However, firmware will * have assigned start and end, so we * need to take this into account */ bus->self->resource[i].end = bus->self->resource[i].end - bus->self->resource[i].start + DINO_BRIDGE_ALIGN; bus->self->resource[i].start = DINO_BRIDGE_ALIGN; } DBG("DEBUG %s assigning %d [0x%lx,0x%lx]\n", bus->self->dev.bus_id, i, bus->self->resource[i].start, bus->self->resource[i].end); pci_assign_resource(bus->self, i); DBG("DEBUG %s after assign %d [0x%lx,0x%lx]\n", bus->self->dev.bus_id, i, bus->self->resource[i].start, bus->self->resource[i].end); } } list_for_each(ln, &bus->devices) { int i; dev = pci_dev_b(ln); if (is_card_dino(&dino_dev->hba.dev->id)) dino_card_fixup(dev); /* ** P2PB's only have 2 BARs, no IRQs. ** I'd like to just ignore them for now. */ if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) continue; /* Adjust the I/O Port space addresses */ for (i = 0; i < PCI_NUM_RESOURCES; i++) { struct resource *res = &dev->resource[i]; if (res->flags & IORESOURCE_IO) { res->start |= port_base; res->end |= port_base; }#ifdef __LP64__ /* Sign Extend MMIO addresses */ else if (res->flags & IORESOURCE_MEM) { res->start |= F_EXTEND(0UL); res->end |= F_EXTEND(0UL); }#endif } /* null out the ROM resource if there is one (we don't * care about an expansion rom on parisc, since it * usually contains (x86) bios code) */ dev->resource[PCI_ROM_RESOURCE].flags = 0; if(dev->irq == 255) {#define DINO_FIX_UNASSIGNED_INTERRUPTS#ifdef DINO_FIX_UNASSIGNED_INTERRUPTS /* This code tries to assign an unassigned * interrupt. Leave it disabled unless you * *really* know what you're doing since the * pin<->interrupt line mapping varies by bus * and machine */ u32 irq_pin; dino_cfg_read(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 1, &irq_pin); irq_pin = (irq_pin + PCI_SLOT(dev->devfn) - 1) % 4 ; printk(KERN_WARNING "Device %s has undefined IRQ, " "setting to %d\n", pci_name(dev), irq_pin); dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, irq_pin); dino_assign_irq(dino_dev, irq_pin, &dev->irq);#else dev->irq = 65535; printk(KERN_WARNING "Device %s has unassigned IRQ\n", pci_name(dev));#endif } else { /* Adjust INT_LINE for that busses region */ dino_assign_irq(dino_dev, dev->irq, &dev->irq); } }}struct pci_bios_ops dino_bios_ops = { .init = dino_bios_init, .fixup_bus = dino_fixup_bus};/* * Initialise a DINO controller chip */static void __initdino_card_init(struct dino_device *dino_dev){ u32 brdg_feat = 0x00784e05; unsigned long status; status = __raw_readl(dino_dev->hba.base_addr+DINO_IO_STATUS); if (status & 0x0000ff80) { __raw_writel(0x00000005, dino_dev->hba.base_addr+DINO_IO_COMMAND); udelay(1); } __raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?