199767f8919635c4928607450d9e0abb932109ceToomas Soome/* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 1995, 1996 Wolfgang Solfrank.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 1995, 1996 TooLs GmbH.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 3. All advertising materials mentioning features or use of this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * must display the following acknowledgement:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This product includes software developed by TooLs GmbH.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. The name of TooLs GmbH may not be used to endorse or promote products
199767f8919635c4928607450d9e0abb932109ceToomas Soome * derived from this software without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 2000 Benno Rice.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Initialiser */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(chosen, "memory", &memory, sizeof(memory)) == -1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(chosen, "mmu", &mmu, sizeof(mmu)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check if we run in real mode. If so, we do not need to map
199767f8919635c4928607450d9e0abb932109ceToomas Soome * memory later on.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(options, "real-mode?", mode, sizeof(mode)) > 0 &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Generic functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Test to see if a service exists. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return firmware millisecond count. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Device tree functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the next sibling of this node or 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the first child of this node or 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the parent of this node or 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the package handle that corresponds to an instance handle. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get the length of a property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_getproplen(phandle_t package, char *propname)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get the value of a property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_getprop(phandle_t package, char *propname, void *buf, int buflen)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get the next property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_nextprop(phandle_t package, char *previous, char *buf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Set the value of a property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX Has a bug on FirePower */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_setprop(phandle_t package, char *propname, void *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Convert a device specifier to a fully qualified pathname. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_canon(const char *device, char *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return a package handle for the specified device. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the fully qualified pathname corresponding to an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_instance_to_path(ihandle_t instance, char *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the fully qualified pathname corresponding to a package. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_package_to_path(phandle_t package, char *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Call the method in the scope of a given instance. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_call_method(char *method, ihandle_t instance, int nargs, int nreturns, ...)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (cp = (cell_t *)(args.args_n_results + (n = nargs)); --n >= 0;)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (cp = (cell_t *)(args.args_n_results + nargs + (n = args.nreturns));
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Device I/O functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Open an instance for a device. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1 || args.instance == 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Close an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Read from an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_read(ihandle_t instance, void *addr, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("OF_read: called with instance=%08x, addr=%p, len=%d\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("OF_read: returning instance=%d, addr=%p, len=%d, actual=%d\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance, args.addr, args.len, args.actual);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Write to an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_write(ihandle_t instance, void *addr, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Seek to a position. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Memory functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Claim an area of memory. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((void *)-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Release an area of memory. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Control transfer functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Reset the system and call "boot <bootspec>". */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (;;) /* just in case */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Suspend and drop back to the Open Firmware interface. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* We may come back. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Shut down and drop back to the Open Firmware interface. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (;;) /* just in case */
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Free <size> bytes starting at <virt>, then call <entry> with <arg>. */
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is a REALLY dirty hack till the firmware gets this going