socfpga_common.c revision 298068
122652Smpp/*-
222652Smpp * Copyright (c) 2014 Ruslan Bukin <br@bsdpad.com>
322652Smpp * All rights reserved.
422652Smpp *
522652Smpp * This software was developed by SRI International and the University of
622652Smpp * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
722652Smpp * ("CTSRD"), as part of the DARPA CRASH research programme.
822652Smpp *
922652Smpp * Redistribution and use in source and binary forms, with or without
1022652Smpp * modification, are permitted provided that the following conditions
1122652Smpp * are met:
1222652Smpp * 1. Redistributions of source code must retain the above copyright
1322652Smpp *    notice, this list of conditions and the following disclaimer.
1422652Smpp * 2. Redistributions in binary form must reproduce the above copyright
1522652Smpp *    notice, this list of conditions and the following disclaimer in the
1622652Smpp *    documentation and/or other materials provided with the distribution.
1722652Smpp *
1822652Smpp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1922652Smpp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2022652Smpp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2122652Smpp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2222652Smpp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2322652Smpp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2422652Smpp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2522652Smpp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2622652Smpp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2722652Smpp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2855547Sphantom * SUCH DAMAGE.
2950476Speter */
3048795Snik
31231292Sbapt#include <sys/cdefs.h>
3222652Smpp__FBSDID("$FreeBSD: head/sys/arm/altera/socfpga/socfpga_common.c 298068 2016-04-15 16:05:41Z andrew $");
3322652Smpp
3422652Smpp#include <sys/param.h>
3522652Smpp#include <sys/systm.h>
3622652Smpp#include <sys/bus.h>
37231292Sbapt#include <sys/kernel.h>
38231292Sbapt
39231292Sbapt#include <dev/fdt/fdt_common.h>
4022652Smpp#include <dev/ofw/openfirm.h>
4184306Sru
4284306Sru#include <machine/bus.h>
4322652Smpp#include <machine/fdt.h>
4424817Sbde
4522652Smpp#include <arm/altera/socfpga/socfpga_rstmgr.h>
4624817Sbde
4722652Smppvoid
4824817Sbdecpu_reset(void)
49231292Sbapt{
50231292Sbapt	uint32_t addr, paddr;
5122652Smpp	bus_addr_t vaddr;
52231292Sbapt	phandle_t node;
5357731Ssheldonh
5422652Smpp	if (rstmgr_warmreset() == 0)
5522652Smpp		goto end;
5622652Smpp
5722652Smpp	node = OF_finddevice("rstmgr");
5822652Smpp	if (node == -1)
5922652Smpp		goto end;
6022652Smpp
6122652Smpp	if ((OF_getprop(node, "reg", &paddr, sizeof(paddr))) > 0) {
6222652Smpp		addr = fdt32_to_cpu(paddr);
6322652Smpp		if (bus_space_map(fdtbus_bs_tag, addr, 0x8, 0, &vaddr) == 0) {
6422652Smpp			bus_space_write_4(fdtbus_bs_tag, vaddr,
6522652Smpp			    RSTMGR_CTRL, CTRL_SWWARMRSTREQ);
6657731Ssheldonh		}
6757731Ssheldonh	}
6822652Smpp
6922652Smppend:
7022652Smpp	while (1);
7122652Smpp}
7222652Smpp
7322652Smppstruct fdt_fixup_entry fdt_fixup_table[] = {
7457731Ssheldonh	{ NULL, NULL }
7557731Ssheldonh};
7622652Smpp
7722652Smpp#ifndef INTRNG
7822652Smppstatic int
7922652Smppfdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
8022652Smpp    int *pol)
8122652Smpp{
8281251Sru
8381251Sru	if (!fdt_is_compatible(node, "arm,gic"))
8422652Smpp		return (ENXIO);
8522652Smpp
8622652Smpp	*interrupt = fdt32_to_cpu(intr[0]);
8722652Smpp	*trig = INTR_TRIGGER_CONFORM;
8881251Sru	*pol = INTR_POLARITY_CONFORM;
8922652Smpp	return (0);
9081251Sru}
9122652Smpp
9222652Smppfdt_pic_decode_t fdt_pic_table[] = {
9322652Smpp	&fdt_pic_decode_ic,
9422652Smpp	NULL
9522652Smpp};
9622652Smpp#endif
9722652Smpp