Home | History | Annotate | Line # | Download | only in loongson
bonito_mainbus.c revision 1.2
      1 /*	$NetBSD: bonito_mainbus.c,v 1.2 2012/03/02 13:20:57 nonaka Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 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 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.2 2012/03/02 13:20:57 nonaka Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/conf.h>
     38 #include <sys/reboot.h>
     39 #include <sys/device.h>
     40 
     41 #include <sys/bus.h>
     42 
     43 #include <mips/bonito/bonitoreg.h>
     44 
     45 #include <evbmips/loongson/autoconf.h>
     46 #include <evbmips/loongson/loongson_bus_defs.h>
     47 #include <dev/pci/pcivar.h>
     48 
     49 static int	bonito_mainbus_match(device_t, cfdata_t, void *);
     50 static void	bonito_mainbus_attach(device_t, device_t, void *);
     51 
     52 CFATTACH_DECL_NEW(bonito_mainbus, 0,
     53     bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL);
     54 
     55 extern struct cfdriver bonito_cd;
     56 
     57 int
     58 bonito_mainbus_match(device_t parent, cfdata_t cf, void *aux)
     59 {
     60 	struct mainbus_attach_args * const maa = aux;
     61 
     62 	if (strcmp(maa->maa_name, bonito_cd.cd_name) == 0)
     63 		return (1);
     64 
     65 	return (0);
     66 }
     67 
     68 void
     69 bonito_mainbus_attach(device_t parent, device_t self, void *aux)
     70 {
     71 	struct pcibus_attach_args pba;
     72 	pcireg_t rev;
     73 	bool compatible;
     74 
     75 	self->dv_private = __UNCONST(&sys_platform->bonito_config);
     76 
     77 	/*
     78 	 * Loongson 2F processors do not use a real Bonito64 chip but
     79 	 * their own derivative, which is no longer 100% compatible.
     80 	 * We need to make sure we never try to access an unimplemented
     81 	 * register...
     82 	 */
     83 	if (loongson_ver >= 0x2f)
     84 		compatible = false;
     85 	else
     86 		compatible = true;
     87 
     88 	/*
     89 	 * There is only one PCI controller on a Loongson chip.
     90 	 */
     91 
     92 	rev = PCI_REVISION(REGVAL(BONITO_PCICLASS));
     93 	if (compatible) {
     94 		aprint_normal(": BONITO Memory and PCI controller,"
     95 		    " %s rev. %d.%d\n", BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC",
     96 		    BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev));
     97 	} else {
     98 		aprint_normal(": Memory and PCI-X controller, rev. %d\n",
     99 		    PCI_REVISION(rev));
    100 	}
    101 
    102 	/*
    103 	 * Attach PCI bus.
    104 	 */
    105 
    106 	pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
    107 	pba.pba_bus = 0;
    108 	pba.pba_bridgetag = NULL;
    109 
    110 	pba.pba_iot = &bonito_iot;
    111 	pba.pba_memt = &bonito_memt;
    112 	pba.pba_dmat = &bonito_dmat;
    113 	pba.pba_dmat64 = NULL;
    114 	pba.pba_pc = &bonito_pc;
    115 
    116 	(void) config_found_ia(self, "pcibus", &pba, pcibusprint);
    117 }
    118