]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/alpha/alpha/dec_st550.c
This commit was generated by cvs2svn to compensate for changes in r58653,
[FreeBSD/FreeBSD.git] / sys / alpha / alpha / dec_st550.c
1 /* $FreeBSD$ */
2 /*
3  * Copyright (c) 1995, 1996, 1997 Carnegie-Mellon University.
4  * All rights reserved.
5  *
6  * Author: Chris G. Demetriou
7  * 
8  * Permission to use, copy, modify and distribute this software and
9  * its documentation is hereby granted, provided that both the copyright
10  * notice and this permission notice appear in all copies of the
11  * software, derivative works or modified versions, and any portions
12  * thereof, and that both notices appear in supporting documentation.
13  * 
14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
16  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17  * 
18  * Carnegie Mellon requests users of this software to return to
19  *
20  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
21  *  School of Computer Science
22  *  Carnegie Mellon University
23  *  Pittsburgh PA 15213-3890
24  *
25  * any improvements or extensions that they make and grant Carnegie the
26  * rights to redistribute these changes.
27  */
28 /*
29  * Additional Copyright (c) 1997 by Matthew Jacob for NASA/Ames Research Center
30  */
31 /*
32  * Additional Copyright (c) 1998 by Andrew Gallatin for Duke University
33  */
34
35 #include "opt_ddb.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
41 #include <sys/bus.h>
42 #include <machine/intr.h>
43
44 #include <sys/termios.h>
45
46 #include <machine/rpb.h>
47 #include <machine/cpuconf.h>
48 #include <machine/clock.h>
49 #include <pci/pcireg.h>
50 #include <pci/pcivar.h>
51 #include <alpha/pci/ciareg.h>
52 #include <alpha/pci/ciavar.h>
53
54 #include "sio.h"
55 #include "sc.h"
56
57 #ifndef CONSPEED
58 #define CONSPEED TTYDEF_SPEED
59 #endif
60 static int comcnrate = CONSPEED;
61
62 void st550_init __P((void));
63 static void st550_cons_init __P((void));
64 static void st550_intr_init __P((void));
65 static void pyxis_intr_enable __P((int));
66 static void pyxis_intr_disable __P((int));
67 static void st550_intr_enable __P((int));
68 static void st550_intr_disable __P((int));
69 static void st550_intr_map __P((void *));
70 #define ST550_PCI_IRQ_BEGIN 8
71 #define ST550_PCI_MAX_IRQ  47
72
73 extern int siocnattach __P((int, int));
74 extern int siogdbattach __P((int, int));
75 extern int sccnattach __P((void));
76
77 void
78 st550_init()
79 {
80         platform.family = "Digital Personal Workstation (Miata)";
81
82         if ((platform.model = alpha_dsr_sysname()) == NULL) {
83                 /* XXX Don't know the system variations, yet. */
84                 platform.model = alpha_unknown_sysname();
85         }
86
87         platform.iobus = "cia";
88         platform.cons_init = st550_cons_init;
89         platform.pci_intr_init = st550_intr_init;
90         platform.pci_intr_map = st550_intr_map;
91         platform.pci_intr_disable = st550_intr_disable;
92         platform.pci_intr_enable = st550_intr_enable;
93 }
94
95 extern int comconsole;
96
97 static void
98 st550_cons_init()
99 {
100         struct ctb *ctb;
101
102         cia_init();
103
104 #ifdef DDB
105         siogdbattach(0x2f8, 57600);
106 #endif
107
108         ctb = (struct ctb *)(((caddr_t)hwrpb) + hwrpb->rpb_ctb_off);
109
110         switch (ctb->ctb_term_type) {
111         case 2: 
112                 /* serial console ... */
113                 /* XXX */
114                 {
115                         /*
116                          * Delay to allow PROM putchars to complete.
117                          * FIFO depth * character time,
118                          * character time = (1000000 / (defaultrate / 10))
119                          */
120                         DELAY(160000000 / comcnrate);
121                         comconsole = 0;
122                         if (siocnattach(0x3f8, comcnrate))
123                                 panic("can't init serial console");
124
125                         break;
126                 }
127
128         case 3:
129                 /* display console ... */
130                 /* XXX */
131 #if NSC > 0
132                 sccnattach();
133 #else
134                 panic("not configured to use display && keyboard console");
135 #endif
136                 break;
137
138         default:
139                 printf("ctb->ctb_term_type = 0x%lx\n", ctb->ctb_term_type);
140                 printf("ctb->ctb_turboslot = 0x%lx\n", ctb->ctb_turboslot);
141
142                 panic("consinit: unknown console type %ld\n",
143                     ctb->ctb_term_type);
144         }
145 }
146
147 static void
148 st550_intr_init()
149 {
150         /* This is here because we need to disable extraneous pci interrupts. */
151         int i;
152         for(i = ST550_PCI_IRQ_BEGIN; i <= ST550_PCI_MAX_IRQ; i++)
153                 pyxis_intr_disable(i);
154         /* From Linux... */
155         pyxis_intr_enable(2);   /* enable HALT switch */
156         pyxis_intr_enable(6);   /* enable timer */
157         pyxis_intr_enable(7);   /* enable ISA PIC cascade */
158 }
159
160 static void
161 st550_intr_map(void *arg)
162 {
163         pcicfgregs *cfg = (pcicfgregs *)arg;
164
165         /* There are two main variants of Miata: Miata 1 (Intel SIO)
166          * and Miata {1.5,2} (Cypress).
167          *
168          * The Miata 1 has a CMD PCI IDE wired to compatibility mode at
169          * slot 4 of bus 0.  This variant  has the Pyxis DMA bug.
170          *
171          * On the Miata 1.5 and Miata 2, the Cypress PCI-ISA bridge lives
172          * on device 7 of bus 0.  This device has PCI IDE wired to
173          * compatibility mode on functions 1 and 2.
174          *
175          * There will be no interrupt mapping for these devices, so just
176          * bail out now.
177          */
178         if(cfg->bus == 0) {
179                 if ((hwrpb->rpb_variation & SV_ST_MASK) < SV_ST_MIATA_1_5) {
180                         /* Miata 1 */
181                         if (cfg->slot == 7)
182                                 return;
183                         else if (cfg->func == 4)
184                                 return;
185                 } else {
186                         /* Miata 1.5 or Miata 2 */
187                         if (cfg->slot == 7) {
188                                 if (cfg->func == 0)
189                                         return;
190                                 return;
191                         }
192                 }
193         }
194                 /* Account for the PCI interrupt offset. */
195         /* cfg->intline += ST550_PCI_IRQ_BEGIN; */
196         return;
197 }
198
199 /*
200  * The functions below were written based on a draft copy of the 
201  * 21174 TRM. 
202  */
203 static void
204 pyxis_intr_enable(irq)
205         int irq;
206 {
207         volatile u_int64_t temp;
208
209         alpha_mb();
210         temp =  REGVAL64(PYXIS_INT_MASK);
211         alpha_mb();
212
213         temp |= ( 1L << irq );
214         REGVAL64(PYXIS_INT_MASK) = temp;
215         alpha_mb();
216         temp = REGVAL64(PYXIS_INT_MASK);
217 #if 0
218         printf("pyxis_intr_enable: enabling %d, current mask= ", irq);
219         {
220                 int i;
221                 for ( i = 0; i < 61; i++)
222                         if (temp & (1 << i)){
223                                 printf("%d " ,i);
224                         }       
225                 printf("\n");
226         }
227 #endif
228
229 }
230
231 static void
232 pyxis_intr_disable(irq)
233         int irq;
234 {
235         volatile u_int64_t temp;
236
237         alpha_mb();
238         temp =  REGVAL64(PYXIS_INT_MASK);
239         temp &= ~(1L << irq );
240         REGVAL64(PYXIS_INT_MASK) = temp;
241         alpha_mb();
242         temp = REGVAL64(PYXIS_INT_MASK);
243 #if 0
244         printf("pyxis_intr_disable: disabled %d, current mask ", irq);
245         {
246                 int i;
247                 for ( i = 0; i < 61; i++)
248                         if (temp & (1 << i)){
249                                 printf("%d ",i);
250                         }
251                 printf("\n");
252         }
253 #endif
254
255 }
256
257 static void
258 st550_intr_enable(irq)
259         int irq;
260 {
261         pyxis_intr_enable(irq + ST550_PCI_IRQ_BEGIN);
262 }
263
264 static void
265 st550_intr_disable(irq)
266         int irq;
267 {
268         pyxis_intr_disable(irq + ST550_PCI_IRQ_BEGIN);
269 }