From aa71bc7886908a33ee90db63b3423f39d6c58f87 Mon Sep 17 00:00:00 2001 From: rumble Date: Wed, 30 Aug 2006 23:35:10 +0000 Subject: [PATCH] Generalise pci/pci_machdep.c further and move all mace-specific code into mace/pci_mace.c in preparation for pci devices on the gio(4) bus. --- sys/arch/sgimips/include/pci_machdep.h | 14 +++- sys/arch/sgimips/mace/pci_mace.c | 78 +++++++++++++++++++-- sys/arch/sgimips/pci/pci_machdep.c | 95 ++++++++------------------ 3 files changed, 113 insertions(+), 74 deletions(-) diff --git a/sys/arch/sgimips/include/pci_machdep.h b/sys/arch/sgimips/include/pci_machdep.h index 10ccf51a7cd8..8daf922850ca 100644 --- a/sys/arch/sgimips/include/pci_machdep.h +++ b/sys/arch/sgimips/include/pci_machdep.h @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.h,v 1.8 2006/04/17 14:01:08 tsutsui Exp $ */ +/* $NetBSD: pci_machdep.h,v 1.9 2006/08/30 23:35:10 rumble Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. @@ -34,6 +34,8 @@ * Machine-specific definitions for PCI autoconfiguration. */ +#define __HAVE_PCI_CONF_HOOK + /* * Forward declarations. */ @@ -52,15 +54,24 @@ typedef int pci_intr_handle_t; * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE. */ struct sgimips_pci_chipset { + int (*pc_bus_maxdevs)(pci_chipset_tag_t, int); pcireg_t (*pc_conf_read)(pci_chipset_tag_t, pcitag_t, int); void (*pc_conf_write)(pci_chipset_tag_t, pcitag_t, int, pcireg_t); + int (*pc_conf_hook)(pci_chipset_tag_t, int, int, int, + pcireg_t); + int (*pc_intr_map)(struct pci_attach_args *, + pci_intr_handle_t *); + const char * (*pc_intr_string)(pci_chipset_tag_t pc, + pci_intr_handle_t); void *(*intr_establish)(int , int, int (*)(void *), void *); void (*intr_disestablish)(void *ih); bus_space_tag_t iot; bus_space_handle_t ioh; + void *cookie; + struct extent *pc_memext; /* PCI memory space extent */ struct extent *pc_ioext; /* PCI I/O space extent */ }; @@ -79,6 +90,7 @@ void pci_decompose_tag(pci_chipset_tag_t, pcitag_t, pcireg_t pci_conf_read(pci_chipset_tag_t, pcitag_t, int); void pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); +int pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t); int pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); const char *pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); const struct evcnt *pci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t); diff --git a/sys/arch/sgimips/mace/pci_mace.c b/sys/arch/sgimips/mace/pci_mace.c index 09a0dd45b65d..469825325fb7 100644 --- a/sys/arch/sgimips/mace/pci_mace.c +++ b/sys/arch/sgimips/mace/pci_mace.c @@ -1,4 +1,4 @@ -/* $NetBSD: pci_mace.c,v 1.7 2006/04/17 14:01:08 tsutsui Exp $ */ +/* $NetBSD: pci_mace.c,v 1.8 2006/08/30 23:35:10 rumble Exp $ */ /* * Copyright (c) 2001,2003 Christopher Sekiya @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pci_mace.c,v 1.7 2006/04/17 14:01:08 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_mace.c,v 1.8 2006/08/30 23:35:10 rumble Exp $"); #include "opt_pci.h" #include "pci.h" @@ -91,9 +91,13 @@ struct macepci_softc { static int macepci_match(struct device *, struct cfdata *, void *); static void macepci_attach(struct device *, struct device *, void *); -pcireg_t macepci_conf_read(pci_chipset_tag_t, pcitag_t, int); -void macepci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); -int macepci_intr(void *); +static int macepci_bus_maxdevs(pci_chipset_tag_t, int); +static pcireg_t macepci_conf_read(pci_chipset_tag_t, pcitag_t, int); +static void macepci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t); +static int macepci_intr_map(struct pci_attach_args *, pci_intr_handle_t *); +static const char * + macepci_intr_string(pci_chipset_tag_t, pci_intr_handle_t); +static int macepci_intr(void *); #ifndef PCI_NETBSD_CONFIGURE struct pciaddr pciaddr; @@ -137,8 +141,11 @@ macepci_attach(struct device *parent, struct device *self, void *aux) rev = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_REVISION); printf(": rev %d\n", rev); + pc->pc_bus_maxdevs = macepci_bus_maxdevs; pc->pc_conf_read = macepci_conf_read; pc->pc_conf_write = macepci_conf_write; + pc->pc_intr_map = macepci_intr_map; + pc->pc_intr_string = macepci_intr_string; pc->intr_establish = mace_intr_establish; pc->intr_disestablish = mace_intr_disestablish; @@ -241,6 +248,16 @@ macepci_attach(struct device *parent, struct device *self, void *aux) #endif } +int +macepci_bus_maxdevs(pci_chipset_tag_t pc, int busno) +{ + + if (busno == 0) + return 5; /* 2 on-board SCSI chips, slots 0, 1 and 2 */ + else + return 0; /* XXX */ +} + pcireg_t macepci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg) { @@ -265,6 +282,57 @@ macepci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0); } +int +macepci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) +{ + pci_chipset_tag_t pc = pa->pa_pc; + pcitag_t intrtag = pa->pa_intrtag; + int pin = pa->pa_intrpin; + int bus, dev, func, start; + + pci_decompose_tag(pc, intrtag, &bus, &dev, &func); + + if (dev < 3 && pin != PCI_INTERRUPT_PIN_A) + panic("SCSI0 and SCSI1 must be hardwired!"); + + switch (pin) { + default: + case PCI_INTERRUPT_PIN_NONE: + return -1; + + case PCI_INTERRUPT_PIN_A: + /* + * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt + * for pin A? + */ + *ihp = dev + 7; + return 0; + + case PCI_INTERRUPT_PIN_B: + start = 0; + break; + case PCI_INTERRUPT_PIN_C: + start = 1; + break; + case PCI_INTERRUPT_PIN_D: + start = 2; + break; + } + + /* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */ + *ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3; + return 0; +} + +const char * +macepci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih) +{ + static char irqstr[32]; + + sprintf(irqstr, "crime interrupt %d", ih); + return irqstr; +} + /* * Handle PCI error interrupts. diff --git a/sys/arch/sgimips/pci/pci_machdep.c b/sys/arch/sgimips/pci/pci_machdep.c index 614c30dbfcb0..f7207fce3c73 100644 --- a/sys/arch/sgimips/pci/pci_machdep.c +++ b/sys/arch/sgimips/pci/pci_machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.c,v 1.18 2006/05/14 21:56:33 elad Exp $ */ +/* $NetBSD: pci_machdep.c,v 1.19 2006/08/30 23:35:10 rumble Exp $ */ /* * Copyright (c) 2000 Soren S. Jorvang @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.18 2006/05/14 21:56:33 elad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.19 2006/08/30 23:35:10 rumble Exp $"); #include "opt_pci.h" #include "pci.h" @@ -55,30 +55,20 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.18 2006/05/14 21:56:33 elad Exp $" #include #include #include +#include -/* - * PCI doesn't have any special needs; just use - * the generic versions of these functions. - */ -struct sgimips_bus_dma_tag pci_bus_dma_tag = { - _bus_dmamap_create, - _bus_dmamap_destroy, - _bus_dmamap_load, - _bus_dmamap_load_mbuf, - _bus_dmamap_load_uio, - _bus_dmamap_load_raw, - _bus_dmamap_unload, - _bus_dmamap_sync_mips3, - _bus_dmamem_alloc, - _bus_dmamem_free, - _bus_dmamem_map, - _bus_dmamem_unmap, - _bus_dmamem_mmap, -}; +struct sgimips_bus_dma_tag pci_bus_dma_tag; void pci_attach_hook(struct device *parent, struct device *self, struct pcibus_attach_args *pba) { + /* + * PCI doesn't have any special needs; just use + * the generic versions of these functions as + * established in sgimips_bus_dma_init(). + */ + pci_bus_dma_tag = sgimips_default_bus_dma_tag; /* struct copy */ + /* XXX */ return; @@ -88,10 +78,7 @@ int pci_bus_maxdevs(pci_chipset_tag_t pc, int busno) { - if (busno == 0) - return 5; /* 2 on-board SCSI chips, slots 0, 1 and 2 */ - else - return 32; /* XXX */ + return (*pc->pc_bus_maxdevs)(pc, busno); } pcitag_t @@ -130,52 +117,13 @@ pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data) int pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp) { - pci_chipset_tag_t pc = pa->pa_pc; - pcitag_t intrtag = pa->pa_intrtag; - int pin = pa->pa_intrpin; - int bus, dev, func, start; - - pci_decompose_tag(pc, intrtag, &bus, &dev, &func); - - if (dev < 3 && pin != PCI_INTERRUPT_PIN_A) - panic("SCSI0 and SCSI1 must be hardwired!"); - - switch (pin) { - default: - case PCI_INTERRUPT_PIN_NONE: - return -1; - - case PCI_INTERRUPT_PIN_A: - /* - * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt - * for pin A? - */ - *ihp = dev + 7; - return 0; - - case PCI_INTERRUPT_PIN_B: - start = 0; - break; - case PCI_INTERRUPT_PIN_C: - start = 1; - break; - case PCI_INTERRUPT_PIN_D: - start = 2; - break; - } - - /* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */ - *ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3; - return 0; + return (*pa->pa_pc->pc_intr_map)(pa, ihp); } const char * pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih) { - static char irqstr[32]; - - sprintf(irqstr, "crime interrupt %d", ih); - return irqstr; + return (*pc->pc_intr_string)(pc, ih); } const struct evcnt * @@ -191,17 +139,28 @@ pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level, int (*func)(void *), void *arg) { - return (void *)(pc->intr_establish)(ih, 0, func, arg); + return (void *)(*pc->intr_establish)(ih, 0, func, arg); } void pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie) { - (pc->intr_disestablish)(cookie); + (*pc->intr_disestablish)(cookie); } #ifdef PCI_NETBSD_CONFIGURE +int +pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function, + pcireg_t id) +{ + + if (pc->pc_conf_hook) + return (*pc->pc_conf_hook)(pc, bus, device, function, id); + else + return (PCI_CONF_DEFAULT); +} + void pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz, int *iline)