1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
/* $NetBSD: pci.c,v 1.6 2022/02/16 23:49:26 riastradh Exp $ */
/*
* Copyright (C) 1995-1997 Gary Thomas (gdt@linuxppc.org)
* All rights reserved.
*
* Adapted from a program by:
* Steve Sellgren
* San Francisco Indigo Company
* sfindigo!sellgren@uunet.uu.net
* Adapted for Moto boxes by:
* Pat Kane & Mark Scott, 1996
* Fixed for IBM/PowerStack II Pat Kane 1997
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Gary Thomas.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <lib/libsa/stand.h>
#include <sys/bswap.h>
#include <dev/pci/pcireg.h>
#include "boot.h"
#define NSLOTS 5
#define NPCIREGS 10
/*
* should use devfunc number/indirect method to be totally safe on
* all machines, this works for now on 3 slot Moto boxes
*/
#define PCI_CONFIG_SPACE_BASE 0x80800000
#define PCI_CONFIG_SPACE(d, f) \
(u_long *)(PCI_CONFIG_SPACE_BASE | (1 << (d)) | ((f) << 8))
struct PCI_ConfigInfo {
u_long *config_addr;
u_long regs[NPCIREGS];
} PCI_slots [NSLOTS] = {
{ PCI_CONFIG_SPACE(11, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
{ PCI_CONFIG_SPACE(12, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
{ PCI_CONFIG_SPACE(13, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
{ PCI_CONFIG_SPACE(14, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
{ PCI_CONFIG_SPACE(15, 0), { 0xDE, 0xAD, 0xBE, 0xEF } },
};
#define DEVID (PCI_ID_REG >> 2)
#define CMD (PCI_COMMAND_STATUS_REG >> 2)
#define CLASS (PCI_CLASS_REG >> 2)
#define BAR_BASE (PCI_MAPREG_START >> 2)
/*
* The following code modifies the PCI Command register
* to enable memory and I/O accesses.
*/
void
enablePCI(int slot, int io, int mem, int master)
{
volatile u_char *ppci;
u_char enable = 0;
if (io)
enable |= PCI_COMMAND_IO_ENABLE;
if (mem)
enable |= PCI_COMMAND_MEM_ENABLE;
if (master)
enable |= PCI_COMMAND_MASTER_ENABLE;
ppci = (u_char *)&PCI_slots[slot].config_addr[CMD];
*ppci = enable;
__asm volatile("eieio" ::: "memory");
}
void
scanPCI(void)
{
struct PCI_ConfigInfo *pslot;
int slt, r;
for (slt = 0; slt < NSLOTS; slt++) {
pslot = &PCI_slots[slt];
for (r = 0; r < NPCIREGS; r++)
pslot->regs[r] = bswap32(pslot->config_addr[r]);
}
}
int
findPCIVga(void)
{
struct PCI_ConfigInfo *pslot;
int theSlot = -1;
int highVgaSlot = -1;
int slt;
for (slt = 0; slt < NSLOTS; slt++) {
pslot = &PCI_slots[slt];
if (pslot->regs[DEVID] != 0xffffffff) { /* card in slot ? */
if (PCI_CLASS(pslot->regs[CLASS]) ==
PCI_CLASS_DISPLAY) {
highVgaSlot = slt;
if ((pslot->regs[CMD] & 0x03)) { /* did firmware enable it ? */
theSlot = slt;
}
}
}
}
if (theSlot == -1)
theSlot = highVgaSlot;
return theSlot;
}
int
PCISlotnum(u_int bus, u_int dev, u_int func)
{
u_long *tag;
int i;
if (bus != 0 ||
dev < 11 || dev > 15 ||
func > 7)
return -1;
tag = PCI_CONFIG_SPACE(dev, func);
for (i = 0; i < sizeof(PCI_slots) / sizeof(struct PCI_ConfigInfo); i++)
if (tag == PCI_slots[i].config_addr)
return i;
return -1;
}
/* return Vendor ID of card in the slot */
int
PCIVendor(int slotnum)
{
struct PCI_ConfigInfo *pslot;
pslot = &PCI_slots[slotnum];
return pslot->regs[DEVID] & 0xffff;
}
/* return mapped address for I/O or Memory */
u_long
PCIAddress(int slotnum, u_int bar, int type)
{
struct PCI_ConfigInfo *pslot;
if (bar >= 6)
return 0xffffffff;
pslot = &PCI_slots[slotnum];
if (pslot->regs[DEVID] == 0xffffffff ||
PCI_MAPREG_TYPE(pslot->regs[BAR_BASE + bar]) != type)
return 0xffffffff;
return PCI_MAPREG_MEM_ADDR(pslot->regs[BAR_BASE + bar]);
}
#ifdef DEBUG
void
printPCIslots(void)
{
int i;
for (i = 0; i < NSLOTS; i++) {
printf("PCI Slot number: %d", i);
printf(" Vendor ID: 0x%x\n", PCIVendor(i));
}
}
#endif /* DEBUG */
|