xref: /openbsd/sys/arch/hppa/dev/uturn.c (revision e5dd7070)
1 /*	$OpenBSD: uturn.c,v 1.7 2010/04/29 13:48:29 jsing Exp $	*/
2 
3 /*
4  * Copyright (c) 2004 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /* TODO IOA programming */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/device.h>
34 #include <sys/reboot.h>
35 
36 #include <machine/iomod.h>
37 #include <machine/autoconf.h>
38 
39 #include <hppa/dev/cpudevs.h>
40 
41 struct uturn_regs {
42 	u_int64_t	resv0[2];
43 	u_int64_t	status;		/* 0x10: */
44 	u_int64_t	resv1[5];
45 	u_int64_t	debug;		/* 0x40: */
46 };
47 
48 struct uturn_softc {
49 	struct device sc_dv;
50 
51 	struct uturn_regs volatile *sc_regs;
52 };
53 
54 int	uturnmatch(struct device *, void *, void *);
55 void	uturnattach(struct device *, struct device *, void *);
56 
57 struct cfattach uturn_ca = {
58 	sizeof(struct uturn_softc), uturnmatch, uturnattach
59 };
60 
61 struct cfdriver uturn_cd = {
62 	NULL, "uturn", DV_DULL
63 };
64 
65 int
66 uturnmatch(parent, cfdata, aux)
67 	struct device *parent;
68 	void *cfdata;
69 	void *aux;
70 {
71 	struct confargs *ca = aux;
72 	/* struct cfdata *cf = cfdata; */
73 
74 	/* there will be only one */
75 	if (ca->ca_type.iodc_type != HPPA_TYPE_IOA ||
76 	    ca->ca_type.iodc_sv_model != HPPA_IOA_UTURN)
77 		return 0;
78 
79 	if (ca->ca_type.iodc_model == 0x58 &&
80 	    ca->ca_type.iodc_revision >= 0x20)
81 		return 0;
82 
83 	return 1;
84 }
85 
86 void
87 uturnattach(parent, self, aux)
88 	struct device *parent;
89 	struct device *self;
90 	void *aux;
91 {
92 	struct confargs *ca = aux, nca;
93 	struct uturn_softc *sc = (struct uturn_softc *)self;
94 	bus_space_handle_t ioh;
95 	hppa_hpa_t hpa;
96 
97 	if (bus_space_map(ca->ca_iot, ca->ca_hpa, IOMOD_HPASIZE, 0, &ioh)) {
98 		printf(": can't map IO space\n");
99 		return;
100 	}
101 	sc->sc_regs = (struct uturn_regs *)ca->ca_hpa;
102 
103 	printf(": %s rev %d\n",
104 	    ca->ca_type.iodc_revision < 0x10? "U2" : "UTurn",
105 	    ca->ca_type.iodc_revision & 0xf);
106 
107 	/* keep it real */
108 	((struct iomod *)ioh)->io_control = 0x80;
109 
110 	/*
111 	 * U2/UTurn is actually a combination of an Upper Bus
112 	 * Converter (UBC) and a Lower Bus Converter (LBC).  This
113 	 * driver attaches to the UBC; the LBC isn't very interesting,
114 	 * so we skip it.  This is easy, since it always is module 63,
115 	 * hence the MAXMODBUS - 1 below.
116 	 */
117 	nca = *ca;
118 	nca.ca_hpamask = HPPA_IOBEGIN;
119 	pdc_scanbus(self, &nca, MAXMODBUS - 1, 0, 0);
120 
121 	/* XXX On some machines, PDC doesn't tell us about all devices. */
122 	switch (cpu_hvers) {
123 	case HPPA_BOARD_HP809:
124 	case HPPA_BOARD_HP819:
125 	case HPPA_BOARD_HP829:
126 	case HPPA_BOARD_HP839:
127 	case HPPA_BOARD_HP849:
128 	case HPPA_BOARD_HP859:
129 	case HPPA_BOARD_HP869:
130 		hpa = ((struct iomod *)ioh)->io_io_low << 16;
131 		pdc_scanbus(self, &nca, MAXMODBUS - 1, hpa, 0);
132 		break;
133 	default:
134 		break;
135 	}
136 }
137