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# $FreeBSD$ 2791416fb2SNathan Whitehorn# 2891416fb2SNathan Whitehorn 2991416fb2SNathan Whitehorn#include <dev/ofw/openfirm.h> 3091416fb2SNathan Whitehorn#include <dev/ofw/ofwvar.h> 3191416fb2SNathan Whitehorn 3291416fb2SNathan Whitehorn/** 3391416fb2SNathan Whitehorn * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations 3491416fb2SNathan Whitehorn * @brief A set of methods to implement the Open Firmware client side interface. 3591416fb2SNathan Whitehorn * @{ 3691416fb2SNathan Whitehorn */ 3791416fb2SNathan Whitehorn 3891416fb2SNathan WhitehornINTERFACE ofw; 3991416fb2SNathan Whitehorn 4091416fb2SNathan Whitehorn/** 4191416fb2SNathan Whitehorn * @brief Initialize OFW client interface 4291416fb2SNathan Whitehorn * 4391416fb2SNathan Whitehorn * @param _cookie A handle to the client interface, generally the OF 4491416fb2SNathan Whitehorn * callback routine. 4591416fb2SNathan Whitehorn */ 468297758aSRafal JaworowskiMETHOD int init { 4791416fb2SNathan Whitehorn ofw_t _ofw; 4891416fb2SNathan Whitehorn void *_cookie; 4991416fb2SNathan Whitehorn}; 5091416fb2SNathan Whitehorn 5191416fb2SNathan Whitehorn/** 52481d6b54SMarius Strobl * @brief Return next sibling of node. 5391416fb2SNathan Whitehorn * 5491416fb2SNathan Whitehorn * @param _node Selected node 5591416fb2SNathan Whitehorn */ 5691416fb2SNathan WhitehornMETHOD phandle_t peer { 5791416fb2SNathan Whitehorn ofw_t _ofw; 5891416fb2SNathan Whitehorn phandle_t _node; 5991416fb2SNathan Whitehorn}; 6091416fb2SNathan Whitehorn 6191416fb2SNathan Whitehorn/** 62481d6b54SMarius Strobl * @brief Return parent of node. 6391416fb2SNathan Whitehorn * 6491416fb2SNathan Whitehorn * @param _node Selected node 6591416fb2SNathan Whitehorn */ 6691416fb2SNathan WhitehornMETHOD phandle_t parent { 6791416fb2SNathan Whitehorn ofw_t _ofw; 6891416fb2SNathan Whitehorn phandle_t _node; 6991416fb2SNathan Whitehorn}; 7091416fb2SNathan Whitehorn 7191416fb2SNathan Whitehorn/** 72481d6b54SMarius Strobl * @brief Return first child of node. 7391416fb2SNathan Whitehorn * 7491416fb2SNathan Whitehorn * @param _node Selected node 7591416fb2SNathan Whitehorn */ 7691416fb2SNathan WhitehornMETHOD phandle_t child { 7791416fb2SNathan Whitehorn ofw_t _ofw; 7891416fb2SNathan Whitehorn phandle_t _node; 7991416fb2SNathan Whitehorn}; 8091416fb2SNathan Whitehorn 8191416fb2SNathan Whitehorn/** 82481d6b54SMarius Strobl * @brief Return package corresponding to instance. 8391416fb2SNathan Whitehorn * 8491416fb2SNathan Whitehorn * @param _handle Selected instance 8591416fb2SNathan Whitehorn */ 8691416fb2SNathan WhitehornMETHOD phandle_t instance_to_package { 8791416fb2SNathan Whitehorn ofw_t _ofw; 8891416fb2SNathan Whitehorn ihandle_t _handle; 8991416fb2SNathan Whitehorn}; 9091416fb2SNathan Whitehorn 9191416fb2SNathan Whitehorn/** 92481d6b54SMarius Strobl * @brief Return length of node property. 9391416fb2SNathan Whitehorn * 9491416fb2SNathan Whitehorn * @param _node Selected node 9591416fb2SNathan Whitehorn * @param _prop Property name 9691416fb2SNathan Whitehorn */ 9791416fb2SNathan WhitehornMETHOD ssize_t getproplen { 9891416fb2SNathan Whitehorn ofw_t _ofw; 9991416fb2SNathan Whitehorn phandle_t _node; 10091416fb2SNathan Whitehorn const char *_prop; 10191416fb2SNathan Whitehorn}; 10291416fb2SNathan Whitehorn 10391416fb2SNathan Whitehorn/** 104481d6b54SMarius Strobl * @brief Read node property. 10591416fb2SNathan Whitehorn * 10691416fb2SNathan Whitehorn * @param _node Selected node 10791416fb2SNathan Whitehorn * @param _prop Property name 10891416fb2SNathan Whitehorn * @param _buf Pointer to buffer 10991416fb2SNathan Whitehorn * @param _size Size of buffer 11091416fb2SNathan Whitehorn */ 11191416fb2SNathan WhitehornMETHOD ssize_t getprop { 11291416fb2SNathan Whitehorn ofw_t _ofw; 11391416fb2SNathan Whitehorn phandle_t _node; 11491416fb2SNathan Whitehorn const char *_prop; 11591416fb2SNathan Whitehorn void *_buf; 11691416fb2SNathan Whitehorn size_t _size; 11791416fb2SNathan Whitehorn}; 11891416fb2SNathan Whitehorn 11991416fb2SNathan Whitehorn/** 120481d6b54SMarius Strobl * @brief Get next property name. 12191416fb2SNathan Whitehorn * 12291416fb2SNathan Whitehorn * @param _node Selected node 12391416fb2SNathan Whitehorn * @param _prop Current property name 12491416fb2SNathan Whitehorn * @param _buf Buffer for next property name 12591416fb2SNathan Whitehorn * @param _size Size of buffer 12691416fb2SNathan Whitehorn */ 12791416fb2SNathan WhitehornMETHOD int nextprop { 12891416fb2SNathan Whitehorn ofw_t _ofw; 12991416fb2SNathan Whitehorn phandle_t _node; 13091416fb2SNathan Whitehorn const char *_prop; 13191416fb2SNathan Whitehorn char *_buf; 13291416fb2SNathan Whitehorn size_t _size; 13391416fb2SNathan Whitehorn}; 13491416fb2SNathan Whitehorn 13591416fb2SNathan Whitehorn/** 136481d6b54SMarius Strobl * @brief Set property. 13791416fb2SNathan Whitehorn * 13891416fb2SNathan Whitehorn * @param _node Selected node 13991416fb2SNathan Whitehorn * @param _prop Property name 14091416fb2SNathan Whitehorn * @param _buf Value to set 14191416fb2SNathan Whitehorn * @param _size Size of buffer 14291416fb2SNathan Whitehorn */ 14391416fb2SNathan WhitehornMETHOD int setprop { 14491416fb2SNathan Whitehorn ofw_t _ofw; 14591416fb2SNathan Whitehorn phandle_t _node; 14691416fb2SNathan Whitehorn const char *_prop; 14791416fb2SNathan Whitehorn const void *_buf; 14891416fb2SNathan Whitehorn size_t _size; 14991416fb2SNathan Whitehorn}; 15091416fb2SNathan Whitehorn 15191416fb2SNathan Whitehorn/** 152481d6b54SMarius Strobl * @brief Canonicalize path. 15391416fb2SNathan Whitehorn * 15491416fb2SNathan Whitehorn * @param _path Path to canonicalize 15591416fb2SNathan Whitehorn * @param _buf Buffer for canonicalized path 15691416fb2SNathan Whitehorn * @param _size Size of buffer 15791416fb2SNathan Whitehorn */ 15891416fb2SNathan WhitehornMETHOD ssize_t canon { 15991416fb2SNathan Whitehorn ofw_t _ofw; 16091416fb2SNathan Whitehorn const char *_path; 16191416fb2SNathan Whitehorn char *_buf; 16291416fb2SNathan Whitehorn size_t _size; 16391416fb2SNathan Whitehorn}; 16491416fb2SNathan Whitehorn 16591416fb2SNathan Whitehorn/** 166481d6b54SMarius Strobl * @brief Return phandle for named device. 16791416fb2SNathan Whitehorn * 16891416fb2SNathan Whitehorn * @param _path Device path 16991416fb2SNathan Whitehorn */ 17091416fb2SNathan WhitehornMETHOD phandle_t finddevice { 17191416fb2SNathan Whitehorn ofw_t _ofw; 17291416fb2SNathan Whitehorn const char *_path; 17391416fb2SNathan Whitehorn}; 17491416fb2SNathan Whitehorn 17591416fb2SNathan Whitehorn/** 176481d6b54SMarius Strobl * @brief Return path for node instance. 17791416fb2SNathan Whitehorn * 17891416fb2SNathan Whitehorn * @param _handle Instance handle 17991416fb2SNathan Whitehorn * @param _path Buffer for path 18091416fb2SNathan Whitehorn * @param _size Size of buffer 18191416fb2SNathan Whitehorn */ 18291416fb2SNathan WhitehornMETHOD ssize_t instance_to_path { 18391416fb2SNathan Whitehorn ofw_t _ofw; 18491416fb2SNathan Whitehorn ihandle_t _handle; 18591416fb2SNathan Whitehorn char *_path; 18691416fb2SNathan Whitehorn size_t _size; 18791416fb2SNathan Whitehorn}; 18891416fb2SNathan Whitehorn 18991416fb2SNathan Whitehorn/** 190481d6b54SMarius Strobl * @brief Return path for node. 19191416fb2SNathan Whitehorn * 19291416fb2SNathan Whitehorn * @param _node Package node 19391416fb2SNathan Whitehorn * @param _path Buffer for path 19491416fb2SNathan Whitehorn * @param _size Size of buffer 19591416fb2SNathan Whitehorn */ 19691416fb2SNathan WhitehornMETHOD ssize_t package_to_path { 19791416fb2SNathan Whitehorn ofw_t _ofw; 19891416fb2SNathan Whitehorn phandle_t _node; 19991416fb2SNathan Whitehorn char *_path; 20091416fb2SNathan Whitehorn size_t _size; 20191416fb2SNathan Whitehorn}; 20291416fb2SNathan Whitehorn 20391416fb2SNathan Whitehorn# Methods for OF method calls (optional) 20491416fb2SNathan Whitehorn 20591416fb2SNathan Whitehorn/** 20691416fb2SNathan Whitehorn * @brief Test to see if a service exists. 20791416fb2SNathan Whitehorn * 20891416fb2SNathan Whitehorn * @param _name name of the service 20991416fb2SNathan Whitehorn */ 21091416fb2SNathan WhitehornMETHOD int test { 21191416fb2SNathan Whitehorn ofw_t _ofw; 21291416fb2SNathan Whitehorn const char *_name; 21391416fb2SNathan Whitehorn}; 21491416fb2SNathan Whitehorn 21591416fb2SNathan Whitehorn/** 216481d6b54SMarius Strobl * @brief Call method belonging to an instance handle. 21791416fb2SNathan Whitehorn * 21891416fb2SNathan Whitehorn * @param _instance Instance handle 21991416fb2SNathan Whitehorn * @param _method Method name 22091416fb2SNathan Whitehorn * @param _nargs Number of arguments 22191416fb2SNathan Whitehorn * @param _nreturns Number of return values 22291416fb2SNathan Whitehorn * @param _args_and_returns Values for arguments, followed by returns 22391416fb2SNathan Whitehorn */ 22491416fb2SNathan Whitehorn 22591416fb2SNathan WhitehornMETHOD int call_method { 22691416fb2SNathan Whitehorn ofw_t _ofw; 22791416fb2SNathan Whitehorn ihandle_t _instance; 22891416fb2SNathan Whitehorn const char *_method; 22991416fb2SNathan Whitehorn int _nargs; 23091416fb2SNathan Whitehorn int _nreturns; 23191416fb2SNathan Whitehorn 232*054e5dcbSNathan Whitehorn cell_t *_args_and_returns; 23391416fb2SNathan Whitehorn}; 23491416fb2SNathan Whitehorn 23591416fb2SNathan Whitehorn/** 236481d6b54SMarius Strobl * @brief Interpret a forth command. 23791416fb2SNathan Whitehorn * 23891416fb2SNathan Whitehorn * @param _cmd Command 23991416fb2SNathan Whitehorn * @param _nreturns Number of return values 24091416fb2SNathan Whitehorn * @param _returns Values for returns 24191416fb2SNathan Whitehorn */ 24291416fb2SNathan Whitehorn 24391416fb2SNathan WhitehornMETHOD int interpret { 24491416fb2SNathan Whitehorn ofw_t _ofw; 24591416fb2SNathan Whitehorn const char *_cmd; 24691416fb2SNathan Whitehorn int _nreturns; 24791416fb2SNathan Whitehorn unsigned long *_returns; 24891416fb2SNathan Whitehorn}; 24991416fb2SNathan Whitehorn 25091416fb2SNathan Whitehorn# Device I/O Functions (optional) 25191416fb2SNathan Whitehorn 25291416fb2SNathan Whitehorn/** 253481d6b54SMarius Strobl * @brief Open node, returning instance handle. 25491416fb2SNathan Whitehorn * 25591416fb2SNathan Whitehorn * @param _path Path to node 25691416fb2SNathan Whitehorn */ 25791416fb2SNathan WhitehornMETHOD ihandle_t open { 25891416fb2SNathan Whitehorn ofw_t _ofw; 25991416fb2SNathan Whitehorn const char *_path; 26091416fb2SNathan Whitehorn} 26191416fb2SNathan Whitehorn 26291416fb2SNathan Whitehorn/** 263481d6b54SMarius Strobl * @brief Close node instance. 26491416fb2SNathan Whitehorn * 26591416fb2SNathan Whitehorn * @param _instance Instance to close 26691416fb2SNathan Whitehorn */ 26791416fb2SNathan WhitehornMETHOD void close { 26891416fb2SNathan Whitehorn ofw_t _ofw; 26991416fb2SNathan Whitehorn ihandle_t _instance; 27091416fb2SNathan Whitehorn} 27191416fb2SNathan Whitehorn 27291416fb2SNathan Whitehorn/** 273481d6b54SMarius Strobl * @brief Read from device. 27491416fb2SNathan Whitehorn * 27591416fb2SNathan Whitehorn * @param _instance Device instance 27691416fb2SNathan Whitehorn * @param _buf Buffer to read to 27791416fb2SNathan Whitehorn * @param _size Size of buffer 27891416fb2SNathan Whitehorn */ 27991416fb2SNathan WhitehornMETHOD ssize_t read { 28091416fb2SNathan Whitehorn ofw_t _ofw; 28191416fb2SNathan Whitehorn ihandle_t _instance; 28291416fb2SNathan Whitehorn void *_buf; 28391416fb2SNathan Whitehorn size_t size; 28491416fb2SNathan Whitehorn} 28591416fb2SNathan Whitehorn 28691416fb2SNathan Whitehorn/** 287481d6b54SMarius Strobl * @brief Write to device. 28891416fb2SNathan Whitehorn * 28991416fb2SNathan Whitehorn * @param _instance Device instance 29091416fb2SNathan Whitehorn * @param _buf Buffer to write from 29191416fb2SNathan Whitehorn * @param _size Size of buffer 29291416fb2SNathan Whitehorn */ 29391416fb2SNathan WhitehornMETHOD ssize_t write { 29491416fb2SNathan Whitehorn ofw_t _ofw; 29591416fb2SNathan Whitehorn ihandle_t _instance; 29691416fb2SNathan Whitehorn const void *_buf; 29791416fb2SNathan Whitehorn size_t size; 29891416fb2SNathan Whitehorn} 29991416fb2SNathan Whitehorn 30091416fb2SNathan Whitehorn/** 301481d6b54SMarius Strobl * @brief Seek device. 30291416fb2SNathan Whitehorn * 30391416fb2SNathan Whitehorn * @param _instance Device instance 30491416fb2SNathan Whitehorn * @param _off Offset to which to seek 30591416fb2SNathan Whitehorn */ 30691416fb2SNathan WhitehornMETHOD int seek { 30791416fb2SNathan Whitehorn ofw_t _ofw; 30891416fb2SNathan Whitehorn ihandle_t _instance; 30991416fb2SNathan Whitehorn uint64_t _off; 31091416fb2SNathan Whitehorn} 31191416fb2SNathan Whitehorn 31291416fb2SNathan Whitehorn# Open Firmware memory management 31391416fb2SNathan Whitehorn 31491416fb2SNathan Whitehorn/** 315481d6b54SMarius Strobl * @brief Claim virtual memory. 31691416fb2SNathan Whitehorn * 31791416fb2SNathan Whitehorn * @param _addr Requested memory location (NULL for first available) 31891416fb2SNathan Whitehorn * @param _size Requested size in bytes 31991416fb2SNathan Whitehorn * @param _align Requested alignment 32091416fb2SNathan Whitehorn */ 32191416fb2SNathan WhitehornMETHOD caddr_t claim { 32291416fb2SNathan Whitehorn ofw_t _ofw; 32391416fb2SNathan Whitehorn void *_addr; 32491416fb2SNathan Whitehorn size_t _size; 32591416fb2SNathan Whitehorn u_int _align; 32691416fb2SNathan Whitehorn} 32791416fb2SNathan Whitehorn 32891416fb2SNathan Whitehorn/** 329481d6b54SMarius Strobl * @brief Release virtual memory. 33091416fb2SNathan Whitehorn * 33191416fb2SNathan Whitehorn * @param _addr Memory location 33291416fb2SNathan Whitehorn * @param _size Size in bytes 33391416fb2SNathan Whitehorn */ 33491416fb2SNathan WhitehornMETHOD void release { 33591416fb2SNathan Whitehorn ofw_t _ofw; 33691416fb2SNathan Whitehorn void *_addr; 33791416fb2SNathan Whitehorn size_t _size; 33891416fb2SNathan Whitehorn}; 33991416fb2SNathan Whitehorn 34091416fb2SNathan Whitehorn# Commands for returning control to the firmware 34191416fb2SNathan Whitehorn 34291416fb2SNathan Whitehorn/** 343481d6b54SMarius Strobl * @brief Temporarily return control to firmware. 34491416fb2SNathan Whitehorn */ 34591416fb2SNathan WhitehornMETHOD void enter { 34691416fb2SNathan Whitehorn ofw_t _ofw; 34791416fb2SNathan Whitehorn}; 34891416fb2SNathan Whitehorn 34991416fb2SNathan Whitehorn/** 350481d6b54SMarius Strobl * @brief Halt and return control to firmware. 35191416fb2SNathan Whitehorn */ 35291416fb2SNathan WhitehornMETHOD void exit { 35391416fb2SNathan Whitehorn ofw_t _ofw; 35491416fb2SNathan Whitehorn}; 355