xref: /openbsd/sys/arch/hppa/dev/sti_pci_machdep.c (revision 771fbea0)
1 /*	$OpenBSD: sti_pci_machdep.c,v 1.2 2009/04/10 17:11:27 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
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; ) {
55 		cf = pci_conf_read(paa->pa_pc, paa->pa_tag, bar);
56 
57 		if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) {
58 			rc = pci_io_find(paa->pa_pc, paa->pa_tag, bar, &addr,
59 			    NULL);
60 			bar += 4;
61 		} else {
62 			rc = pci_mem_find(paa->pa_pc, paa->pa_tag, bar, &addr,
63 			    NULL, NULL);
64 			if (PCI_MAPREG_MEM_TYPE(cf) ==
65 			    PCI_MAPREG_MEM_TYPE_64BIT)
66 				bar += 8;
67 			else
68 				bar += 4;
69 		}
70 
71 		if (rc == 0 &&
72 		    (hppa_hpa_t)addr == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa)
73 			return 1;
74 	}
75 
76 	return 0;
77 }
78