pci_conf_setfunc(psycho_pci_conf_read, psycho_pci_conf_write);
psycho_attach(parent, self, aux)	struct device *parent, *self;	void *aux;{	struct psycho_softc *sc = (struct psycho_softc *)self;	struct psycho_softc *osc = NULL;	struct psycho_pbm *pp;	struct pcibus_attach_args pba;	struct mainbus_attach_args *ma = aux;	bus_space_handle_t bh;	u_int64_t csr;	int psycho_br[2], n;	struct pci_ctl *pci_ctl;	struct psycho_type *ptype;	printf("\n");	sc->sc_node = ma->ma_node;	sc->sc_bustag = ma->ma_bustag;	sc->sc_dmatag = ma->ma_dmatag;	/*	 * call the model-specific initialisation routine.	 */	for (ptype = psycho_types; ptype->p_name != NULL; ptype++) {		char *str;		str = getpropstring(ma->ma_node, "model");		if (strcmp(str, ptype->p_name) == 0)			break;		str = getpropstring(ma->ma_node, "compatible");		if (strcmp(str, ptype->p_name) == 0)			break;	}	if (ptype->p_name == NULL)		panic("psycho_attach: unknown model?");	sc->sc_mode = ptype->p_type;	/*	 * The psycho gets three register banks:	 * (0) per-PBM configuration and status registers	 * (1) per-PBM PCI configuration space, containing only the	 *     PBM 256-byte PCI header	 * (2) the shared psycho configuration registers (struct psychoreg)	 *	 * XXX use the prom address for the psycho registers?  we do so far.	 */	/* Register layouts are different.  stuupid. */	if (sc->sc_mode == PSYCHO_MODE_PSYCHO) {		sc->sc_basepaddr = (paddr_t)ma->ma_reg[2].ur_paddr;		if (ma->ma_naddress > 2) {			sc->sc_regs = (struct psychoreg *)			    (u_long)ma->ma_address[2];			pci_ctl = (struct pci_ctl *)			    (u_long)ma->ma_address[0];		} else if (ma->ma_nreg > 2) {			bus_space_handle_t handle;			/* We need to map this in ourselves. */			if (bus_space_map2(sc->sc_bustag, 0,			    ma->ma_reg[2].ur_paddr, ma->ma_reg[2].ur_len,			    0, NULL, &handle))				panic("psycho_attach: cannot map regs");			sc->sc_regs = (struct psychoreg *)(u_long)handle;			if (bus_space_map2(sc->sc_bustag, 0,			    ma->ma_reg[0].ur_paddr, ma->ma_reg[0].ur_len,			    0, NULL, &handle))				panic("psycho_attach: cannot map ctl");/* XXX -- this is lost but never unmapped */			pci_ctl = (struct pci_ctl *)(u_long)handle;		} else			panic("psycho_attach: %d not enough registers",			    ma->ma_nreg);	} else {		sc->sc_basepaddr = (paddr_t)ma->ma_reg[0].ur_paddr;		if (ma->ma_naddress) {			sc->sc_regs = (struct psychoreg *)			    (u_long)ma->ma_address[0];			pci_ctl = (struct pci_ctl *)&sc->sc_regs->psy_pcictl[0];		} else if (ma->ma_nreg) {			bus_space_handle_t handle;			/* We need to map this in ourselves. */			if (bus_space_map2(sc->sc_bustag, 0,			    ma->ma_reg[0].ur_paddr, ma->ma_reg[0].ur_len,			    0, NULL, &handle))				panic("psycho_attach: cannot map regs");			sc->sc_regs = (struct psychoreg *)(u_long)handle;			pci_ctl = (struct pci_ctl *)&sc->sc_regs->psy_pcictl[0];		} else			panic("psycho_attach: %d not enough registers",			    ma->ma_nreg);	}	csr = sc->sc_regs->psy_csr;	sc->sc_ign = 0x7c0; /* APB IGN is always 0x7c */	if (sc->sc_mode == PSYCHO_MODE_PSYCHO)		sc->sc_ign = PSYCHO_GCSR_IGN(csr) << 6;	printf("%s: impl %d, version %d: ign %x ", ptype->p_name,	    PSYCHO_GCSR_IMPL(csr), PSYCHO_GCSR_VERS(csr), sc->sc_ign);	/*	 * Match other psycho's that are already configured against	 * the base physical address. This will be the same for a	 * pair of devices that share register space.	 */	for (n = 0; n < psycho_cd.cd_ndevs; n++) {		struct psycho_softc *asc =		    (struct psycho_softc *)psycho_cd.cd_devs[n];		if (asc == NULL || asc == sc)			/* This entry is not there or it is me */			continue;		if (asc->sc_basepaddr != sc->sc_basepaddr)			/* This is an unrelated psycho */			continue;		/* Found partner */		osc = asc;		break;	}	/* Oh, dear.  OK, lets get started */	/*	 * Setup the PCI control register	 */	csr = bus_space_read_8(sc->sc_bustag,	    (bus_space_handle_t)(u_long)&pci_ctl->pci_csr, 0);	csr |= PCICTL_MRLM | PCICTL_ARB_PARK | PCICTL_ERRINTEN |	    PCICTL_4ENABLE;	csr &= ~(PCICTL_SERR | PCICTL_CPU_PRIO | PCICTL_ARB_PRIO |	    PCICTL_RTRYWAIT);	bus_space_write_8(sc->sc_bustag,	    (bus_space_handle_t)(u_long)&pci_ctl->pci_csr, 0, csr);	/*	 * Allocate our psycho_pbm	 */	pp = sc->sc_psycho_this = malloc(sizeof *pp, M_DEVBUF, M_NOWAIT);	if (pp == NULL)		panic("could not allocate psycho pbm");	memset(pp, 0, sizeof *pp);	pp->pp_sc = sc;	/* grab the psycho ranges */	psycho_get_ranges(sc->sc_node, &pp->pp_range, &pp->pp_nrange);	/* get the bus-range for the psycho */	psycho_get_bus_range(sc->sc_node, psycho_br);	pba.pba_bus = psycho_br[0];	printf("bus range %u to %u", psycho_br[0], psycho_br[1]);	printf("; PCI bus %d", psycho_br[0]);	pci_conf_setfunc(psycho_pci_conf_read, psycho_pci_conf_write);	pp->pp_pcictl = &sc->sc_regs->psy_pcictl[0];	/* allocate our tags */	pp->pp_memt = psycho_alloc_mem_tag(pp);	pp->pp_iot = psycho_alloc_io_tag(pp);	pp->pp_dmat = psycho_alloc_dma_tag(pp);	pp->pp_flags = (pp->pp_memt ? PCI_FLAGS_MEM_ENABLED : 0) |	    (pp->pp_iot ? PCI_FLAGS_IO_ENABLED : 0);	/* allocate a chipset for this */	pp->pp_pc = psycho_alloc_chipset(pp, sc->sc_node, &_sparc_pci_chipset);	/* setup the rest of the psycho pbm */	pba.pba_pc = pp->pp_pc;	printf("\n");	/*	 * And finally, if we're a sabre or the first of a pair of psycho's to	 * arrive here, start up the IOMMU and get a config space tag.	 */	if (osc == NULL) {		/*		 * Establish handlers for interesting interrupts....		 *		 * XXX We need to remember these and remove this to support		 * hotplug on the UPA/FHC bus.		 *		 * XXX Not all controllers have these, but installing them		 * is better than trying to sort through this mess.		 */		psycho_set_intr(sc, 15, psycho_ue,		    &sc->sc_regs->ue_int_map,		    &sc->sc_regs->ue_clr_int);		psycho_set_intr(sc, 1, psycho_ce,		    &sc->sc_regs->ce_int_map,		    &sc->sc_regs->ce_clr_int);		psycho_set_intr(sc, 15, psycho_bus_a,		    &sc->sc_regs->pciaerr_int_map,		    &sc->sc_regs->pciaerr_clr_int);		psycho_set_intr(sc, 15, psycho_bus_b,		    &sc->sc_regs->pciberr_int_map,		    &sc->sc_regs->pciberr_clr_int);#if 0		psycho_set_intr(sc, 15, psycho_powerfail,		    &sc->sc_regs->power_int_map, 		    &sc->sc_regs->power_clr_int);#endif		psycho_set_intr(sc, 1, psycho_wakeup,		    &sc->sc_regs->pwrmgt_int_map, 		    &sc->sc_regs->pwrmgt_clr_int);		/*		 * Setup IOMMU and PCI configuration if we're the first		 * of a pair of psycho's to arrive here.		 *		 * We should calculate a TSB size based on amount of RAM		 * and number of bus controllers and number an type of		 * child devices.		 *		 * For the moment, 32KB should be more than enough.		 */		sc->sc_is = malloc(sizeof(struct iommu_state),			M_DEVBUF, M_NOWAIT);		if (sc->sc_is == NULL)			panic("psycho_attach: malloc iommu_state");		sc->sc_is->is_sb[0] = NULL;		sc->sc_is->is_sb[1] = NULL;		if (getproplen(sc->sc_node, "no-streaming-cache") >= 0)			sc->sc_is->is_sb[0] = &pci_ctl->pci_strbuf;		psycho_iommu_init(sc, 2);		sc->sc_configtag = psycho_alloc_config_tag(sc->sc_psycho_this);		if (bus_space_map2(sc->sc_bustag,		    PCI_CONFIG_BUS_SPACE, sc->sc_basepaddr + 0x01000000,		    0x0100000, 0, 0, &bh))			panic("could not map psycho PCI configuration space");		sc->sc_configaddr = (off_t)bh;	} else {		/* Just copy IOMMU state, config tag and address */		sc->sc_is = osc->sc_is;		sc->sc_configtag = osc->sc_configtag;		sc->sc_configaddr = osc->sc_configaddr;		if (getproplen(sc->sc_node, "no-streaming-cache") >= 0)			sc->sc_is->is_sb[1] = &pci_ctl->pci_strbuf;		iommu_reset(sc->sc_is);	}	/*	 * XXX Linux magic, helps U30	 * "PROM sets the IRQ retry value too low, increase it."	 */	sc->sc_regs->intr_retry_timer = 0xff;	/*	 * attach the pci.. note we pass PCI A tags, etc., for the sabre here.	 */	pba.pba_busname = "pci";#if 0	pba.pba_flags = sc->sc_psycho_this->pp_flags;#endif	pba.pba_dmat = sc->sc_psycho_this->pp_dmat;	pba.pba_iot = sc->sc_psycho_this->pp_iot;	pba.pba_memt = sc->sc_psycho_this->pp_memt;	config_found(self, &pba, psycho_print);}