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
|
/* $OpenBSD: sti_pci_machdep.c,v 1.2 2009/04/10 17:11:27 miod Exp $ */
/*
* Copyright (c) 2007, 2009 Miodrag Vallat.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice, this permission notice, and the disclaimer below
* appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/iomod.h>
#include <machine/autoconf.h>
#include <dev/pci/pcivar.h>
int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *);
int
sti_pci_is_console(struct pci_attach_args *paa, bus_addr_t *bases)
{
u_int32_t cf;
bus_addr_t addr;
int bar;
int rc;
/*
* PAGE0 console information will point to one of our BARs,
* but depending on the particular sti model, this might not
* be the BAR mapping the rom (region #0).
*
* For example, on Visualize FXe, regions #0, #2 and #3 are
* mapped by BAR 0x18, while region #1 is mapped by BAR 0x10,
* which matches PAGE0 console address.
*
* Rather than trying to be smart, reread the region->BAR array
* again, and compare the BAR mapping region #1 against PAGE0
* values, we simply try all the valid BARs; if any of them
* matches what PAGE0 says, then we are the console, and it
* doesn't matter which BAR matched.
*/
for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; ) {
cf = pci_conf_read(paa->pa_pc, paa->pa_tag, bar);
if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) {
rc = pci_io_find(paa->pa_pc, paa->pa_tag, bar, &addr,
NULL);
bar += 4;
} else {
rc = pci_mem_find(paa->pa_pc, paa->pa_tag, bar, &addr,
NULL, NULL);
if (PCI_MAPREG_MEM_TYPE(cf) ==
PCI_MAPREG_MEM_TYPE_64BIT)
bar += 8;
else
bar += 4;
}
if (rc == 0 &&
(hppa_hpa_t)addr == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa)
return 1;
}
return 0;
}
|