Home | History | Annotate | Line # | Download | only in dev
pic.c revision 1.5
      1  1.5   pooka /* $NetBSD: pic.c,v 1.5 2004/04/10 19:07:06 pooka Exp $	 */
      2  1.1  sekiya 
      3  1.1  sekiya /*
      4  1.1  sekiya  * Copyright (c) 2002 Steve Rumble
      5  1.1  sekiya  * All rights reserved.
      6  1.1  sekiya  *
      7  1.1  sekiya  * Redistribution and use in source and binary forms, with or without
      8  1.1  sekiya  * modification, are permitted provided that the following conditions
      9  1.1  sekiya  * are met:
     10  1.1  sekiya  * 1. Redistributions of source code must retain the above copyright
     11  1.1  sekiya  *    notice, this list of conditions and the following disclaimer.
     12  1.1  sekiya  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  sekiya  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  sekiya  *    documentation and/or other materials provided with the distribution.
     15  1.1  sekiya  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  sekiya  *    derived from this software without specific prior written permission.
     17  1.1  sekiya  *
     18  1.1  sekiya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  sekiya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  sekiya  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  sekiya  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  sekiya  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  sekiya  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  sekiya  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  sekiya  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  sekiya  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  sekiya  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  sekiya  */
     29  1.1  sekiya 
     30  1.1  sekiya #include <sys/param.h>
     31  1.1  sekiya #include <sys/device.h>
     32  1.1  sekiya #include <sys/systm.h>
     33  1.1  sekiya 
     34  1.1  sekiya #include <machine/cpu.h>
     35  1.1  sekiya #include <machine/locore.h>
     36  1.1  sekiya #include <machine/autoconf.h>
     37  1.1  sekiya #include <machine/bus.h>
     38  1.1  sekiya #include <machine/machtype.h>
     39  1.2  sekiya #include <machine/sysconf.h>
     40  1.1  sekiya 
     41  1.1  sekiya #include <sgimips/dev/picreg.h>
     42  1.1  sekiya 
     43  1.1  sekiya #include "locators.h"
     44  1.1  sekiya 
     45  1.1  sekiya struct pic_softc {
     46  1.1  sekiya 	struct device   sc_dev;
     47  1.1  sekiya 
     48  1.1  sekiya 	bus_space_tag_t iot;
     49  1.1  sekiya 	bus_space_handle_t ioh;
     50  1.1  sekiya 
     51  1.1  sekiya };
     52  1.1  sekiya 
     53  1.1  sekiya static int      pic_match(struct device *, struct cfdata *, void *);
     54  1.1  sekiya static void     pic_attach(struct device *, struct device *, void *);
     55  1.1  sekiya static int      pic_print(void *, const char *);
     56  1.1  sekiya void		pic_bus_reset(void);
     57  1.4   pooka void		pic_watchdog_enable(void);
     58  1.4   pooka void		pic_watchdog_disable(void);
     59  1.1  sekiya void		pic_watchdog_tickle(void);
     60  1.1  sekiya 
     61  1.1  sekiya CFATTACH_DECL(pic, sizeof(struct pic_softc),
     62  1.1  sekiya 	      pic_match, pic_attach, NULL, NULL);
     63  1.1  sekiya 
     64  1.1  sekiya struct pic_attach_args {
     65  1.1  sekiya 	const char     *iaa_name;
     66  1.1  sekiya 
     67  1.1  sekiya 	bus_space_tag_t iaa_st;
     68  1.1  sekiya 	bus_space_handle_t iaa_sh;
     69  1.1  sekiya };
     70  1.1  sekiya 
     71  1.1  sekiya static struct pic_softc psc;
     72  1.1  sekiya 
     73  1.1  sekiya static int
     74  1.1  sekiya pic_match(struct device * parent, struct cfdata * match, void *aux)
     75  1.1  sekiya {
     76  1.1  sekiya 	/*
     77  1.1  sekiya 	 * PIC exists on IP12 systems. It appears to be the immediate
     78  1.1  sekiya 	 * ancestor of the mc, for mips1 processors.
     79  1.1  sekiya 	 */
     80  1.4   pooka 	if (mach_type == MACH_SGI_IP12)
     81  1.4   pooka 		return (1);
     82  1.4   pooka 	else
     83  1.1  sekiya 		return (0);
     84  1.1  sekiya }
     85  1.1  sekiya 
     86  1.1  sekiya static void
     87  1.1  sekiya pic_attach(struct device * parent, struct device * self, void *aux)
     88  1.1  sekiya {
     89  1.1  sekiya 	u_int32_t       reg;
     90  1.1  sekiya 	char            picstr[80] = "";
     91  1.1  sekiya 	struct pic_attach_args iaa;
     92  1.1  sekiya 	struct mainbus_attach_args *ma = aux;
     93  1.1  sekiya 
     94  1.1  sekiya 	psc.iot = SGIMIPS_BUS_SPACE_HPC;
     95  1.1  sekiya 	if (bus_space_map(psc.iot, ma->ma_addr, 0,
     96  1.1  sekiya 			  BUS_SPACE_MAP_LINEAR, &psc.ioh))
     97  1.1  sekiya 		panic("pic_attach: could not allocate memory\n");
     98  1.1  sekiya 
     99  1.2  sekiya 	platform.bus_reset = pic_bus_reset;
    100  1.4   pooka 	platform.watchdog_enable = pic_watchdog_enable;
    101  1.4   pooka 	platform.watchdog_disable = pic_watchdog_disable;
    102  1.3  sekiya 	platform.watchdog_reset = pic_watchdog_tickle;
    103  1.2  sekiya 
    104  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_SYSID);
    105  1.1  sekiya 	reg = (reg >> PIC_SYSID_REVSHIFT) & PIC_SYSID_REVMASK;
    106  1.5   pooka 	printf("\npic0: Revision %c", reg + 64);
    107  1.1  sekiya 
    108  1.1  sekiya 	/* enable refresh, set big-endian, memory parity, allow slave access */
    109  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_CPUCTRL);
    110  1.1  sekiya 	reg |= (PIC_CPUCTRL_REFRESH | PIC_CPUCTRL_BIGENDIAN | PIC_CPUCTRL_MPR |
    111  1.1  sekiya 		PIC_CPUCTRL_SLAVE);
    112  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_CPUCTRL, reg);
    113  1.1  sekiya 
    114  1.1  sekiya 	/* query the mode register to see what's going on */
    115  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_MODE);
    116  1.1  sekiya 	printf(": dblk (0x%x), iblk (0x%x)\n", reg & PIC_MODE_DBSIZ,
    117  1.1  sekiya 	       reg & PIC_MODE_IBSIZ);
    118  1.1  sekiya 
    119  1.1  sekiya 	if (reg & PIC_MODE_NOCACHE)
    120  1.1  sekiya 		strcat(picstr, "cache disabled");
    121  1.1  sekiya 	else
    122  1.1  sekiya 		strcat(picstr, "cache enabled");
    123  1.1  sekiya 
    124  1.1  sekiya 	if (reg & PIC_MODE_ISTREAM)
    125  1.1  sekiya 		strcat(picstr, ", instr streaming");
    126  1.1  sekiya 
    127  1.1  sekiya 	if (reg & PIC_MODE_STOREPARTIAL)
    128  1.1  sekiya 		strcat(picstr, ", store partial");
    129  1.1  sekiya 
    130  1.1  sekiya 	if (reg & PIC_MODE_BUSDRIVE)
    131  1.1  sekiya 		strcat(picstr, ", bus drive");
    132  1.1  sekiya 
    133  1.1  sekiya 	printf("pic0: %s", picstr);
    134  1.1  sekiya 
    135  1.1  sekiya 	/* gio32 allow master, real time devices */
    136  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_GIO32ARB_SLOT0);
    137  1.1  sekiya 	reg &= ~(PIC_GIO32ARB_SLOT_SLAVE | PIC_GIO32ARB_SLOT_LONG);
    138  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_GIO32ARB_SLOT0, reg);
    139  1.1  sekiya 
    140  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_GIO32ARB_SLOT1);
    141  1.1  sekiya 	reg &= ~(PIC_GIO32ARB_SLOT_SLAVE | PIC_GIO32ARB_SLOT_LONG);
    142  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_GIO32ARB_SLOT1, reg);
    143  1.1  sekiya 
    144  1.1  sekiya 	/* default gio32 burst time */
    145  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_GIO32ARB_BURST,
    146  1.1  sekiya 			  PIC_GIO32ARB_DEFBURST);
    147  1.1  sekiya 
    148  1.1  sekiya 	/* default gio32 delay time */
    149  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_GIO32ARB_DELAY,
    150  1.1  sekiya 			  PIC_GIO32ARB_DEFDELAY);
    151  1.1  sekiya 
    152  1.1  sekiya 	printf("\n");
    153  1.1  sekiya 
    154  1.1  sekiya 	/* XXX gio only on IP12 Indigo (?). does pic exist anywhere else? */
    155  1.1  sekiya 	iaa.iaa_name = "gio";
    156  1.1  sekiya 	(void) config_found(self, (void *) &iaa, pic_print);
    157  1.1  sekiya 
    158  1.1  sekiya 	/* Enable watchdog, reset it */
    159  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_CPUCTRL)
    160  1.1  sekiya 		| (PIC_CPUCTRL_WDOG);
    161  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_CPUCTRL, reg);
    162  1.1  sekiya }
    163  1.1  sekiya 
    164  1.1  sekiya 
    165  1.1  sekiya static int
    166  1.1  sekiya pic_print(void *aux, const char *name)
    167  1.1  sekiya {
    168  1.1  sekiya 	struct pic_attach_args *iaa = aux;
    169  1.1  sekiya 
    170  1.1  sekiya 	if (name)
    171  1.1  sekiya 		aprint_normal("%s at %s", iaa->iaa_name, name);
    172  1.1  sekiya 
    173  1.1  sekiya 	return UNCONF;
    174  1.1  sekiya }
    175  1.1  sekiya 
    176  1.1  sekiya void
    177  1.1  sekiya pic_bus_reset(void)
    178  1.1  sekiya {
    179  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_PARITY_ERROR, 0);
    180  1.1  sekiya }
    181  1.1  sekiya 
    182  1.1  sekiya void
    183  1.4   pooka pic_watchdog_enable()
    184  1.4   pooka {
    185  1.4   pooka 	uint32_t reg;
    186  1.4   pooka 
    187  1.4   pooka 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_CPUCTRL);
    188  1.4   pooka 	reg |= PIC_CPUCTRL_WDOG;
    189  1.4   pooka 	bus_space_write_4(psc.iot, psc.ioh, PIC_CPUCTRL, reg);
    190  1.4   pooka }
    191  1.4   pooka 
    192  1.4   pooka void
    193  1.4   pooka pic_watchdog_disable()
    194  1.1  sekiya {
    195  1.4   pooka 	uint32_t reg;
    196  1.1  sekiya 
    197  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_CPUCTRL)
    198  1.4   pooka 	reg &= ~(PIC_CPUCTRL_WDOG);
    199  1.4   pooka 	bus_space_write_4(psc.iot, psc.ioh, PIC_CPUCTRL, reg);
    200  1.4   pooka }
    201  1.4   pooka 
    202  1.4   pooka void
    203  1.4   pooka pic_watchdog_tickle()
    204  1.4   pooka {
    205  1.4   pooka 	uint32_t reg;
    206  1.4   pooka 
    207  1.4   pooka 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_CPUCTRL)
    208  1.4   pooka 	reg &= ~(PIC_CPUCTRL_WDOG);
    209  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_CPUCTRL, reg);
    210  1.1  sekiya 	reg = bus_space_read_4(psc.iot, psc.ioh, PIC_CPUCTRL)
    211  1.4   pooka 	reg =| (PIC_CPUCTRL_WDOG);
    212  1.1  sekiya 	bus_space_write_4(psc.iot, psc.ioh, PIC_CPUCTRL, reg);
    213  1.1  sekiya }
    214