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