Home | History | Annotate | Line # | Download | only in pci
      1 /*	$NetBSD: pcib.c,v 1.18 2021/08/07 16:18:47 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.
      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  * 	from:  i386/pci/pcib.c,v 1.12
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.18 2021/08/07 16:18:47 thorpej Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 
     41 #include <sys/bus.h>
     42 
     43 #include <dev/isa/isavar.h>
     44 
     45 #include <dev/pci/pcivar.h>
     46 #include <dev/pci/pcireg.h>
     47 
     48 #include <dev/pci/pcidevs.h>
     49 
     50 #include "isadma.h"
     51 
     52 int	pcibmatch(device_t, cfdata_t, void *);
     53 void	pcibattach(device_t, device_t, void *);
     54 
     55 CFATTACH_DECL_NEW(pcib, 0,
     56     pcibmatch, pcibattach, NULL, NULL);
     57 
     58 void	pcib_callback(device_t);
     59 
     60 int
     61 pcibmatch(device_t parent, cfdata_t match, void *aux)
     62 {
     63 	struct pci_attach_args *pa = aux;
     64 
     65 	/*
     66 	 * Match tested PCI-ISA bridges.
     67 	 */
     68 	switch (PCI_VENDOR(pa->pa_id)) {
     69 	case PCI_VENDOR_ALI:
     70 		switch (PCI_PRODUCT(pa->pa_id)) {
     71 		case PCI_PRODUCT_ALI_M1533:
     72 			return (1);
     73 		}
     74 		break;
     75 	}
     76 
     77 	return (0);
     78 }
     79 
     80 void
     81 pcibattach(device_t parent, device_t self, void *aux)
     82 {
     83 	struct pci_attach_args *pa = aux;
     84 	char devinfo[256];
     85 
     86 	printf("\n");
     87 
     88 	/*
     89 	 * Just print out a description and set the ISA bus
     90 	 * callback.
     91 	 */
     92 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
     93 	printf("%s: %s (rev. 0x%02x)\n", device_xname(self), devinfo,
     94 	    PCI_REVISION(pa->pa_class));
     95 
     96 	/* Set the ISA bus callback */
     97 	config_defer(self, pcib_callback);
     98 }
     99 
    100 void
    101 pcib_callback(device_t self)
    102 {
    103 	struct isabus_attach_args iba;
    104 
    105 	/*
    106 	 * Attach the ISA bus behind this bridge.
    107 	 */
    108 	memset(&iba, 0, sizeof(iba));
    109 	iba.iba_iot = &isa_io_bs_tag;
    110 	iba.iba_memt = &isa_mem_bs_tag;
    111 #if NISADMA > 0
    112 	iba.iba_dmat = &isa_bus_dma_tag;
    113 #endif
    114 	config_found(self, &iba, isabusprint, CFARGS_NONE);
    115 }
    116