Home | History | Annotate | Line # | Download | only in mvmeppc
      1 /*	$NetBSD: mainbus.c,v 1.22 2021/08/07 16:19:00 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Christopher G. Demetriou
     17  *	for the NetBSD Project.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.22 2021/08/07 16:19:00 thorpej Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 #include <sys/kmem.h>
     40 
     41 #include <machine/autoconf.h>
     42 #include <sys/bus.h>
     43 
     44 #include "pci.h"
     45 #include "opt_pci.h"
     46 #include <dev/pci/pcivar.h>
     47 #include <dev/pci/pciconf.h>
     48 #include <machine/pci_machdep.h>
     49 #include <machine/isa_machdep.h>
     50 
     51 int	mainbus_match(device_t, cfdata_t, void *);
     52 void	mainbus_attach(device_t, device_t, void *);
     53 
     54 CFATTACH_DECL_NEW(mainbus, 0,
     55     mainbus_match, mainbus_attach, NULL, NULL);
     56 
     57 int	mainbus_print(void *, const char *);
     58 
     59 
     60 /* There can be only one */
     61 static int mainbus_found;
     62 struct powerpc_isa_chipset genppc_ict;
     63 struct genppc_pci_chipset *genppc_pct;
     64 
     65 #define	PCI_IO_START	0x00008000
     66 #define	PCI_IO_END	0x0000ffff
     67 #define	PCI_IO_SIZE	((PCI_IO_END - PCI_IO_START) + 1)
     68 
     69 #define	PCI_MEM_START	0x00000000
     70 #define	PCI_MEM_END	0x0fffffff
     71 #define	PCI_MEM_SIZE	((PCI_MEM_END - PCI_MEM_START) + 1)
     72 
     73 /*
     74  * Probe for the mainbus; always succeeds.
     75  */
     76 int
     77 mainbus_match(device_t parent, cfdata_t match, void *aux)
     78 {
     79 
     80 	if (mainbus_found)
     81 		return 0;
     82 	return 1;
     83 }
     84 
     85 /*
     86  * Attach the mainbus.
     87  */
     88 void
     89 mainbus_attach(device_t parent, device_t self, void *aux)
     90 {
     91 	struct pcibus_attach_args pba;
     92 #if NPCI > 0
     93 	struct genppc_pci_chipset_businfo *pbi;
     94 #endif
     95 
     96 	mainbus_found = 1;
     97 
     98 	aprint_normal("\n");
     99 
    100 	/* attach cpu */
    101 	config_found(self, NULL, mainbus_print,
    102 	    CFARGS(.iattr = "mainbus"));
    103 
    104 	/*
    105 	 * XXX Note also that the presence of a PCI bus should
    106 	 * XXX _always_ be checked, and if present the bus should be
    107 	 * XXX 'found'.  However, because of the structure of the code,
    108 	 * XXX that's not currently possible.
    109 	 */
    110 #if NPCI > 0
    111 	genppc_pct = kmem_alloc(sizeof(struct genppc_pci_chipset), KM_SLEEP);
    112 	mvmeppc_pci_get_chipset_tag(genppc_pct);
    113 
    114 	pbi = kmem_alloc(sizeof(struct genppc_pci_chipset_businfo), KM_SLEEP);
    115 	pbi->pbi_properties = prop_dictionary_create();
    116 	KASSERT(pbi->pbi_properties != NULL);
    117 
    118 	SIMPLEQ_INIT(&genppc_pct->pc_pbi);
    119 	SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
    120 
    121 #ifdef PCI_NETBSD_CONFIGURE
    122 	struct pciconf_resources *pcires = pciconf_resource_init();
    123 
    124 	pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
    125 	    PCI_IO_START, PCI_IO_SIZE);
    126 	pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
    127 	    PCI_MEM_START, PCI_MEM_SIZE);
    128 
    129 	pci_configure_bus(genppc_pct, pcires, 0, CACHELINESIZE);
    130 
    131 	pciconf_resource_fini(pcires);
    132 #endif
    133 
    134 	pba.pba_iot = &prep_io_space_tag;
    135 	pba.pba_memt = &prep_mem_space_tag;
    136 	pba.pba_dmat = &pci_bus_dma_tag;
    137 	pba.pba_dmat64 = NULL;
    138 	pba.pba_pc = genppc_pct;
    139 	pba.pba_bus = 0;
    140 	pba.pba_bridgetag = NULL;
    141 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    142 	config_found(self, &pba, pcibusprint,
    143 	    CFARGS(.iattr = "pcibus"));
    144 #endif
    145 }
    146 
    147 int
    148 mainbus_print(void *aux, const char *pnp)
    149 {
    150 
    151 	if (pnp)
    152 		aprint_normal("cpu at %s", pnp);
    153 
    154 	return (UNCONF);
    155 }
    156