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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#include <sys/param.h>
#include <sys/devconf.h>
#include <pci/pcivar.h>
#include <pci/pcireg.h>
#include <scsi/scsiconf.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <i386/isa/isa_device.h>
#include <i386/eisa/eisaconf.h>
#include <stdio.h>
#include <string.h>
#include "lsdev.h"
static void print_isa(struct devconf *);
static void print_eisa(struct devconf *);
static void print_pci(struct devconf *);
static void print_scsi(struct devconf *);
static void print_disk(struct devconf *);
void
hprint_config(void)
{
printf("# This listing automatically generated by lsdev(1)\n");
}
void
print_config(struct devconf *dc)
{
if(vflag)
printf("%d: ", dc->dc_number);
switch(dc->dc_devtype) {
case MDDT_CPU:
printf("# CPU %s%d", dc->dc_name, dc->dc_unit);
break;
case MDDT_BUS:
printf("controller %s%d", dc->dc_name, dc->dc_unit);
break;
case MDDT_ISA:
if(dc->dc_datalen >= ISA_EXTERNALLEN) {
print_isa(dc);
} else {
printit:
printf("%s%d at %s%d",
dc->dc_name, dc->dc_unit, dc->dc_pname,
dc->dc_punit);
}
break;
case MDDT_EISA:
if(dc->dc_datalen >= EISA_EXTERNALLEN) {
print_eisa(dc);
} else {
goto printit;
}
break;
case MDDT_PCI:
if(dc->dc_datalen >= PCI_EXTERNAL_LEN) {
print_pci(dc);
} else {
goto printit;
}
break;
case MDDT_SCSI:
if(dc->dc_datalen >= SCSI_EXTERNALLEN) {
print_scsi(dc);
} else {
goto printit;
}
break;
case MDDT_DISK:
if(dc->dc_datalen >= DISK_EXTERNALLEN) {
print_disk(dc);
} else {
goto printit;
}
break;
default:
if(dc->dc_devtype >= NDEVTYPES) {
printf("%s%d (#%d) at %s%d",
dc->dc_name, dc->dc_unit, dc->dc_devtype,
dc->dc_pname, dc->dc_punit);
} else {
printf("%s%d (%s) at %s%d",
dc->dc_name, dc->dc_unit,
devtypes[dc->dc_devtype], dc->dc_pname,
dc->dc_punit);
}
break;
}
fputc('\n', stdout);
}
static void
print_isa(struct devconf *dc)
{
struct isa_device *id = (struct isa_device *)dc->dc_data;
printf("%s%d\tat isa?", dc->dc_name, dc->dc_unit);
if(dc->dc_md.mddc_imask[0]) {
printf(" %3.3s", dc->dc_md.mddc_imask);
}
if(vflag) {
printf(" (id %d)", id->id_id);
}
if(id->id_iobase) {
if(id->id_iobase < 0) {
printf(" port ?");
} else {
printf(" port 0x%x", id->id_iobase);
}
}
if(id->id_irq) {
int bit = ffs(id->id_irq) - 1;
if(id->id_irq & ~(1 << bit)) {
printf(" irq ?");
} else {
printf(" irq %d", bit);
}
}
if(id->id_drq >= 0) {
printf(" drq %d", id->id_drq);
}
if(id->id_maddr) {
if((unsigned long)id->id_maddr == ~0UL) {
printf(" iomem ?");
} else {
printf(" iomem 0x%lx",
(unsigned long)id->id_maddr & ~KERNBASE);
}
}
if(id->id_msize) {
if(id->id_msize < 0) {
printf(" iosiz ?");
} else {
printf(" iosiz %d", id->id_msize);
}
}
if(id->id_flags) {
printf(" flags 0x%x", id->id_flags);
}
}
static void
print_eisa_resvaddrs(struct resvlist *list)
{
resvaddr_t *rp;
for (rp = list->lh_first; rp; rp = rp->links.le_next)
printf(" %#lx-%#lx%s", rp->addr, rp->addr + rp->size - 1,
rp->links.le_next ? "," : "");
}
static void
print_eisa(struct devconf *dc)
{
struct eisa_device *e_dev = (struct eisa_device *)dc->dc_data;
printf("%s%d\tat eisa0 slot %d #",
dc->dc_name,
dc->dc_unit,
e_dev->ioconf.slot);
print_eisa_resvaddrs(&e_dev->ioconf.ioaddrs);
print_eisa_resvaddrs(&e_dev->ioconf.maddrs);
if(e_dev->ioconf.irq)
printf(" irq %d", ffs(e_dev->ioconf.irq) - 1);
}
static void
print_pci(struct devconf *dc)
{
/*
** PCI is capable of true autoconfiguration.
** The pci_device structure isn't required at all.
**
** You can retrieve the configuration info
** from the configuration space.
*/
struct pci_externalize_buffer *pd =
(struct pci_externalize_buffer *)dc->dc_data;
u_long data;
int pin, line;
printf("%s%d\tat pci%d:%d",
dc->dc_name, dc->dc_unit,
pd->peb_pci_info.pi_bus,
pd->peb_pci_info.pi_device);
/*
** For now we show only the interrupt configuration,
** because this may collide with other parts of the
** configuration.
*/
data = pd->peb_config[PCI_INTERRUPT_REG / 4];
pin = PCI_INTERRUPT_PIN_EXTRACT (data);
line = PCI_INTERRUPT_LINE_EXTRACT (data);
/*
** You may of course display all the configuration registers.
** Hint: The #defines are in <i386/pci/pcireg.h>
*/
if (pin) printf (" # int %c irq %d", pin + ('a'-1), line);
}
static void
print_scsi(struct devconf *dc)
{
struct scsi_link *sl = (struct scsi_link *)dc->dc_data;
printf("%s%d at SCSI bus %d:%d:%d",
dc->dc_name, dc->dc_unit, sl->scsibus, sl->target,
sl->lun);
if(vflag) {
if(sl->flags & SDEV_MEDIA_LOADED)
printf(" (ready)");
if(sl->flags & SDEV_OPEN)
printf(" (open)");
if(sl->flags & SDEV_BOUNCE)
printf(" (bounce)");
}
}
static void
print_disk(struct devconf *dc)
{
int *slavep = (int *)dc->dc_data;
printf("%s%d at %s%d drive %d",
dc->dc_name, dc->dc_unit, dc->dc_pname, dc->dc_punit, *slavep);
}
|