pci_milan.c revision 1.2.10.2 1 1.2.10.2 nathanw /* $NetBSD: pci_milan.c,v 1.2.10.2 2002/01/11 23:38:13 nathanw Exp $ */
2 1.2.10.2 nathanw
3 1.2.10.2 nathanw /*-
4 1.2.10.2 nathanw * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.2.10.2 nathanw * All rights reserved.
6 1.2.10.2 nathanw *
7 1.2.10.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.10.2 nathanw * by Leo Weppelman.
9 1.2.10.2 nathanw *
10 1.2.10.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.10.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.10.2 nathanw * are met:
13 1.2.10.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.10.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.10.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.10.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.10.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.10.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.10.2 nathanw * must display the following acknowledgement:
20 1.2.10.2 nathanw * This product includes software developed by the NetBSD
21 1.2.10.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.10.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.10.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.10.2 nathanw * from this software without specific prior written permission.
25 1.2.10.2 nathanw *
26 1.2.10.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.10.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.10.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.10.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.10.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.10.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.10.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.10.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.10.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.10.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.10.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.10.2 nathanw */
38 1.2.10.2 nathanw
39 1.2.10.2 nathanw #include <sys/types.h>
40 1.2.10.2 nathanw #include <sys/param.h>
41 1.2.10.2 nathanw #include <sys/systm.h>
42 1.2.10.2 nathanw #include <sys/device.h>
43 1.2.10.2 nathanw
44 1.2.10.2 nathanw #include <dev/pci/pcivar.h>
45 1.2.10.2 nathanw #include <dev/pci/pcireg.h>
46 1.2.10.2 nathanw
47 1.2.10.2 nathanw #include <dev/isa/isavar.h> /* isa_intr_{dis}establish */
48 1.2.10.2 nathanw #include <dev/isa/isareg.h> /* isa_intr_{dis}establish */
49 1.2.10.2 nathanw
50 1.2.10.2 nathanw #include <machine/bswap.h>
51 1.2.10.2 nathanw #include <machine/isa_machdep.h> /* isa_intr_{dis}establish */
52 1.2.10.2 nathanw
53 1.2.10.2 nathanw #include <atari/pci/pci_vga.h>
54 1.2.10.2 nathanw #include <atari/dev/grf_etreg.h>
55 1.2.10.2 nathanw
56 1.2.10.2 nathanw int
57 1.2.10.2 nathanw pci_bus_maxdevs(pc, busno)
58 1.2.10.2 nathanw pci_chipset_tag_t pc;
59 1.2.10.2 nathanw int busno;
60 1.2.10.2 nathanw {
61 1.2.10.2 nathanw return (6);
62 1.2.10.2 nathanw }
63 1.2.10.2 nathanw
64 1.2.10.2 nathanw /*
65 1.2.10.2 nathanw * These are defined in locore.s:
66 1.2.10.2 nathanw */
67 1.2.10.2 nathanw pcireg_t milan_pci_confread(pcitag_t);
68 1.2.10.2 nathanw void milan_pci_confwrite(u_long, pcireg_t);
69 1.2.10.2 nathanw u_long plx_status;
70 1.2.10.2 nathanw
71 1.2.10.2 nathanw pcireg_t
72 1.2.10.2 nathanw pci_conf_read(pc, tag, reg)
73 1.2.10.2 nathanw pci_chipset_tag_t pc;
74 1.2.10.2 nathanw pcitag_t tag;
75 1.2.10.2 nathanw int reg;
76 1.2.10.2 nathanw {
77 1.2.10.2 nathanw u_long data;
78 1.2.10.2 nathanw
79 1.2.10.2 nathanw data = bswap32(milan_pci_confread(tag | reg));
80 1.2.10.2 nathanw if ((plx_status) & 0xf9000000) {
81 1.2.10.2 nathanw /*
82 1.2.10.2 nathanw * Access error, assume nothing there...
83 1.2.10.2 nathanw */
84 1.2.10.2 nathanw data = 0xffffffff;
85 1.2.10.2 nathanw }
86 1.2.10.2 nathanw return(data);
87 1.2.10.2 nathanw }
88 1.2.10.2 nathanw
89 1.2.10.2 nathanw
90 1.2.10.2 nathanw void
91 1.2.10.2 nathanw pci_conf_write(pc, tag, reg, data)
92 1.2.10.2 nathanw pci_chipset_tag_t pc;
93 1.2.10.2 nathanw pcitag_t tag;
94 1.2.10.2 nathanw int reg;
95 1.2.10.2 nathanw pcireg_t data;
96 1.2.10.2 nathanw {
97 1.2.10.2 nathanw milan_pci_confwrite(tag | reg, bswap32(data));
98 1.2.10.2 nathanw }
99 1.2.10.2 nathanw
100 1.2.10.2 nathanw void *
101 1.2.10.2 nathanw pci_intr_establish(pc, ih, level, ih_fun, ih_arg)
102 1.2.10.2 nathanw pci_chipset_tag_t pc;
103 1.2.10.2 nathanw pci_intr_handle_t ih;
104 1.2.10.2 nathanw int level;
105 1.2.10.2 nathanw int (*ih_fun) __P((void *));
106 1.2.10.2 nathanw void *ih_arg;
107 1.2.10.2 nathanw {
108 1.2.10.2 nathanw if (ih == 0 || ih >= 16 || ih == 2)
109 1.2.10.2 nathanw panic("pci_intr_establish: bogus handle 0x%x\n", ih);
110 1.2.10.2 nathanw return isa_intr_establish(NULL, ih, IST_LEVEL, level, ih_fun, ih_arg);
111 1.2.10.2 nathanw }
112 1.2.10.2 nathanw
113 1.2.10.2 nathanw void
114 1.2.10.2 nathanw pci_intr_disestablish(pc, cookie)
115 1.2.10.2 nathanw pci_chipset_tag_t pc;
116 1.2.10.2 nathanw void *cookie;
117 1.2.10.2 nathanw {
118 1.2.10.2 nathanw isa_intr_disestablish(NULL, cookie);
119 1.2.10.2 nathanw }
120 1.2.10.2 nathanw
121 1.2.10.2 nathanw /*
122 1.2.10.2 nathanw * VGA related stuff...
123 1.2.10.2 nathanw * XXX: Currently, you can only boot the Milan through loadbsd.ttp, hence the
124 1.2.10.2 nathanw * text mode ;-)
125 1.2.10.2 nathanw * It looks like the Milan BIOS is initializing the VGA card in a reasonably
126 1.2.10.2 nathanw * standard text mode. However, the screen mode is 640*480 instead of 640*400.
127 1.2.10.2 nathanw * Since wscons does not handle the right by default, the card is reprogrammed
128 1.2.10.2 nathanw * to 640*400 using only 'standard' VGA registers (I hope!). So this ought to
129 1.2.10.2 nathanw * work on cards other than the S3Trio card I have tested it on.
130 1.2.10.2 nathanw */
131 1.2.10.2 nathanw static u_char crt_tab[] = {
132 1.2.10.2 nathanw 0x60, 0x53, 0x4f, 0x14, 0x56, 0x05, 0xc1, 0x1f,
133 1.2.10.2 nathanw 0x00, 0x4f, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00,
134 1.2.10.2 nathanw 0x98, 0x3d, 0x8f, 0x28, 0x0f, 0x8f, 0xc1, 0xc3,
135 1.2.10.2 nathanw 0xff };
136 1.2.10.2 nathanw
137 1.2.10.2 nathanw /*
138 1.2.10.2 nathanw * XXX: Why are we repeating this everywhere! (Leo)
139 1.2.10.2 nathanw */
140 1.2.10.2 nathanw #define PCI_LINMEMBASE 0x0e000000
141 1.2.10.2 nathanw
142 1.2.10.2 nathanw void
143 1.2.10.2 nathanw milan_vga_init(pc, tag, id, ba, fb)
144 1.2.10.2 nathanw pci_chipset_tag_t pc;
145 1.2.10.2 nathanw pcitag_t tag;
146 1.2.10.2 nathanw int id;
147 1.2.10.2 nathanw volatile u_char *ba;
148 1.2.10.2 nathanw u_char *fb;
149 1.2.10.2 nathanw {
150 1.2.10.2 nathanw int i, csr;
151 1.2.10.2 nathanw
152 1.2.10.2 nathanw /* Turn on the card */
153 1.2.10.2 nathanw pci_conf_write(pc, tag, PCI_MAPREG_START, PCI_LINMEMBASE);
154 1.2.10.2 nathanw csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
155 1.2.10.2 nathanw csr |= (PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_IO_ENABLE);
156 1.2.10.2 nathanw csr |= PCI_COMMAND_MASTER_ENABLE;
157 1.2.10.2 nathanw pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
158 1.2.10.2 nathanw
159 1.2.10.2 nathanw /*
160 1.2.10.2 nathanw * Make sure we're allowed to write all crt-registers and reload them.
161 1.2.10.2 nathanw */
162 1.2.10.2 nathanw WCrt(ba, CRT_ID_END_VER_RETR, (RCrt(ba, CRT_ID_END_VER_RETR) & 0x7f));
163 1.2.10.2 nathanw
164 1.2.10.2 nathanw for (i = 0; i < 0x18; i++)
165 1.2.10.2 nathanw WCrt(ba, i, crt_tab[i]);
166 1.2.10.2 nathanw
167 1.2.10.2 nathanw /*
168 1.2.10.2 nathanw * The Milan has a white border... make it black
169 1.2.10.2 nathanw */
170 1.2.10.2 nathanw WAttr(ba, 0x11, 0|0x20);
171 1.2.10.2 nathanw }
172