Home | History | Annotate | Line # | Download | only in hpc
hpc.c revision 1.18
      1  1.18    sekiya /*	$NetBSD: hpc.c,v 1.18 2003/11/22 03:58:52 sekiya Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*
      4   1.1   thorpej  * Copyright (c) 2000 Soren S. Jorvang
      5   1.1   thorpej  * Copyright (c) 2001 Rafal K. Boni
      6   1.3   thorpej  * Copyright (c) 2001 Jason R. Thorpe
      7   1.1   thorpej  * All rights reserved.
      8   1.7    simonb  *
      9   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     10   1.1   thorpej  * modification, are permitted provided that the following conditions
     11   1.1   thorpej  * are met:
     12   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     13   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     14   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     16   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     17   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     18   1.1   thorpej  *    must display the following acknowledgement:
     19   1.1   thorpej  *          This product includes software developed for the
     20  1.16    keihan  *          NetBSD Project.  See http://www.NetBSD.org/ for
     21   1.1   thorpej  *          information about NetBSD.
     22   1.1   thorpej  * 4. The name of the author may not be used to endorse or promote products
     23   1.1   thorpej  *    derived from this software without specific prior written permission.
     24   1.7    simonb  *
     25   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     26   1.1   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     27   1.1   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28   1.1   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     29   1.1   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     30   1.1   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     31   1.1   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     32   1.1   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     33   1.1   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     34   1.1   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35   1.1   thorpej  */
     36  1.13     lukem 
     37  1.13     lukem #include <sys/cdefs.h>
     38  1.18    sekiya __KERNEL_RCSID(0, "$NetBSD: hpc.c,v 1.18 2003/11/22 03:58:52 sekiya Exp $");
     39   1.1   thorpej 
     40   1.1   thorpej #include <sys/param.h>
     41   1.1   thorpej #include <sys/systm.h>
     42   1.1   thorpej #include <sys/device.h>
     43   1.1   thorpej #include <sys/reboot.h>
     44   1.1   thorpej 
     45   1.1   thorpej #include <machine/machtype.h>
     46   1.1   thorpej 
     47   1.1   thorpej #include <sgimips/gio/gioreg.h>
     48   1.1   thorpej #include <sgimips/gio/giovar.h>
     49   1.1   thorpej 
     50   1.1   thorpej #include <sgimips/hpc/hpcvar.h>
     51   1.1   thorpej #include <sgimips/hpc/hpcreg.h>
     52   1.1   thorpej #include <sgimips/hpc/iocreg.h>
     53   1.1   thorpej 
     54   1.1   thorpej #include "locators.h"
     55   1.1   thorpej 
     56   1.3   thorpej const struct hpc_device {
     57   1.3   thorpej 	const char *hd_name;
     58   1.3   thorpej 	bus_addr_t hd_devoff;
     59   1.3   thorpej 	bus_addr_t hd_dmaoff;
     60   1.3   thorpej 	int hd_irq;
     61   1.3   thorpej 	int hd_sysmask;
     62   1.3   thorpej } hpc_devices[] = {
     63   1.3   thorpej 	{ "zsc",
     64   1.3   thorpej 	  /* XXX Magic numbers */
     65   1.3   thorpej 	  HPC_PBUS_CH6_DEVREGS + 0x30,	0,
     66   1.3   thorpej 	  29,
     67  1.17    sekiya 	  HPCDEV_IP22 | HPCDEV_IP24 },
     68  1.17    sekiya 
     69  1.17    sekiya 	{ "pckbc",
     70  1.17    sekiya 	  HPC_PBUS_CH6_DEVREGS + 0x40, 0,
     71  1.17    sekiya 	  28,
     72   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
     73   1.3   thorpej 
     74   1.3   thorpej 	{ "sq",
     75   1.3   thorpej 	  HPC_ENET_DEVREGS, HPC_ENET_REGS,
     76   1.3   thorpej 	  3,
     77   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
     78   1.3   thorpej 
     79   1.3   thorpej 	{ "wdsc",
     80   1.3   thorpej 	  HPC_SCSI0_DEVREGS, HPC_SCSI0_REGS,
     81   1.3   thorpej 	  1,	/* XXX 1 = IRQ_LOCAL0 + 1 */
     82   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
     83   1.3   thorpej 
     84   1.3   thorpej 	{ "wdsc",
     85   1.3   thorpej 	  HPC_SCSI1_DEVREGS, HPC_SCSI1_REGS,
     86   1.3   thorpej 	  2,	/* XXX 2 = IRQ_LOCAL0 + 2 */
     87   1.3   thorpej 	  HPCDEV_IP22 },
     88  1.18    sekiya 
     89  1.18    sekiya 	{ "dpclock",
     90  1.18    sekiya 	  HPC1_PBUS_BBRAM, 0,
     91  1.18    sekiya 	  -1,
     92  1.18    sekiya 	  HPCDEV_IP20 },
     93   1.3   thorpej 
     94   1.3   thorpej 	{ "dsclock",
     95   1.3   thorpej 	  HPC_PBUS_BBRAM, 0,
     96   1.3   thorpej 	  -1,
     97   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
     98  1.14  lonewolf 
     99  1.14  lonewolf 	{ "haltwo",
    100  1.14  lonewolf 	  HPC_PBUS_CH0_DEVREGS, HPC_PBUS_DMAREGS,
    101  1.14  lonewolf 	  8 + 4, /* XXX IRQ_LOCAL1 + 4 */
    102  1.15  lonewolf 	  HPCDEV_IP22 | HPCDEV_IP24 },
    103   1.3   thorpej 
    104   1.3   thorpej 	{ NULL,
    105   1.3   thorpej 	  0, 0,
    106   1.3   thorpej 	  0,
    107   1.3   thorpej 	  0
    108   1.3   thorpej 	}
    109   1.3   thorpej };
    110   1.3   thorpej 
    111   1.1   thorpej struct hpc_softc {
    112   1.1   thorpej 	struct device 		sc_dev;
    113   1.1   thorpej 
    114   1.1   thorpej 	bus_addr_t		sc_base;
    115   1.1   thorpej 
    116   1.1   thorpej 	bus_space_tag_t		sc_ct;
    117   1.1   thorpej 	bus_space_handle_t	sc_ch;
    118   1.1   thorpej };
    119   1.1   thorpej 
    120   1.1   thorpej extern int mach_type;		/* IPxx type */
    121   1.1   thorpej extern int mach_subtype;	/* subtype: eg., Guiness/Fullhouse for IP22 */
    122   1.1   thorpej extern int mach_boardrev;	/* machine board revision, in case it matters */
    123   1.1   thorpej 
    124   1.2       wdk extern struct sgimips_bus_dma_tag sgimips_default_bus_dma_tag;
    125   1.2       wdk 
    126   1.6     rafal static int powerintr_established;
    127   1.6     rafal 
    128   1.3   thorpej int	hpc_match(struct device *, struct cfdata *, void *);
    129   1.3   thorpej void	hpc_attach(struct device *, struct device *, void *);
    130   1.3   thorpej int	hpc_print(void *, const char *);
    131   1.1   thorpej 
    132   1.3   thorpej int	hpc_submatch(struct device *, struct cfdata *, void *);
    133   1.3   thorpej 
    134   1.3   thorpej int	hpc_power_intr(void *);
    135   1.1   thorpej 
    136  1.11   thorpej CFATTACH_DECL(hpc, sizeof(struct hpc_softc),
    137  1.11   thorpej     hpc_match, hpc_attach, NULL, NULL);
    138   1.1   thorpej 
    139   1.3   thorpej int
    140   1.3   thorpej hpc_match(struct device *parent, struct cfdata *cf, void *aux)
    141   1.1   thorpej {
    142   1.1   thorpej 	struct gio_attach_args* ga = aux;
    143   1.1   thorpej 
    144   1.1   thorpej 	/* Make sure it's actually there and readable */
    145   1.1   thorpej 	if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
    146   1.1   thorpej 		return 0;
    147   1.1   thorpej 
    148   1.7    simonb 	return 1;
    149   1.1   thorpej }
    150   1.1   thorpej 
    151   1.3   thorpej void
    152   1.3   thorpej hpc_attach(struct device *parent, struct device *self, void *aux)
    153   1.1   thorpej {
    154   1.1   thorpej 	struct hpc_softc *sc = (struct hpc_softc *)self;
    155   1.1   thorpej 	struct gio_attach_args* ga = aux;
    156   1.1   thorpej 	struct hpc_attach_args ha;
    157   1.3   thorpej 	const struct hpc_device *hd;
    158   1.3   thorpej 	int sysmask, hpctype;
    159   1.3   thorpej 
    160   1.3   thorpej 	switch (mach_type) {
    161   1.3   thorpej 	case MACH_SGI_IP22:
    162   1.3   thorpej 		hpctype = 3;
    163   1.3   thorpej 		if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
    164   1.3   thorpej 			sysmask = HPCDEV_IP22;
    165   1.3   thorpej 		else
    166   1.3   thorpej 			sysmask = HPCDEV_IP24;
    167   1.3   thorpej 		break;
    168   1.3   thorpej 
    169   1.3   thorpej 	default:
    170   1.9    provos 		panic("hpc_attach: can't handle HPC on an IP%d",
    171   1.3   thorpej 		    mach_type);
    172   1.3   thorpej 	};
    173   1.1   thorpej 
    174   1.3   thorpej 	printf(": SGI HPC%d\n", hpctype);
    175   1.1   thorpej 
    176   1.1   thorpej 	sc->sc_ct = 1;
    177   1.1   thorpej 	sc->sc_ch = ga->ga_ioh;
    178   1.1   thorpej 
    179   1.1   thorpej 	sc->sc_base = ga->ga_addr;
    180   1.3   thorpej 
    181   1.3   thorpej 	for (hd = hpc_devices; hd->hd_name != NULL; hd++) {
    182   1.5     rafal 		if (!(hd->hd_sysmask & sysmask))
    183   1.5     rafal 			continue;
    184   1.5     rafal 
    185   1.5     rafal 		ha.ha_name = hd->hd_name;
    186   1.5     rafal 		ha.ha_devoff = hd->hd_devoff;
    187   1.5     rafal 		ha.ha_dmaoff = hd->hd_dmaoff;
    188   1.5     rafal 		ha.ha_irq = hd->hd_irq;
    189   1.5     rafal 
    190   1.5     rafal 		/* XXX This is disgusting. */
    191   1.5     rafal 		ha.ha_st = 1;
    192   1.5     rafal 		ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
    193   1.5     rafal 		ha.ha_dmat = &sgimips_default_bus_dma_tag;
    194   1.5     rafal 
    195   1.5     rafal 		(void) config_found_sm(self, &ha, hpc_print, hpc_submatch);
    196   1.3   thorpej 	}
    197   1.1   thorpej 
    198   1.7    simonb 	/*
    199   1.7    simonb 	 * XXX: Only attach the powerfail interrupt once, since the
    200   1.6     rafal 	 * interrupt code doesn't let you share interrupt just yet.
    201   1.6     rafal 	 *
    202   1.7    simonb 	 * Since the powerfail interrupt is hardcoded to read from
    203   1.6     rafal 	 * a specific register anyway (XXX#2!), we don't care when
    204   1.6     rafal 	 * it gets attached, as long as it only happens once.
    205   1.1   thorpej 	 */
    206   1.6     rafal 	if (!powerintr_established) {
    207   1.6     rafal 		cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
    208   1.6     rafal 		powerintr_established++;
    209   1.6     rafal 	}
    210   1.1   thorpej }
    211   1.1   thorpej 
    212   1.3   thorpej int
    213   1.3   thorpej hpc_submatch(struct device *parent, struct cfdata *cf, void *aux)
    214   1.1   thorpej {
    215   1.1   thorpej 	struct hpc_attach_args *ha = aux;
    216   1.1   thorpej 
    217   1.3   thorpej 	if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
    218  1.12   thorpej 	    (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
    219   1.3   thorpej 		return (0);
    220   1.1   thorpej 
    221   1.8   thorpej 	return (config_match(parent, cf, aux));
    222   1.3   thorpej }
    223   1.3   thorpej 
    224   1.3   thorpej int
    225   1.3   thorpej hpc_print(void *aux, const char *pnp)
    226   1.3   thorpej {
    227   1.3   thorpej 	struct hpc_attach_args *ha = aux;
    228   1.1   thorpej 
    229   1.3   thorpej 	if (pnp)
    230   1.3   thorpej 		printf("%s at %s", ha->ha_name, pnp);
    231   1.1   thorpej 
    232   1.3   thorpej 	printf(" offset 0x%lx", ha->ha_devoff);
    233   1.1   thorpej 
    234   1.3   thorpej 	return (UNCONF);
    235   1.1   thorpej }
    236   1.1   thorpej 
    237   1.3   thorpej int
    238   1.3   thorpej hpc_power_intr(void *arg)
    239   1.1   thorpej {
    240   1.1   thorpej 	u_int32_t pwr_reg;
    241   1.1   thorpej 
    242   1.1   thorpej 	pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
    243   1.1   thorpej 	*((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
    244   1.1   thorpej 
    245   1.1   thorpej 	printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
    246   1.1   thorpej 
    247   1.1   thorpej 	if (pwr_reg & 2)
    248   1.3   thorpej 		cpu_reboot(RB_HALT, NULL);
    249   1.1   thorpej 
    250   1.1   thorpej 	return 1;
    251   1.1   thorpej }
    252