Home | History | Annotate | Line # | Download | only in pci
      1 /*	$NetBSD: pcmb.c,v 1.23 2025/10/19 20:52:09 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe and Jaromir Dolecek.
      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 /*
     33  * "Driver" for PCI-MCA Bridges.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: pcmb.c,v 1.23 2025/10/19 20:52:09 thorpej Exp $");
     38 
     39 #include <sys/types.h>
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/device.h>
     43 #include <sys/bus.h>
     44 
     45 #include <dev/mca/mcavar.h>
     46 
     47 #include <dev/pci/pcivar.h>
     48 #include <dev/pci/pcireg.h>
     49 
     50 #include <dev/pci/pcidevs.h>
     51 
     52 #include "mca.h"
     53 
     54 int	pcmbmatch(device_t, cfdata_t, void *);
     55 void	pcmbattach(device_t, device_t, void *);
     56 
     57 CFATTACH_DECL_NEW(pcmb, 0, pcmbmatch, pcmbattach, NULL, NULL);
     58 
     59 void	pcmb_callback(device_t);
     60 
     61 int
     62 pcmbmatch(device_t parent, cfdata_t match, void *aux)
     63 {
     64 	struct pci_attach_args *pa = aux;
     65 
     66 	/*
     67 	 * Match anything which claims to be PCI-MCA bridge.
     68 	 */
     69 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE
     70 	    && PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_MC)
     71 		return (1);
     72 
     73 	return (0);
     74 }
     75 
     76 void
     77 pcmbattach(device_t parent, device_t self, void *aux)
     78 {
     79 	struct pci_attach_args *pa = aux;
     80 	char devinfo[256];
     81 
     82 	aprint_naive("\n");
     83 	aprint_normal("\n");
     84 
     85 	/*
     86 	 * Just print out a description and defer configuration
     87 	 * until all PCI devices have been attached.
     88 	 */
     89 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
     90 	aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
     91 	    PCI_REVISION(pa->pa_class));
     92 
     93 	config_defer(self, pcmb_callback);
     94 }
     95 
     96 void
     97 pcmb_callback(device_t self)
     98 {
     99 	struct mcabus_attach_args ma;
    100 
    101 	/*
    102 	 * Attach MCA bus behind this bridge.
    103 	 */
    104 	ma.mba_iot = x86_bus_space_io;
    105 	ma.mba_memt = x86_bus_space_mem;
    106 #if NMCA > 0
    107 	ma.mba_dmat = &mca_bus_dma_tag;
    108 #endif
    109 	ma.mba_mc = NULL;
    110 	ma.mba_bus = 0;
    111 	mcabus_attach(self, &ma);
    112 }
    113