/**************************************************************************** * * Copyright (C) 2002-2003, Karlsruhe University * * File path: piggybacker/common/ieee1275.cc * Description: Provides access to the Open Firmware client access callback. * Ripped out of the kernel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: ieee1275.cc,v 1.5 2005/01/19 14:01:00 cvansch Exp $ * ***************************************************************************/ #include #include word_t call_addr = 0; __unused prom_handle_t prom_stdout = INVALID_PROM_HANDLE; __unused prom_handle_t prom_stdin = INVALID_PROM_HANDLE; __unused prom_handle_t prom_chosen = INVALID_PROM_HANDLE; __unused prom_handle_t prom_options = INVALID_PROM_HANDLE; __unused prom_handle_t prom_memory = INVALID_PROM_HANDLE; __unused prom_handle_t prom_mmu = INVALID_PROM_HANDLE; #define ToPointer32(x) (unsigned int)((unsigned long)x & 0xffffffff) int prom_get_path( prom_handle_t phandle, const char *service, char *path, int pathlen ) { struct { unsigned int service; int nargs; int nret; unsigned int phandle; unsigned int path; int pathlen; int size; } args; args.service = ToPointer32(service); args.nargs = 3; args.nret = 1; args.phandle = ToPointer32(phandle); args.path = ToPointer32(path); args.pathlen = pathlen; args.size = -1; prom_entry( &args ); if( args.size > -1 ) path[args.size] = '\0'; return args.size; } int prom_package_to_path( prom_handle_t phandle, char *path, int pathlen ) { return prom_get_path( phandle, "package-to-path", path, pathlen ); } int prom_instance_to_path( prom_handle_t ihandle, char *path, int pathlen ) { return prom_get_path( ihandle, "instance-to-path", path, pathlen ); } prom_handle_t prom_instance_to_package( prom_handle_t ihandle ) { struct { unsigned int service; int nargs; int nret; unsigned int ihandle; int phandle; } args; args.service = ToPointer32("instance-to-package"); args.nargs = 1; args.nret = 1; args.ihandle = ToPointer32(ihandle); args.phandle = ToPointer32(INVALID_PROM_HANDLE); prom_entry( &args ); return (prom_handle_t)(word_t)args.phandle; } int prom_next_prop( prom_handle_t node, const char *prev_name, char *name ) { struct { unsigned int service; int nargs; int nret; unsigned int node; unsigned int prev_name; unsigned int name; int flag; } args; args.service = ToPointer32("nextprop"); args.nargs = 3; args.nret = 1; args.node = ToPointer32(node); args.prev_name = ToPointer32(prev_name); args.name = ToPointer32(name); args.flag = -1; prom_entry( &args ); return args.flag; } int prom_read( prom_handle_t phandle, void *buf, int len ) { struct { unsigned int service; int nargs; int nret; unsigned int phandle; unsigned int buf; int len; int actual; } args; args.service = ToPointer32("read"); args.nargs = 3; args.nret = 1; args.phandle = ToPointer32(phandle); args.buf = ToPointer32(buf); args.len = len; args.actual = -1; prom_entry( &args ); return args.actual; } int prom_write( prom_handle_t phandle, const void *buf, int len ) { struct { unsigned int service; int nargs; int nret; unsigned int phandle; unsigned int buf; int len; int actual; } args; args.service = ToPointer32("write"); args.nargs = 3; args.nret = 1; args.phandle = ToPointer32(phandle); args.buf = ToPointer32(buf); args.len = len; args.actual = -1; prom_entry( &args ); return args.actual; } void prom_puts( const char *msg ) { unsigned start, current, len; char nl[] = "\r\n"; current = 0; do { start = current; /* Look for a newline. */ while( msg[current] && (msg[current] != '\n') ) current++; /* If we have a string, print it. */ len = current-start; if( len > 0 ) prom_write( prom_stdout, msg, len ); /* Print a newline. */ prom_write( prom_stdout, nl, sizeof(nl) ); /* Skip the newline. */ if( msg[current] == '\n' ) current++; } while( msg[current] ); } prom_handle_t prom_find_device( const char *name ) { struct { unsigned int service; int nargs; int nret; unsigned int name; int phandle; } args; args.service = ToPointer32("finddevice"); args.nargs = 1; args.nret = 1; args.name = ToPointer32(name); args.phandle = ToPointer32(INVALID_PROM_HANDLE); prom_entry( &args ); return (prom_handle_t)(word_t)args.phandle; } int prom_get_prop( prom_handle_t phandle, const char *name, void *buf, int buflen ) { struct { unsigned int service; int nargs; int nret; unsigned int phandle; unsigned int name; unsigned int buf; int buflen; int size; } args; args.service = ToPointer32("getprop"); args.nargs = 4; args.nret = 1; args.phandle = ToPointer32(phandle); args.name = ToPointer32(name); for (int i=0; i