191416fb2SNathan Whitehorn#- 291416fb2SNathan Whitehorn# Copyright (c) 2008 Nathan Whitehorn 391416fb2SNathan Whitehorn# All rights reserved. 491416fb2SNathan Whitehorn# 591416fb2SNathan Whitehorn# Redistribution and use in source and binary forms, with or without 691416fb2SNathan Whitehorn# modification, are permitted provided that the following conditions 791416fb2SNathan Whitehorn# are met: 891416fb2SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 991416fb2SNathan Whitehorn# notice, this list of conditions and the following disclaimer. 1091416fb2SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 1191416fb2SNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 1291416fb2SNathan Whitehorn# documentation and/or other materials provided with the distribution. 1391416fb2SNathan Whitehorn# 1491416fb2SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1591416fb2SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1691416fb2SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1791416fb2SNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1891416fb2SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1991416fb2SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2091416fb2SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2191416fb2SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2291416fb2SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2391416fb2SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2491416fb2SNathan Whitehorn# SUCH DAMAGE. 2591416fb2SNathan Whitehorn# 2691416fb2SNathan Whitehorn# 2791416fb2SNathan Whitehorn 2891416fb2SNathan Whitehorn#include <dev/ofw/openfirm.h> 2991416fb2SNathan Whitehorn#include <dev/ofw/ofwvar.h> 3091416fb2SNathan Whitehorn 3191416fb2SNathan Whitehorn/** 3291416fb2SNathan Whitehorn * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations 3391416fb2SNathan Whitehorn * @brief A set of methods to implement the Open Firmware client side interface. 3491416fb2SNathan Whitehorn * @{ 3591416fb2SNathan Whitehorn */ 3691416fb2SNathan Whitehorn 3791416fb2SNathan WhitehornINTERFACE ofw; 3891416fb2SNathan Whitehorn 3991416fb2SNathan Whitehorn/** 4091416fb2SNathan Whitehorn * @brief Initialize OFW client interface 4191416fb2SNathan Whitehorn * 4291416fb2SNathan Whitehorn * @param _cookie A handle to the client interface, generally the OF 4391416fb2SNathan Whitehorn * callback routine. 4491416fb2SNathan Whitehorn */ 458297758aSRafal JaworowskiMETHOD int init { 4691416fb2SNathan Whitehorn ofw_t _ofw; 4791416fb2SNathan Whitehorn void *_cookie; 4891416fb2SNathan Whitehorn}; 4991416fb2SNathan Whitehorn 5091416fb2SNathan Whitehorn/** 51481d6b54SMarius Strobl * @brief Return next sibling of node. 5291416fb2SNathan Whitehorn * 5391416fb2SNathan Whitehorn * @param _node Selected node 5491416fb2SNathan Whitehorn */ 5591416fb2SNathan WhitehornMETHOD phandle_t peer { 5691416fb2SNathan Whitehorn ofw_t _ofw; 5791416fb2SNathan Whitehorn phandle_t _node; 5891416fb2SNathan Whitehorn}; 5991416fb2SNathan Whitehorn 6091416fb2SNathan Whitehorn/** 61481d6b54SMarius Strobl * @brief Return parent of node. 6291416fb2SNathan Whitehorn * 6391416fb2SNathan Whitehorn * @param _node Selected node 6491416fb2SNathan Whitehorn */ 6591416fb2SNathan WhitehornMETHOD phandle_t parent { 6691416fb2SNathan Whitehorn ofw_t _ofw; 6791416fb2SNathan Whitehorn phandle_t _node; 6891416fb2SNathan Whitehorn}; 6991416fb2SNathan Whitehorn 7091416fb2SNathan Whitehorn/** 71481d6b54SMarius Strobl * @brief Return first child of node. 7291416fb2SNathan Whitehorn * 7391416fb2SNathan Whitehorn * @param _node Selected node 7491416fb2SNathan Whitehorn */ 7591416fb2SNathan WhitehornMETHOD phandle_t child { 7691416fb2SNathan Whitehorn ofw_t _ofw; 7791416fb2SNathan Whitehorn phandle_t _node; 7891416fb2SNathan Whitehorn}; 7991416fb2SNathan Whitehorn 8091416fb2SNathan Whitehorn/** 81481d6b54SMarius Strobl * @brief Return package corresponding to instance. 8291416fb2SNathan Whitehorn * 8391416fb2SNathan Whitehorn * @param _handle Selected instance 8491416fb2SNathan Whitehorn */ 8591416fb2SNathan WhitehornMETHOD phandle_t instance_to_package { 8691416fb2SNathan Whitehorn ofw_t _ofw; 8791416fb2SNathan Whitehorn ihandle_t _handle; 8891416fb2SNathan Whitehorn}; 8991416fb2SNathan Whitehorn 9091416fb2SNathan Whitehorn/** 91481d6b54SMarius Strobl * @brief Return length of node property. 9291416fb2SNathan Whitehorn * 9391416fb2SNathan Whitehorn * @param _node Selected node 9491416fb2SNathan Whitehorn * @param _prop Property name 9591416fb2SNathan Whitehorn */ 9691416fb2SNathan WhitehornMETHOD ssize_t getproplen { 9791416fb2SNathan Whitehorn ofw_t _ofw; 9891416fb2SNathan Whitehorn phandle_t _node; 9991416fb2SNathan Whitehorn const char *_prop; 10091416fb2SNathan Whitehorn}; 10191416fb2SNathan Whitehorn 10291416fb2SNathan Whitehorn/** 103481d6b54SMarius Strobl * @brief Read node property. 10491416fb2SNathan Whitehorn * 10591416fb2SNathan Whitehorn * @param _node Selected node 10691416fb2SNathan Whitehorn * @param _prop Property name 10791416fb2SNathan Whitehorn * @param _buf Pointer to buffer 10891416fb2SNathan Whitehorn * @param _size Size of buffer 10991416fb2SNathan Whitehorn */ 11091416fb2SNathan WhitehornMETHOD ssize_t getprop { 11191416fb2SNathan Whitehorn ofw_t _ofw; 11291416fb2SNathan Whitehorn phandle_t _node; 11391416fb2SNathan Whitehorn const char *_prop; 11491416fb2SNathan Whitehorn void *_buf; 11591416fb2SNathan Whitehorn size_t _size; 11691416fb2SNathan Whitehorn}; 11791416fb2SNathan Whitehorn 11891416fb2SNathan Whitehorn/** 119481d6b54SMarius Strobl * @brief Get next property name. 12091416fb2SNathan Whitehorn * 12191416fb2SNathan Whitehorn * @param _node Selected node 12291416fb2SNathan Whitehorn * @param _prop Current property name 12391416fb2SNathan Whitehorn * @param _buf Buffer for next property name 12491416fb2SNathan Whitehorn * @param _size Size of buffer 12591416fb2SNathan Whitehorn */ 12691416fb2SNathan WhitehornMETHOD int nextprop { 12791416fb2SNathan Whitehorn ofw_t _ofw; 12891416fb2SNathan Whitehorn phandle_t _node; 12991416fb2SNathan Whitehorn const char *_prop; 13091416fb2SNathan Whitehorn char *_buf; 13191416fb2SNathan Whitehorn size_t _size; 13291416fb2SNathan Whitehorn}; 13391416fb2SNathan Whitehorn 13491416fb2SNathan Whitehorn/** 135481d6b54SMarius Strobl * @brief Set property. 13691416fb2SNathan Whitehorn * 13791416fb2SNathan Whitehorn * @param _node Selected node 13891416fb2SNathan Whitehorn * @param _prop Property name 13991416fb2SNathan Whitehorn * @param _buf Value to set 14091416fb2SNathan Whitehorn * @param _size Size of buffer 14191416fb2SNathan Whitehorn */ 14291416fb2SNathan WhitehornMETHOD int setprop { 14391416fb2SNathan Whitehorn ofw_t _ofw; 14491416fb2SNathan Whitehorn phandle_t _node; 14591416fb2SNathan Whitehorn const char *_prop; 14691416fb2SNathan Whitehorn const void *_buf; 14791416fb2SNathan Whitehorn size_t _size; 14891416fb2SNathan Whitehorn}; 14991416fb2SNathan Whitehorn 15091416fb2SNathan Whitehorn/** 151481d6b54SMarius Strobl * @brief Canonicalize path. 15291416fb2SNathan Whitehorn * 15391416fb2SNathan Whitehorn * @param _path Path to canonicalize 15491416fb2SNathan Whitehorn * @param _buf Buffer for canonicalized path 15591416fb2SNathan Whitehorn * @param _size Size of buffer 15691416fb2SNathan Whitehorn */ 15791416fb2SNathan WhitehornMETHOD ssize_t canon { 15891416fb2SNathan Whitehorn ofw_t _ofw; 15991416fb2SNathan Whitehorn const char *_path; 16091416fb2SNathan Whitehorn char *_buf; 16191416fb2SNathan Whitehorn size_t _size; 16291416fb2SNathan Whitehorn}; 16391416fb2SNathan Whitehorn 16491416fb2SNathan Whitehorn/** 165481d6b54SMarius Strobl * @brief Return phandle for named device. 16691416fb2SNathan Whitehorn * 16791416fb2SNathan Whitehorn * @param _path Device path 16891416fb2SNathan Whitehorn */ 16991416fb2SNathan WhitehornMETHOD phandle_t finddevice { 17091416fb2SNathan Whitehorn ofw_t _ofw; 17191416fb2SNathan Whitehorn const char *_path; 17291416fb2SNathan Whitehorn}; 17391416fb2SNathan Whitehorn 17491416fb2SNathan Whitehorn/** 175481d6b54SMarius Strobl * @brief Return path for node instance. 17691416fb2SNathan Whitehorn * 17791416fb2SNathan Whitehorn * @param _handle Instance handle 17891416fb2SNathan Whitehorn * @param _path Buffer for path 17991416fb2SNathan Whitehorn * @param _size Size of buffer 18091416fb2SNathan Whitehorn */ 18191416fb2SNathan WhitehornMETHOD ssize_t instance_to_path { 18291416fb2SNathan Whitehorn ofw_t _ofw; 18391416fb2SNathan Whitehorn ihandle_t _handle; 18491416fb2SNathan Whitehorn char *_path; 18591416fb2SNathan Whitehorn size_t _size; 18691416fb2SNathan Whitehorn}; 18791416fb2SNathan Whitehorn 18891416fb2SNathan Whitehorn/** 189481d6b54SMarius Strobl * @brief Return path for node. 19091416fb2SNathan Whitehorn * 19191416fb2SNathan Whitehorn * @param _node Package node 19291416fb2SNathan Whitehorn * @param _path Buffer for path 19391416fb2SNathan Whitehorn * @param _size Size of buffer 19491416fb2SNathan Whitehorn */ 19591416fb2SNathan WhitehornMETHOD ssize_t package_to_path { 19691416fb2SNathan Whitehorn ofw_t _ofw; 19791416fb2SNathan Whitehorn phandle_t _node; 19891416fb2SNathan Whitehorn char *_path; 19991416fb2SNathan Whitehorn size_t _size; 20091416fb2SNathan Whitehorn}; 20191416fb2SNathan Whitehorn 20291416fb2SNathan Whitehorn# Methods for OF method calls (optional) 20391416fb2SNathan Whitehorn 20491416fb2SNathan Whitehorn/** 20591416fb2SNathan Whitehorn * @brief Test to see if a service exists. 20691416fb2SNathan Whitehorn * 20791416fb2SNathan Whitehorn * @param _name name of the service 20891416fb2SNathan Whitehorn */ 20991416fb2SNathan WhitehornMETHOD int test { 21091416fb2SNathan Whitehorn ofw_t _ofw; 21191416fb2SNathan Whitehorn const char *_name; 21291416fb2SNathan Whitehorn}; 21391416fb2SNathan Whitehorn 21491416fb2SNathan Whitehorn/** 215481d6b54SMarius Strobl * @brief Call method belonging to an instance handle. 21691416fb2SNathan Whitehorn * 21791416fb2SNathan Whitehorn * @param _instance Instance handle 21891416fb2SNathan Whitehorn * @param _method Method name 21991416fb2SNathan Whitehorn * @param _nargs Number of arguments 22091416fb2SNathan Whitehorn * @param _nreturns Number of return values 22191416fb2SNathan Whitehorn * @param _args_and_returns Values for arguments, followed by returns 22291416fb2SNathan Whitehorn */ 22391416fb2SNathan Whitehorn 22491416fb2SNathan WhitehornMETHOD int call_method { 22591416fb2SNathan Whitehorn ofw_t _ofw; 22691416fb2SNathan Whitehorn ihandle_t _instance; 22791416fb2SNathan Whitehorn const char *_method; 22891416fb2SNathan Whitehorn int _nargs; 22991416fb2SNathan Whitehorn int _nreturns; 23091416fb2SNathan Whitehorn 231054e5dcbSNathan Whitehorn cell_t *_args_and_returns; 23291416fb2SNathan Whitehorn}; 23391416fb2SNathan Whitehorn 23491416fb2SNathan Whitehorn/** 235481d6b54SMarius Strobl * @brief Interpret a forth command. 23691416fb2SNathan Whitehorn * 23791416fb2SNathan Whitehorn * @param _cmd Command 23891416fb2SNathan Whitehorn * @param _nreturns Number of return values 23991416fb2SNathan Whitehorn * @param _returns Values for returns 24091416fb2SNathan Whitehorn */ 24191416fb2SNathan Whitehorn 24291416fb2SNathan WhitehornMETHOD int interpret { 24391416fb2SNathan Whitehorn ofw_t _ofw; 24491416fb2SNathan Whitehorn const char *_cmd; 24591416fb2SNathan Whitehorn int _nreturns; 246*cdb25d82SMarius Strobl cell_t *_returns; 24791416fb2SNathan Whitehorn}; 24891416fb2SNathan Whitehorn 24991416fb2SNathan Whitehorn# Device I/O Functions (optional) 25091416fb2SNathan Whitehorn 25191416fb2SNathan Whitehorn/** 252481d6b54SMarius Strobl * @brief Open node, returning instance handle. 25391416fb2SNathan Whitehorn * 25491416fb2SNathan Whitehorn * @param _path Path to node 25591416fb2SNathan Whitehorn */ 25691416fb2SNathan WhitehornMETHOD ihandle_t open { 25791416fb2SNathan Whitehorn ofw_t _ofw; 25891416fb2SNathan Whitehorn const char *_path; 25991416fb2SNathan Whitehorn} 26091416fb2SNathan Whitehorn 26191416fb2SNathan Whitehorn/** 262481d6b54SMarius Strobl * @brief Close node instance. 26391416fb2SNathan Whitehorn * 26491416fb2SNathan Whitehorn * @param _instance Instance to close 26591416fb2SNathan Whitehorn */ 26691416fb2SNathan WhitehornMETHOD void close { 26791416fb2SNathan Whitehorn ofw_t _ofw; 26891416fb2SNathan Whitehorn ihandle_t _instance; 26991416fb2SNathan Whitehorn} 27091416fb2SNathan Whitehorn 27191416fb2SNathan Whitehorn/** 272481d6b54SMarius Strobl * @brief Read from device. 27391416fb2SNathan Whitehorn * 27491416fb2SNathan Whitehorn * @param _instance Device instance 27591416fb2SNathan Whitehorn * @param _buf Buffer to read to 27691416fb2SNathan Whitehorn * @param _size Size of buffer 27791416fb2SNathan Whitehorn */ 27891416fb2SNathan WhitehornMETHOD ssize_t read { 27991416fb2SNathan Whitehorn ofw_t _ofw; 28091416fb2SNathan Whitehorn ihandle_t _instance; 28191416fb2SNathan Whitehorn void *_buf; 28291416fb2SNathan Whitehorn size_t size; 28391416fb2SNathan Whitehorn} 28491416fb2SNathan Whitehorn 28591416fb2SNathan Whitehorn/** 286481d6b54SMarius Strobl * @brief Write to device. 28791416fb2SNathan Whitehorn * 28891416fb2SNathan Whitehorn * @param _instance Device instance 28991416fb2SNathan Whitehorn * @param _buf Buffer to write from 29091416fb2SNathan Whitehorn * @param _size Size of buffer 29191416fb2SNathan Whitehorn */ 29291416fb2SNathan WhitehornMETHOD ssize_t write { 29391416fb2SNathan Whitehorn ofw_t _ofw; 29491416fb2SNathan Whitehorn ihandle_t _instance; 29591416fb2SNathan Whitehorn const void *_buf; 29691416fb2SNathan Whitehorn size_t size; 29791416fb2SNathan Whitehorn} 29891416fb2SNathan Whitehorn 29991416fb2SNathan Whitehorn/** 300481d6b54SMarius Strobl * @brief Seek device. 30191416fb2SNathan Whitehorn * 30291416fb2SNathan Whitehorn * @param _instance Device instance 30391416fb2SNathan Whitehorn * @param _off Offset to which to seek 30491416fb2SNathan Whitehorn */ 30591416fb2SNathan WhitehornMETHOD int seek { 30691416fb2SNathan Whitehorn ofw_t _ofw; 30791416fb2SNathan Whitehorn ihandle_t _instance; 30891416fb2SNathan Whitehorn uint64_t _off; 30991416fb2SNathan Whitehorn} 31091416fb2SNathan Whitehorn 31191416fb2SNathan Whitehorn# Open Firmware memory management 31291416fb2SNathan Whitehorn 31391416fb2SNathan Whitehorn/** 314481d6b54SMarius Strobl * @brief Claim virtual memory. 31591416fb2SNathan Whitehorn * 31691416fb2SNathan Whitehorn * @param _addr Requested memory location (NULL for first available) 31791416fb2SNathan Whitehorn * @param _size Requested size in bytes 31891416fb2SNathan Whitehorn * @param _align Requested alignment 31991416fb2SNathan Whitehorn */ 32091416fb2SNathan WhitehornMETHOD caddr_t claim { 32191416fb2SNathan Whitehorn ofw_t _ofw; 32291416fb2SNathan Whitehorn void *_addr; 32391416fb2SNathan Whitehorn size_t _size; 32491416fb2SNathan Whitehorn u_int _align; 32591416fb2SNathan Whitehorn} 32691416fb2SNathan Whitehorn 32791416fb2SNathan Whitehorn/** 328481d6b54SMarius Strobl * @brief Release virtual memory. 32991416fb2SNathan Whitehorn * 33091416fb2SNathan Whitehorn * @param _addr Memory location 33191416fb2SNathan Whitehorn * @param _size Size in bytes 33291416fb2SNathan Whitehorn */ 33391416fb2SNathan WhitehornMETHOD void release { 33491416fb2SNathan Whitehorn ofw_t _ofw; 33591416fb2SNathan Whitehorn void *_addr; 33691416fb2SNathan Whitehorn size_t _size; 33791416fb2SNathan Whitehorn}; 33891416fb2SNathan Whitehorn 33991416fb2SNathan Whitehorn# Commands for returning control to the firmware 34091416fb2SNathan Whitehorn 34191416fb2SNathan Whitehorn/** 342481d6b54SMarius Strobl * @brief Temporarily return control to firmware. 34391416fb2SNathan Whitehorn */ 34491416fb2SNathan WhitehornMETHOD void enter { 34591416fb2SNathan Whitehorn ofw_t _ofw; 34691416fb2SNathan Whitehorn}; 34791416fb2SNathan Whitehorn 34891416fb2SNathan Whitehorn/** 349481d6b54SMarius Strobl * @brief Halt and return control to firmware. 35091416fb2SNathan Whitehorn */ 35191416fb2SNathan WhitehornMETHOD void exit { 35291416fb2SNathan Whitehorn ofw_t _ofw; 35391416fb2SNathan Whitehorn}; 354