Home | History | Annotate | Line # | Download | only in dev
psycho.c revision 1.52
      1  1.52   provos /*	$NetBSD: psycho.c,v 1.52 2002/09/27 15:36:49 provos Exp $	*/
      2   1.1      mrg 
      3   1.1      mrg /*
      4  1.46      eeh  * Copyright (c) 2001, 2002 Eduardo E. Horvath
      5   1.3      mrg  * Copyright (c) 1999, 2000 Matthew R. Green
      6   1.1      mrg  * All rights reserved.
      7   1.1      mrg  *
      8   1.1      mrg  * Redistribution and use in source and binary forms, with or without
      9   1.1      mrg  * modification, are permitted provided that the following conditions
     10   1.1      mrg  * are met:
     11   1.1      mrg  * 1. Redistributions of source code must retain the above copyright
     12   1.1      mrg  *    notice, this list of conditions and the following disclaimer.
     13   1.1      mrg  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1      mrg  *    notice, this list of conditions and the following disclaimer in the
     15   1.1      mrg  *    documentation and/or other materials provided with the distribution.
     16   1.1      mrg  * 3. The name of the author may not be used to endorse or promote products
     17   1.1      mrg  *    derived from this software without specific prior written permission.
     18   1.1      mrg  *
     19   1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20   1.1      mrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21   1.1      mrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22   1.1      mrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23   1.1      mrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     24   1.1      mrg  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25   1.1      mrg  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     26   1.1      mrg  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     27   1.1      mrg  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1      mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1      mrg  * SUCH DAMAGE.
     30   1.1      mrg  */
     31   1.1      mrg 
     32   1.7      mrg #include "opt_ddb.h"
     33   1.7      mrg 
     34   1.1      mrg /*
     35  1.34      eeh  * Support for `psycho' and `psycho+' UPA to PCI bridge and
     36  1.34      eeh  * UltraSPARC IIi and IIe `sabre' PCI controllers.
     37   1.1      mrg  */
     38   1.1      mrg 
     39   1.1      mrg #ifdef DEBUG
     40   1.7      mrg #define PDB_PROM	0x01
     41  1.34      eeh #define PDB_BUSMAP	0x02
     42  1.34      eeh #define PDB_INTR	0x04
     43   1.3      mrg int psycho_debug = 0x0;
     44   1.1      mrg #define DPRINTF(l, s)   do { if (psycho_debug & l) printf s; } while (0)
     45   1.1      mrg #else
     46   1.1      mrg #define DPRINTF(l, s)
     47   1.1      mrg #endif
     48   1.1      mrg 
     49   1.1      mrg #include <sys/param.h>
     50   1.7      mrg #include <sys/device.h>
     51   1.7      mrg #include <sys/errno.h>
     52   1.1      mrg #include <sys/extent.h>
     53   1.7      mrg #include <sys/malloc.h>
     54   1.7      mrg #include <sys/systm.h>
     55   1.1      mrg #include <sys/time.h>
     56  1.34      eeh #include <sys/reboot.h>
     57   1.1      mrg 
     58   1.1      mrg #define _SPARC_BUS_DMA_PRIVATE
     59   1.1      mrg #include <machine/bus.h>
     60   1.1      mrg #include <machine/autoconf.h>
     61  1.18      eeh #include <machine/psl.h>
     62   1.1      mrg 
     63   1.1      mrg #include <dev/pci/pcivar.h>
     64   1.1      mrg #include <dev/pci/pcireg.h>
     65   1.1      mrg 
     66   1.1      mrg #include <sparc64/dev/iommureg.h>
     67   1.1      mrg #include <sparc64/dev/iommuvar.h>
     68   1.1      mrg #include <sparc64/dev/psychoreg.h>
     69   1.1      mrg #include <sparc64/dev/psychovar.h>
     70   1.7      mrg #include <sparc64/sparc64/cache.h>
     71   1.1      mrg 
     72   1.8      mrg #include "ioconf.h"
     73   1.8      mrg 
     74   1.1      mrg static pci_chipset_tag_t psycho_alloc_chipset __P((struct psycho_pbm *, int,
     75   1.1      mrg 						   pci_chipset_tag_t));
     76   1.1      mrg static void psycho_get_bus_range __P((int, int *));
     77   1.1      mrg static void psycho_get_ranges __P((int, struct psycho_ranges **, int *));
     78  1.34      eeh static void psycho_set_intr __P((struct psycho_softc *, int, void *,
     79  1.34      eeh 	u_int64_t *, u_int64_t *));
     80  1.34      eeh 
     81  1.34      eeh /* Interrupt handlers */
     82  1.34      eeh static int psycho_ue __P((void *));
     83  1.34      eeh static int psycho_ce __P((void *));
     84  1.34      eeh static int psycho_bus_a __P((void *));
     85  1.34      eeh static int psycho_bus_b __P((void *));
     86  1.34      eeh static int psycho_powerfail __P((void *));
     87  1.34      eeh static int psycho_wakeup __P((void *));
     88  1.34      eeh 
     89   1.1      mrg 
     90   1.1      mrg /* IOMMU support */
     91  1.13      eeh static void psycho_iommu_init __P((struct psycho_softc *, int));
     92   1.1      mrg 
     93   1.7      mrg /*
     94   1.7      mrg  * bus space and bus dma support for UltraSPARC `psycho'.  note that most
     95   1.7      mrg  * of the bus dma support is provided by the iommu dvma controller.
     96   1.7      mrg  */
     97  1.44      eeh static paddr_t psycho_bus_mmap __P((bus_space_tag_t, bus_addr_t, off_t,
     98  1.44      eeh 				    int, int));
     99  1.44      eeh static int _psycho_bus_map __P((bus_space_tag_t, bus_addr_t, bus_size_t, int,
    100  1.44      eeh 				vaddr_t, bus_space_handle_t *));
    101  1.21       pk static void *psycho_intr_establish __P((bus_space_tag_t, int, int, int,
    102   1.7      mrg 				int (*) __P((void *)), void *));
    103   1.7      mrg 
    104   1.7      mrg static int psycho_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
    105   1.7      mrg 				   bus_size_t, struct proc *, int));
    106   1.7      mrg static void psycho_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
    107   1.9      eeh static int psycho_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
    108   1.9      eeh 		    bus_dma_segment_t *, int, bus_size_t, int));
    109   1.7      mrg static void psycho_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    110   1.7      mrg 				    bus_size_t, int));
    111   1.7      mrg int psycho_dmamem_alloc __P((bus_dma_tag_t, bus_size_t, bus_size_t, bus_size_t,
    112   1.7      mrg 			     bus_dma_segment_t *, int, int *, int));
    113   1.7      mrg void psycho_dmamem_free __P((bus_dma_tag_t, bus_dma_segment_t *, int));
    114   1.7      mrg int psycho_dmamem_map __P((bus_dma_tag_t, bus_dma_segment_t *, int, size_t,
    115   1.7      mrg 			   caddr_t *, int));
    116   1.7      mrg void psycho_dmamem_unmap __P((bus_dma_tag_t, caddr_t, size_t));
    117   1.7      mrg 
    118   1.7      mrg /* base pci_chipset */
    119   1.1      mrg extern struct sparc_pci_chipset _sparc_pci_chipset;
    120   1.1      mrg 
    121   1.1      mrg /*
    122   1.1      mrg  * autoconfiguration
    123   1.1      mrg  */
    124   1.1      mrg static	int	psycho_match __P((struct device *, struct cfdata *, void *));
    125   1.1      mrg static	void	psycho_attach __P((struct device *, struct device *, void *));
    126   1.1      mrg static	int	psycho_print __P((void *aux, const char *p));
    127   1.1      mrg 
    128   1.1      mrg struct cfattach psycho_ca = {
    129   1.1      mrg         sizeof(struct psycho_softc), psycho_match, psycho_attach
    130   1.1      mrg };
    131   1.1      mrg 
    132   1.1      mrg /*
    133  1.34      eeh  * "sabre" is the UltraSPARC IIi onboard UPA to PCI bridge.  It manages a
    134  1.34      eeh  * single PCI bus and does not have a streaming buffer.  It often has an APB
    135  1.34      eeh  * (advanced PCI bridge) connected to it, which was designed specifically for
    136  1.34      eeh  * the IIi.  The APB let's the IIi handle two independednt PCI buses, and
    137  1.34      eeh  * appears as two "simba"'s underneath the sabre.
    138  1.34      eeh  *
    139  1.34      eeh  * "psycho" and "psycho+" is a dual UPA to PCI bridge.  It sits on the UPA bus
    140  1.34      eeh  * and manages two PCI buses.  "psycho" has two 64-bit 33MHz buses, while
    141  1.34      eeh  * "psycho+" controls both a 64-bit 33Mhz and a 64-bit 66Mhz PCI bus.  You
    142  1.34      eeh  * will usually find a "psycho+" since I don't think the original "psycho"
    143  1.34      eeh  * ever shipped, and if it did it would be in the U30.
    144  1.34      eeh  *
    145  1.34      eeh  * Each "psycho" PCI bus appears as a separate OFW node, but since they are
    146  1.34      eeh  * both part of the same IC, they only have a single register space.  As such,
    147  1.34      eeh  * they need to be configured together, even though the autoconfiguration will
    148  1.34      eeh  * attach them separately.
    149  1.34      eeh  *
    150  1.34      eeh  * On UltraIIi machines, "sabre" itself usually takes pci0, with "simba" often
    151  1.34      eeh  * as pci1 and pci2, although they have been implemented with other PCI bus
    152  1.34      eeh  * numbers on some machines.
    153  1.34      eeh  *
    154  1.34      eeh  * On UltraII machines, there can be any number of "psycho+" ICs, each
    155  1.34      eeh  * providing two PCI buses.
    156  1.34      eeh  *
    157  1.34      eeh  *
    158  1.34      eeh  * XXXX The psycho/sabre node has an `interrupts' attribute.  They contain
    159  1.34      eeh  * the values of the following interrupts in this order:
    160   1.1      mrg  *
    161  1.34      eeh  * PCI Bus Error	(30)
    162  1.34      eeh  * DMA UE		(2e)
    163  1.34      eeh  * DMA CE		(2f)
    164  1.34      eeh  * Power Fail		(25)
    165  1.34      eeh  *
    166  1.34      eeh  * We really should attach handlers for each.
    167   1.1      mrg  *
    168   1.1      mrg  */
    169  1.35      eeh 
    170   1.1      mrg #define	ROM_PCI_NAME		"pci"
    171  1.35      eeh 
    172  1.35      eeh struct psycho_names {
    173  1.35      eeh 	char *p_name;
    174  1.35      eeh 	int p_type;
    175  1.35      eeh } psycho_names[] = {
    176  1.35      eeh 	{ "SUNW,psycho",        PSYCHO_MODE_PSYCHO      },
    177  1.35      eeh 	{ "pci108e,8000",       PSYCHO_MODE_PSYCHO      },
    178  1.35      eeh 	{ "SUNW,sabre",         PSYCHO_MODE_SABRE       },
    179  1.35      eeh 	{ "pci108e,a000",       PSYCHO_MODE_SABRE       },
    180  1.35      eeh 	{ "pci108e,a001",       PSYCHO_MODE_SABRE       },
    181  1.35      eeh 	{ NULL, 0 }
    182  1.35      eeh };
    183   1.1      mrg 
    184   1.1      mrg static	int
    185   1.1      mrg psycho_match(parent, match, aux)
    186   1.1      mrg 	struct device	*parent;
    187   1.1      mrg 	struct cfdata	*match;
    188   1.1      mrg 	void		*aux;
    189   1.1      mrg {
    190   1.1      mrg 	struct mainbus_attach_args *ma = aux;
    191  1.38      eeh 	char *model = PROM_getpropstring(ma->ma_node, "model");
    192  1.35      eeh 	int i;
    193   1.1      mrg 
    194   1.1      mrg 	/* match on a name of "pci" and a sabre or a psycho */
    195  1.35      eeh 	if (strcmp(ma->ma_name, ROM_PCI_NAME) == 0) {
    196  1.35      eeh 		for (i=0; psycho_names[i].p_name; i++)
    197  1.35      eeh 			if (strcmp(model, psycho_names[i].p_name) == 0)
    198  1.35      eeh 				return (1);
    199  1.35      eeh 
    200  1.38      eeh 		model = PROM_getpropstring(ma->ma_node, "compatible");
    201  1.35      eeh 		for (i=0; psycho_names[i].p_name; i++)
    202  1.35      eeh 			if (strcmp(model, psycho_names[i].p_name) == 0)
    203  1.35      eeh 				return (1);
    204  1.35      eeh 	}
    205   1.1      mrg 	return (0);
    206   1.1      mrg }
    207   1.1      mrg 
    208  1.34      eeh /*
    209  1.34      eeh  * SUNW,psycho initialisation ..
    210  1.34      eeh  *	- find the per-psycho registers
    211  1.34      eeh  *	- figure out the IGN.
    212  1.34      eeh  *	- find our partner psycho
    213  1.34      eeh  *	- configure ourselves
    214  1.34      eeh  *	- bus range, bus,
    215  1.34      eeh  *	- get interrupt-map and interrupt-map-mask
    216  1.34      eeh  *	- setup the chipsets.
    217  1.34      eeh  *	- if we're the first of the pair, initialise the IOMMU, otherwise
    218  1.34      eeh  *	  just copy it's tags and addresses.
    219  1.34      eeh  */
    220   1.1      mrg static	void
    221   1.1      mrg psycho_attach(parent, self, aux)
    222   1.1      mrg 	struct device *parent, *self;
    223   1.1      mrg 	void *aux;
    224   1.1      mrg {
    225   1.1      mrg 	struct psycho_softc *sc = (struct psycho_softc *)self;
    226  1.34      eeh 	struct psycho_softc *osc = NULL;
    227  1.34      eeh 	struct psycho_pbm *pp;
    228  1.47  thorpej 	struct pcibus_attach_args pba;
    229   1.1      mrg 	struct mainbus_attach_args *ma = aux;
    230  1.34      eeh 	bus_space_handle_t bh;
    231  1.34      eeh 	u_int64_t csr;
    232  1.35      eeh 	int psycho_br[2], n, i;
    233  1.45      eeh 	bus_space_handle_t pci_ctl;
    234  1.38      eeh 	char *model = PROM_getpropstring(ma->ma_node, "model");
    235   1.1      mrg 
    236   1.1      mrg 	printf("\n");
    237   1.1      mrg 
    238   1.1      mrg 	sc->sc_node = ma->ma_node;
    239   1.1      mrg 	sc->sc_bustag = ma->ma_bustag;
    240   1.1      mrg 	sc->sc_dmatag = ma->ma_dmatag;
    241   1.1      mrg 
    242   1.1      mrg 	/*
    243  1.45      eeh 	 * Identify the device.
    244   1.1      mrg 	 */
    245  1.35      eeh 	for (i=0; psycho_names[i].p_name; i++)
    246  1.35      eeh 		if (strcmp(model, psycho_names[i].p_name) == 0) {
    247  1.35      eeh 			sc->sc_mode = psycho_names[i].p_type;
    248  1.35      eeh 			goto found;
    249  1.35      eeh 		}
    250  1.35      eeh 
    251  1.38      eeh 	model = PROM_getpropstring(ma->ma_node, "compatible");
    252  1.35      eeh 	for (i=0; psycho_names[i].p_name; i++)
    253  1.35      eeh 		if (strcmp(model, psycho_names[i].p_name) == 0) {
    254  1.35      eeh 			sc->sc_mode = psycho_names[i].p_type;
    255  1.35      eeh 			goto found;
    256  1.35      eeh 		}
    257  1.34      eeh 
    258  1.35      eeh 	panic("unknown psycho model %s", model);
    259  1.35      eeh found:
    260   1.1      mrg 
    261   1.1      mrg 	/*
    262  1.22       pk 	 * The psycho gets three register banks:
    263  1.22       pk 	 * (0) per-PBM configuration and status registers
    264  1.22       pk 	 * (1) per-PBM PCI configuration space, containing only the
    265  1.22       pk 	 *     PBM 256-byte PCI header
    266  1.22       pk 	 * (2) the shared psycho configuration registers (struct psychoreg)
    267  1.22       pk 	 */
    268  1.34      eeh 
    269  1.34      eeh 	/* Register layouts are different.  stuupid. */
    270  1.34      eeh 	if (sc->sc_mode == PSYCHO_MODE_PSYCHO) {
    271  1.34      eeh 		sc->sc_basepaddr = (paddr_t)ma->ma_reg[2].ur_paddr;
    272  1.34      eeh 
    273  1.34      eeh 		if (ma->ma_naddress > 2) {
    274  1.45      eeh 			sparc_promaddr_to_handle(sc->sc_bustag,
    275  1.45      eeh 				ma->ma_address[2], &sc->sc_bh);
    276  1.45      eeh 			sparc_promaddr_to_handle(sc->sc_bustag,
    277  1.45      eeh 				ma->ma_address[0], &pci_ctl);
    278  1.45      eeh 
    279  1.34      eeh 			sc->sc_regs = (struct psychoreg *)
    280  1.45      eeh 				bus_space_vaddr(sc->sc_bustag, sc->sc_bh);
    281  1.34      eeh 		} else if (ma->ma_nreg > 2) {
    282  1.34      eeh 
    283  1.34      eeh 			/* We need to map this in ourselves. */
    284  1.44      eeh 			if (bus_space_map(sc->sc_bustag,
    285  1.34      eeh 				ma->ma_reg[2].ur_paddr,
    286  1.45      eeh 				ma->ma_reg[2].ur_len, BUS_SPACE_MAP_LINEAR,
    287  1.45      eeh 				&sc->sc_bh))
    288  1.34      eeh 				panic("psycho_attach: cannot map regs");
    289  1.45      eeh 			sc->sc_regs = (struct psychoreg *)
    290  1.45      eeh 				bus_space_vaddr(sc->sc_bustag, sc->sc_bh);
    291  1.34      eeh 
    292  1.44      eeh 			if (bus_space_map(sc->sc_bustag,
    293  1.34      eeh 				ma->ma_reg[0].ur_paddr,
    294  1.45      eeh 				ma->ma_reg[0].ur_len, BUS_SPACE_MAP_LINEAR,
    295  1.45      eeh 				&pci_ctl))
    296  1.34      eeh 				panic("psycho_attach: cannot map ctl");
    297  1.34      eeh 		} else
    298  1.34      eeh 			panic("psycho_attach: %d not enough registers",
    299  1.34      eeh 				ma->ma_nreg);
    300  1.34      eeh 	} else {
    301  1.34      eeh 		sc->sc_basepaddr = (paddr_t)ma->ma_reg[0].ur_paddr;
    302  1.34      eeh 
    303  1.34      eeh 		if (ma->ma_naddress) {
    304  1.45      eeh 			sparc_promaddr_to_handle(sc->sc_bustag,
    305  1.45      eeh 				ma->ma_address[0], &sc->sc_bh);
    306  1.34      eeh 			sc->sc_regs = (struct psychoreg *)
    307  1.45      eeh 				bus_space_vaddr(sc->sc_bustag, sc->sc_bh);
    308  1.45      eeh 			bus_space_subregion(sc->sc_bustag, sc->sc_bh,
    309  1.45      eeh 				offsetof(struct psychoreg,  psy_pcictl),
    310  1.45      eeh 				sizeof(struct pci_ctl), &pci_ctl);
    311  1.34      eeh 		} else if (ma->ma_nreg) {
    312  1.34      eeh 
    313  1.34      eeh 			/* We need to map this in ourselves. */
    314  1.44      eeh 			if (bus_space_map(sc->sc_bustag,
    315  1.34      eeh 				ma->ma_reg[0].ur_paddr,
    316  1.45      eeh 				ma->ma_reg[0].ur_len, BUS_SPACE_MAP_LINEAR,
    317  1.45      eeh 				&sc->sc_bh))
    318  1.34      eeh 				panic("psycho_attach: cannot map regs");
    319  1.45      eeh 			sc->sc_regs = (struct psychoreg *)
    320  1.45      eeh 				bus_space_vaddr(sc->sc_bustag, sc->sc_bh);
    321  1.45      eeh 
    322  1.45      eeh 			bus_space_subregion(sc->sc_bustag, sc->sc_bh,
    323  1.45      eeh 				offsetof(struct psychoreg,  psy_pcictl),
    324  1.45      eeh 				sizeof(struct pci_ctl), &pci_ctl);
    325  1.34      eeh 		} else
    326  1.34      eeh 			panic("psycho_attach: %d not enough registers",
    327  1.34      eeh 				ma->ma_nreg);
    328  1.34      eeh 	}
    329  1.23       pk 
    330  1.45      eeh 
    331  1.45      eeh 	csr = bus_space_read_8(sc->sc_bustag, sc->sc_bh,
    332  1.45      eeh 		offsetof(struct psychoreg, psy_csr));
    333  1.34      eeh 	sc->sc_ign = 0x7c0; /* APB IGN is always 0x7c */
    334  1.34      eeh 	if (sc->sc_mode == PSYCHO_MODE_PSYCHO)
    335  1.34      eeh 		sc->sc_ign = PSYCHO_GCSR_IGN(csr) << 6;
    336  1.24       pk 
    337  1.34      eeh 	printf("%s: impl %d, version %d: ign %x ",
    338  1.34      eeh 		model, PSYCHO_GCSR_IMPL(csr), PSYCHO_GCSR_VERS(csr),
    339  1.34      eeh 		sc->sc_ign);
    340  1.22       pk 	/*
    341  1.24       pk 	 * Match other psycho's that are already configured against
    342  1.24       pk 	 * the base physical address. This will be the same for a
    343  1.24       pk 	 * pair of devices that share register space.
    344   1.1      mrg 	 */
    345   1.3      mrg 	for (n = 0; n < psycho_cd.cd_ndevs; n++) {
    346   1.8      mrg 
    347  1.24       pk 		struct psycho_softc *asc =
    348  1.24       pk 			(struct psycho_softc *)psycho_cd.cd_devs[n];
    349   1.3      mrg 
    350  1.24       pk 		if (asc == NULL || asc == sc)
    351  1.24       pk 			/* This entry is not there or it is me */
    352  1.24       pk 			continue;
    353  1.23       pk 
    354  1.24       pk 		if (asc->sc_basepaddr != sc->sc_basepaddr)
    355  1.24       pk 			/* This is an unrelated psycho */
    356   1.3      mrg 			continue;
    357   1.3      mrg 
    358  1.24       pk 		/* Found partner */
    359  1.24       pk 		osc = asc;
    360   1.8      mrg 		break;
    361   1.8      mrg 	}
    362   1.8      mrg 
    363   1.3      mrg 
    364   1.3      mrg 	/* Oh, dear.  OK, lets get started */
    365   1.3      mrg 
    366  1.24       pk 	/*
    367  1.24       pk 	 * Setup the PCI control register
    368  1.24       pk 	 */
    369  1.45      eeh 	csr = bus_space_read_8(sc->sc_bustag, pci_ctl,
    370  1.45      eeh 		offsetof(struct pci_ctl, pci_csr));
    371   1.8      mrg 	csr |= PCICTL_MRLM |
    372   1.8      mrg 	       PCICTL_ARB_PARK |
    373   1.8      mrg 	       PCICTL_ERRINTEN |
    374   1.8      mrg 	       PCICTL_4ENABLE;
    375   1.8      mrg 	csr &= ~(PCICTL_SERR |
    376   1.8      mrg 		 PCICTL_CPU_PRIO |
    377   1.8      mrg 		 PCICTL_ARB_PRIO |
    378   1.8      mrg 		 PCICTL_RTRYWAIT);
    379  1.45      eeh 	bus_space_write_8(sc->sc_bustag, pci_ctl,
    380  1.45      eeh 		offsetof(struct pci_ctl, pci_csr), csr);
    381   1.8      mrg 
    382  1.24       pk 
    383  1.24       pk 	/*
    384  1.24       pk 	 * Allocate our psycho_pbm
    385  1.24       pk 	 */
    386  1.22       pk 	pp = sc->sc_psycho_this = malloc(sizeof *pp, M_DEVBUF, M_NOWAIT);
    387  1.22       pk 	if (pp == NULL)
    388   1.8      mrg 		panic("could not allocate psycho pbm");
    389   1.8      mrg 
    390  1.22       pk 	memset(pp, 0, sizeof *pp);
    391  1.22       pk 
    392  1.22       pk 	pp->pp_sc = sc;
    393   1.8      mrg 
    394   1.8      mrg 	/* grab the psycho ranges */
    395  1.22       pk 	psycho_get_ranges(sc->sc_node, &pp->pp_range, &pp->pp_nrange);
    396   1.8      mrg 
    397   1.8      mrg 	/* get the bus-range for the psycho */
    398   1.8      mrg 	psycho_get_bus_range(sc->sc_node, psycho_br);
    399   1.8      mrg 
    400  1.47  thorpej 	pba.pba_bus = psycho_br[0];
    401  1.48      eeh 	pba.pba_bridgetag = NULL;
    402   1.8      mrg 
    403   1.8      mrg 	printf("bus range %u to %u", psycho_br[0], psycho_br[1]);
    404  1.23       pk 	printf("; PCI bus %d", psycho_br[0]);
    405   1.8      mrg 
    406  1.45      eeh 	pp->pp_pcictl = pci_ctl;
    407   1.8      mrg 
    408   1.8      mrg 	/* allocate our tags */
    409   1.8      mrg 	pp->pp_memt = psycho_alloc_mem_tag(pp);
    410   1.8      mrg 	pp->pp_iot = psycho_alloc_io_tag(pp);
    411   1.8      mrg 	pp->pp_dmat = psycho_alloc_dma_tag(pp);
    412   1.8      mrg 	pp->pp_flags = (pp->pp_memt ? PCI_FLAGS_MEM_ENABLED : 0) |
    413   1.8      mrg 		       (pp->pp_iot ? PCI_FLAGS_IO_ENABLED : 0);
    414   1.8      mrg 
    415   1.8      mrg 	/* allocate a chipset for this */
    416   1.8      mrg 	pp->pp_pc = psycho_alloc_chipset(pp, sc->sc_node, &_sparc_pci_chipset);
    417   1.8      mrg 
    418   1.8      mrg 	/* setup the rest of the psycho pbm */
    419  1.47  thorpej 	pba.pba_pc = psycho_alloc_chipset(pp, sc->sc_node, pp->pp_pc);
    420   1.8      mrg 
    421   1.8      mrg 	printf("\n");
    422   1.8      mrg 
    423   1.8      mrg 	/*
    424  1.34      eeh 	 * And finally, if we're a sabre or the first of a pair of psycho's to
    425  1.24       pk 	 * arrive here, start up the IOMMU and get a config space tag.
    426   1.8      mrg 	 */
    427  1.24       pk 	if (osc == NULL) {
    428  1.40      eeh 		uint64_t timeo;
    429  1.34      eeh 
    430  1.34      eeh 		/*
    431  1.34      eeh 		 * Establish handlers for interesting interrupts....
    432  1.34      eeh 		 *
    433  1.34      eeh 		 * XXX We need to remember these and remove this to support
    434  1.34      eeh 		 * hotplug on the UPA/FHC bus.
    435  1.34      eeh 		 *
    436  1.34      eeh 		 * XXX Not all controllers have these, but installing them
    437  1.34      eeh 		 * is better than trying to sort through this mess.
    438  1.34      eeh 		 */
    439  1.34      eeh 		psycho_set_intr(sc, 15, psycho_ue,
    440  1.34      eeh 			&sc->sc_regs->ue_int_map,
    441  1.34      eeh 			&sc->sc_regs->ue_clr_int);
    442  1.34      eeh 		psycho_set_intr(sc, 1, psycho_ce,
    443  1.34      eeh 			&sc->sc_regs->ce_int_map,
    444  1.34      eeh 			&sc->sc_regs->ce_clr_int);
    445  1.34      eeh 		psycho_set_intr(sc, 15, psycho_bus_a,
    446  1.34      eeh 			&sc->sc_regs->pciaerr_int_map,
    447  1.34      eeh 			&sc->sc_regs->pciaerr_clr_int);
    448  1.34      eeh 		psycho_set_intr(sc, 15, psycho_bus_b,
    449  1.34      eeh 			&sc->sc_regs->pciberr_int_map,
    450  1.34      eeh 			&sc->sc_regs->pciberr_clr_int);
    451  1.34      eeh 		psycho_set_intr(sc, 15, psycho_powerfail,
    452  1.34      eeh 			&sc->sc_regs->power_int_map,
    453  1.34      eeh 			&sc->sc_regs->power_clr_int);
    454  1.34      eeh 		psycho_set_intr(sc, 1, psycho_wakeup,
    455  1.34      eeh 			&sc->sc_regs->pwrmgt_int_map,
    456  1.34      eeh 			&sc->sc_regs->pwrmgt_clr_int);
    457  1.40      eeh 
    458  1.40      eeh 
    459  1.40      eeh 		/*
    460  1.40      eeh 		 * Apparently a number of machines with psycho and psycho+
    461  1.40      eeh 		 * controllers have interrupt latency issues.  We'll try
    462  1.40      eeh 		 * setting the interrupt retry timeout to 0xff which gives us
    463  1.40      eeh 		 * a retry of 3-6 usec (which is what sysio is set to) for the
    464  1.40      eeh 		 * moment, which seems to help alleviate this problem.
    465  1.40      eeh 		 */
    466  1.45      eeh 		timeo = sc->sc_regs->intr_retry_timer;
    467  1.40      eeh 		if (timeo > 0xfff) {
    468  1.40      eeh #ifdef DEBUG
    469  1.40      eeh 			printf("decreasing interrupt retry timeout "
    470  1.40      eeh 				"from %lx to 0xff\n", (long)timeo);
    471  1.40      eeh #endif
    472  1.45      eeh 			sc->sc_regs->intr_retry_timer = 0xff;
    473  1.40      eeh 		}
    474  1.34      eeh 
    475  1.13      eeh 		/*
    476  1.24       pk 		 * Setup IOMMU and PCI configuration if we're the first
    477  1.24       pk 		 * of a pair of psycho's to arrive here.
    478  1.24       pk 		 *
    479  1.13      eeh 		 * We should calculate a TSB size based on amount of RAM
    480  1.34      eeh 		 * and number of bus controllers and number an type of
    481  1.34      eeh 		 * child devices.
    482  1.13      eeh 		 *
    483  1.13      eeh 		 * For the moment, 32KB should be more than enough.
    484  1.13      eeh 		 */
    485  1.39      eeh 		sc->sc_is = malloc(sizeof(struct iommu_state),
    486  1.39      eeh 			M_DEVBUF, M_NOWAIT);
    487  1.39      eeh 		if (sc->sc_is == NULL)
    488  1.39      eeh 			panic("psycho_attach: malloc iommu_state");
    489  1.39      eeh 
    490  1.50      eeh 		/* Point the strbuf_ctl at the iommu_state */
    491  1.50      eeh 		pp->pp_sb.sb_is = sc->sc_is;
    492  1.39      eeh 
    493  1.51      eeh 		sc->sc_is->is_sb[0] = sc->sc_is->is_sb[1] = NULL;
    494  1.45      eeh 		if (PROM_getproplen(sc->sc_node, "no-streaming-cache") < 0) {
    495  1.50      eeh 			struct strbuf_ctl *sb = &pp->pp_sb;
    496  1.50      eeh 			vaddr_t va = (vaddr_t)&pp->pp_flush[0x40];
    497  1.50      eeh 
    498  1.50      eeh 			/*
    499  1.50      eeh 			 * Initialize the strbuf_ctl.
    500  1.50      eeh 			 *
    501  1.50      eeh 			 * The flush sync buffer must be 64-byte aligned.
    502  1.50      eeh 			 */
    503  1.50      eeh 			sb->sb_flush = (void *)(va & ~0x3f);
    504  1.50      eeh 
    505  1.49      eeh 			bus_space_subregion(sc->sc_bustag, pci_ctl,
    506  1.45      eeh 				offsetof(struct pci_ctl, pci_strbuf),
    507  1.50      eeh 				sizeof (struct iommu_strbuf), &sb->sb_sb);
    508  1.50      eeh 
    509  1.50      eeh 			/* Point our iommu at the strbuf_ctl */
    510  1.50      eeh 			sc->sc_is->is_sb[0] = sb;
    511  1.45      eeh 		}
    512  1.39      eeh 
    513  1.13      eeh 		psycho_iommu_init(sc, 2);
    514   1.8      mrg 
    515   1.8      mrg 		sc->sc_configtag = psycho_alloc_config_tag(sc->sc_psycho_this);
    516  1.44      eeh 
    517  1.44      eeh 		/*
    518  1.44      eeh 		 * XXX This is a really ugly hack because PCI config space
    519  1.44      eeh 		 * is explicitly handled with unmapped accesses.
    520  1.44      eeh 		 */
    521  1.44      eeh 		i = sc->sc_bustag->type;
    522  1.44      eeh 		sc->sc_bustag->type = PCI_CONFIG_BUS_SPACE;
    523  1.44      eeh 		if (bus_space_map(sc->sc_bustag, sc->sc_basepaddr + 0x01000000,
    524  1.44      eeh 			0x0100000, 0, &bh))
    525  1.23       pk 			panic("could not map psycho PCI configuration space");
    526  1.44      eeh 		sc->sc_bustag->type = i;
    527  1.45      eeh 		sc->sc_configaddr = bh;
    528   1.8      mrg 	} else {
    529  1.24       pk 		/* Just copy IOMMU state, config tag and address */
    530  1.24       pk 		sc->sc_is = osc->sc_is;
    531   1.8      mrg 		sc->sc_configtag = osc->sc_configtag;
    532   1.8      mrg 		sc->sc_configaddr = osc->sc_configaddr;
    533  1.39      eeh 
    534  1.50      eeh 		/* Point the strbuf_ctl at the iommu_state */
    535  1.50      eeh 		pp->pp_sb.sb_is = sc->sc_is;
    536  1.50      eeh 
    537  1.45      eeh 		if (PROM_getproplen(sc->sc_node, "no-streaming-cache") < 0) {
    538  1.50      eeh 			struct strbuf_ctl *sb = &pp->pp_sb;
    539  1.50      eeh 			vaddr_t va = (vaddr_t)&pp->pp_flush[0x40];
    540  1.50      eeh 
    541  1.50      eeh 			/*
    542  1.50      eeh 			 * Initialize the strbuf_ctl.
    543  1.50      eeh 			 *
    544  1.50      eeh 			 * The flush sync buffer must be 64-byte aligned.
    545  1.50      eeh 			 */
    546  1.50      eeh 			sb->sb_flush = (void *)(va & ~0x3f);
    547  1.50      eeh 
    548  1.49      eeh 			bus_space_subregion(sc->sc_bustag, pci_ctl,
    549  1.45      eeh 				offsetof(struct pci_ctl, pci_strbuf),
    550  1.50      eeh 				sizeof (struct iommu_strbuf), &sb->sb_sb);
    551  1.50      eeh 
    552  1.50      eeh 			/* Point our iommu at the strbuf_ctl */
    553  1.50      eeh 			sc->sc_is->is_sb[1] = sb;
    554  1.45      eeh 		}
    555  1.39      eeh 		iommu_reset(sc->sc_is);
    556   1.8      mrg 	}
    557  1.34      eeh 
    558  1.34      eeh 	/*
    559  1.34      eeh 	 * attach the pci.. note we pass PCI A tags, etc., for the sabre here.
    560  1.34      eeh 	 */
    561  1.47  thorpej 	pba.pba_busname = "pci";
    562  1.47  thorpej 	pba.pba_flags = sc->sc_psycho_this->pp_flags;
    563  1.47  thorpej 	pba.pba_dmat = sc->sc_psycho_this->pp_dmat;
    564  1.47  thorpej 	pba.pba_iot = sc->sc_psycho_this->pp_iot;
    565  1.47  thorpej 	pba.pba_memt = sc->sc_psycho_this->pp_memt;
    566  1.34      eeh 
    567  1.34      eeh 	config_found(self, &pba, psycho_print);
    568  1.34      eeh }
    569  1.34      eeh 
    570  1.34      eeh static	int
    571  1.34      eeh psycho_print(aux, p)
    572  1.34      eeh 	void *aux;
    573  1.34      eeh 	const char *p;
    574  1.34      eeh {
    575  1.34      eeh 
    576  1.34      eeh 	if (p == NULL)
    577  1.34      eeh 		return (UNCONF);
    578  1.34      eeh 	return (QUIET);
    579  1.34      eeh }
    580  1.34      eeh 
    581  1.34      eeh static void
    582  1.34      eeh psycho_set_intr(sc, ipl, handler, mapper, clearer)
    583  1.34      eeh 	struct psycho_softc *sc;
    584  1.34      eeh 	int ipl;
    585  1.34      eeh 	void *handler;
    586  1.34      eeh 	u_int64_t *mapper;
    587  1.34      eeh 	u_int64_t *clearer;
    588  1.34      eeh {
    589  1.34      eeh 	struct intrhand *ih;
    590  1.34      eeh 
    591  1.34      eeh 	ih = (struct intrhand *)malloc(sizeof(struct intrhand),
    592  1.34      eeh 		M_DEVBUF, M_NOWAIT);
    593  1.34      eeh 	ih->ih_arg = sc;
    594  1.34      eeh 	ih->ih_map = mapper;
    595  1.34      eeh 	ih->ih_clr = clearer;
    596  1.34      eeh 	ih->ih_fun = handler;
    597  1.34      eeh 	ih->ih_pil = (1<<ipl);
    598  1.34      eeh 	ih->ih_number = INTVEC(*(ih->ih_map));
    599  1.34      eeh 	intr_establish(ipl, ih);
    600  1.34      eeh 	*(ih->ih_map) |= INTMAP_V;
    601   1.1      mrg }
    602   1.1      mrg 
    603   1.1      mrg /*
    604   1.1      mrg  * PCI bus support
    605   1.1      mrg  */
    606   1.1      mrg 
    607   1.1      mrg /*
    608   1.1      mrg  * allocate a PCI chipset tag and set it's cookie.
    609   1.1      mrg  */
    610   1.1      mrg static pci_chipset_tag_t
    611   1.1      mrg psycho_alloc_chipset(pp, node, pc)
    612   1.1      mrg 	struct psycho_pbm *pp;
    613   1.1      mrg 	int node;
    614   1.1      mrg 	pci_chipset_tag_t pc;
    615   1.1      mrg {
    616   1.1      mrg 	pci_chipset_tag_t npc;
    617   1.1      mrg 
    618   1.1      mrg 	npc = malloc(sizeof *npc, M_DEVBUF, M_NOWAIT);
    619   1.1      mrg 	if (npc == NULL)
    620   1.1      mrg 		panic("could not allocate pci_chipset_tag_t");
    621   1.1      mrg 	memcpy(npc, pc, sizeof *pc);
    622   1.1      mrg 	npc->cookie = pp;
    623  1.34      eeh 	npc->rootnode = node;
    624   1.1      mrg 
    625   1.1      mrg 	return (npc);
    626   1.1      mrg }
    627   1.1      mrg 
    628   1.1      mrg /*
    629   1.1      mrg  * grovel the OBP for various psycho properties
    630   1.1      mrg  */
    631   1.1      mrg static void
    632   1.1      mrg psycho_get_bus_range(node, brp)
    633   1.1      mrg 	int node;
    634   1.1      mrg 	int *brp;
    635   1.1      mrg {
    636   1.1      mrg 	int n;
    637   1.1      mrg 
    638  1.38      eeh 	if (PROM_getprop(node, "bus-range", sizeof(*brp), &n, (void **)&brp))
    639   1.1      mrg 		panic("could not get psycho bus-range");
    640   1.1      mrg 	if (n != 2)
    641   1.1      mrg 		panic("broken psycho bus-range");
    642   1.1      mrg 	DPRINTF(PDB_PROM, ("psycho debug: got `bus-range' for node %08x: %u - %u\n", node, brp[0], brp[1]));
    643   1.1      mrg }
    644   1.1      mrg 
    645   1.1      mrg static void
    646   1.1      mrg psycho_get_ranges(node, rp, np)
    647   1.1      mrg 	int node;
    648   1.1      mrg 	struct psycho_ranges **rp;
    649   1.1      mrg 	int *np;
    650   1.1      mrg {
    651   1.1      mrg 
    652  1.38      eeh 	if (PROM_getprop(node, "ranges", sizeof(**rp), np, (void **)rp))
    653   1.1      mrg 		panic("could not get psycho ranges");
    654   1.1      mrg 	DPRINTF(PDB_PROM, ("psycho debug: got `ranges' for node %08x: %d entries\n", node, *np));
    655   1.1      mrg }
    656   1.1      mrg 
    657  1.34      eeh /*
    658  1.34      eeh  * Interrupt handlers.
    659  1.34      eeh  */
    660  1.34      eeh 
    661  1.34      eeh static int
    662  1.34      eeh psycho_ue(arg)
    663  1.34      eeh 	void *arg;
    664  1.34      eeh {
    665  1.34      eeh 	struct psycho_softc *sc = (struct psycho_softc *)arg;
    666  1.34      eeh 	struct psychoreg *regs = sc->sc_regs;
    667  1.36      eeh 	long long afsr = regs->psy_ue_afsr;
    668  1.36      eeh 	long long afar = regs->psy_ue_afar;
    669  1.41      eeh 	long size = NBPG<<(sc->sc_is->is_tsbsize);
    670  1.41      eeh 	struct iommu_state *is = sc->sc_is;
    671  1.36      eeh 	char bits[128];
    672  1.34      eeh 
    673  1.34      eeh 	/*
    674  1.34      eeh 	 * It's uncorrectable.  Dump the regs and panic.
    675  1.34      eeh 	 */
    676  1.46      eeh 	printf("%s: uncorrectable DMA error AFAR %llx pa %llx AFSR %llx:\n%s\n",
    677  1.36      eeh 		sc->sc_dev.dv_xname, afar,
    678  1.41      eeh 		(long long)iommu_extract(is, (vaddr_t)afar), afsr,
    679  1.36      eeh 		bitmask_snprintf(afsr, PSYCHO_UE_AFSR_BITS,
    680  1.36      eeh 			bits, sizeof(bits)));
    681  1.41      eeh 
    682  1.41      eeh 	/* Sometimes the AFAR points to an IOTSB entry */
    683  1.41      eeh 	if (afar >= is->is_ptsb && afar < is->is_ptsb + size) {
    684  1.42   martin 		printf("IOVA %llx IOTTE %llx\n",
    685  1.42   martin 			(long long)((afar - is->is_ptsb) * NBPG + is->is_dvmabase),
    686  1.41      eeh 			(long long)ldxa(afar, ASI_PHYS_CACHED));
    687  1.41      eeh 	}
    688  1.43      chs #ifdef DDB
    689  1.41      eeh 	Debugger();
    690  1.43      chs #endif
    691  1.41      eeh 	regs->psy_ue_afar = 0;
    692  1.41      eeh 	regs->psy_ue_afsr = 0;
    693  1.34      eeh 	return (1);
    694  1.34      eeh }
    695  1.34      eeh static int
    696  1.34      eeh psycho_ce(arg)
    697  1.34      eeh 	void *arg;
    698   1.1      mrg {
    699  1.34      eeh 	struct psycho_softc *sc = (struct psycho_softc *)arg;
    700  1.34      eeh 	struct psychoreg *regs = sc->sc_regs;
    701  1.34      eeh 
    702  1.34      eeh 	/*
    703  1.34      eeh 	 * It's correctable.  Dump the regs and continue.
    704  1.34      eeh 	 */
    705   1.1      mrg 
    706  1.34      eeh 	printf("%s: correctable DMA error AFAR %llx AFSR %llx\n",
    707  1.34      eeh 		sc->sc_dev.dv_xname,
    708  1.34      eeh 		(long long)regs->psy_ce_afar, (long long)regs->psy_ce_afsr);
    709  1.34      eeh 	return (1);
    710   1.1      mrg }
    711  1.34      eeh static int
    712  1.34      eeh psycho_bus_a(arg)
    713  1.34      eeh 	void *arg;
    714  1.34      eeh {
    715  1.34      eeh 	struct psycho_softc *sc = (struct psycho_softc *)arg;
    716  1.34      eeh 	struct psychoreg *regs = sc->sc_regs;
    717  1.34      eeh 
    718  1.34      eeh 	/*
    719  1.34      eeh 	 * It's uncorrectable.  Dump the regs and panic.
    720  1.34      eeh 	 */
    721   1.1      mrg 
    722  1.52   provos 	panic("%s: PCI bus A error AFAR %llx AFSR %llx",
    723  1.34      eeh 		sc->sc_dev.dv_xname,
    724  1.35      eeh 		(long long)regs->psy_pcictl[0].pci_afar,
    725  1.35      eeh 		(long long)regs->psy_pcictl[0].pci_afsr);
    726  1.34      eeh 	return (1);
    727  1.34      eeh }
    728  1.34      eeh static int
    729  1.34      eeh psycho_bus_b(arg)
    730  1.34      eeh 	void *arg;
    731   1.1      mrg {
    732  1.34      eeh 	struct psycho_softc *sc = (struct psycho_softc *)arg;
    733  1.34      eeh 	struct psychoreg *regs = sc->sc_regs;
    734  1.34      eeh 
    735  1.34      eeh 	/*
    736  1.34      eeh 	 * It's uncorrectable.  Dump the regs and panic.
    737  1.34      eeh 	 */
    738   1.1      mrg 
    739  1.52   provos 	panic("%s: PCI bus B error AFAR %llx AFSR %llx",
    740  1.34      eeh 		sc->sc_dev.dv_xname,
    741  1.35      eeh 		(long long)regs->psy_pcictl[0].pci_afar,
    742  1.35      eeh 		(long long)regs->psy_pcictl[0].pci_afsr);
    743  1.34      eeh 	return (1);
    744   1.1      mrg }
    745  1.34      eeh static int
    746  1.34      eeh psycho_powerfail(arg)
    747  1.34      eeh 	void *arg;
    748  1.34      eeh {
    749   1.1      mrg 
    750  1.34      eeh 	/*
    751  1.34      eeh 	 * We lost power.  Try to shut down NOW.
    752  1.34      eeh 	 */
    753  1.34      eeh 	printf("Power Failure Detected: Shutting down NOW.\n");
    754  1.34      eeh 	cpu_reboot(RB_POWERDOWN|RB_HALT, NULL);
    755  1.34      eeh 	return (1);
    756  1.34      eeh }
    757  1.34      eeh static
    758  1.34      eeh int psycho_wakeup(arg)
    759  1.34      eeh 	void *arg;
    760   1.1      mrg {
    761  1.34      eeh 	struct psycho_softc *sc = (struct psycho_softc *)arg;
    762   1.1      mrg 
    763  1.34      eeh 	/*
    764  1.34      eeh 	 * Gee, we don't really have a framework to deal with this
    765  1.34      eeh 	 * properly.
    766  1.34      eeh 	 */
    767  1.34      eeh 	printf("%s: power management wakeup\n",	sc->sc_dev.dv_xname);
    768  1.34      eeh 	return (1);
    769   1.1      mrg }
    770   1.1      mrg 
    771  1.34      eeh 
    772  1.34      eeh 
    773   1.1      mrg /*
    774   1.1      mrg  * initialise the IOMMU..
    775   1.1      mrg  */
    776   1.1      mrg void
    777  1.13      eeh psycho_iommu_init(sc, tsbsize)
    778   1.1      mrg 	struct psycho_softc *sc;
    779  1.13      eeh 	int tsbsize;
    780   1.1      mrg {
    781   1.1      mrg 	char *name;
    782  1.39      eeh 	struct iommu_state *is = sc->sc_is;
    783  1.34      eeh 	u_int32_t iobase = -1;
    784  1.34      eeh 	int *vdma = NULL;
    785  1.34      eeh 	int nitem;
    786  1.24       pk 
    787   1.1      mrg 	/* punch in our copies */
    788  1.24       pk 	is->is_bustag = sc->sc_bustag;
    789  1.45      eeh 	bus_space_subregion(sc->sc_bustag, sc->sc_bh,
    790  1.45      eeh 		offsetof(struct psychoreg, psy_iommu),
    791  1.45      eeh 		sizeof (struct iommureg),
    792  1.45      eeh 		&is->is_iommu);
    793   1.1      mrg 
    794  1.34      eeh 	/*
    795  1.34      eeh 	 * Separate the men from the boys.  Get the `virtual-dma'
    796  1.34      eeh 	 * property for sabre and use that to make sure the damn
    797  1.34      eeh 	 * iommu works.
    798  1.34      eeh 	 *
    799  1.34      eeh 	 * We could query the `#virtual-dma-size-cells' and
    800  1.34      eeh 	 * `#virtual-dma-addr-cells' and DTRT, but I'm lazy.
    801  1.34      eeh 	 */
    802  1.38      eeh 	if (!PROM_getprop(sc->sc_node, "virtual-dma", sizeof(vdma), &nitem,
    803  1.34      eeh 		(void **)&vdma)) {
    804  1.34      eeh 		/* Damn.  Gotta use these values. */
    805  1.34      eeh 		iobase = vdma[0];
    806  1.34      eeh #define	TSBCASE(x)	case 1<<((x)+23): tsbsize = (x); break
    807  1.34      eeh 		switch (vdma[1]) {
    808  1.34      eeh 			TSBCASE(1); TSBCASE(2); TSBCASE(3);
    809  1.34      eeh 			TSBCASE(4); TSBCASE(5); TSBCASE(6);
    810  1.34      eeh 		default:
    811  1.34      eeh 			printf("bogus tsb size %x, using 7\n", vdma[1]);
    812  1.34      eeh 			TSBCASE(7);
    813  1.34      eeh 		}
    814  1.34      eeh #undef TSBCASE
    815  1.34      eeh 	}
    816  1.34      eeh 
    817   1.1      mrg 	/* give us a nice name.. */
    818   1.1      mrg 	name = (char *)malloc(32, M_DEVBUF, M_NOWAIT);
    819   1.1      mrg 	if (name == 0)
    820   1.1      mrg 		panic("couldn't malloc iommu name");
    821   1.1      mrg 	snprintf(name, 32, "%s dvma", sc->sc_dev.dv_xname);
    822   1.1      mrg 
    823  1.34      eeh 	iommu_init(name, is, tsbsize, iobase);
    824   1.7      mrg }
    825   1.7      mrg 
    826   1.7      mrg /*
    827   1.7      mrg  * below here is bus space and bus dma support
    828   1.7      mrg  */
    829   1.7      mrg bus_space_tag_t
    830   1.7      mrg psycho_alloc_bus_tag(pp, type)
    831   1.7      mrg 	struct psycho_pbm *pp;
    832   1.7      mrg 	int type;
    833   1.7      mrg {
    834   1.7      mrg 	struct psycho_softc *sc = pp->pp_sc;
    835   1.7      mrg 	bus_space_tag_t bt;
    836   1.7      mrg 
    837   1.7      mrg 	bt = (bus_space_tag_t)
    838   1.7      mrg 		malloc(sizeof(struct sparc_bus_space_tag), M_DEVBUF, M_NOWAIT);
    839   1.7      mrg 	if (bt == NULL)
    840   1.7      mrg 		panic("could not allocate psycho bus tag");
    841   1.7      mrg 
    842   1.7      mrg 	bzero(bt, sizeof *bt);
    843   1.7      mrg 	bt->cookie = pp;
    844   1.7      mrg 	bt->parent = sc->sc_bustag;
    845   1.7      mrg 	bt->type = type;
    846   1.7      mrg 	bt->sparc_bus_map = _psycho_bus_map;
    847   1.7      mrg 	bt->sparc_bus_mmap = psycho_bus_mmap;
    848   1.7      mrg 	bt->sparc_intr_establish = psycho_intr_establish;
    849   1.7      mrg 	return (bt);
    850   1.7      mrg }
    851   1.7      mrg 
    852   1.7      mrg bus_dma_tag_t
    853   1.7      mrg psycho_alloc_dma_tag(pp)
    854   1.7      mrg 	struct psycho_pbm *pp;
    855   1.7      mrg {
    856   1.7      mrg 	struct psycho_softc *sc = pp->pp_sc;
    857   1.7      mrg 	bus_dma_tag_t dt, pdt = sc->sc_dmatag;
    858   1.7      mrg 
    859   1.7      mrg 	dt = (bus_dma_tag_t)
    860   1.7      mrg 		malloc(sizeof(struct sparc_bus_dma_tag), M_DEVBUF, M_NOWAIT);
    861   1.7      mrg 	if (dt == NULL)
    862   1.7      mrg 		panic("could not allocate psycho dma tag");
    863   1.7      mrg 
    864   1.7      mrg 	bzero(dt, sizeof *dt);
    865   1.7      mrg 	dt->_cookie = pp;
    866   1.7      mrg 	dt->_parent = pdt;
    867   1.7      mrg #define PCOPY(x)	dt->x = pdt->x
    868   1.7      mrg 	PCOPY(_dmamap_create);
    869   1.7      mrg 	PCOPY(_dmamap_destroy);
    870   1.7      mrg 	dt->_dmamap_load = psycho_dmamap_load;
    871   1.7      mrg 	PCOPY(_dmamap_load_mbuf);
    872   1.7      mrg 	PCOPY(_dmamap_load_uio);
    873   1.9      eeh 	dt->_dmamap_load_raw = psycho_dmamap_load_raw;
    874   1.7      mrg 	dt->_dmamap_unload = psycho_dmamap_unload;
    875   1.7      mrg 	dt->_dmamap_sync = psycho_dmamap_sync;
    876   1.7      mrg 	dt->_dmamem_alloc = psycho_dmamem_alloc;
    877   1.7      mrg 	dt->_dmamem_free = psycho_dmamem_free;
    878   1.7      mrg 	dt->_dmamem_map = psycho_dmamem_map;
    879   1.7      mrg 	dt->_dmamem_unmap = psycho_dmamem_unmap;
    880   1.7      mrg 	PCOPY(_dmamem_mmap);
    881   1.7      mrg #undef	PCOPY
    882   1.7      mrg 	return (dt);
    883   1.7      mrg }
    884   1.7      mrg 
    885   1.7      mrg /*
    886   1.7      mrg  * bus space support.  <sparc64/dev/psychoreg.h> has a discussion about
    887   1.7      mrg  * PCI physical addresses.
    888   1.7      mrg  */
    889   1.7      mrg 
    890   1.7      mrg static int get_childspace __P((int));
    891   1.7      mrg 
    892   1.7      mrg static int
    893   1.7      mrg get_childspace(type)
    894   1.7      mrg 	int type;
    895   1.7      mrg {
    896   1.7      mrg 	int ss;
    897   1.7      mrg 
    898   1.7      mrg 	switch (type) {
    899   1.7      mrg 	case PCI_CONFIG_BUS_SPACE:
    900   1.7      mrg 		ss = 0x00;
    901   1.7      mrg 		break;
    902   1.7      mrg 	case PCI_IO_BUS_SPACE:
    903   1.7      mrg 		ss = 0x01;
    904   1.7      mrg 		break;
    905   1.7      mrg 	case PCI_MEMORY_BUS_SPACE:
    906   1.7      mrg 		ss = 0x02;
    907   1.7      mrg 		break;
    908   1.7      mrg #if 0
    909   1.7      mrg 	/* we don't do 64 bit memory space */
    910   1.7      mrg 	case PCI_MEMORY64_BUS_SPACE:
    911   1.7      mrg 		ss = 0x03;
    912   1.7      mrg 		break;
    913   1.7      mrg #endif
    914   1.7      mrg 	default:
    915   1.7      mrg 		panic("get_childspace: unknown bus type");
    916   1.7      mrg 	}
    917   1.7      mrg 
    918   1.7      mrg 	return (ss);
    919   1.7      mrg }
    920   1.7      mrg 
    921   1.7      mrg static int
    922  1.44      eeh _psycho_bus_map(t, offset, size, flags, unused, hp)
    923   1.7      mrg 	bus_space_tag_t t;
    924   1.7      mrg 	bus_addr_t offset;
    925   1.7      mrg 	bus_size_t size;
    926   1.7      mrg 	int	flags;
    927  1.44      eeh 	vaddr_t unused;
    928   1.7      mrg 	bus_space_handle_t *hp;
    929   1.7      mrg {
    930   1.7      mrg 	struct psycho_pbm *pp = t->cookie;
    931   1.7      mrg 	struct psycho_softc *sc = pp->pp_sc;
    932   1.7      mrg 	int i, ss;
    933   1.7      mrg 
    934  1.44      eeh 	DPRINTF(PDB_BUSMAP,
    935  1.44      eeh 		("_psycho_bus_map: type %d off %qx sz %qx flags %d",
    936  1.44      eeh 			t->type, (unsigned long long)offset,
    937  1.44      eeh 			(unsigned long long)size, flags));
    938   1.7      mrg 
    939   1.7      mrg 	ss = get_childspace(t->type);
    940   1.7      mrg 	DPRINTF(PDB_BUSMAP, (" cspace %d", ss));
    941   1.7      mrg 
    942   1.7      mrg 	for (i = 0; i < pp->pp_nrange; i++) {
    943   1.7      mrg 		bus_addr_t paddr;
    944   1.7      mrg 
    945   1.7      mrg 		if (((pp->pp_range[i].cspace >> 24) & 0x03) != ss)
    946   1.7      mrg 			continue;
    947   1.7      mrg 
    948   1.7      mrg 		paddr = pp->pp_range[i].phys_lo + offset;
    949   1.7      mrg 		paddr |= ((bus_addr_t)pp->pp_range[i].phys_hi<<32);
    950   1.7      mrg 		DPRINTF(PDB_BUSMAP, ("\n_psycho_bus_map: mapping paddr space %lx offset %lx paddr %qx\n",
    951  1.27     fvdl 			       (long)ss, (long)offset,
    952  1.27     fvdl 			       (unsigned long long)paddr));
    953  1.44      eeh 		return ((*sc->sc_bustag->sparc_bus_map)(t, paddr, size,
    954  1.44      eeh 			flags, 0, hp));
    955   1.7      mrg 	}
    956   1.7      mrg 	DPRINTF(PDB_BUSMAP, (" FAILED\n"));
    957   1.7      mrg 	return (EINVAL);
    958   1.7      mrg }
    959   1.7      mrg 
    960  1.37      eeh static paddr_t
    961  1.37      eeh psycho_bus_mmap(t, paddr, off, prot, flags)
    962   1.7      mrg 	bus_space_tag_t t;
    963   1.7      mrg 	bus_addr_t paddr;
    964  1.37      eeh 	off_t off;
    965  1.37      eeh 	int prot;
    966   1.7      mrg 	int flags;
    967   1.7      mrg {
    968   1.7      mrg 	bus_addr_t offset = paddr;
    969   1.7      mrg 	struct psycho_pbm *pp = t->cookie;
    970   1.7      mrg 	struct psycho_softc *sc = pp->pp_sc;
    971   1.7      mrg 	int i, ss;
    972   1.7      mrg 
    973   1.7      mrg 	ss = get_childspace(t->type);
    974   1.7      mrg 
    975  1.37      eeh 	DPRINTF(PDB_BUSMAP, ("_psycho_bus_mmap: prot %x flags %d pa %qx\n",
    976  1.37      eeh 		prot, flags, (unsigned long long)paddr));
    977   1.7      mrg 
    978   1.7      mrg 	for (i = 0; i < pp->pp_nrange; i++) {
    979   1.7      mrg 		bus_addr_t paddr;
    980   1.7      mrg 
    981   1.7      mrg 		if (((pp->pp_range[i].cspace >> 24) & 0x03) != ss)
    982   1.7      mrg 			continue;
    983   1.7      mrg 
    984   1.7      mrg 		paddr = pp->pp_range[i].phys_lo + offset;
    985   1.7      mrg 		paddr |= ((bus_addr_t)pp->pp_range[i].phys_hi<<32);
    986  1.37      eeh 		DPRINTF(PDB_BUSMAP, ("\n_psycho_bus_mmap: mapping paddr "
    987  1.37      eeh 			"space %lx offset %lx paddr %qx\n",
    988  1.27     fvdl 			       (long)ss, (long)offset,
    989  1.27     fvdl 			       (unsigned long long)paddr));
    990  1.37      eeh 		return (bus_space_mmap(sc->sc_bustag, paddr, off,
    991  1.37      eeh 				       prot, flags));
    992   1.7      mrg 	}
    993   1.7      mrg 
    994   1.7      mrg 	return (-1);
    995   1.7      mrg }
    996   1.7      mrg 
    997   1.7      mrg 
    998   1.7      mrg /*
    999   1.7      mrg  * install an interrupt handler for a PCI device
   1000   1.7      mrg  */
   1001   1.7      mrg void *
   1002  1.21       pk psycho_intr_establish(t, ihandle, level, flags, handler, arg)
   1003   1.7      mrg 	bus_space_tag_t t;
   1004  1.21       pk 	int ihandle;
   1005   1.7      mrg 	int level;
   1006   1.7      mrg 	int flags;
   1007   1.7      mrg 	int (*handler) __P((void *));
   1008   1.7      mrg 	void *arg;
   1009   1.7      mrg {
   1010   1.7      mrg 	struct psycho_pbm *pp = t->cookie;
   1011   1.7      mrg 	struct psycho_softc *sc = pp->pp_sc;
   1012   1.7      mrg 	struct intrhand *ih;
   1013  1.34      eeh 	volatile u_int64_t *intrmapptr = NULL, *intrclrptr = NULL;
   1014  1.34      eeh 	int64_t intrmap = 0;
   1015   1.7      mrg 	int ino;
   1016  1.34      eeh 	long vec = INTVEC(ihandle);
   1017   1.7      mrg 
   1018   1.7      mrg 	ih = (struct intrhand *)
   1019   1.7      mrg 		malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT);
   1020   1.7      mrg 	if (ih == NULL)
   1021   1.7      mrg 		return (NULL);
   1022   1.7      mrg 
   1023  1.34      eeh 	/*
   1024  1.34      eeh 	 * Hunt through all the interrupt mapping regs to look for our
   1025  1.34      eeh 	 * interrupt vector.
   1026  1.34      eeh 	 *
   1027  1.34      eeh 	 * XXX We only compare INOs rather than IGNs since the firmware may
   1028  1.34      eeh 	 * not provide the IGN and the IGN is constant for all device on that
   1029  1.34      eeh 	 * PCI controller.  This could cause problems for the FFB/external
   1030  1.34      eeh 	 * interrupt which has a full vector that can be set arbitrarily.
   1031  1.34      eeh 	 */
   1032  1.34      eeh 
   1033  1.34      eeh 
   1034  1.31      mrg 	DPRINTF(PDB_INTR, ("\npsycho_intr_establish: ihandle %x vec %lx", ihandle, vec));
   1035   1.7      mrg 	ino = INTINO(vec);
   1036   1.7      mrg 	DPRINTF(PDB_INTR, (" ino %x", ino));
   1037  1.34      eeh 
   1038  1.34      eeh 	/* If the device didn't ask for an IPL, use the one encoded. */
   1039  1.34      eeh 	if (level == IPL_NONE) level = INTLEV(vec);
   1040  1.34      eeh 	/* If it still has no level, print a warning and assign IPL 2 */
   1041  1.34      eeh 	if (level == IPL_NONE) {
   1042  1.34      eeh 		printf("ERROR: no IPL, setting IPL 2.\n");
   1043  1.34      eeh 		level = 2;
   1044  1.34      eeh 	}
   1045  1.34      eeh 
   1046   1.7      mrg 	if ((flags & BUS_INTR_ESTABLISH_SOFTINTR) == 0) {
   1047   1.7      mrg 
   1048  1.27     fvdl 		DPRINTF(PDB_INTR, ("\npsycho: intr %lx: %p\nHunting for IRQ...\n",
   1049   1.7      mrg 		    (long)ino, intrlev[ino]));
   1050   1.7      mrg 
   1051  1.34      eeh 		/* Hunt thru obio first */
   1052  1.34      eeh 		for (intrmapptr = &sc->sc_regs->scsi_int_map,
   1053  1.34      eeh 			     intrclrptr = &sc->sc_regs->scsi_clr_int;
   1054  1.51      eeh 		     intrmapptr < &sc->sc_regs->ffb0_int_map;
   1055  1.34      eeh 		     intrmapptr++, intrclrptr++) {
   1056  1.34      eeh 			if (INTINO(*intrmapptr) == ino)
   1057  1.34      eeh 				goto found;
   1058  1.34      eeh 		}
   1059   1.7      mrg 
   1060  1.34      eeh 		/* Now do PCI interrupts */
   1061  1.34      eeh 		for (intrmapptr = &sc->sc_regs->pcia_slot0_int,
   1062  1.34      eeh 			     intrclrptr = &sc->sc_regs->pcia0_clr_int[0];
   1063  1.34      eeh 		     intrmapptr <= &sc->sc_regs->pcib_slot3_int;
   1064  1.34      eeh 		     intrmapptr++, intrclrptr += 4) {
   1065  1.34      eeh 			if (((*intrmapptr ^ vec) & 0x3c) == 0) {
   1066  1.34      eeh 				intrclrptr += vec & 0x3;
   1067  1.34      eeh 				goto found;
   1068  1.34      eeh 			}
   1069   1.7      mrg 		}
   1070  1.51      eeh 
   1071  1.51      eeh 		/* Finally check the two FFB slots */
   1072  1.51      eeh 		intrclrptr = NULL; /* XXX? */
   1073  1.51      eeh 		for (intrmapptr = &sc->sc_regs->ffb0_int_map;
   1074  1.51      eeh 		     intrmapptr <= &sc->sc_regs->ffb1_int_map;
   1075  1.51      eeh 		     intrmapptr++) {
   1076  1.51      eeh 			if (INTVEC(*intrmapptr) == ino)
   1077  1.51      eeh 				goto found;
   1078  1.51      eeh 		}
   1079  1.51      eeh 
   1080  1.34      eeh 		printf("Cannot find interrupt vector %lx\n", vec);
   1081  1.34      eeh 		return (NULL);
   1082   1.7      mrg 
   1083  1.34      eeh 	found:
   1084   1.7      mrg 		/* Register the map and clear intr registers */
   1085   1.7      mrg 		ih->ih_map = intrmapptr;
   1086   1.7      mrg 		ih->ih_clr = intrclrptr;
   1087   1.7      mrg 	}
   1088  1.10      mrg #ifdef NOT_DEBUG
   1089   1.7      mrg 	if (psycho_debug & PDB_INTR) {
   1090   1.7      mrg 		long i;
   1091   1.7      mrg 
   1092   1.7      mrg 		for (i = 0; i < 500000000; i++)
   1093   1.7      mrg 			continue;
   1094   1.7      mrg 	}
   1095   1.7      mrg #endif
   1096   1.7      mrg 
   1097   1.7      mrg 	ih->ih_fun = handler;
   1098   1.7      mrg 	ih->ih_arg = arg;
   1099  1.34      eeh 	ih->ih_pil = level;
   1100  1.24       pk 	ih->ih_number = ino | sc->sc_ign;
   1101  1.19       pk 
   1102  1.19       pk 	DPRINTF(PDB_INTR, (
   1103  1.19       pk 	    "; installing handler %p arg %p with ino %u pil %u\n",
   1104  1.19       pk 	    handler, arg, (u_int)ino, (u_int)ih->ih_pil));
   1105  1.19       pk 
   1106   1.7      mrg 	intr_establish(ih->ih_pil, ih);
   1107  1.34      eeh 
   1108  1.34      eeh 	/*
   1109  1.34      eeh 	 * Enable the interrupt now we have the handler installed.
   1110  1.34      eeh 	 * Read the current value as we can't change it besides the
   1111  1.34      eeh 	 * valid bit so so make sure only this bit is changed.
   1112  1.34      eeh 	 *
   1113  1.34      eeh 	 * XXXX --- we really should use bus_space for this.
   1114  1.34      eeh 	 */
   1115  1.34      eeh 	if (intrmapptr) {
   1116  1.34      eeh 		intrmap = *intrmapptr;
   1117  1.34      eeh 		DPRINTF(PDB_INTR, ("; read intrmap = %016qx",
   1118  1.34      eeh 			(unsigned long long)intrmap));
   1119  1.34      eeh 
   1120  1.34      eeh 		/* Enable the interrupt */
   1121  1.34      eeh 		intrmap |= INTMAP_V;
   1122  1.34      eeh 		DPRINTF(PDB_INTR, ("; addr of intrmapptr = %p", intrmapptr));
   1123  1.34      eeh 		DPRINTF(PDB_INTR, ("; writing intrmap = %016qx\n",
   1124  1.34      eeh 			(unsigned long long)intrmap));
   1125  1.34      eeh 		*intrmapptr = intrmap;
   1126  1.34      eeh 		DPRINTF(PDB_INTR, ("; reread intrmap = %016qx",
   1127  1.34      eeh 			(unsigned long long)(intrmap = *intrmapptr)));
   1128  1.34      eeh 	}
   1129   1.7      mrg 	return (ih);
   1130   1.7      mrg }
   1131   1.7      mrg 
   1132   1.7      mrg /*
   1133   1.7      mrg  * hooks into the iommu dvma calls.
   1134   1.7      mrg  */
   1135   1.7      mrg int
   1136   1.7      mrg psycho_dmamap_load(t, map, buf, buflen, p, flags)
   1137   1.7      mrg 	bus_dma_tag_t t;
   1138   1.7      mrg 	bus_dmamap_t map;
   1139   1.7      mrg 	void *buf;
   1140   1.7      mrg 	bus_size_t buflen;
   1141   1.7      mrg 	struct proc *p;
   1142   1.7      mrg 	int flags;
   1143   1.7      mrg {
   1144   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1145   1.7      mrg 
   1146  1.50      eeh 	return (iommu_dvmamap_load(t, &pp->pp_sb, map, buf, buflen, p, flags));
   1147   1.7      mrg }
   1148   1.7      mrg 
   1149   1.7      mrg void
   1150   1.7      mrg psycho_dmamap_unload(t, map)
   1151   1.7      mrg 	bus_dma_tag_t t;
   1152   1.7      mrg 	bus_dmamap_t map;
   1153   1.7      mrg {
   1154   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1155   1.7      mrg 
   1156  1.50      eeh 	iommu_dvmamap_unload(t, &pp->pp_sb, map);
   1157   1.9      eeh }
   1158   1.9      eeh 
   1159   1.9      eeh int
   1160  1.10      mrg psycho_dmamap_load_raw(t, map, segs, nsegs, size, flags)
   1161  1.10      mrg 	bus_dma_tag_t t;
   1162   1.9      eeh 	bus_dmamap_t map;
   1163   1.9      eeh 	bus_dma_segment_t *segs;
   1164   1.9      eeh 	int nsegs;
   1165   1.9      eeh 	bus_size_t size;
   1166   1.9      eeh 	int flags;
   1167   1.9      eeh {
   1168   1.9      eeh 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1169   1.9      eeh 
   1170  1.50      eeh 	return (iommu_dvmamap_load_raw(t, &pp->pp_sb, map, segs, nsegs, flags, size));
   1171   1.7      mrg }
   1172   1.7      mrg 
   1173   1.7      mrg void
   1174   1.7      mrg psycho_dmamap_sync(t, map, offset, len, ops)
   1175   1.7      mrg 	bus_dma_tag_t t;
   1176   1.7      mrg 	bus_dmamap_t map;
   1177   1.7      mrg 	bus_addr_t offset;
   1178   1.7      mrg 	bus_size_t len;
   1179   1.7      mrg 	int ops;
   1180   1.7      mrg {
   1181   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1182   1.7      mrg 
   1183  1.13      eeh 	if (ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) {
   1184  1.13      eeh 		/* Flush the CPU then the IOMMU */
   1185  1.13      eeh 		bus_dmamap_sync(t->_parent, map, offset, len, ops);
   1186  1.50      eeh 		iommu_dvmamap_sync(t, &pp->pp_sb, map, offset, len, ops);
   1187  1.13      eeh 	}
   1188  1.13      eeh 	if (ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) {
   1189  1.13      eeh 		/* Flush the IOMMU then the CPU */
   1190  1.50      eeh 		iommu_dvmamap_sync(t, &pp->pp_sb, map, offset, len, ops);
   1191  1.13      eeh 		bus_dmamap_sync(t->_parent, map, offset, len, ops);
   1192  1.13      eeh 	}
   1193  1.13      eeh 
   1194   1.7      mrg }
   1195   1.7      mrg 
   1196   1.7      mrg int
   1197   1.7      mrg psycho_dmamem_alloc(t, size, alignment, boundary, segs, nsegs, rsegs, flags)
   1198   1.7      mrg 	bus_dma_tag_t t;
   1199   1.7      mrg 	bus_size_t size;
   1200   1.7      mrg 	bus_size_t alignment;
   1201   1.7      mrg 	bus_size_t boundary;
   1202   1.7      mrg 	bus_dma_segment_t *segs;
   1203   1.7      mrg 	int nsegs;
   1204   1.7      mrg 	int *rsegs;
   1205   1.7      mrg 	int flags;
   1206   1.7      mrg {
   1207   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1208   1.7      mrg 
   1209  1.50      eeh 	return (iommu_dvmamem_alloc(t, &pp->pp_sb, size, alignment, boundary,
   1210   1.7      mrg 	    segs, nsegs, rsegs, flags));
   1211   1.7      mrg }
   1212   1.7      mrg 
   1213   1.7      mrg void
   1214   1.7      mrg psycho_dmamem_free(t, segs, nsegs)
   1215   1.7      mrg 	bus_dma_tag_t t;
   1216   1.7      mrg 	bus_dma_segment_t *segs;
   1217   1.7      mrg 	int nsegs;
   1218   1.7      mrg {
   1219   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1220   1.7      mrg 
   1221  1.50      eeh 	iommu_dvmamem_free(t, &pp->pp_sb, segs, nsegs);
   1222   1.7      mrg }
   1223   1.7      mrg 
   1224   1.7      mrg int
   1225   1.7      mrg psycho_dmamem_map(t, segs, nsegs, size, kvap, flags)
   1226   1.7      mrg 	bus_dma_tag_t t;
   1227   1.7      mrg 	bus_dma_segment_t *segs;
   1228   1.7      mrg 	int nsegs;
   1229   1.7      mrg 	size_t size;
   1230   1.7      mrg 	caddr_t *kvap;
   1231   1.7      mrg 	int flags;
   1232   1.7      mrg {
   1233   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1234   1.7      mrg 
   1235  1.50      eeh 	return (iommu_dvmamem_map(t, &pp->pp_sb, segs, nsegs, size, kvap, flags));
   1236   1.7      mrg }
   1237   1.7      mrg 
   1238   1.7      mrg void
   1239   1.7      mrg psycho_dmamem_unmap(t, kva, size)
   1240   1.7      mrg 	bus_dma_tag_t t;
   1241   1.7      mrg 	caddr_t kva;
   1242   1.7      mrg 	size_t size;
   1243   1.7      mrg {
   1244   1.7      mrg 	struct psycho_pbm *pp = (struct psycho_pbm *)t->_cookie;
   1245   1.7      mrg 
   1246  1.50      eeh 	iommu_dvmamem_unmap(t, &pp->pp_sb, kva, size);
   1247   1.1      mrg }
   1248