199767f8919635c4928607450d9e0abb932109ceToomas Soome/* $NetBSD: Locore.c,v 1.7 2000/08/20 07:04:59 tsubai Exp $ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 1995, 1996 Wolfgang Solfrank.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 1995, 1996 TooLs GmbH.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
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 * are met:
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 *
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 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (C) 2000 Benno Rice.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
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 * are met:
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 *
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 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome__FBSDID("$FreeBSD$");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <machine/stdarg.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <stand.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "openfirm.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint (*openfirmware)(void *);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomephandle_t chosen;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeihandle_t mmu;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeihandle_t memory;
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint real_mode = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Initialiser */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_init(int (*openfirm)(void *))
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome phandle_t options;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char mode[sizeof("true")];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware = openfirm;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((chosen = OF_finddevice("/chosen")) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_exit();
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(chosen, "memory", &memory, sizeof(memory)) == -1) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome memory = OF_open("/memory");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (memory == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome memory = OF_open("/memory@0");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (memory == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_exit();
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(chosen, "mmu", &mmu, sizeof(mmu)) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_exit();
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check if we run in real mode. If so, we do not need to map
199767f8919635c4928607450d9e0abb932109ceToomas Soome * memory later on.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome options = OF_finddevice("/options");
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (OF_getprop(options, "real-mode?", mode, sizeof(mode)) > 0 &&
199767f8919635c4928607450d9e0abb932109ceToomas Soome strcmp(mode, "true") == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome real_mode = 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Generic functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Test to see if a service exists. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_test(char *name)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t service;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t missing;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"test",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.service = (cell_t)name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.missing);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return firmware millisecond count. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_milliseconds()
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t ms;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"milliseconds",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.ms);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Device tree functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the next sibling of this node or 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomephandle_t
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_peer(phandle_t node)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t next;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"peer",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.node = node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.next);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the first child of this node or 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomephandle_t
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_child(phandle_t node)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t child;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"child",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.node = node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.child);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the parent of this node or 0. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomephandle_t
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_parent(phandle_t node)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t parent;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"parent",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.node = node;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.parent);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the package handle that corresponds to an instance handle. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomephandle_t
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_instance_to_package(ihandle_t instance)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"instance-to-package",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.package);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get the length of a property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_getproplen(phandle_t package, char *propname)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t propname;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t proplen;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"getproplen",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 2,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.package = package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.propname = (cell_t)propname;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.proplen);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get the value of a property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_getprop(phandle_t package, char *propname, void *buf, int buflen)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t propname;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buflen;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"getprop",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 4,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.package = package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.propname = (cell_t)propname;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buf = (cell_t)buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buflen = buflen;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Get the next property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_nextprop(phandle_t package, char *previous, char *buf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t previous;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t flag;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"nextprop",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.package = package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.previous = (cell_t)previous;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buf = (cell_t)buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.flag);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Set the value of a property of a package. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX Has a bug on FirePower */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_setprop(phandle_t package, char *propname, void *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t propname;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"setprop",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 4,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.package = package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.propname = (cell_t)propname;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buf = (cell_t)buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Convert a device specifier to a fully qualified pathname. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_canon(const char *device, char *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t device;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"canon",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.device = (cell_t)device;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buf = (cell_t)buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return a package handle for the specified device. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomephandle_t
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_finddevice(const char *device)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t device;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"finddevice",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.device = (cell_t)device;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.package);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the fully qualified pathname corresponding to an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_instance_to_path(ihandle_t instance, char *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"instance-to-path",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buf = (cell_t)buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Return the fully qualified pathname corresponding to a package. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_package_to_path(phandle_t package, char *buf, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"package-to-path",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.package = package;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.buf = (cell_t)buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Call the method in the scope of a given instance. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_call_method(char *method, ihandle_t instance, int nargs, int nreturns, ...)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome va_list ap;
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t method;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t args_n_results[12];
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"call-method",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 2,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t *cp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int n;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (nargs > 6)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.nargs = nargs + 2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.nreturns = nreturns + 1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.method = (cell_t)method;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome va_start(ap, nreturns);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (cp = (cell_t *)(args.args_n_results + (n = nargs)); --n >= 0;)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *--cp = va_arg(ap, cell_t);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (args.args_n_results[nargs])
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.args_n_results[nargs]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (cp = (cell_t *)(args.args_n_results + nargs + (n = args.nreturns));
199767f8919635c4928607450d9e0abb932109ceToomas Soome --n > 0;)
199767f8919635c4928607450d9e0abb932109ceToomas Soome *va_arg(ap, cell_t *) = *--cp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome va_end(ap);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Device I/O functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Open an instance for a device. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeihandle_t
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_open(char *device)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t device;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"open",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.device = (cell_t)device;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1 || args.instance == 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.instance);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Close an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_close(ihandle_t instance)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"close",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Read from an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_read(ihandle_t instance, void *addr, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t actual;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"read",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.addr = (cell_t)addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(OPENFIRM_DEBUG)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("OF_read: called with instance=%08x, addr=%p, len=%d\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance, args.addr, args.len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(OPENFIRM_DEBUG)
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#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.actual);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Write to an instance. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_write(ihandle_t instance, void *addr, int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t actual;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"write",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.addr = (cell_t)addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.actual);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Seek to a position. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_seek(ihandle_t instance, u_int64_t pos)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t poshi;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t poslo;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t status;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"seek",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.instance = instance;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.poshi = pos >> 32;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.poslo = pos;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (args.status);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Memory functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Claim an area of memory. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid *
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_claim(void *virt, u_int size, u_int align)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t virt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t align;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t baseaddr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"claim",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.virt = (cell_t)virt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.align = align;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (openfirmware(&args) == -1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((void *)-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return ((void *)args.baseaddr);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Release an area of memory. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_release(void *virt, u_int size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t virt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"release",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 2,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.virt = (cell_t)virt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Control transfer functions
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Reset the system and call "boot <bootspec>". */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_boot(char *bootspec)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t bootspec;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"boot",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.bootspec = (cell_t)bootspec;
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (;;) /* just in case */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Suspend and drop back to the Open Firmware interface. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_enter()
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"enter",
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* We may come back. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Shut down and drop back to the Open Firmware interface. */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_exit()
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"exit",
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (;;) /* just in case */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_quiesce()
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"quiesce",
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Free <size> bytes starting at <virt>, then call <entry> with <arg>. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if 0
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t name;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nargs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t nreturns;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t virt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t entry;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t arg;
199767f8919635c4928607450d9e0abb932109ceToomas Soome cell_t len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } args = {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (cell_t)"chain",
199767f8919635c4928607450d9e0abb932109ceToomas Soome 5,
199767f8919635c4928607450d9e0abb932109ceToomas Soome };
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.virt = (cell_t)virt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.entry = (cell_t)entry;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.arg = (cell_t)arg;
199767f8919635c4928607450d9e0abb932109ceToomas Soome args.len = len;
199767f8919635c4928607450d9e0abb932109ceToomas Soome openfirmware(&args);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeOF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is a REALLY dirty hack till the firmware gets this going
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (size > 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome OF_release(virt, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome entry(0, 0, openfirmware, arg, len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif