dino.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,078 行 · 第 1/3 页
C
1,078 行
dino_enable_irq(void *irq_dev, int irq){ struct dino_device *dino_dev = DINO_DEV(irq_dev); /* ** clear pending IRQ bits ** ** This does NOT change ILR state! ** See comments in dino_unmask_irq() for ILR usage. */ gsc_readl(dino_dev->hba.base_addr+DINO_IPR); dino_unmask_irq(irq_dev, irq);}static struct irq_region_ops dino_irq_ops = { .disable_irq = dino_mask_irq, /* ??? */ .enable_irq = dino_enable_irq, .mask_irq = dino_mask_irq, .unmask_irq = dino_unmask_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_tdino_isr(int irq, void *intr_dev, struct pt_regs *regs){ struct dino_device *dino_dev = DINO_DEV(intr_dev); u32 mask; int ilr_loop = 100; extern void do_irq(struct irqaction *a, int i, struct pt_regs *p); /* read and acknowledge pending interrupts */#ifdef DINO_DEBUG dino_dev->dino_irr0 =#endif mask = gsc_readl(dino_dev->hba.base_addr+DINO_IRR0) & DINO_IRR_MASK;ilr_again: while (mask) { int irq; irq = __ffs(mask); mask &= ~(1<<irq); DBG(KERN_WARNING "%s(%x, %p) mask %0x\n", __FUNCTION__, irq, intr_dev, mask); do_irq(&dino_dev->dino_region->action[irq], dino_dev->dino_region->data.irqbase + irq, regs); } /* 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 = gsc_readl(dino_dev->hba.base_addr+DINO_ILR) & dino_dev->imr; if (mask) { if (--ilr_loop > 0) goto ilr_again; printk(KERN_ERR "Dino %lx: stuck interrupt %d\n", dino_dev->hba.base_addr, mask); return IRQ_NONE; } return IRQ_HANDLED;}static int dino_choose_irq(struct parisc_device *dev){ int irq = -1; switch (dev->id.sversion) { case 0x00084: irq = 8; break; /* PS/2 */ case 0x0008c: irq = 10; break; /* RS232 */ case 0x00096: irq = 8; break; /* PS/2 */ } return irq;}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, unsigned long 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 = %lx\n", i, res->start, base_addr + DINO_IO_ADDR_EN); gsc_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 sysdata 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); dev->irq = (irq_pin + PCI_SLOT(dev->devfn) - 1) % 4 ; dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, dev->irq); dev->irq += dino_dev->dino_region->data.irqbase; printk(KERN_WARNING "Device %s has undefined IRQ, setting to %d\n", dev->slot_name, irq_pin);#else dev->irq = 65535; printk(KERN_WARNING "Device %s has unassigned IRQ\n", dev->slot_name); #endif } else { /* Adjust INT_LINE for that busses region */ dev->irq += dino_dev->dino_region->data.irqbase; } }}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; gsc_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK); gsc_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN); gsc_writel(0x00000000, dino_dev->hba.base_addr+DINO_ICR);#if 1/* REVISIT - should be a runtime check (eg if (CPU_IS_PCX_L) ...) */ /* ** PCX-L processors don't support XQL like Dino wants it. ** PCX-L2 ignore XQL signal and it doesn't matter. */ brdg_feat &= ~0x4; /* UXQL */#endif gsc_writel( brdg_feat, dino_dev->hba.base_addr+DINO_BRDG_FEAT); /* ** Don't enable address decoding until we know which I/O range ** currently is available from the host. Only affects MMIO ** and not I/O port space. */ gsc_writel(0x00000000, dino_dev->hba.base_addr+DINO_IO_ADDR_EN); gsc_writel(0x00000000, dino_dev->hba.base_addr+DINO_DAMODE);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?