Home | History | Annotate | Line # | Download | only in sam460ex
autoconf.c revision 1.2
      1 /*	$NetBSD: autoconf.c,v 1.2 2026/06/16 23:37:49 rkujawa Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2012, 2014, 2024, 2026 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Radoslaw Kujawa.
      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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * Copyright 2004 Shigeyuki Fukushima.
     33  * All rights reserved.
     34  *
     35  * Written by Shigeyuki Fukushima for The NetBSD Project.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above
     43  *    copyright notice, this list of conditions and the following
     44  *    disclaimer in the documentation and/or other materials provided
     45  *    with the distribution.
     46  * 3. The name of the author may not be used to endorse or promote
     47  *    products derived from this software without specific prior
     48  *    written permission.
     49  *
     50  * THIS SOFTWARE IS PROVIDED THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     51  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     52  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     53  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
     54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     55  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
     56  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     57  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     58  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     59  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     60  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
     61  * DAMAGE.
     62  */
     63 
     64 /*
     65  * Autoconfiguration for the ACube Sam460ex (AMCC 460EX).
     66  * Modeled on evbppc/obs405/obs600_autoconf.c.
     67  */
     68 
     69 #include <sys/cdefs.h>
     70 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.2 2026/06/16 23:37:49 rkujawa Exp $");
     71 
     72 #include <sys/param.h>
     73 #include <sys/device.h>
     74 #include <sys/disklabel.h>
     75 #include <sys/intr.h>
     76 #include <sys/systm.h>
     77 
     78 #include <machine/sam460ex.h>
     79 
     80 #include <powerpc/ibm4xx/amcc460ex.h>
     81 #include <powerpc/ibm4xx/cpu.h>
     82 #include <powerpc/ibm4xx/dcr4xx.h>
     83 
     84 /*
     85  * Determine device configuration for a machine.
     86  */
     87 void
     88 cpu_configure(void)
     89 {
     90 
     91 	/* UIC */
     92 	mtdcr(DCR_UIC1_BASE + DCR_UIC_PR,
     93 	    mfdcr(DCR_UIC1_BASE + DCR_UIC_PR) & ~0x80000000);
     94 	mtdcr(DCR_UIC1_BASE + DCR_UIC_TR,
     95 	    mfdcr(DCR_UIC1_BASE + DCR_UIC_TR) & ~0x80000000);
     96 	mtdcr(DCR_UIC1_BASE + DCR_UIC_SR, 0x80000000);
     97 	mtdcr(DCR_UIC3_BASE + DCR_UIC_PR,
     98 	    mfdcr(DCR_UIC3_BASE + DCR_UIC_PR) & ~0x000ff000);
     99 	mtdcr(DCR_UIC3_BASE + DCR_UIC_TR,
    100 	    mfdcr(DCR_UIC3_BASE + DCR_UIC_TR) & ~0x000ff000);
    101 	mtdcr(DCR_UIC3_BASE + DCR_UIC_SR, 0x000ff000);
    102 
    103 	/*
    104 	 * Initialize intr and add the cascaded UICs.
    105 	 * UIC0 = 0, UIC1 = +32, UIC2 = +64, UIC3 = +96.
    106 	 */
    107 	intr_init();
    108 	pic_add(&pic_uic1);
    109 	pic_add(&pic_uic2);
    110 	pic_add(&pic_uic3);
    111 
    112 	if (config_rootfound("plb", NULL) == NULL)
    113 		panic("configure: mainbus not configured");
    114 
    115 	pic_finish_setup();
    116 
    117 	genppc_cpu_configure();
    118 }
    119 
    120 void
    121 device_register(device_t dev, void *aux)
    122 {
    123 
    124 	ibm4xx_device_register(dev, aux, sam460ex_com_freq());
    125 
    126 	/* "console=fb" in bootargs: the SM502 wsdisplay becomes console */
    127 	if (sam460ex_console_fb && device_is_a(dev, "voyagerfb"))
    128 		prop_dictionary_set_bool(device_properties(dev),
    129 		    "is_console", true);
    130 
    131 	/*
    132 	 * Match a "root=" from the bootargs.
    133 	 */
    134 	if (bootspec != NULL) {
    135 		size_t len = strlen(bootspec);
    136 		int part = 0;
    137 
    138 		if (len > 1 && bootspec[len - 1] >= 'a' &&
    139 		    bootspec[len - 1] < 'a' + MAXPARTITIONS &&
    140 		    bootspec[len - 2] >= '0' && bootspec[len - 2] <= '9') {
    141 			part = bootspec[len - 1] - 'a';
    142 			len--;
    143 		}
    144 		if (strncmp(device_xname(dev), bootspec, len) == 0 &&
    145 		    device_xname(dev)[len] == '\0') {
    146 			booted_device = dev;
    147 			booted_partition = part;
    148 		}
    149 	}
    150 }
    151 
    152