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