From owner-p4-projects@FreeBSD.ORG Mon Jan 12 04:30:39 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 30B46106577D; Mon, 12 Jan 2009 04:30:39 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4857106567A for ; Mon, 12 Jan 2009 04:30:38 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id D17F38FC08 for ; Mon, 12 Jan 2009 04:30:38 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0C4UcIq022797 for ; Mon, 12 Jan 2009 04:30:38 GMT (envelope-from gonzo@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0C4Ucsw022795 for perforce@freebsd.org; Mon, 12 Jan 2009 04:30:38 GMT (envelope-from gonzo@FreeBSD.org) Date: Mon, 12 Jan 2009 04:30:38 GMT Message-Id: <200901120430.n0C4Ucsw022795@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko To: Perforce Change Reviews Cc: Subject: PERFORCE change 156000 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jan 2009 04:30:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=156000 Change 156000 by gonzo@gonzo_figaro on 2009/01/12 04:30:08 - More stuff for PCI core initialization - Add resources/interrupts management code Affected files ... .. //depot/projects/mips2/src/sys/dev/siba/siba_pcib.c#7 edit .. //depot/projects/mips2/src/sys/dev/siba/siba_pcibvar.h#5 edit .. //depot/projects/mips2/src/sys/dev/siba/sibareg.h#5 edit Differences ... ==== //depot/projects/mips2/src/sys/dev/siba/siba_pcib.c#7 (text+ko) ==== @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -86,14 +87,11 @@ * TODO: code cleanup. */ -static int siba_pcib_activate_resource(device_t, device_t, int, - int, struct resource *); static struct resource * siba_pcib_alloc_resource(device_t, device_t, int, int *, u_long , u_long, u_long, u_int); static int siba_pcib_attach(device_t); -static int siba_pcib_deactivate_resource(device_t, device_t, int, - int, struct resource *); +static int siba_pcib_intr(void *); static int siba_pcib_maxslots(device_t); static int siba_pcib_probe(device_t); static uint32_t @@ -126,23 +124,19 @@ return (ENXIO); } -//extern int rman_debug; - static int siba_pcib_attach(device_t dev) { struct siba_pcib_softc *sc = device_get_softc(dev); int rid; uint32_t ctl; - uint16_t vid, svid; - + sc->sc_dev = dev; /* * Allocate the resources which the parent bus has already * determined for us. */ rid = MIPS_MEM_RID; /* XXX */ - //rman_debug = 1; sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE); if (sc->sc_mem == NULL) { @@ -171,44 +165,61 @@ SBPCI_WRITE_4(sc, SIBA_PCI_TRANS0, SIBA_PCI_TRANS_IO); SBPCI_WRITE_4(sc, SIBA_PCI_TRANS1, SIBA_PCI_TRANS_CFG0); - SBPCI_WRITE_4(sc, SIBA_PCI_TRANS2, SIBA_PCI_TRANS_MEM); + SBPCI_WRITE_4(sc, SIBA_PCI_TRANS2, + SIBA_PCI_TRANS_MEM | SIBA_PCI_MEM_START); + DELAY(100); - vid = siba_pcib_read_config(dev, 0, 0, 0, 0, 2); - svid = siba_pcib_read_config(dev, 0, 0, 0, 2, 2); - printf("bridge vid=%08x, svid=%08x\n", vid, svid); + siba_pcib_write_config(dev, 0, 0, 0, PCIR_COMMAND, + PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN, 2); + siba_pcib_write_config(dev, 0, 0, 0, PCIR_STATUS, + 0, 2); + DELAY(100); + SBPCI_WRITE_4(sc, SIBA_PCI_BP_INTR_MASK, SIBA_PCI_BP_INTR_MASK_INTA); -#if 0 - bus_space_handle_t sc_cfg_hand; - int error; - /* - * XXX this doesn't actually do anything on mips; however... should - * we not be mapping to KSEG1? we need to wire down the range. + * Initialize resource managers */ - error = bus_space_map(sc->sc_bt, SBPCI_CFGBASE, SBPCI_CFGSIZE, - 0, &sc_cfg_hand); - if (error) { - device_printf(dev, "cannot map PCI configuration space\n"); - return (ENXIO); + sc->sc_mem_rman.rm_type = RMAN_ARRAY; + sc->sc_mem_rman.rm_descr = "SiBa PCI core memory"; + if (rman_init(&sc->sc_mem_rman) != 0 || + rman_manage_region(&sc->sc_mem_rman, SIBA_PCI_MEM_START, + SIBA_PCI_MEM_START + SIBA_PCI_MEM_SIZE - 1) != 0) { + panic("siba_pcib_attach: failed to set up memory rman"); + } + + sc->sc_io_rman.rm_type = RMAN_ARRAY; + sc->sc_io_rman.rm_descr = "SiBa PCI core memory"; + if (rman_init(&sc->sc_io_rman) != 0 || + rman_manage_region(&sc->sc_io_rman, SIBA_PCI_IO_START, + SIBA_PCI_IO_START + SIBA_PCI_IO_SIZE - 1) != 0) { + panic("siba_pcib_attach: failed to set up memory rman"); } - device_printf(dev, "mapped pci config space at 0x%08x\n", - (uint32_t)sc_cfg_hand); + + sc->sc_irq_rman.rm_type = RMAN_ARRAY; + sc->sc_irq_rman.rm_descr = "SiBa PCI core IRQs"; + if (rman_init(&sc->sc_irq_rman) != 0 || + rman_manage_region(&sc->sc_irq_rman, 0, + 99) != 0) + panic("siba_pcib_attach: failed to set up IRQ rman"); - /* - * Setup configuration, io, and dma space windows. - * XXX we need to be able to do type 1 too. - * we probably don't need to be able to do i/o cycles. - */ - SBPCI_WRITE_4(sc->sc_mem, SBPCI_SBTOPCI0, 1); /* I/O read/write window */ - SBPCI_WRITE_4(sc->sc_mem, SBPCI_SBTOPCI1, 2); /* type 0 configuration only */ - SBPCI_WRITE_4(sc->sc_mem, SBPCI_SBTOPCI2, 1 << 30); /* memory only */ - DELAY(500); + /* Hook up our interrupt handler. */ + rid = 0; + if ((sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, + 0UL, ~0UL, 1, + RF_SHAREABLE | RF_ACTIVE)) == NULL) { + device_printf(dev, "unable to allocate IRQ resource\n"); + return ENXIO; + } - /* XXX resource managers */ -#endif + if ((bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC, + siba_pcib_intr, NULL, sc, &sc->sc_ih))) { + device_printf(dev, + "WARNING: unable to register interrupt handler\n"); + return ENXIO; + } device_add_child(dev, "pci", -1); return (bus_generic_attach(dev)); @@ -240,6 +251,7 @@ struct siba_pcib_softc *sc; sc = device_get_softc(dev); + switch (which) { case PCIB_IVAR_BUS: sc->sc_bus = value; @@ -251,12 +263,29 @@ static int siba_pcib_setup_intr(device_t dev, device_t child, struct resource *ires, - int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, + int flags, driver_filter_t *filt, driver_intr_t *handler, void *arg, void **cookiep) { + struct siba_pcib_softc *sc = device_get_softc(dev); + struct intr_event *event; + int irq, error; + + irq = rman_get_start(ires); + + event = sc->sc_irq_event; + if (event == NULL) { + error = intr_event_create(&event, (void *)irq, 0, irq, + (mask_fn)mips_mask_irq, (mask_fn)mips_unmask_irq, + (mask_fn)mips_unmask_irq, NULL, "siba_pcib intr%d:", irq); + if (error) + return 0; + sc->sc_irq_event = event; + } + + intr_event_add_handler(event, device_get_nameunit(child), filt, + handler, arg, intr_priority(flags), flags, cookiep); - return (BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, - filt, intr, arg, cookiep)); + return (0); } static int @@ -264,75 +293,65 @@ void *cookie) { - return (BUS_TEARDOWN_INTR(device_get_parent(dev), child, vec, cookie)); + return (intr_event_remove_handler(cookie)); +} + +static int +siba_pcib_intr(void *v) +{ + struct siba_pcib_softc *sc = v; + struct intr_event *event; + + event = sc->sc_irq_event; + + if (!event || TAILQ_EMPTY(&event->ie_handlers)) + return FILTER_STRAY; + + /* TODO: frame instead of NULL? */ + intr_event_handle(event, NULL); + /* XXX: Log stray IRQs */ + + return FILTER_HANDLED; } + static struct resource * siba_pcib_alloc_resource(device_t bus, device_t child, int type, int *rid, u_long start, u_long end, u_long count, unsigned int flags) { -#if 1 + struct siba_pcib_softc *sc = device_get_softc(bus); + struct resource *rv = NULL; + struct rman *rm; - //device_printf(bus, "%s: not yet implemented\n", __func__); - return (NULL); -#else - bus_space_tag_t tag; - struct siba_pcib_softc *sc = device_get_softc(bus); - struct rman *rmanp; - struct resource *rv; - - tag = 0; - rv = NULL; switch (type) { case SYS_RES_IRQ: - rmanp = &sc->sc_irq_rman; + rm = &sc->sc_irq_rman; break; - case SYS_RES_MEMORY: - rmanp = &sc->sc_mem_rman; - tag = &sc->sc_pci_memt; + rm = &sc->sc_mem_rman; + break; + case SYS_RES_IOPORT: + rm = &sc->sc_io_rman; break; - default: - return (rv); + return (NULL); } - rv = rman_reserve_resource(rmanp, start, end, count, flags, child); - if (rv != NULL) { - rman_set_rid(rv, *rid); - if (type == SYS_RES_MEMORY) { -#if 0 - rman_set_bustag(rv, tag); - rman_set_bushandle(rv, rman_get_bushandle(sc->sc_mem) + - (rman_get_start(rv) - IXP425_PCI_MEM_HWBASE)); -#endif - } - } + rv = rman_reserve_resource(rm, start, end, count, flags, child); - return (rv); -#endif -} + if (rv == NULL) + return (NULL); -static int -siba_pcib_activate_resource(device_t bus, device_t child, int type, int rid, - struct resource *r) -{ + rman_set_rid(rv, *rid); - device_printf(bus, "%s: not yet implemented\n", __func__); - device_printf(bus, "%s called activate_resource\n", - device_get_nameunit(child)); - return (ENXIO); -} + if (flags & RF_ACTIVE) { + if (bus_activate_resource(child, type, *rid, rv)) { + rman_release_resource(rv); + return (NULL); + } + } -static int -siba_pcib_deactivate_resource(device_t bus, device_t child, int type, int rid, - struct resource *r) -{ - - device_printf(bus, "%s: not yet implemented\n", __func__); - device_printf(bus, "%s called deactivate_resource\n", - device_get_nameunit(child)); - return (ENXIO); + return (rv); } static int @@ -424,7 +443,7 @@ return (val); break; default: - panic("%s: wrong bytes count", __func__); + panic("%s: wrong bytes count: %d", __func__, bytes); break; } } @@ -475,7 +494,7 @@ case 4: break; default: - panic("%s: wrong bytes count", __func__); + panic("%s: wrong bytes count: %d", __func__, bytes); break; } @@ -486,8 +505,8 @@ siba_pcib_route_interrupt(device_t bridge, device_t device, int pin) { - //device_printf(bridge, "%s: not yet implemented\n", __func__); - return (-1); + /* It doesn't matter actually, all devices share PCI core interrupt */ + return (0); } static device_method_t siba_pcib_methods[] = { @@ -502,8 +521,8 @@ DEVMETHOD(bus_setup_intr, siba_pcib_setup_intr), DEVMETHOD(bus_teardown_intr, siba_pcib_teardown_intr), DEVMETHOD(bus_alloc_resource, siba_pcib_alloc_resource), - DEVMETHOD(bus_activate_resource, siba_pcib_activate_resource), - DEVMETHOD(bus_deactivate_resource, siba_pcib_deactivate_resource), + DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), + DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), DEVMETHOD(bus_release_resource, siba_pcib_release_resource), /* pcib interface */ ==== //depot/projects/mips2/src/sys/dev/siba/siba_pcibvar.h#5 (text+ko) ==== @@ -36,21 +36,18 @@ bus_write_4((sc)->sc_mem, (reg), (val)) struct siba_pcib_softc { - device_t sc_dev; /* Device ID */ - u_int sc_bus; /* PCI bus number */ - struct resource *sc_mem; /* siba memory window */ - struct resource *sc_csr; /* config space */ + device_t sc_dev; /* Device ID */ + uintptr_t sc_bus; + + struct resource *sc_mem; -#if 0 - bus_space_tag_t sc_bt; - bus_space_handle_t sc_bh; - bus_addr_t sc_maddr; - bus_size_t sc_msize; + struct resource *sc_irq; + struct intr_event *sc_irq_event; + void *sc_ih; - struct bus_space sc_pci_memt; - struct bus_space sc_pci_iot; - bus_dma_tag_t sc_dmat; -#endif + struct rman sc_mem_rman; + struct rman sc_io_rman; + struct rman sc_irq_rman; }; #endif /* _SIBA_PCIBVAR_H_ */ ==== //depot/projects/mips2/src/sys/dev/siba/sibareg.h#5 (text+ko) ==== @@ -103,6 +103,8 @@ #define SIBA_PCI_BP_INTR_STATUS 0x0020 #define SIBA_PCI_BP_INTR_MASK 0x0024 +#define SIBA_PCI_BP_INTR_MASK_INTA 0x01 +#define SIBA_PCI_BP_INTR_MASK_INTB 0x02 #define SIBA_PCI_BP_PCI_MBOX 0x0028 #define SIBA_PCI_BP_BCAST_ADDR 0x0050 @@ -121,4 +123,10 @@ #define SIBA_PCI_TRANS1 0x0104 #define SIBA_PCI_TRANS2 0x0108 +/* PCIcore resources */ +#define SIBA_PCI_MEM_START 0x40000000UL +#define SIBA_PCI_MEM_SIZE 0x40000000UL +#define SIBA_PCI_IO_START 0x100 +#define SIBA_PCI_IO_SIZE 0x700 + #endif /* _SIBA_SIBAREG_H_ */