io.c revision 1.1.64.3 1 1.1.64.3 yamt /* $NetBSD: io.c,v 1.1.64.3 2006/08/11 15:42:41 yamt Exp $ */
2 1.1 nonaka
3 1.1 nonaka /*-
4 1.1 nonaka * Copyright (C) 1995-1997 Gary Thomas (gdt (at) linuxppc.org)
5 1.1 nonaka * All rights reserved.
6 1.1 nonaka *
7 1.1 nonaka * PCI/ISA I/O support
8 1.1 nonaka *
9 1.1 nonaka * Redistribution and use in source and binary forms, with or without
10 1.1 nonaka * modification, are permitted provided that the following conditions
11 1.1 nonaka * are met:
12 1.1 nonaka * 1. Redistributions of source code must retain the above copyright
13 1.1 nonaka * notice, this list of conditions and the following disclaimer.
14 1.1 nonaka * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 nonaka * notice, this list of conditions and the following disclaimer in the
16 1.1 nonaka * documentation and/or other materials provided with the distribution.
17 1.1 nonaka * 3. All advertising materials mentioning features or use of this software
18 1.1 nonaka * must display the following acknowledgement:
19 1.1 nonaka * This product includes software developed by Gary Thomas.
20 1.1 nonaka * 4. The name of the author may not be used to endorse or promote products
21 1.1 nonaka * derived from this software without specific prior written permission.
22 1.1 nonaka *
23 1.1 nonaka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 nonaka * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 nonaka * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 nonaka * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 nonaka * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 nonaka * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 nonaka * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 nonaka * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 nonaka * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 nonaka * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 nonaka */
34 1.1 nonaka
35 1.1 nonaka #include <lib/libsa/stand.h>
36 1.1.64.2 yamt #include <sys/bswap.h>
37 1.1 nonaka #include "boot.h"
38 1.1 nonaka
39 1.1.64.2 yamt #define PCI_NSLOTS 8
40 1.1.64.2 yamt #define PCI_NREGS 5
41 1.1.64.2 yamt #define PCI_DEVID 0
42 1.1.64.2 yamt #define PCI_CMD 1
43 1.1.64.2 yamt #define PCI_CLASS 2
44 1.1.64.2 yamt #define PCI_MEMBASE 4
45 1.1.64.2 yamt
46 1.1.64.2 yamt
47 1.1 nonaka volatile u_char *ISA_io = (u_char *)0x80000000;
48 1.1.64.2 yamt volatile u_char *ISA_mem = (u_char *)0xc0000000;
49 1.1.64.2 yamt volatile char *videomem = (char *)0xc00b8000; /* + vram offset */
50 1.1.64.2 yamt
51 1.1.64.2 yamt struct PCI_cinfo {
52 1.1.64.2 yamt u_long *config_addr;
53 1.1.64.2 yamt u_long regs[PCI_NREGS];
54 1.1.64.2 yamt } PCI_slots[PCI_NSLOTS] = {
55 1.1.64.2 yamt { (u_long *)0x80808000, {0xDEADBEEF,} },
56 1.1.64.2 yamt { (u_long *)0x80800800, {0xDEADBEEF,} },
57 1.1.64.2 yamt { (u_long *)0x80801000, {0xDEADBEEF,} },
58 1.1.64.2 yamt { (u_long *)0x80802000, {0xDEADBEEF,} },
59 1.1.64.2 yamt { (u_long *)0x80804000, {0xDEADBEEF,} },
60 1.1.64.2 yamt { (u_long *)0x80810000, {0xDEADBEEF,} },
61 1.1.64.2 yamt { (u_long *)0x80820000, {0xDEADBEEF,} },
62 1.1.64.2 yamt { (u_long *)0x80840000, {0xDEADBEEF,} },
63 1.1.64.2 yamt };
64 1.1 nonaka
65 1.1 nonaka void
66 1.1.64.1 yamt outb(int port, char val)
67 1.1 nonaka {
68 1.1 nonaka
69 1.1 nonaka ISA_io[port] = val;
70 1.1 nonaka }
71 1.1 nonaka
72 1.1.64.2 yamt inline void
73 1.1.64.2 yamt outw(int port, u_int16_t val)
74 1.1.64.2 yamt {
75 1.1.64.2 yamt outb(port, val>>8);
76 1.1.64.2 yamt outb(port+1, val);
77 1.1.64.2 yamt }
78 1.1.64.2 yamt
79 1.1 nonaka u_char
80 1.1.64.1 yamt inb(int port)
81 1.1 nonaka {
82 1.1 nonaka
83 1.1 nonaka return (ISA_io[port]);
84 1.1 nonaka }
85 1.1 nonaka
86 1.1 nonaka u_long
87 1.1.64.1 yamt local_to_PCI(u_long addr)
88 1.1 nonaka {
89 1.1 nonaka
90 1.1 nonaka return ((addr & 0x7FFFFFFF) | 0x80000000);
91 1.1 nonaka }
92 1.1.64.2 yamt
93 1.1.64.2 yamt void
94 1.1.64.2 yamt unlockVideo(int slot)
95 1.1.64.2 yamt {
96 1.1.64.2 yamt volatile u_int8_t *ppci;
97 1.1.64.2 yamt
98 1.1.64.2 yamt ppci = (u_int8_t *)PCI_slots[slot].config_addr;
99 1.1.64.2 yamt ppci[4] = 0x0003; /* enable memory and IO Access */
100 1.1.64.3 yamt #if 0
101 1.1.64.2 yamt ppci[0x10] = 0x00000; /* Turn off memory mapping */
102 1.1.64.2 yamt ppci[0x11] = 0x00000; /* mem base = 0 */
103 1.1.64.2 yamt ppci[0x12] = 0x00000;
104 1.1.64.2 yamt ppci[0x13] = 0x00000;
105 1.1.64.3 yamt #endif
106 1.1.64.2 yamt __asm__ volatile("eieio");
107 1.1.64.2 yamt
108 1.1.64.2 yamt outb(0x3d4, 0x11);
109 1.1.64.2 yamt outb(0x3d5, 0x0e); /* unlock CR0-CR7 */
110 1.1.64.2 yamt }
111 1.1.64.2 yamt
112 1.1.64.2 yamt int
113 1.1.64.2 yamt scan_PCI(int start)
114 1.1.64.2 yamt {
115 1.1.64.2 yamt int slot, r;
116 1.1.64.2 yamt struct PCI_cinfo *pslot;
117 1.1.64.2 yamt int VGAslot = -1;
118 1.1.64.2 yamt int highVGAslot = 0;
119 1.1.64.2 yamt
120 1.1.64.2 yamt for (slot = start + 1; slot < PCI_NSLOTS; slot++) {
121 1.1.64.2 yamt pslot = &PCI_slots[slot];
122 1.1.64.2 yamt for (r = 0; r < PCI_NREGS; r++)
123 1.1.64.2 yamt pslot->regs[r] = bswap32(pslot->config_addr[r]);
124 1.1.64.2 yamt if (pslot->regs[PCI_DEVID] != 0xffffffff) {
125 1.1.64.2 yamt /* we have a card */
126 1.1.64.2 yamt if (((pslot->regs[PCI_CLASS] & 0xffffff00) ==
127 1.1.64.2 yamt 0x03000000) ||
128 1.1.64.2 yamt ((pslot->regs[PCI_CLASS] & 0xffffff00) ==
129 1.1.64.2 yamt 0x00010000)) {
130 1.1.64.2 yamt /* it's a VGA card */
131 1.1.64.2 yamt highVGAslot = slot;
132 1.1.64.2 yamt if ((pslot->regs[PCI_CMD] & 0x03)) {
133 1.1.64.2 yamt /* fW enabled it */
134 1.1.64.2 yamt VGAslot = slot;
135 1.1.64.2 yamt break;
136 1.1.64.2 yamt }
137 1.1.64.2 yamt }
138 1.1.64.2 yamt }
139 1.1.64.2 yamt }
140 1.1.64.2 yamt return VGAslot;
141 1.1.64.2 yamt }
142 1.1.64.2 yamt
143 1.1.64.2 yamt int
144 1.1.64.2 yamt PCI_vendor(int slotnum)
145 1.1.64.2 yamt {
146 1.1.64.2 yamt struct PCI_cinfo *pslot = &PCI_slots[slotnum];
147 1.1.64.2 yamt
148 1.1.64.2 yamt return (pslot->regs[PCI_DEVID] & 0xffff);
149 1.1.64.2 yamt }
150