Home | History | Annotate | Line # | Download | only in mpcsa
mpcsa_machdep.c revision 1.7.2.1
      1  1.7.2.1     tls /*	$Id: mpcsa_machdep.c,v 1.7.2.1 2012/11/20 03:01:16 tls Exp $	*/
      2  1.7.2.1     tls /*	$NetBSD: mpcsa_machdep.c,v 1.7.2.1 2012/11/20 03:01:16 tls Exp $	*/
      3      1.2    matt 
      4      1.2    matt /*
      5      1.2    matt  * Copyright (c) 2007 Embedtronics Oy
      6      1.2    matt  * Based on tsarm_machdep.c
      7      1.2    matt  *
      8      1.2    matt  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
      9      1.2    matt  * All rights reserved.
     10      1.2    matt  *
     11      1.2    matt  * Based on code written by Jason R. Thorpe and Steve C. Woodford for
     12      1.2    matt  * Wasabi Systems, Inc.
     13      1.2    matt  *
     14      1.2    matt  * Redistribution and use in source and binary forms, with or without
     15      1.2    matt  * modification, are permitted provided that the following conditions
     16      1.2    matt  * are met:
     17      1.2    matt  * 1. Redistributions of source code must retain the above copyright
     18      1.2    matt  *    notice, this list of conditions and the following disclaimer.
     19      1.2    matt  * 2. Redistributions in binary form must reproduce the above copyright
     20      1.2    matt  *    notice, this list of conditions and the following disclaimer in the
     21      1.2    matt  *    documentation and/or other materials provided with the distribution.
     22      1.2    matt  * 3. All advertising materials mentioning features or use of this software
     23      1.2    matt  *    must display the following acknowledgement:
     24      1.2    matt  *	This product includes software developed for the NetBSD Project by
     25      1.2    matt  *	Wasabi Systems, Inc.
     26      1.2    matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     27      1.2    matt  *    or promote products derived from this software without specific prior
     28      1.2    matt  *    written permission.
     29      1.2    matt  *
     30      1.2    matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     31      1.2    matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     32      1.2    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     33      1.2    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     34      1.2    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     35      1.2    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     36      1.2    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     37      1.2    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     38      1.2    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     39      1.2    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     40      1.2    matt  * POSSIBILITY OF SUCH DAMAGE.
     41      1.2    matt  */
     42      1.2    matt 
     43      1.2    matt /*
     44      1.2    matt  * Copyright (c) 1997,1998 Mark Brinicombe.
     45      1.2    matt  * Copyright (c) 1997,1998 Causality Limited.
     46      1.2    matt  * All rights reserved.
     47      1.2    matt  *
     48      1.2    matt  * Redistribution and use in source and binary forms, with or without
     49      1.2    matt  * modification, are permitted provided that the following conditions
     50      1.2    matt  * are met:
     51      1.2    matt  * 1. Redistributions of source code must retain the above copyright
     52      1.2    matt  *    notice, this list of conditions and the following disclaimer.
     53      1.2    matt  * 2. Redistributions in binary form must reproduce the above copyright
     54      1.2    matt  *    notice, this list of conditions and the following disclaimer in the
     55      1.2    matt  *    documentation and/or other materials provided with the distribution.
     56      1.2    matt  * 3. All advertising materials mentioning features or use of this software
     57      1.2    matt  *    must display the following acknowledgement:
     58      1.2    matt  *	This product includes software developed by Mark Brinicombe
     59      1.2    matt  *	for the NetBSD Project.
     60      1.2    matt  * 4. The name of the company nor the name of the author may be used to
     61      1.2    matt  *    endorse or promote products derived from this software without specific
     62      1.2    matt  *    prior written permission.
     63      1.2    matt  *
     64      1.2    matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     65      1.2    matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     66      1.2    matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     67      1.2    matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     68      1.2    matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     69      1.2    matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     70      1.2    matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71      1.2    matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72      1.2    matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73      1.2    matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74      1.2    matt  * SUCH DAMAGE.
     75      1.2    matt  *
     76      1.5     wiz  * Machine dependent functions for kernel setup for Iyonix.
     77      1.2    matt  */
     78      1.2    matt 
     79      1.2    matt #include <sys/cdefs.h>
     80  1.7.2.1     tls __KERNEL_RCSID(0, "$NetBSD: mpcsa_machdep.c,v 1.7.2.1 2012/11/20 03:01:16 tls Exp $");
     81      1.2    matt 
     82      1.2    matt #include "opt_ddb.h"
     83      1.2    matt #include "opt_kgdb.h"
     84      1.2    matt #include "opt_pmap_debug.h"
     85      1.2    matt 
     86      1.2    matt #include <sys/param.h>
     87      1.2    matt #include <sys/device.h>
     88      1.2    matt #include <sys/systm.h>
     89      1.2    matt #include <sys/kernel.h>
     90      1.2    matt #include <sys/exec.h>
     91      1.2    matt #include <sys/proc.h>
     92      1.2    matt #include <sys/msgbuf.h>
     93      1.2    matt #include <sys/reboot.h>
     94      1.2    matt #include <sys/termios.h>
     95      1.2    matt #include <sys/ksyms.h>
     96      1.2    matt 
     97      1.2    matt #include <uvm/uvm_extern.h>
     98      1.2    matt 
     99      1.2    matt #include <dev/cons.h>
    100      1.2    matt 
    101      1.2    matt #include <machine/db_machdep.h>
    102      1.2    matt #include <ddb/db_sym.h>
    103      1.2    matt #include <ddb/db_extern.h>
    104      1.2    matt 
    105      1.2    matt #define	DRAM_BLOCKS	1
    106      1.2    matt #include <machine/bootconfig.h>
    107      1.6  dyoung #include <sys/bus.h>
    108      1.2    matt #include <machine/cpu.h>
    109      1.2    matt #include <machine/frame.h>
    110      1.2    matt #include <arm/undefined.h>
    111      1.2    matt 
    112      1.2    matt #include <arm/arm32/machdep.h>
    113      1.2    matt 
    114      1.2    matt #include <arm/at91/at91reg.h>
    115      1.2    matt #include <arm/at91/at91var.h>
    116      1.2    matt 
    117      1.2    matt #include <dev/ic/comreg.h>
    118      1.2    matt #include <dev/ic/comvar.h>
    119      1.2    matt 
    120      1.2    matt #include <machine/autoconf.h>
    121      1.2    matt 
    122      1.2    matt #include "seeprom.h"
    123      1.2    matt #if NSEEPROM > 0
    124      1.2    matt #include <net/if.h>
    125      1.2    matt #include <net/if_ether.h>
    126      1.2    matt #include <dev/i2c/i2cvar.h>
    127      1.2    matt #include <dev/i2c/at24cxxvar.h>
    128      1.2    matt #endif
    129      1.2    matt #include <arm/at91/at91twivar.h>
    130      1.2    matt 
    131      1.2    matt #if TODO
    132      1.2    matt #include "epcom.h"
    133      1.2    matt #if NEPCOM > 0
    134      1.2    matt #include <arm/ep93xx/epcomvar.h>
    135      1.2    matt #endif
    136      1.2    matt 
    137      1.2    matt #include "isa.h"
    138      1.2    matt #if NISA > 0
    139      1.2    matt #include <dev/isa/isareg.h>
    140      1.2    matt #include <dev/isa/isavar.h>
    141      1.2    matt #endif
    142      1.2    matt 
    143      1.2    matt #include <machine/isa_machdep.h>
    144      1.2    matt 
    145      1.2    matt #include <evbarm/mpcsa/mpcsareg.h>
    146      1.2    matt #endif	// TODO
    147      1.2    matt 
    148      1.2    matt #include <arm/at91/at91rm9200reg.h>
    149      1.2    matt #include <arm/at91/at91rm9200busvar.h>
    150      1.2    matt 
    151      1.2    matt #include "opt_ipkdb.h"
    152      1.2    matt #include "ksyms.h"
    153      1.2    matt 
    154      1.2    matt #include <arm/at91/at91busvar.h>
    155      1.2    matt #include <arm/at91/at91pdcreg.h>
    156      1.2    matt #include <arm/at91/at91dbgureg.h>
    157      1.2    matt #include <arm/at91/at91reg.h>
    158      1.2    matt #include <arm/at91/at91streg.h>
    159      1.2    matt 
    160      1.2    matt /* boot configuration: */
    161      1.2    matt BootConfig bootconfig;		/* Boot config storage */
    162      1.2    matt char *boot_args = NULL;
    163      1.2    matt char *boot_file = NULL;
    164      1.2    matt 
    165      1.2    matt /* hmmm */
    166      1.2    matt static struct arm32_dma_range mpcsa_dma_ranges[4];
    167      1.2    matt static struct at91bus_machdep mpcsabus;
    168      1.2    matt static at91bus_tag_t old_at91bus_tag;
    169      1.2    matt 
    170      1.2    matt /* Prototypes */
    171      1.2    matt static void mpcsa_device_register(device_t dev, void *aux);
    172      1.2    matt static void mpcsabus_init(struct at91bus_clocks *);
    173      1.2    matt static void mpcsabus_peripheral_clock(int pid, int enable);
    174      1.2    matt static uint32_t mpcsabus_gpio_mask(int pid);
    175      1.2    matt 
    176      1.2    matt 
    177      1.2    matt /*
    178      1.2    matt  * void cpu_reboot(int howto, char *bootstr)
    179      1.2    matt  *
    180      1.2    matt  * Reboots the system
    181      1.2    matt  *
    182      1.2    matt  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    183      1.2    matt  * then reset the CPU.
    184      1.2    matt  */
    185      1.2    matt void
    186      1.2    matt cpu_reboot(int howto, char *bootstr)
    187      1.2    matt {
    188      1.2    matt 
    189      1.2    matt 	/*
    190      1.2    matt 	 * If we are still cold then hit the air brakes
    191      1.2    matt 	 * and crash to earth fast
    192      1.2    matt 	 */
    193      1.2    matt 	if (cold) {
    194      1.2    matt 		doshutdownhooks();
    195      1.3  dyoung 		pmf_system_shutdown(boothowto);
    196      1.2    matt 		printf("\r\n");
    197      1.2    matt 		printf("The operating system has halted.\r\n");
    198      1.2    matt 		printf("Please press any key to reboot.\r\n");
    199      1.2    matt 		cngetc();
    200      1.2    matt 		printf("\r\nrebooting...\r\n");
    201      1.2    matt 		goto reset;
    202      1.2    matt 	}
    203      1.2    matt 
    204      1.2    matt 	/* Disable console buffering */
    205      1.2    matt 
    206      1.2    matt 	/*
    207      1.2    matt 	 * If RB_NOSYNC was not specified sync the discs.
    208      1.2    matt 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    209      1.2    matt 	 * unmount.  It looks like syslogd is getting woken up only to find
    210      1.2    matt 	 * that it cannot page part of the binary in as the filesystem has
    211      1.2    matt 	 * been unmounted.
    212      1.2    matt 	 */
    213      1.2    matt 	if (!(howto & RB_NOSYNC))
    214      1.2    matt 		bootsync();
    215      1.2    matt 
    216      1.2    matt 	/* Say NO to interrupts */
    217      1.2    matt 	splhigh();
    218      1.2    matt 
    219      1.2    matt 	/* Do a dump if requested. */
    220      1.2    matt 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    221      1.2    matt 		dumpsys();
    222      1.2    matt 
    223      1.2    matt 	/* Run any shutdown hooks */
    224      1.2    matt 	doshutdownhooks();
    225      1.2    matt 
    226      1.3  dyoung 	pmf_system_shutdown(boothowto);
    227      1.3  dyoung 
    228      1.2    matt 	/* Make sure IRQ's are disabled */
    229      1.2    matt 	IRQdisable;
    230      1.2    matt 
    231      1.2    matt 	if (howto & RB_HALT) {
    232      1.2    matt 		printf("\r\n");
    233      1.2    matt 		printf("The operating system has halted.\r\n");
    234      1.2    matt 		printf("Please press any key to reboot.\r\n");
    235      1.2    matt 		cngetc();
    236      1.2    matt 	}
    237      1.2    matt 
    238      1.2    matt 	printf("\r\nrebooting...\r\n");
    239      1.2    matt  reset:
    240      1.2    matt 	/*
    241      1.2    matt 	 * Make really really sure that all interrupts are disabled,
    242      1.2    matt 	 * and poke the Internal Bus and Peripheral Bus reset lines.
    243      1.2    matt 	 */
    244      1.2    matt 	(void) disable_interrupts(I32_bit|F32_bit);
    245      1.2    matt 	STREG(ST_WDMR)	= ST_WDMR_EXTEN | ST_WDMR_RSTEN | 1;
    246      1.2    matt 	STREG(ST_CR)	= ST_CR_WDRST;
    247      1.2    matt 	for (;;);
    248      1.2    matt }
    249      1.2    matt 
    250      1.2    matt /*
    251      1.2    matt  * u_int initarm(...)
    252      1.2    matt  *
    253      1.2    matt  * Initial entry point on startup. This gets called before main() is
    254      1.2    matt  * entered.
    255      1.2    matt  * It should be responsible for setting up everything that must be
    256      1.2    matt  * in place when main is called.
    257      1.2    matt  * This includes
    258      1.2    matt  *   Taking a copy of the boot configuration structure.
    259      1.2    matt  *   Initialising the physical console so characters can be printed.
    260      1.2    matt  *   Setting up page tables for the kernel
    261      1.2    matt  *   Initialising interrupt controllers to a sane default state
    262      1.2    matt  */
    263      1.2    matt u_int
    264      1.2    matt initarm(void *arg)
    265      1.2    matt {
    266      1.2    matt 	u_int ret;
    267      1.2    matt 	/*
    268      1.2    matt 	 * basic AT91 initialization:
    269      1.2    matt 	 */
    270      1.2    matt 	if (at91bus_init())
    271      1.2    matt 		panic("%s: at91bus_init() failed", __FUNCTION__);
    272      1.2    matt 
    273      1.2    matt 	if (AT91_CHIP_ID() == AT91RM9200_CHIP_ID) {
    274      1.2    matt 		memcpy(&mpcsabus, at91bus_tag, sizeof(mpcsabus));
    275      1.2    matt 		mpcsabus.init = mpcsabus_init;
    276      1.2    matt 		mpcsabus.peripheral_clock = mpcsabus_peripheral_clock;
    277      1.2    matt 		mpcsabus.gpio_mask = mpcsabus_gpio_mask;
    278      1.2    matt 		old_at91bus_tag = at91bus_tag;
    279      1.2    matt 		at91bus_tag = &mpcsabus;
    280      1.2    matt 	}
    281      1.2    matt 
    282      1.2    matt  	/* Fake bootconfig structure for the benefit of pmap.c */
    283      1.2    matt  	/* XXX must make the memory description h/w independent */
    284      1.2    matt  	bootconfig.dramblocks = 1;
    285      1.2    matt  	bootconfig.dram[0].address = 0x20000000UL;
    286      1.2    matt  	bootconfig.dram[0].pages =   0x04000000UL / PAGE_SIZE;
    287      1.2    matt 	ret = at91bus_setup(&bootconfig);
    288      1.2    matt 
    289      1.2    matt 	if (AT91_CHIP_ID() != AT91RM9200_CHIP_ID)
    290      1.2    matt 		panic("%s: processor is not AT91RM9200", __FUNCTION__);
    291      1.2    matt 
    292      1.2    matt 	/* we've a specific device_register routine */
    293      1.2    matt 	evbarm_device_register = mpcsa_device_register;
    294      1.2    matt 
    295      1.2    matt 	/* We return the new stack pointer address */
    296      1.2    matt 	return ret;
    297      1.2    matt }
    298      1.2    matt 
    299      1.2    matt 
    300      1.2    matt bus_dma_tag_t
    301      1.2    matt at91_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
    302      1.2    matt {
    303      1.2    matt 	int i;
    304      1.2    matt 	struct arm32_bus_dma_tag *dmat;
    305      1.2    matt 
    306      1.2    matt 	for (i = 0; i < bootconfig.dramblocks; i++) {
    307      1.2    matt 		mpcsa_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
    308      1.2    matt 		mpcsa_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
    309      1.2    matt 		mpcsa_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
    310      1.2    matt 			PAGE_SIZE;
    311      1.2    matt 	}
    312      1.2    matt 
    313      1.2    matt 	dmat = dma_tag_template;
    314      1.2    matt 
    315      1.2    matt 	dmat->_ranges = mpcsa_dma_ranges;
    316      1.2    matt 	dmat->_nranges = bootconfig.dramblocks;
    317      1.2    matt 
    318      1.2    matt 	return dmat;
    319      1.2    matt }
    320      1.2    matt 
    321      1.2    matt void mpcsabus_init(struct at91bus_clocks *clocks)
    322      1.2    matt {
    323      1.2    matt 	(*old_at91bus_tag->init)(clocks);
    324      1.2    matt }
    325      1.2    matt 
    326      1.2    matt uint32_t mpcsabus_gpio_mask(int pid)
    327      1.2    matt {
    328      1.2    matt 	switch (pid) {
    329      1.2    matt 	case PID_PIOA:	return ~0x00000300U;
    330      1.2    matt 	case PID_PIOB:	return ~0x0000783FU;
    331      1.2    matt 	case PID_PIOC:	return ~0x00000000U;
    332      1.2    matt 	case PID_PIOD:	return ~0x0003F000U;
    333      1.2    matt 	default:	return ~0x00000000U;
    334      1.2    matt 	}
    335      1.2    matt }
    336      1.2    matt 
    337      1.2    matt void mpcsabus_peripheral_clock(int pid, int enable)
    338      1.2    matt {
    339      1.2    matt 	switch (pid) {
    340      1.2    matt 	case PID_TWI:
    341      1.2    matt 		if (enable) {
    342      1.2    matt 			PIOA_WRITE(PIO_ASR, 0x06000000);	// assign to peripheral A
    343      1.2    matt 			PIOA_WRITE(PIO_PDR, 0x06000000);	// assign to peripherals
    344      1.2    matt 			PIOA_WRITE(PIO_MDER, 0x06000000);	// I2C pins in open-drain mode
    345      1.2    matt 		}
    346      1.2    matt 		break;
    347      1.2    matt 
    348      1.2    matt 	case PID_SPI:
    349      1.2    matt 		if (enable) {
    350      1.2    matt 			PIOA_WRITE(PIO_ASR, 0x00000007);	// assign to peripheral A
    351      1.2    matt 			PIOA_WRITE(PIO_PDR, 0x00000007);	// assign to peripherals
    352      1.2    matt 		}
    353      1.2    matt 		break;
    354      1.2    matt 	}
    355      1.2    matt 	(*old_at91bus_tag->peripheral_clock)(pid, enable);
    356      1.2    matt }
    357      1.2    matt 
    358      1.2    matt 
    359      1.2    matt static void mpcsa_device_register(device_t dev, void *aux)
    360      1.2    matt {
    361      1.2    matt 	static uint8_t eth_addr[ETHER_ADDR_LEN];
    362      1.2    matt 
    363      1.2    matt 	if (device_is_a(dev, "at91emac")) {
    364      1.2    matt 		cfdriver_t cd = config_cfdriver_lookup("at91twi");
    365      1.2    matt 		device_t twi_dev = 0;
    366      1.2    matt 		i2c_tag_t i2c = 0;
    367      1.2    matt 		if (cd && (twi_dev = device_lookup(cd, 0)) != NULL) {
    368  1.7.2.1     tls 			struct at91twi_softc *sc = device_private(twi_dev);
    369      1.2    matt 			i2c = &sc->sc_i2c;
    370      1.2    matt 		}
    371      1.2    matt 		if (i2c && seeprom_bootstrap_read(i2c, 0x50, 0x00, 4096,
    372      1.2    matt 					   eth_addr, ETHER_ADDR_LEN) == 0) {
    373      1.2    matt 			prop_data_t pd = prop_data_create_data_nocopy(
    374      1.2    matt 				eth_addr, ETHER_ADDR_LEN);
    375      1.2    matt 			KASSERT(pd != NULL);
    376      1.2    matt 			if (prop_dictionary_set(device_properties(dev),
    377      1.4  martin 						"mac-address", pd) == FALSE) {
    378      1.2    matt 				printf("WARNING: unable to set mac-addr property "
    379  1.7.2.1     tls 				       "for %s\n", device_xname(dev));
    380      1.2    matt 			}
    381      1.2    matt 		} else {
    382      1.2    matt 			printf("%s: WARNING: unable to read MAC address from SEEPROM\n",
    383  1.7.2.1     tls 			       device_xname(dev));
    384      1.2    matt 		}
    385      1.2    matt 	}
    386      1.2    matt }
    387