Home | History | Annotate | Line # | Download | only in algor
      1 /*	$NetBSD: autoconf.c,v 1.23 2025/10/03 14:05:11 thorpej 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: autoconf.c,v 1.23 2025/10/03 14:05:11 thorpej Exp $");
     34 
     35 #include "opt_algor_p4032.h"
     36 #include "opt_algor_p5064.h"
     37 #include "opt_algor_p6032.h"
     38 
     39 #include <sys/param.h>
     40 #include <sys/bus.h>
     41 #include <sys/conf.h>
     42 #include <sys/device.h>
     43 #include <sys/intr.h>
     44 #include <sys/reboot.h>
     45 #include <sys/systm.h>
     46 
     47 #include <dev/pci/pcivar.h>
     48 
     49 #include <net/if.h>
     50 #include <net/if_ether.h>
     51 
     52 #include <algor/autoconf.h>
     53 
     54 #ifdef ALGOR_P4032
     55 #include <algor/algor/algor_p4032var.h>
     56 #endif
     57 
     58 void
     59 cpu_configure(void)
     60 {
     61 
     62 	intr_init();
     63 
     64 	(void) splhigh();
     65 	if (config_rootfound("mainbus", NULL) == 0)
     66 		panic("no mainbus found");
     67 
     68 	/*
     69 	 * Hardware interrupts will be enabled in
     70 	 * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
     71 	 * to avoid hardclock(9) by CPU INT5 before softclockintr is
     72 	 * initialized in initclocks().
     73 	 */
     74 }
     75 
     76 void
     77 cpu_rootconf(void)
     78 {
     79 
     80 	rootconf();
     81 }
     82 
     83 #if defined(ALGOR_P4032)
     84 #define	BUILTIN_ETHERNET_P(pa)						\
     85 	((pa)->pa_bus == 0 && (pa)->pa_device == 5 && (pa)->pa_function == 0)
     86 #elif defined(ALGOR_P5064)
     87 #define	BUILTIN_ETHERNET_P(pa)						\
     88 	((pa)->pa_bus == 0 && (pa)->pa_device == 0 && (pa)->pa_function == 0)
     89 #elif defined(ALGOR_P6032)
     90 #define	BUILTIN_ETHERNET_P(pa)						\
     91 	((pa)->pa_bus == 0 && (pa)->pa_device == 16 && (pa)->pa_function == 0)
     92 #else
     93 #define	BUILTIN_ETHERNET_P(pa)	0
     94 #endif
     95 
     96 void
     97 device_register(device_t dev, void *aux)
     98 {
     99 	device_t pdev;
    100 
    101 	/*
    102 	 * We don't ever know the boot device.  But that's because the
    103 	 * firmware only loads from the network or the parallel port.
    104 	 */
    105 
    106 	/*
    107 	 * Fetch the MAC address for the built-in Ethernet (we grab it
    108 	 * from PMON earlier in the boot process).
    109 	 */
    110 	if ((pdev = device_parent(dev)) != NULL && device_is_a(pdev, "pci")) {
    111 		struct pci_attach_args *pa = aux;
    112 
    113 		if (BUILTIN_ETHERNET_P(pa)) {
    114 			if (! device_setprop_data(dev, "mac-address",
    115 						  algor_ethaddr,
    116 						  ETHER_ADDR_LEN)) {
    117 				printf("WARNING: unable to set mac-addr "
    118 				    "property for %s\n", device_xname(dev));
    119 			}
    120 #if defined(ALGOR_P4032)
    121 			/*
    122 			 * XXX This is gross, disgusting, and otherwise vile,
    123 			 * XXX but V962 rev. < B2 have broken DMA FIFOs.  Give
    124 			 * XXX the on-board Ethernet a different DMA window
    125 			 * XXX that has pre-fetching disabled so that Ethernet
    126 			 * XXX performance doesn't completely suck.
    127 			 */
    128 			pa->pa_dmat = &p4032_configuration.ac_pci_pf_dmat;
    129 			pa->pa_dmat64 = NULL;
    130 #endif /* ALGOR_P4032 */
    131 		}
    132 	}
    133 }
    134