Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: cpc_mainbus.c,v 1.8 2020/11/21 15:42:20 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: cpc_mainbus.c,v 1.8 2020/11/21 15:42:20 thorpej Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/extent.h>
     37 #include <sys/device.h>
     38 #include <sys/kmem.h>
     39 #include <sys/systm.h>
     40 
     41 #include <sys/bus.h>
     42 #include "locators.h"
     43 
     44 #include <dev/pci/pcivar.h>
     45 #include <dev/pci/pcireg.h>
     46 #include <dev/pci/pciconf.h>
     47 
     48 #include <dev/ic/cpc700reg.h>
     49 #include <dev/ic/cpc700var.h>
     50 #include <dev/ic/cpc700uic.h>
     51 
     52 #include <machine/pmppc.h>
     53 #include <arch/evbppc/pmppc/dev/mainbus.h>
     54 
     55 struct genppc_pci_chipset *genppc_pct;
     56 
     57 void
     58 cpc_attach(device_t self, pci_chipset_tag_t pc, bus_space_tag_t mem,
     59 	   bus_space_tag_t pciio, bus_dma_tag_t tag, int attachpci,
     60 	   uint freq);
     61 
     62 static int	cpc_mainbus_match(device_t, cfdata_t, void *);
     63 static void	cpc_mainbus_attach(device_t, device_t, void *);
     64 
     65 CFATTACH_DECL_NEW(cpc_mainbus, 0,
     66     cpc_mainbus_match, cpc_mainbus_attach, NULL, NULL);
     67 
     68 int
     69 cpc_mainbus_match(device_t parent, cfdata_t cf, void *aux)
     70 {
     71 	struct mainbus_attach_args *maa = aux;
     72 
     73 	return (strcmp(maa->mb_name, "cpc") == 0);
     74 }
     75 
     76 void
     77 cpc_mainbus_attach(device_t parent, device_t self, void *aux)
     78 {
     79 	struct genppc_pci_chipset_businfo *pbi;
     80 
     81 	genppc_pct = kmem_alloc(sizeof(struct genppc_pci_chipset), KM_SLEEP);
     82 	pmppc_pci_get_chipset_tag(genppc_pct);
     83 	pbi = kmem_alloc(sizeof(struct genppc_pci_chipset_businfo), KM_SLEEP);
     84 	pbi->pbi_properties = prop_dictionary_create();
     85 	KASSERT(pbi->pbi_properties != NULL);
     86 	SIMPLEQ_INIT(&genppc_pct->pc_pbi);
     87 	SIMPLEQ_INSERT_TAIL(&genppc_pct->pc_pbi, pbi, next);
     88 
     89 	cpc_attach(self, genppc_pct, &pmppc_mem_tag, &pmppc_pci_io_tag,
     90 		   &pci_bus_dma_tag, a_config.a_is_monarch,
     91 		   a_config.a_bus_freq);
     92 
     93 	if (!a_config.a_is_monarch)
     94 		aprint_error_dev(self, "not Monarch, pci not attached\n");
     95 }
     96