Home | History | Annotate | Line # | Download | only in bebox
      1 /*	$NetBSD: mainbus.c,v 1.35 2021/08/07 16:18:47 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.35 2021/08/07 16:18:47 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 union mainbus_attach_args {
     60 	const char *mba_busname;		/* first elem of all */
     61 	struct pcibus_attach_args mba_pba;
     62 };
     63 
     64 
     65 /* There can be only one */
     66 int mainbus_found = 0;
     67 struct powerpc_isa_chipset genppc_ict;
     68 struct genppc_pci_chipset *genppc_pct;
     69 
     70 #define	PCI_IO_START	0x00008000
     71 #define	PCI_IO_END	0x0000ffff
     72 #define	PCI_IO_SIZE	((PCI_IO_END - PCI_IO_START) + 1)
     73 
     74 #define	PCI_MEM_START	0x00000000
     75 #define	PCI_MEM_END	0x0fffffff
     76 #define	PCI_MEM_SIZE	((PCI_MEM_END - PCI_MEM_START) + 1)
     77 
     78 /*
     79  * Probe for the mainbus; always succeeds.
     80  */
     81 int
     82 mainbus_match(device_t parent, cfdata_t match, void *aux)
     83 {
     84 	return 1;
     85 }
     86 
     87 /*
     88  * Attach the mainbus.
     89  */
     90 void
     91 mainbus_attach(device_t parent, device_t self, void *aux)
     92 {
     93 	union mainbus_attach_args mba;
     94 	struct confargs ca;
     95 
     96 #if NPCI > 0
     97 	struct genppc_pci_chipset_businfo *pbi;
     98 #endif
     99 
    100 	mainbus_found = 1;
    101 
    102 	aprint_normal("\n");
    103 
    104 #if defined(RESIDUAL_DATA_DUMP)
    105 	print_residual_device_info();
    106 #endif
    107 
    108 	/*
    109 	 * Always find the CPU
    110 	 */
    111 	ca.ca_name = "cpu";
    112 	ca.ca_node = 0;
    113 	config_found(self, &ca, mainbus_print,
    114 	    CFARGS(.iattr = "mainbus"));
    115 	ca.ca_name = "cpu";
    116 	ca.ca_node = 1;
    117 	config_found(self, &ca, mainbus_print,
    118 	    CFARGS(.iattr = "mainbus"));
    119 
    120 	/*
    121 	 * XXX Note also that the presence of a PCI bus should
    122 	 * XXX _always_ be checked, and if present the bus should be
    123 	 * XXX 'found'.  However, because of the structure of the code,
    124 	 * XXX that's not currently possible.
    125 	 */
    126 
    127 #if NPCI > 0
    128 	genppc_pct = kmem_alloc(sizeof(struct genppc_pci_chipset), KM_SLEEP);
    129 	bebox_pci_get_chipset_tag(genppc_pct);
    130 
    131 	pbi = kmem_alloc(sizeof(struct genppc_pci_chipset_businfo), KM_SLEEP);
    132 	pbi->pbi_properties = prop_dictionary_create();
    133         KASSERT(pbi->pbi_properties != NULL);
    134 
    135 	SIMPLEQ_INIT(&genppc_pct->pc_pbi);
    136 	SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
    137 
    138 #ifdef PCI_NETBSD_CONFIGURE
    139 	struct pciconf_resources *pcires = pciconf_resource_init();
    140 
    141 	pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
    142 	    PCI_IO_START, PCI_IO_SIZE);
    143 	pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
    144 	    PCI_MEM_START, PCI_MEM_SIZE);
    145 
    146 	pci_configure_bus(genppc_pct, pcires, 0, CACHELINESIZE);
    147 
    148 	pciconf_resource_fini(pcires);
    149 #endif /* PCI_NETBSD_CONFIGURE */
    150 #endif /* NPCI */
    151 
    152 #if NPCI > 0
    153 	memset(&mba, 0, sizeof(mba));
    154 	mba.mba_pba.pba_iot = &prep_io_space_tag;
    155 	mba.mba_pba.pba_memt = &prep_mem_space_tag;
    156 	mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
    157 	mba.mba_pba.pba_dmat64 = NULL;
    158 	mba.mba_pba.pba_pc = genppc_pct;
    159 	mba.mba_pba.pba_bus = 0;
    160 	mba.mba_pba.pba_bridgetag = NULL;
    161 	mba.mba_pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    162 	config_found(self, &mba.mba_pba, pcibusprint,
    163 	    CFARGS(.iattr = "pcibus"));
    164 #endif /* NPCI */
    165 
    166 #ifdef RESIDUAL_DATA_DUMP
    167 	SIMPLEQ_FOREACH(pbi, &genppc_pct->pc_pbi, next)
    168 	    printf("%s\n", prop_dictionary_externalize(pbi->pbi_properties));
    169 #endif
    170 
    171 }
    172 
    173 int
    174 mainbus_print(void *aux, const char *pnp)
    175 {
    176 
    177 	if (pnp)
    178 		aprint_normal("cpu at %s", pnp);
    179 	return (UNCONF);
    180 }
    181