Home | History | Annotate | Line # | Download | only in hpc
hpc.c revision 1.37
      1  1.37    sekiya /*	$NetBSD: hpc.c,v 1.37 2006/09/01 04:47:44 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.37    sekiya __KERNEL_RCSID(0, "$NetBSD: hpc.c,v 1.37 2006/09/01 04:47:44 sekiya Exp $");
     39   1.1   thorpej 
     40   1.1   thorpej #include <sys/param.h>
     41   1.1   thorpej #include <sys/systm.h>
     42  1.26    sekiya #include <sys/kernel.h>
     43   1.1   thorpej #include <sys/device.h>
     44   1.1   thorpej #include <sys/reboot.h>
     45  1.26    sekiya #include <sys/callout.h>
     46   1.1   thorpej 
     47   1.1   thorpej #include <machine/machtype.h>
     48   1.1   thorpej 
     49   1.1   thorpej #include <sgimips/gio/gioreg.h>
     50   1.1   thorpej #include <sgimips/gio/giovar.h>
     51   1.1   thorpej 
     52   1.1   thorpej #include <sgimips/hpc/hpcvar.h>
     53   1.1   thorpej #include <sgimips/hpc/hpcreg.h>
     54  1.21    sekiya #include <sgimips/ioc/iocreg.h>
     55   1.1   thorpej 
     56   1.1   thorpej #include "locators.h"
     57   1.1   thorpej 
     58  1.29    rumble #define HPC_REVISION_MASK	0x3
     59  1.29    rumble #define HPC_REVISION_1		0x1
     60  1.29    rumble #define HPC_REVISION_15		0x2
     61  1.29    rumble #define HPC_REVISION_3		0x3
     62  1.29    rumble 
     63   1.3   thorpej const struct hpc_device {
     64   1.3   thorpej 	const char *hd_name;
     65  1.29    rumble 	bus_addr_t hd_base;
     66   1.3   thorpej 	bus_addr_t hd_devoff;
     67   1.3   thorpej 	bus_addr_t hd_dmaoff;
     68   1.3   thorpej 	int hd_irq;
     69   1.3   thorpej 	int hd_sysmask;
     70   1.3   thorpej } hpc_devices[] = {
     71   1.3   thorpej 	{ "zsc",
     72  1.29    rumble 	  HPC_BASE_ADDRESS_0,
     73   1.3   thorpej 	  /* XXX Magic numbers */
     74  1.31    rumble 	  HPC3_PBUS_CH6_DEVREGS + IOC_SERIAL_REGS, 0,
     75   1.3   thorpej 	  29,
     76  1.17    sekiya 	  HPCDEV_IP22 | HPCDEV_IP24 },
     77  1.17    sekiya 
     78  1.25    sekiya 	/* probe order is important for IP20 zsc */
     79  1.25    sekiya 
     80  1.24    sekiya 	{ "zsc",        /* serial 0/1 duart 1 */
     81  1.29    rumble 	  HPC_BASE_ADDRESS_0,
     82  1.24    sekiya 	  0x0d10, 0,
     83  1.24    sekiya 	  5,
     84  1.27     pooka 	  HPCDEV_IP12 | HPCDEV_IP20 },
     85  1.24    sekiya 
     86  1.29    rumble 	{ "zsc",        /* kbd/ms duart 0 */
     87  1.29    rumble 	  HPC_BASE_ADDRESS_0,
     88  1.25    sekiya 	  0x0d00, 0,
     89  1.25    sekiya 	  5,
     90  1.27     pooka 	  HPCDEV_IP12 | HPCDEV_IP20 },
     91  1.25    sekiya 
     92  1.17    sekiya 	{ "pckbc",
     93  1.29    rumble 	  HPC_BASE_ADDRESS_0,
     94  1.31    rumble 	  HPC3_PBUS_CH6_DEVREGS + IOC_KB_REGS, 0,
     95  1.17    sekiya 	  28,
     96   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
     97   1.3   thorpej 
     98   1.3   thorpej 	{ "sq",
     99  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    100  1.31    rumble 	  HPC3_ENET_DEVREGS, HPC3_ENET_REGS,
    101   1.3   thorpej 	  3,
    102   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
    103   1.3   thorpej 
    104  1.22    sekiya 	{ "sq",
    105  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    106  1.22    sekiya 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
    107  1.22    sekiya 	  3,
    108  1.27     pooka 	  HPCDEV_IP12 | HPCDEV_IP20 },
    109  1.22    sekiya 
    110  1.29    rumble 	{ "sq",
    111  1.29    rumble 	  HPC_BASE_ADDRESS_1,
    112  1.29    rumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
    113  1.29    rumble 	  6,
    114  1.29    rumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
    115  1.29    rumble 
    116  1.29    rumble 	{ "sq",
    117  1.29    rumble 	  HPC_BASE_ADDRESS_1,
    118  1.29    rumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
    119  1.29    rumble 	  22,
    120  1.29    rumble 	  HPCDEV_IP24 },
    121  1.29    rumble 
    122  1.29    rumble 	{ "sq",
    123  1.29    rumble 	  HPC_BASE_ADDRESS_2,
    124  1.29    rumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
    125  1.29    rumble 	  15,
    126  1.29    rumble 	  HPCDEV_IP12 | HPCDEV_IP20 },
    127  1.29    rumble 
    128  1.29    rumble 	{ "sq",
    129  1.29    rumble 	  HPC_BASE_ADDRESS_2,
    130  1.29    rumble 	  HPC1_ENET_DEVREGS, HPC1_ENET_REGS,
    131  1.29    rumble 	  23,
    132  1.29    rumble 	  HPCDEV_IP24 },
    133  1.29    rumble 
    134   1.3   thorpej 	{ "wdsc",
    135  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    136  1.31    rumble 	  HPC3_SCSI0_DEVREGS, HPC3_SCSI0_REGS,
    137   1.3   thorpej 	  1,	/* XXX 1 = IRQ_LOCAL0 + 1 */
    138   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
    139   1.3   thorpej 
    140   1.3   thorpej 	{ "wdsc",
    141  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    142  1.31    rumble 	  HPC3_SCSI1_DEVREGS, HPC3_SCSI1_REGS,
    143   1.3   thorpej 	  2,	/* XXX 2 = IRQ_LOCAL0 + 2 */
    144   1.3   thorpej 	  HPCDEV_IP22 },
    145  1.18    sekiya 
    146  1.22    sekiya 	{ "wdsc",
    147  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    148  1.22    sekiya 	  HPC1_SCSI0_DEVREGS, HPC1_SCSI0_REGS,
    149  1.22    sekiya 	  2,    /* XXX 1 = IRQ_LOCAL0 + 2 */
    150  1.27     pooka 	  HPCDEV_IP12 | HPCDEV_IP20 },
    151  1.22    sekiya 
    152  1.18    sekiya 	{ "dpclock",
    153  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    154  1.18    sekiya 	  HPC1_PBUS_BBRAM, 0,
    155  1.18    sekiya 	  -1,
    156  1.27     pooka 	  HPCDEV_IP12 | HPCDEV_IP20 },
    157   1.3   thorpej 
    158   1.3   thorpej 	{ "dsclock",
    159  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    160  1.31    rumble 	  HPC3_PBUS_BBRAM, 0,
    161   1.3   thorpej 	  -1,
    162   1.3   thorpej 	  HPCDEV_IP22 | HPCDEV_IP24 },
    163  1.14  lonewolf 
    164  1.14  lonewolf 	{ "haltwo",
    165  1.29    rumble 	  HPC_BASE_ADDRESS_0,
    166  1.31    rumble 	  HPC3_PBUS_CH0_DEVREGS, HPC3_PBUS_DMAREGS,
    167  1.14  lonewolf 	  8 + 4, /* XXX IRQ_LOCAL1 + 4 */
    168  1.15  lonewolf 	  HPCDEV_IP22 | HPCDEV_IP24 },
    169   1.3   thorpej 
    170  1.35  kurahone 	{ "pi1ppc",
    171  1.35  kurahone 	  HPC_BASE_ADDRESS_0,
    172  1.35  kurahone 	  HPC3_PBUS_CH6_DEVREGS + IOC_PLP_REGS, 0,
    173  1.35  kurahone 	  -1,
    174  1.35  kurahone 	  HPCDEV_IP22 | HPCDEV_IP24 },
    175  1.35  kurahone 
    176   1.3   thorpej 	{ NULL,
    177  1.29    rumble 	  0,
    178   1.3   thorpej 	  0, 0,
    179   1.3   thorpej 	  0,
    180   1.3   thorpej 	  0
    181   1.3   thorpej 	}
    182   1.3   thorpej };
    183   1.3   thorpej 
    184   1.1   thorpej struct hpc_softc {
    185   1.1   thorpej 	struct device 		sc_dev;
    186   1.1   thorpej 
    187   1.1   thorpej 	bus_addr_t		sc_base;
    188   1.1   thorpej 
    189   1.1   thorpej 	bus_space_tag_t		sc_ct;
    190   1.1   thorpej 	bus_space_handle_t	sc_ch;
    191   1.1   thorpej };
    192   1.1   thorpej 
    193  1.22    sekiya static struct hpc_values hpc1_values = {
    194  1.23    sekiya 	.revision =		1,
    195  1.23    sekiya 	.scsi0_regs =		HPC1_SCSI0_REGS,
    196  1.23    sekiya 	.scsi0_regs_size =	HPC1_SCSI0_REGS_SIZE,
    197  1.23    sekiya 	.scsi0_cbp =		HPC1_SCSI0_CBP,
    198  1.23    sekiya 	.scsi0_ndbp = 		HPC1_SCSI0_NDBP,
    199  1.23    sekiya 	.scsi0_bc =		HPC1_SCSI0_BC,
    200  1.23    sekiya 	.scsi0_ctl =		HPC1_SCSI0_CTL,
    201  1.23    sekiya 	.scsi0_gio =		HPC1_SCSI0_GIO,
    202  1.23    sekiya 	.scsi0_dev =		HPC1_SCSI0_DEV,
    203  1.23    sekiya 	.scsi0_dmacfg =		HPC1_SCSI0_DMACFG,
    204  1.23    sekiya 	.scsi0_piocfg =		HPC1_SCSI0_PIOCFG,
    205  1.23    sekiya 	.scsi1_regs =		HPC1_SCSI1_REGS,
    206  1.23    sekiya 	.scsi1_regs_size =	HPC1_SCSI1_REGS_SIZE,
    207  1.23    sekiya 	.scsi1_cbp =		HPC1_SCSI1_CBP,
    208  1.23    sekiya 	.scsi1_ndbp =		HPC1_SCSI1_NDBP,
    209  1.23    sekiya 	.scsi1_bc =		HPC1_SCSI1_BC,
    210  1.23    sekiya 	.scsi1_ctl =		HPC1_SCSI1_CTL,
    211  1.23    sekiya 	.scsi1_gio =		HPC1_SCSI1_GIO,
    212  1.23    sekiya 	.scsi1_dev =		HPC1_SCSI1_DEV,
    213  1.23    sekiya 	.scsi1_dmacfg =		HPC1_SCSI1_DMACFG,
    214  1.23    sekiya 	.scsi1_piocfg =		HPC1_SCSI1_PIOCFG,
    215  1.23    sekiya 	.dmactl_dir =		HPC1_DMACTL_DIR,
    216  1.23    sekiya 	.dmactl_flush =		HPC1_DMACTL_FLUSH,
    217  1.23    sekiya 	.dmactl_active =	HPC1_DMACTL_ACTIVE,
    218  1.23    sekiya 	.dmactl_reset =		HPC1_DMACTL_RESET,
    219  1.23    sekiya 	.enet_regs =		HPC1_ENET_REGS,
    220  1.23    sekiya 	.enet_regs_size =	HPC1_ENET_REGS_SIZE,
    221  1.23    sekiya 	.enet_intdelay =	HPC1_ENET_INTDELAY,
    222  1.30    rumble 	.enet_intdelayval =	HPC1_ENET_INTDELAY_OFF,
    223  1.23    sekiya 	.enetr_cbp =		HPC1_ENETR_CBP,
    224  1.23    sekiya 	.enetr_ndbp =		HPC1_ENETR_NDBP,
    225  1.23    sekiya 	.enetr_bc =		HPC1_ENETR_BC,
    226  1.23    sekiya 	.enetr_ctl =		HPC1_ENETR_CTL,
    227  1.23    sekiya 	.enetr_ctl_active =	HPC1_ENETR_CTL_ACTIVE,
    228  1.23    sekiya 	.enetr_reset =		HPC1_ENETR_RESET,
    229  1.23    sekiya 	.enetr_dmacfg =		0,
    230  1.30    rumble 	.enetr_piocfg =		0,
    231  1.23    sekiya 	.enetx_cbp =		HPC1_ENETX_CBP,
    232  1.23    sekiya 	.enetx_ndbp =		HPC1_ENETX_NDBP,
    233  1.23    sekiya 	.enetx_bc =		HPC1_ENETX_BC,
    234  1.23    sekiya 	.enetx_ctl =		HPC1_ENETX_CTL,
    235  1.23    sekiya 	.enetx_ctl_active =	HPC1_ENETX_CTL_ACTIVE,
    236  1.30    rumble 	.enetx_dev =		0,
    237  1.23    sekiya 	.enetr_fifo =		HPC1_ENETR_FIFO,
    238  1.23    sekiya 	.enetr_fifo_size =	HPC1_ENETR_FIFO_SIZE,
    239  1.23    sekiya 	.enetx_fifo =		HPC1_ENETX_FIFO,
    240  1.23    sekiya 	.enetx_fifo_size =	HPC1_ENETX_FIFO_SIZE,
    241  1.23    sekiya 	.scsi0_devregs_size =	HPC1_SCSI0_DEVREGS_SIZE,
    242  1.23    sekiya 	.scsi1_devregs_size =	HPC1_SCSI0_DEVREGS_SIZE,
    243  1.23    sekiya 	.enet_devregs =		HPC1_ENET_DEVREGS,
    244  1.23    sekiya 	.enet_devregs_size =	HPC1_ENET_DEVREGS_SIZE,
    245  1.30    rumble 	.pbus_fifo =		0,
    246  1.30    rumble 	.pbus_fifo_size =	0,
    247  1.30    rumble 	.pbus_bbram =		0,
    248  1.22    sekiya #define MAX_SCSI_XFER   (512*1024)
    249  1.23    sekiya 	.scsi_max_xfer =	MAX_SCSI_XFER,
    250  1.23    sekiya 	.scsi_dma_segs =	(MAX_SCSI_XFER / 4096),
    251  1.23    sekiya 	.scsi_dma_segs_size =	4096,
    252  1.23    sekiya 	.clk_freq =		100,
    253  1.23    sekiya 	.dma_datain_cmd =	(HPC1_DMACTL_ACTIVE | HPC1_DMACTL_DIR),
    254  1.23    sekiya 	.dma_dataout_cmd =	HPC1_DMACTL_ACTIVE,
    255  1.23    sekiya 	.scsi_dmactl_flush =	HPC1_DMACTL_FLUSH,
    256  1.23    sekiya 	.scsi_dmactl_active =	HPC1_DMACTL_ACTIVE,
    257  1.23    sekiya 	.scsi_dmactl_reset =	HPC1_DMACTL_RESET
    258  1.22    sekiya };
    259  1.22    sekiya 
    260  1.22    sekiya static struct hpc_values hpc3_values = {
    261  1.37    sekiya 	.revision =		3,
    262  1.31    rumble 	.scsi0_regs =		HPC3_SCSI0_REGS,
    263  1.31    rumble 	.scsi0_regs_size =	HPC3_SCSI0_REGS_SIZE,
    264  1.31    rumble 	.scsi0_cbp =		HPC3_SCSI0_CBP,
    265  1.31    rumble 	.scsi0_ndbp =		HPC3_SCSI0_NDBP,
    266  1.31    rumble 	.scsi0_bc =		HPC3_SCSI0_BC,
    267  1.31    rumble 	.scsi0_ctl =		HPC3_SCSI0_CTL,
    268  1.31    rumble 	.scsi0_gio =		HPC3_SCSI0_GIO,
    269  1.31    rumble 	.scsi0_dev =		HPC3_SCSI0_DEV,
    270  1.31    rumble 	.scsi0_dmacfg =		HPC3_SCSI0_DMACFG,
    271  1.31    rumble 	.scsi0_piocfg =		HPC3_SCSI0_PIOCFG,
    272  1.31    rumble 	.scsi1_regs =		HPC3_SCSI1_REGS,
    273  1.31    rumble 	.scsi1_regs_size =	HPC3_SCSI1_REGS_SIZE,
    274  1.31    rumble 	.scsi1_cbp =		HPC3_SCSI1_CBP,
    275  1.31    rumble 	.scsi1_ndbp =		HPC3_SCSI1_NDBP,
    276  1.31    rumble 	.scsi1_bc =		HPC3_SCSI1_BC,
    277  1.31    rumble 	.scsi1_ctl =		HPC3_SCSI1_CTL,
    278  1.31    rumble 	.scsi1_gio =		HPC3_SCSI1_GIO,
    279  1.31    rumble 	.scsi1_dev =		HPC3_SCSI1_DEV,
    280  1.31    rumble 	.scsi1_dmacfg =		HPC3_SCSI1_DMACFG,
    281  1.31    rumble 	.scsi1_piocfg =		HPC3_SCSI1_PIOCFG,
    282  1.31    rumble 	.dmactl_dir =		HPC3_DMACTL_DIR,
    283  1.31    rumble 	.dmactl_flush =		HPC3_DMACTL_FLUSH,
    284  1.31    rumble 	.dmactl_active =	HPC3_DMACTL_ACTIVE,
    285  1.31    rumble 	.dmactl_reset =		HPC3_DMACTL_RESET,
    286  1.31    rumble 	.enet_regs =		HPC3_ENET_REGS,
    287  1.31    rumble 	.enet_regs_size =	HPC3_ENET_REGS_SIZE,
    288  1.23    sekiya 	.enet_intdelay =	0,
    289  1.23    sekiya 	.enet_intdelayval =	0,
    290  1.31    rumble 	.enetr_cbp =		HPC3_ENETR_CBP,
    291  1.31    rumble 	.enetr_ndbp =		HPC3_ENETR_NDBP,
    292  1.31    rumble 	.enetr_bc =		HPC3_ENETR_BC,
    293  1.31    rumble 	.enetr_ctl =		HPC3_ENETR_CTL,
    294  1.31    rumble 	.enetr_ctl_active =	HPC3_ENETR_CTL_ACTIVE,
    295  1.31    rumble 	.enetr_reset =		HPC3_ENETR_RESET,
    296  1.31    rumble 	.enetr_dmacfg =		HPC3_ENETR_DMACFG,
    297  1.31    rumble 	.enetr_piocfg =		HPC3_ENETR_PIOCFG,
    298  1.31    rumble 	.enetx_cbp =		HPC3_ENETX_CBP,
    299  1.31    rumble 	.enetx_ndbp =		HPC3_ENETX_NDBP,
    300  1.31    rumble 	.enetx_bc =		HPC3_ENETX_BC,
    301  1.31    rumble 	.enetx_ctl =		HPC3_ENETX_CTL,
    302  1.31    rumble 	.enetx_ctl_active =	HPC3_ENETX_CTL_ACTIVE,
    303  1.31    rumble 	.enetx_dev =		HPC3_ENETX_DEV,
    304  1.31    rumble 	.enetr_fifo =		HPC3_ENETR_FIFO,
    305  1.31    rumble 	.enetr_fifo_size =	HPC3_ENETR_FIFO_SIZE,
    306  1.31    rumble 	.enetx_fifo =		HPC3_ENETX_FIFO,
    307  1.31    rumble 	.enetx_fifo_size =	HPC3_ENETX_FIFO_SIZE,
    308  1.31    rumble 	.scsi0_devregs_size =	HPC3_SCSI0_DEVREGS_SIZE,
    309  1.31    rumble 	.scsi1_devregs_size =	HPC3_SCSI1_DEVREGS_SIZE,
    310  1.31    rumble 	.enet_devregs =		HPC3_ENET_DEVREGS,
    311  1.31    rumble 	.enet_devregs_size =	HPC3_ENET_DEVREGS_SIZE,
    312  1.31    rumble 	.pbus_fifo =		HPC3_PBUS_FIFO,
    313  1.31    rumble 	.pbus_fifo_size =	HPC3_PBUS_FIFO_SIZE,
    314  1.31    rumble 	.pbus_bbram =		HPC3_PBUS_BBRAM,
    315  1.23    sekiya 	.scsi_max_xfer =	MAX_SCSI_XFER,
    316  1.23    sekiya 	.scsi_dma_segs =	(MAX_SCSI_XFER / 8192),
    317  1.23    sekiya 	.scsi_dma_segs_size =	8192,
    318  1.23    sekiya 	.clk_freq =		100,
    319  1.31    rumble 	.dma_datain_cmd =	HPC3_DMACTL_ACTIVE,
    320  1.31    rumble 	.dma_dataout_cmd =	(HPC3_DMACTL_ACTIVE | HPC3_DMACTL_DIR),
    321  1.31    rumble 	.scsi_dmactl_flush =	HPC3_DMACTL_FLUSH,
    322  1.31    rumble 	.scsi_dmactl_active =	HPC3_DMACTL_ACTIVE,
    323  1.31    rumble 	.scsi_dmactl_reset =	HPC3_DMACTL_RESET
    324  1.22    sekiya };
    325  1.22    sekiya 
    326  1.22    sekiya 
    327   1.1   thorpej extern int mach_type;		/* IPxx type */
    328   1.1   thorpej extern int mach_subtype;	/* subtype: eg., Guiness/Fullhouse for IP22 */
    329   1.1   thorpej extern int mach_boardrev;	/* machine board revision, in case it matters */
    330   1.1   thorpej 
    331   1.2       wdk extern struct sgimips_bus_dma_tag sgimips_default_bus_dma_tag;
    332   1.2       wdk 
    333   1.6     rafal static int powerintr_established;
    334   1.6     rafal 
    335   1.3   thorpej int	hpc_match(struct device *, struct cfdata *, void *);
    336   1.3   thorpej void	hpc_attach(struct device *, struct device *, void *);
    337   1.3   thorpej int	hpc_print(void *, const char *);
    338   1.1   thorpej 
    339  1.29    rumble int	hpc_revision(struct hpc_softc *, struct gio_attach_args *);
    340  1.29    rumble 
    341  1.32  drochner int	hpc_submatch(struct device *, struct cfdata *,
    342  1.33  drochner 		     const int *, void *);
    343   1.3   thorpej 
    344   1.3   thorpej int	hpc_power_intr(void *);
    345   1.1   thorpej 
    346  1.26    sekiya #if defined(BLINK)
    347  1.26    sekiya static struct callout hpc_blink_ch = CALLOUT_INITIALIZER;
    348  1.26    sekiya static void	hpc_blink(void *);
    349  1.26    sekiya #endif
    350  1.26    sekiya 
    351  1.11   thorpej CFATTACH_DECL(hpc, sizeof(struct hpc_softc),
    352  1.11   thorpej     hpc_match, hpc_attach, NULL, NULL);
    353   1.1   thorpej 
    354   1.3   thorpej int
    355   1.3   thorpej hpc_match(struct device *parent, struct cfdata *cf, void *aux)
    356   1.1   thorpej {
    357   1.1   thorpej 	struct gio_attach_args* ga = aux;
    358   1.1   thorpej 
    359   1.1   thorpej 	/* Make sure it's actually there and readable */
    360   1.1   thorpej 	if (badaddr((void*)MIPS_PHYS_TO_KSEG1(ga->ga_addr), sizeof(u_int32_t)))
    361   1.1   thorpej 		return 0;
    362   1.1   thorpej 
    363   1.7    simonb 	return 1;
    364   1.1   thorpej }
    365   1.1   thorpej 
    366   1.3   thorpej void
    367   1.3   thorpej hpc_attach(struct device *parent, struct device *self, void *aux)
    368   1.1   thorpej {
    369   1.1   thorpej 	struct hpc_softc *sc = (struct hpc_softc *)self;
    370   1.1   thorpej 	struct gio_attach_args* ga = aux;
    371   1.1   thorpej 	struct hpc_attach_args ha;
    372   1.3   thorpej 	const struct hpc_device *hd;
    373  1.27     pooka 	uint32_t hpctype;
    374  1.27     pooka 	int sysmask;
    375   1.3   thorpej 
    376   1.3   thorpej 	switch (mach_type) {
    377  1.27     pooka 	case MACH_SGI_IP12:
    378  1.27     pooka 		sysmask = HPCDEV_IP12;
    379  1.27     pooka 		break;
    380  1.27     pooka 
    381  1.20    sekiya 	case MACH_SGI_IP20:
    382  1.20    sekiya 		sysmask = HPCDEV_IP20;
    383  1.20    sekiya 		break;
    384  1.23    sekiya 
    385   1.3   thorpej 	case MACH_SGI_IP22:
    386   1.3   thorpej 		if (mach_subtype == MACH_SGI_IP22_FULLHOUSE)
    387   1.3   thorpej 			sysmask = HPCDEV_IP22;
    388   1.3   thorpej 		else
    389   1.3   thorpej 			sysmask = HPCDEV_IP24;
    390   1.3   thorpej 		break;
    391   1.3   thorpej 
    392   1.3   thorpej 	default:
    393  1.23    sekiya 		panic("hpc_attach: can't handle HPC on an IP%d", mach_type);
    394   1.3   thorpej 	};
    395   1.1   thorpej 
    396  1.29    rumble 	if ((hpctype = hpc_revision(sc, ga)) == 0)
    397  1.29    rumble 		panic("hpc_attach: could not identify HPC revision\n");
    398  1.24    sekiya 
    399  1.29    rumble 	/* force big-endian mode */
    400  1.29    rumble 	if (hpctype == 15)
    401  1.29    rumble 		*(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr+HPC1_BIGENDIAN) = 0;
    402  1.23    sekiya 
    403  1.23    sekiya 	printf(": SGI HPC%d%s\n", (hpctype ==  3) ? 3 : 1,
    404  1.23    sekiya 				  (hpctype == 15) ? ".5" : "");
    405   1.1   thorpej 
    406   1.1   thorpej 	sc->sc_ct = 1;
    407   1.1   thorpej 	sc->sc_ch = ga->ga_ioh;
    408   1.1   thorpej 
    409   1.1   thorpej 	sc->sc_base = ga->ga_addr;
    410   1.3   thorpej 
    411   1.3   thorpej 	for (hd = hpc_devices; hd->hd_name != NULL; hd++) {
    412  1.29    rumble 		if (!(hd->hd_sysmask & sysmask) || hd->hd_base != sc->sc_base)
    413   1.5     rafal 			continue;
    414   1.5     rafal 
    415   1.5     rafal 		ha.ha_name = hd->hd_name;
    416   1.5     rafal 		ha.ha_devoff = hd->hd_devoff;
    417   1.5     rafal 		ha.ha_dmaoff = hd->hd_dmaoff;
    418   1.5     rafal 		ha.ha_irq = hd->hd_irq;
    419   1.5     rafal 
    420   1.5     rafal 		/* XXX This is disgusting. */
    421   1.5     rafal 		ha.ha_st = 1;
    422   1.5     rafal 		ha.ha_sh = MIPS_PHYS_TO_KSEG1(sc->sc_base);
    423   1.5     rafal 		ha.ha_dmat = &sgimips_default_bus_dma_tag;
    424  1.22    sekiya 		if (hpctype == 3)
    425  1.22    sekiya 			ha.hpc_regs = &hpc3_values;
    426  1.22    sekiya 		else
    427  1.22    sekiya 			ha.hpc_regs = &hpc1_values;
    428  1.23    sekiya 		ha.hpc_regs->revision = hpctype;
    429   1.5     rafal 
    430  1.32  drochner 		(void) config_found_sm_loc(self, "hpc", NULL, &ha, hpc_print,
    431  1.32  drochner 					   hpc_submatch);
    432   1.3   thorpej 	}
    433   1.1   thorpej 
    434   1.7    simonb 	/*
    435   1.7    simonb 	 * XXX: Only attach the powerfail interrupt once, since the
    436   1.6     rafal 	 * interrupt code doesn't let you share interrupt just yet.
    437   1.6     rafal 	 *
    438   1.7    simonb 	 * Since the powerfail interrupt is hardcoded to read from
    439   1.6     rafal 	 * a specific register anyway (XXX#2!), we don't care when
    440   1.6     rafal 	 * it gets attached, as long as it only happens once.
    441   1.1   thorpej 	 */
    442  1.23    sekiya 	if (mach_type == MACH_SGI_IP22 && !powerintr_established) {
    443   1.6     rafal 		cpu_intr_establish(9, IPL_NONE, hpc_power_intr, sc);
    444   1.6     rafal 		powerintr_established++;
    445   1.6     rafal 	}
    446  1.26    sekiya 
    447  1.26    sekiya #if defined(BLINK)
    448  1.28     pooka 	if (mach_type == MACH_SGI_IP12 || mach_type == MACH_SGI_IP20)
    449  1.26    sekiya 		hpc_blink(sc);
    450  1.26    sekiya #endif
    451   1.1   thorpej }
    452   1.1   thorpej 
    453   1.3   thorpej int
    454  1.29    rumble hpc_revision(struct hpc_softc *sc, struct gio_attach_args *ga)
    455  1.29    rumble {
    456  1.29    rumble 	int hpctype;
    457  1.29    rumble 
    458  1.29    rumble 	/* Allow forcing of our hpc revision. */
    459  1.36   thorpej 	switch (device_cfdata(&sc->sc_dev)->cf_flags & HPC_REVISION_MASK) {
    460  1.29    rumble 	case HPC_REVISION_1:
    461  1.29    rumble 		return (1);
    462  1.29    rumble 
    463  1.29    rumble 	case HPC_REVISION_15:
    464  1.29    rumble 		return (15);
    465  1.29    rumble 
    466  1.29    rumble 	case HPC_REVISION_3:
    467  1.29    rumble 		return (3);
    468  1.29    rumble 	}
    469  1.29    rumble 
    470  1.29    rumble 	/* XXX We should really come up with an autodetect mechanism */
    471  1.29    rumble 	switch (mach_type) {
    472  1.29    rumble 	case MACH_SGI_IP12:
    473  1.29    rumble 		hpctype = 1;
    474  1.29    rumble 		break;
    475  1.29    rumble 
    476  1.29    rumble 	case MACH_SGI_IP20:
    477  1.29    rumble 		hpctype = 15;
    478  1.29    rumble 		break;
    479  1.29    rumble 
    480  1.29    rumble 	case MACH_SGI_IP22:
    481  1.29    rumble 		hpctype = 3;
    482  1.29    rumble 		break;
    483  1.29    rumble 
    484  1.29    rumble 	default:
    485  1.29    rumble 		return (0);
    486  1.29    rumble 	}
    487  1.29    rumble 
    488  1.29    rumble 	/*
    489  1.29    rumble 	 * Verify HPC1 or HPC1.5
    490  1.29    rumble 	 *
    491  1.29    rumble 	 * For some reason the endian register isn't mapped on all
    492  1.29    rumble 	 * machines (HPC1 machines?).
    493  1.29    rumble 	 */
    494  1.29    rumble 	if (hpctype == 1 || hpctype == 15) {
    495  1.29    rumble 		u_int32_t reg;
    496  1.29    rumble 
    497  1.29    rumble 		if (!badaddr((void *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
    498  1.29    rumble 		    HPC1_BIGENDIAN), 4)) {
    499  1.29    rumble 			reg = *(uint32_t *)MIPS_PHYS_TO_KSEG1(ga->ga_addr +
    500  1.29    rumble 			    HPC1_BIGENDIAN);
    501  1.29    rumble 
    502  1.29    rumble 			if (((reg >> HPC1_REVSHIFT) & HPC1_REVMASK) ==
    503  1.29    rumble 			    HPC1_REV15)
    504  1.29    rumble 				hpctype = 15;
    505  1.29    rumble 			else
    506  1.29    rumble 				hpctype = 1;
    507  1.29    rumble 		} else
    508  1.29    rumble 			hpctype = 1;
    509  1.29    rumble 	}
    510  1.29    rumble 
    511  1.29    rumble 	return (hpctype);
    512  1.29    rumble }
    513  1.29    rumble 
    514  1.29    rumble int
    515  1.32  drochner hpc_submatch(struct device *parent, struct cfdata *cf,
    516  1.33  drochner 	     const int *ldesc, void *aux)
    517   1.1   thorpej {
    518   1.1   thorpej 	struct hpc_attach_args *ha = aux;
    519   1.1   thorpej 
    520   1.3   thorpej 	if (cf->cf_loc[HPCCF_OFFSET] != HPCCF_OFFSET_DEFAULT &&
    521  1.12   thorpej 	    (bus_addr_t) cf->cf_loc[HPCCF_OFFSET] != ha->ha_devoff)
    522   1.3   thorpej 		return (0);
    523   1.1   thorpej 
    524   1.8   thorpej 	return (config_match(parent, cf, aux));
    525   1.3   thorpej }
    526   1.3   thorpej 
    527   1.3   thorpej int
    528   1.3   thorpej hpc_print(void *aux, const char *pnp)
    529   1.3   thorpej {
    530   1.3   thorpej 	struct hpc_attach_args *ha = aux;
    531   1.1   thorpej 
    532   1.3   thorpej 	if (pnp)
    533   1.3   thorpej 		printf("%s at %s", ha->ha_name, pnp);
    534   1.1   thorpej 
    535   1.3   thorpej 	printf(" offset 0x%lx", ha->ha_devoff);
    536   1.1   thorpej 
    537   1.3   thorpej 	return (UNCONF);
    538   1.1   thorpej }
    539   1.1   thorpej 
    540   1.3   thorpej int
    541   1.3   thorpej hpc_power_intr(void *arg)
    542   1.1   thorpej {
    543   1.1   thorpej 	u_int32_t pwr_reg;
    544   1.1   thorpej 
    545   1.1   thorpej 	pwr_reg = *((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850));
    546   1.1   thorpej 	*((volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(0x1fbd9850)) = pwr_reg;
    547   1.1   thorpej 
    548   1.1   thorpej 	printf("hpc_power_intr: panel reg = %08x\n", pwr_reg);
    549   1.1   thorpej 
    550   1.1   thorpej 	if (pwr_reg & 2)
    551   1.3   thorpej 		cpu_reboot(RB_HALT, NULL);
    552   1.1   thorpej 
    553   1.1   thorpej 	return 1;
    554   1.1   thorpej }
    555  1.26    sekiya 
    556  1.26    sekiya #if defined(BLINK)
    557  1.26    sekiya static void
    558  1.26    sekiya hpc_blink(void *self)
    559  1.26    sekiya {
    560  1.26    sekiya 	struct hpc_softc *sc = (struct hpc_softc *) self;
    561  1.26    sekiya 	register int	s;
    562  1.26    sekiya 	int	value;
    563  1.26    sekiya 
    564  1.26    sekiya 	s = splhigh();
    565  1.26    sekiya 
    566  1.26    sekiya 	value = *(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(HPC1_AUX_REGS);
    567  1.26    sekiya 	value ^= HPC1_AUX_CONSLED;
    568  1.26    sekiya 	*(volatile u_int32_t *)MIPS_PHYS_TO_KSEG1(HPC1_AUX_REGS) = value;
    569  1.26    sekiya 	splx(s);
    570  1.26    sekiya 
    571  1.26    sekiya 	/*
    572  1.26    sekiya 	 * Blink rate is:
    573  1.26    sekiya 	 *      full cycle every second if completely idle (loadav = 0)
    574  1.26    sekiya 	 *      full cycle every 2 seconds if loadav = 1
    575  1.26    sekiya 	 *      full cycle every 3 seconds if loadav = 2
    576  1.26    sekiya 	 * etc.
    577  1.26    sekiya 	 */
    578  1.26    sekiya 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
    579  1.26    sekiya 	callout_reset(&hpc_blink_ch, s, hpc_blink, sc);
    580  1.26    sekiya }
    581  1.26    sekiya #endif
    582  1.26    sekiya 
    583