ofw_if.m revision 186347
1186347Snwhitehorn#- 2186347Snwhitehorn# Copyright (c) 2008 Nathan Whitehorn 3186347Snwhitehorn# All rights reserved. 4186347Snwhitehorn# 5186347Snwhitehorn# Redistribution and use in source and binary forms, with or without 6186347Snwhitehorn# modification, are permitted provided that the following conditions 7186347Snwhitehorn# are met: 8186347Snwhitehorn# 1. Redistributions of source code must retain the above copyright 9186347Snwhitehorn# notice, this list of conditions and the following disclaimer. 10186347Snwhitehorn# 2. Redistributions in binary form must reproduce the above copyright 11186347Snwhitehorn# notice, this list of conditions and the following disclaimer in the 12186347Snwhitehorn# documentation and/or other materials provided with the distribution. 13186347Snwhitehorn# 14186347Snwhitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15186347Snwhitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16186347Snwhitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17186347Snwhitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18186347Snwhitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19186347Snwhitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20186347Snwhitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21186347Snwhitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22186347Snwhitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23186347Snwhitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24186347Snwhitehorn# SUCH DAMAGE. 25186347Snwhitehorn# 26186347Snwhitehorn# $FreeBSD: head/sys/dev/ofw/ofw_if.m 186347 2008-12-20 00:33:10Z nwhitehorn $ 27186347Snwhitehorn# 28186347Snwhitehorn 29186347Snwhitehorn#include <dev/ofw/openfirm.h> 30186347Snwhitehorn#include <dev/ofw/ofwvar.h> 31186347Snwhitehorn 32186347Snwhitehorn/** 33186347Snwhitehorn * @defgroup OFW ofw - KObj methods for Open Firmware RTAS implementations 34186347Snwhitehorn * @brief A set of methods to implement the Open Firmware client side interface. 35186347Snwhitehorn *@{ 36186347Snwhitehorn */ 37186347Snwhitehorn 38186347SnwhitehornINTERFACE ofw; 39186347Snwhitehorn 40186347Snwhitehorn/** 41186347Snwhitehorn * @brief Initialize OFW client interface 42186347Snwhitehorn * 43186347Snwhitehorn * @param _cookie A handle to the client interface, generally the OF 44186347Snwhitehorn * callback routine. 45186347Snwhitehorn */ 46186347SnwhitehornMETHOD void init { 47186347Snwhitehorn ofw_t _ofw; 48186347Snwhitehorn void *_cookie; 49186347Snwhitehorn}; 50186347Snwhitehorn 51186347Snwhitehorn/** 52186347Snwhitehorn * @brief Return next sibling of node 53186347Snwhitehorn * 54186347Snwhitehorn * @param _node Selected node 55186347Snwhitehorn */ 56186347SnwhitehornMETHOD phandle_t peer { 57186347Snwhitehorn ofw_t _ofw; 58186347Snwhitehorn phandle_t _node; 59186347Snwhitehorn}; 60186347Snwhitehorn 61186347Snwhitehorn/** 62186347Snwhitehorn * @brief Return parent of node 63186347Snwhitehorn * 64186347Snwhitehorn * @param _node Selected node 65186347Snwhitehorn */ 66186347SnwhitehornMETHOD phandle_t parent { 67186347Snwhitehorn ofw_t _ofw; 68186347Snwhitehorn phandle_t _node; 69186347Snwhitehorn}; 70186347Snwhitehorn 71186347Snwhitehorn/** 72186347Snwhitehorn * @brief Return first child of node 73186347Snwhitehorn * 74186347Snwhitehorn * @param _node Selected node 75186347Snwhitehorn */ 76186347SnwhitehornMETHOD phandle_t child { 77186347Snwhitehorn ofw_t _ofw; 78186347Snwhitehorn phandle_t _node; 79186347Snwhitehorn}; 80186347Snwhitehorn 81186347Snwhitehorn/** 82186347Snwhitehorn * @brief Return package corresponding to instance 83186347Snwhitehorn * 84186347Snwhitehorn * @param _handle Selected instance 85186347Snwhitehorn */ 86186347SnwhitehornMETHOD phandle_t instance_to_package { 87186347Snwhitehorn ofw_t _ofw; 88186347Snwhitehorn ihandle_t _handle; 89186347Snwhitehorn}; 90186347Snwhitehorn 91186347Snwhitehorn/** 92186347Snwhitehorn * @brief Return length of node property 93186347Snwhitehorn * 94186347Snwhitehorn * @param _node Selected node 95186347Snwhitehorn * @param _prop Property name 96186347Snwhitehorn */ 97186347SnwhitehornMETHOD ssize_t getproplen { 98186347Snwhitehorn ofw_t _ofw; 99186347Snwhitehorn phandle_t _node; 100186347Snwhitehorn const char *_prop; 101186347Snwhitehorn}; 102186347Snwhitehorn 103186347Snwhitehorn/** 104186347Snwhitehorn * @brief Read node property 105186347Snwhitehorn * 106186347Snwhitehorn * @param _node Selected node 107186347Snwhitehorn * @param _prop Property name 108186347Snwhitehorn * @param _buf Pointer to buffer 109186347Snwhitehorn * @param _size Size of buffer 110186347Snwhitehorn */ 111186347SnwhitehornMETHOD ssize_t getprop { 112186347Snwhitehorn ofw_t _ofw; 113186347Snwhitehorn phandle_t _node; 114186347Snwhitehorn const char *_prop; 115186347Snwhitehorn void *_buf; 116186347Snwhitehorn size_t _size; 117186347Snwhitehorn}; 118186347Snwhitehorn 119186347Snwhitehorn/** 120186347Snwhitehorn * @brief Get next property name 121186347Snwhitehorn * 122186347Snwhitehorn * @param _node Selected node 123186347Snwhitehorn * @param _prop Current property name 124186347Snwhitehorn * @param _buf Buffer for next property name 125186347Snwhitehorn * @param _size Size of buffer 126186347Snwhitehorn */ 127186347SnwhitehornMETHOD int nextprop { 128186347Snwhitehorn ofw_t _ofw; 129186347Snwhitehorn phandle_t _node; 130186347Snwhitehorn const char *_prop; 131186347Snwhitehorn char *_buf; 132186347Snwhitehorn size_t _size; 133186347Snwhitehorn}; 134186347Snwhitehorn 135186347Snwhitehorn/** 136186347Snwhitehorn * @brief Set property 137186347Snwhitehorn * 138186347Snwhitehorn * @param _node Selected node 139186347Snwhitehorn * @param _prop Property name 140186347Snwhitehorn * @param _buf Value to set 141186347Snwhitehorn * @param _size Size of buffer 142186347Snwhitehorn */ 143186347SnwhitehornMETHOD int setprop { 144186347Snwhitehorn ofw_t _ofw; 145186347Snwhitehorn phandle_t _node; 146186347Snwhitehorn const char *_prop; 147186347Snwhitehorn const void *_buf; 148186347Snwhitehorn size_t _size; 149186347Snwhitehorn}; 150186347Snwhitehorn 151186347Snwhitehorn/** 152186347Snwhitehorn * @brief Canonicalize path 153186347Snwhitehorn * 154186347Snwhitehorn * @param _path Path to canonicalize 155186347Snwhitehorn * @param _buf Buffer for canonicalized path 156186347Snwhitehorn * @param _size Size of buffer 157186347Snwhitehorn */ 158186347SnwhitehornMETHOD ssize_t canon { 159186347Snwhitehorn ofw_t _ofw; 160186347Snwhitehorn const char *_path; 161186347Snwhitehorn char *_buf; 162186347Snwhitehorn size_t _size; 163186347Snwhitehorn}; 164186347Snwhitehorn 165186347Snwhitehorn/** 166186347Snwhitehorn * @brief Return phandle for named device 167186347Snwhitehorn * 168186347Snwhitehorn * @param _path Device path 169186347Snwhitehorn */ 170186347SnwhitehornMETHOD phandle_t finddevice { 171186347Snwhitehorn ofw_t _ofw; 172186347Snwhitehorn const char *_path; 173186347Snwhitehorn}; 174186347Snwhitehorn 175186347Snwhitehorn/** 176186347Snwhitehorn * @brief Return path for node instance 177186347Snwhitehorn * 178186347Snwhitehorn * @param _handle Instance handle 179186347Snwhitehorn * @param _path Buffer for path 180186347Snwhitehorn * @param _size Size of buffer 181186347Snwhitehorn */ 182186347SnwhitehornMETHOD ssize_t instance_to_path { 183186347Snwhitehorn ofw_t _ofw; 184186347Snwhitehorn ihandle_t _handle; 185186347Snwhitehorn char *_path; 186186347Snwhitehorn size_t _size; 187186347Snwhitehorn}; 188186347Snwhitehorn 189186347Snwhitehorn/** 190186347Snwhitehorn * @brief Return path for node 191186347Snwhitehorn * 192186347Snwhitehorn * @param _node Package node 193186347Snwhitehorn * @param _path Buffer for path 194186347Snwhitehorn * @param _size Size of buffer 195186347Snwhitehorn */ 196186347SnwhitehornMETHOD ssize_t package_to_path { 197186347Snwhitehorn ofw_t _ofw; 198186347Snwhitehorn phandle_t _node; 199186347Snwhitehorn char *_path; 200186347Snwhitehorn size_t _size; 201186347Snwhitehorn}; 202186347Snwhitehorn 203186347Snwhitehorn 204186347Snwhitehorn# Methods for OF method calls (optional) 205186347Snwhitehorn 206186347Snwhitehorn/** 207186347Snwhitehorn * @brief Test to see if a service exists. 208186347Snwhitehorn * 209186347Snwhitehorn * @param _name name of the service 210186347Snwhitehorn */ 211186347SnwhitehornMETHOD int test { 212186347Snwhitehorn ofw_t _ofw; 213186347Snwhitehorn const char *_name; 214186347Snwhitehorn}; 215186347Snwhitehorn 216186347Snwhitehorn/** 217186347Snwhitehorn * @brief Call method belonging to an instance handle 218186347Snwhitehorn * 219186347Snwhitehorn * @param _instance Instance handle 220186347Snwhitehorn * @param _method Method name 221186347Snwhitehorn * @param _nargs Number of arguments 222186347Snwhitehorn * @param _nreturns Number of return values 223186347Snwhitehorn * @param _args_and_returns Values for arguments, followed by returns 224186347Snwhitehorn */ 225186347Snwhitehorn 226186347SnwhitehornMETHOD int call_method { 227186347Snwhitehorn ofw_t _ofw; 228186347Snwhitehorn ihandle_t _instance; 229186347Snwhitehorn const char *_method; 230186347Snwhitehorn int _nargs; 231186347Snwhitehorn int _nreturns; 232186347Snwhitehorn 233186347Snwhitehorn unsigned long *_args_and_returns; 234186347Snwhitehorn}; 235186347Snwhitehorn 236186347Snwhitehorn/** 237186347Snwhitehorn * @brief Interpret a forth command 238186347Snwhitehorn * 239186347Snwhitehorn * @param _cmd Command 240186347Snwhitehorn * @param _nreturns Number of return values 241186347Snwhitehorn * @param _returns Values for returns 242186347Snwhitehorn */ 243186347Snwhitehorn 244186347SnwhitehornMETHOD int interpret { 245186347Snwhitehorn ofw_t _ofw; 246186347Snwhitehorn const char *_cmd; 247186347Snwhitehorn int _nreturns; 248186347Snwhitehorn unsigned long *_returns; 249186347Snwhitehorn}; 250186347Snwhitehorn 251186347Snwhitehorn# Device I/O Functions (optional) 252186347Snwhitehorn 253186347Snwhitehorn/** 254186347Snwhitehorn * @brief Open node, returning instance handle 255186347Snwhitehorn * 256186347Snwhitehorn * @param _path Path to node 257186347Snwhitehorn */ 258186347SnwhitehornMETHOD ihandle_t open { 259186347Snwhitehorn ofw_t _ofw; 260186347Snwhitehorn const char *_path; 261186347Snwhitehorn} 262186347Snwhitehorn 263186347Snwhitehorn/** 264186347Snwhitehorn * @brief Close node instance 265186347Snwhitehorn * 266186347Snwhitehorn * @param _instance Instance to close 267186347Snwhitehorn */ 268186347SnwhitehornMETHOD void close { 269186347Snwhitehorn ofw_t _ofw; 270186347Snwhitehorn ihandle_t _instance; 271186347Snwhitehorn} 272186347Snwhitehorn 273186347Snwhitehorn/** 274186347Snwhitehorn * @brief Read from device 275186347Snwhitehorn * 276186347Snwhitehorn * @param _instance Device instance 277186347Snwhitehorn * @param _buf Buffer to read to 278186347Snwhitehorn * @param _size Size of buffer 279186347Snwhitehorn */ 280186347SnwhitehornMETHOD ssize_t read { 281186347Snwhitehorn ofw_t _ofw; 282186347Snwhitehorn ihandle_t _instance; 283186347Snwhitehorn void *_buf; 284186347Snwhitehorn size_t size; 285186347Snwhitehorn} 286186347Snwhitehorn 287186347Snwhitehorn/** 288186347Snwhitehorn * @brief Write to device 289186347Snwhitehorn * 290186347Snwhitehorn * @param _instance Device instance 291186347Snwhitehorn * @param _buf Buffer to write from 292186347Snwhitehorn * @param _size Size of buffer 293186347Snwhitehorn */ 294186347SnwhitehornMETHOD ssize_t write { 295186347Snwhitehorn ofw_t _ofw; 296186347Snwhitehorn ihandle_t _instance; 297186347Snwhitehorn const void *_buf; 298186347Snwhitehorn size_t size; 299186347Snwhitehorn} 300186347Snwhitehorn 301186347Snwhitehorn/** 302186347Snwhitehorn * @brief Seek device 303186347Snwhitehorn * 304186347Snwhitehorn * @param _instance Device instance 305186347Snwhitehorn * @param _off Offset to which to seek 306186347Snwhitehorn */ 307186347SnwhitehornMETHOD int seek { 308186347Snwhitehorn ofw_t _ofw; 309186347Snwhitehorn ihandle_t _instance; 310186347Snwhitehorn uint64_t _off; 311186347Snwhitehorn} 312186347Snwhitehorn 313186347Snwhitehorn# Open Firmware memory management 314186347Snwhitehorn 315186347Snwhitehorn/** 316186347Snwhitehorn * @brief Claim virtual memory 317186347Snwhitehorn * 318186347Snwhitehorn * @param _addr Requested memory location (NULL for first available) 319186347Snwhitehorn * @param _size Requested size in bytes 320186347Snwhitehorn * @param _align Requested alignment 321186347Snwhitehorn */ 322186347SnwhitehornMETHOD caddr_t claim { 323186347Snwhitehorn ofw_t _ofw; 324186347Snwhitehorn void *_addr; 325186347Snwhitehorn size_t _size; 326186347Snwhitehorn u_int _align; 327186347Snwhitehorn} 328186347Snwhitehorn 329186347Snwhitehorn/** 330186347Snwhitehorn * @brief Release virtual memory 331186347Snwhitehorn * 332186347Snwhitehorn * @param _addr Memory location 333186347Snwhitehorn * @param _size Size in bytes 334186347Snwhitehorn */ 335186347SnwhitehornMETHOD void release { 336186347Snwhitehorn ofw_t _ofw; 337186347Snwhitehorn void *_addr; 338186347Snwhitehorn size_t _size; 339186347Snwhitehorn}; 340186347Snwhitehorn 341186347Snwhitehorn# Commands for returning control to the firmware 342186347Snwhitehorn 343186347Snwhitehorn/** 344186347Snwhitehorn * @brief Temporarily return control to firmware 345186347Snwhitehorn */ 346186347SnwhitehornMETHOD void enter { 347186347Snwhitehorn ofw_t _ofw; 348186347Snwhitehorn}; 349186347Snwhitehorn 350186347Snwhitehorn/** 351186347Snwhitehorn * @brief Halt and return control to firmware 352186347Snwhitehorn */ 353186347SnwhitehornMETHOD void exit { 354186347Snwhitehorn ofw_t _ofw; 355186347Snwhitehorn}; 356186347Snwhitehorn 357186347Snwhitehorn 358