1 /* $OpenBSD: sti_pci_machdep.c,v 1.3 2023/04/13 15:07:43 miod Exp $ */
2
3 /*
4 * Copyright (c) 2007, 2009 Miodrag Vallat.
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice, this permission notice, and the disclaimer below
9 * appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #include <sys/param.h>
21 #include <sys/systm.h>
22 #include <sys/device.h>
23
24 #include <machine/iomod.h>
25 #include <machine/autoconf.h>
26
27 #include <dev/pci/pcivar.h>
28
29 int sti_pci_is_console(struct pci_attach_args *, bus_addr_t *);
30
31 int
sti_pci_is_console(struct pci_attach_args * paa,bus_addr_t * bases)32 sti_pci_is_console(struct pci_attach_args *paa, bus_addr_t *bases)
33 {
34 u_int32_t cf;
35 bus_addr_t addr;
36 int bar;
37 int rc;
38
39 /*
40 * PAGE0 console information will point to one of our BARs,
41 * but depending on the particular sti model, this might not
42 * be the BAR mapping the rom (region #0).
43 *
44 * For example, on Visualize FXe, regions #0, #2 and #3 are
45 * mapped by BAR 0x18, while region #1 is mapped by BAR 0x10,
46 * which matches PAGE0 console address.
47 *
48 * Rather than trying to be smart, reread the region->BAR array
49 * again, and compare the BAR mapping region #1 against PAGE0
50 * values, we simply try all the valid BARs; if any of them
51 * matches what PAGE0 says, then we are the console, and it
52 * doesn't matter which BAR matched.
53 */
54 for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; bar += 4) {
55 cf = pci_conf_read(paa->pa_pc, paa->pa_tag, bar);
56 rc = pci_mapreg_info(paa->pa_pc, paa->pa_tag, bar,
57 _PCI_MAPREG_TYPEBITS(cf), &addr, NULL, NULL);
58 if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_MEM &&
59 PCI_MAPREG_MEM_TYPE(cf) == PCI_MAPREG_MEM_TYPE_64BIT)
60 bar += 4;
61
62 if (rc == 0 &&
63 (hppa_hpa_t)addr == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa)
64 return 1;
65 }
66
67 return 0;
68 }
69