From 6495aef5b625b9ddae9c4b2602a2881b487d1501 Mon Sep 17 00:00:00 2001 From: Benjamin Herrenschmidt Date: Tue, 15 Jul 2014 11:45:54 +1000 Subject: [PATCH] net-snk: Remove module system It's not used anymore, let's just call directly into the relevant OF functions. While at it, also make socket() actually return an fd. Signed-off-by: Benjamin Herrenschmidt --- clients/net-snk/include/fileio.h | 36 +---- clients/net-snk/include/ioctl.h | 19 --- clients/net-snk/include/kernel.h | 4 + clients/net-snk/include/netdriver_int.h | 116 --------------- clients/net-snk/include/of.h | 8 +- clients/net-snk/include/pci.h | 2 +- clients/net-snk/kernel/Makefile | 2 +- clients/net-snk/kernel/init.c | 17 +-- clients/net-snk/kernel/modules.c | 82 ----------- clients/net-snk/kernel/modules.h | 15 -- clients/net-snk/kernel/systemcall.c | 178 ++++++++++-------------- clients/net-snk/oflib/Makefile | 2 +- clients/net-snk/oflib/ci_device.c | 124 ----------------- clients/net-snk/oflib/of.c | 154 +++----------------- clients/net-snk/oflib/rtas.c | 1 - 15 files changed, 121 insertions(+), 639 deletions(-) delete mode 100644 clients/net-snk/include/ioctl.h delete mode 100644 clients/net-snk/include/netdriver_int.h delete mode 100644 clients/net-snk/kernel/modules.c delete mode 100644 clients/net-snk/kernel/modules.h delete mode 100644 clients/net-snk/oflib/ci_device.c diff --git a/clients/net-snk/include/fileio.h b/clients/net-snk/include/fileio.h index 7c9a2b5..50f9650 100644 --- a/clients/net-snk/include/fileio.h +++ b/clients/net-snk/include/fileio.h @@ -12,40 +12,18 @@ #ifndef FILEIO_H #define FILEIO_H -#include -struct snk_fileio_type; -typedef struct snk_fileio_type snk_fileio_t; +#include -#define FILEIO_TYPE_EMPTY 0 -#define FILEIO_TYPE_USED 1 - -typedef long (*fileio_read_t) - (snk_fileio_t *fileio, char *buf, long len); -typedef long (*fileio_write_t) - (snk_fileio_t *fileio, char *buf, long len); -typedef int (*fileio_ioctl_t) - (snk_fileio_t *fileio, int request, void *data); -typedef int (*fileio_bind_t) - (snk_fileio_t *fileio, const struct sockaddr *, long len); -typedef int (*fileio_connect_t) - (snk_fileio_t *fileio, const struct sockaddr *, long len); -typedef int (*fileio_close_t) - (snk_fileio_t *fileio); +#define FILEIO_TYPE_EMPTY 0 +#define FILEIO_TYPE_FILE 1 +#define FILEIO_TYPE_SOCKET 2 struct snk_fileio_type { - int type; - int idx; - - fileio_read_t read; - fileio_write_t write; - fileio_ioctl_t ioctl; - fileio_bind_t bind; - fileio_connect_t connect; - fileio_close_t close; - - void *data; + int type; + ihandle_t ih; }; +typedef struct snk_fileio_type snk_fileio_t; #define FILEIO_MAX 32 extern snk_fileio_t fd_array[FILEIO_MAX]; diff --git a/clients/net-snk/include/ioctl.h b/clients/net-snk/include/ioctl.h deleted file mode 100644 index c993798..0000000 --- a/clients/net-snk/include/ioctl.h +++ /dev/null @@ -1,19 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2004, 2008 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - - -#ifndef _IOCTL_H -#define _IOCTL_H - -extern int ioctl(int fd, int request, void *data); - -#endif diff --git a/clients/net-snk/include/kernel.h b/clients/net-snk/include/kernel.h index 3fd4ea8..63eb2f4 100644 --- a/clients/net-snk/include/kernel.h +++ b/clients/net-snk/include/kernel.h @@ -15,6 +15,8 @@ #include #include +#include +#include int printk(const char *, ...); void *memcpy(void *, const void *, size_t); @@ -30,6 +32,8 @@ char *strcpy(char *, const char *); int printf(const char *, ...); void *malloc_aligned(size_t size, int align); +int pre_open_ih(int fd, ihandle_t ih); + void exception_forward(void); void undo_exception(void); diff --git a/clients/net-snk/include/netdriver_int.h b/clients/net-snk/include/netdriver_int.h deleted file mode 100644 index 1ebfd75..0000000 --- a/clients/net-snk/include/netdriver_int.h +++ /dev/null @@ -1,116 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2004, 2008 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - -#ifndef _NETDRIVER_INT_H -#define _NETDRIVER_INT_H -#include -#include /* ssize_t */ -#include - -#if defined(__GNUC__) && !defined(UNUSED) -# define UNUSED __attribute__((unused)) -#else -# define UNUSED -#endif - -#define MOD_TYPE_NETWORK 0 -#define MOD_TYPE_OTHER 1 - -typedef int (*mod_init_t) (void); -typedef int (*mod_term_t) (void); -typedef int (*mod_socket_t)(snk_fileio_t *, int dom, int type, int proto); -typedef int (*mod_open_t) (snk_fileio_t *, const char *, int); -typedef int (*mod_read_t) (char *, int); -typedef int (*mod_write_t) (char *, int); -typedef int (*mod_ioctl_t) (int, void *); - -typedef struct { - int version; - int type; - int running; - void *link_addr; - mod_init_t init; - mod_term_t term; - mod_socket_t socket; - mod_open_t open; - mod_read_t read; - mod_write_t write; - mod_ioctl_t ioctl; - - char mac_addr[6]; -} snk_module_t; - -#define MODULES_MAX 10 -extern snk_module_t *snk_modules[MODULES_MAX]; - -typedef int (*print_t) (const char *, ...); -typedef void (*us_delay_t) (unsigned int); -typedef void (*ms_delay_t) (unsigned int); -typedef void *(*malloc_aligned_t) (size_t, int); -typedef void *(*malloc_t) (size_t); -typedef void (*free_t) (void *); -typedef int (*strcmp_t) (const char *, const char *); -typedef int (*snk_call_t) (int, char **); -typedef unsigned int (*io_read_t) (void *, size_t); -typedef int (*io_write_t) (void *, unsigned int, size_t); - -typedef int (*k_open_t) (const char *, int); -typedef int (*k_close_t) (int); -typedef ssize_t (*k_read_t) (int, void *, size_t); -typedef ssize_t (*k_write_t) (int, const void *, size_t); -typedef int (*k_ioctl_t) (int, int, void *); - -typedef void (*modules_remove_t) (int); -typedef snk_module_t *(*modules_load_t) (int); - - -/* - * Constants for different kinds of IOCTL requests - */ - -#define SIOCETHTOOL 0x1000 - -/* - * special structure and constants for IOCTL requests of type ETHTOOL - */ - -#define ETHTOOL_GMAC 0x03 -#define ETHTOOL_SMAC 0x04 -#define ETHTOOL_VERSION 0x05 - -typedef struct { - int idx; - char address[6]; -} ioctl_ethtool_mac_t; - -typedef struct { - unsigned int length; - char *text; -} ioctl_ethtool_version_t; - - -/* - * default structure and constants for IOCTL requests - */ - -#define IF_NAME_SIZE 0xFF - -typedef struct { - char if_name[IF_NAME_SIZE]; - int subcmd; - union { - ioctl_ethtool_mac_t mac; - ioctl_ethtool_version_t version; - } data; -} ioctl_net_data_t; - -#endif /* _NETDRIVER_INT_H */ diff --git a/clients/net-snk/include/of.h b/clients/net-snk/include/of.h index b615297..22411ff 100644 --- a/clients/net-snk/include/of.h +++ b/clients/net-snk/include/of.h @@ -14,6 +14,7 @@ #define OF_H #include +#include #define p32 int #define p32cast (int) (unsigned long) (void*) @@ -34,6 +35,7 @@ phandle_t of_finddevice (const char *); phandle_t of_peer (phandle_t); phandle_t of_child (phandle_t); phandle_t of_parent (phandle_t); +phandle_t of_instance_to_package(ihandle_t ihandle); int of_getprop (phandle_t, const char *, void *, int); void * of_call_method_3 (const char *, ihandle_t, int); int of_test(const char *name); @@ -56,9 +58,13 @@ int vpd_read(unsigned int , unsigned int , char *); int vpd_write(unsigned int , unsigned int , char *); int write_mm_log(char *, unsigned int , unsigned short ); -void get_mac(char *mac); +int of_get_mac(phandle_t device, char *mac); uint64_t get_puid(phandle_t node); void translate_address_dev(uint64_t *, phandle_t); void translate_address(unsigned long *addr); +int of_glue_init(unsigned int * timebase, + size_t _client_start, size_t _client_size); +void of_glue_release(void); + #endif diff --git a/clients/net-snk/include/pci.h b/clients/net-snk/include/pci.h index a063dcc..3b368a4 100644 --- a/clients/net-snk/include/pci.h +++ b/clients/net-snk/include/pci.h @@ -13,7 +13,7 @@ #ifndef _PCI_H #define _PCI_H -#include + #include int pci_calc_bar_size (long long puid, int bus, int devfn, int bar); diff --git a/clients/net-snk/kernel/Makefile b/clients/net-snk/kernel/Makefile index 6846c83..c4b8164 100644 --- a/clients/net-snk/kernel/Makefile +++ b/clients/net-snk/kernel/Makefile @@ -17,7 +17,7 @@ ifndef TOP endif include $(TOP)/make.rules -OBJS = init.o systemcall.o crt0.o timer.o modules.o +OBJS = init.o systemcall.o crt0.o timer.o OBJS2 = entry.o all: kernel.o diff --git a/clients/net-snk/kernel/init.c b/clients/net-snk/kernel/init.c index 77494fc..8ae436f 100644 --- a/clients/net-snk/kernel/init.c +++ b/clients/net-snk/kernel/init.c @@ -18,8 +18,6 @@ #include #include #include -#include /* ioctl */ -#include "modules.h" /* Application entry point .*/ extern int _start(unsigned char *arg_string, long len); @@ -33,9 +31,6 @@ snk_fileio_t fd_array[FILEIO_MAX]; extern uint64_t tb_freq; -int glue_init(unsigned int *, size_t, size_t); -void glue_release(void); - extern char _lowmem_start; extern char _lowmem_end; extern char __client_start; @@ -56,23 +51,19 @@ int _start_kernel(unsigned long p0, unsigned long p1) unsigned int timebase; /* initialize all file descriptor by marking them as empty */ - for(rc=0; rc -#include -#include -#include -#include -#include /* flush_cache */ -#include /* open, close, read, write */ -#include -#include -#include "modules.h" - -snk_module_t * cimod_check_and_install(void); - -extern snk_module_t of_module, ci_module; - -extern char __client_start[]; - -snk_module_t *snk_modules[MODULES_MAX]; - -/* Load module and call init code. - Init code will check, if module is responsible for device. - Returns -1, if not responsible for device, 0 otherwise. -*/ - -void -modules_init(void) -{ - int i; - - snk_modules[0] = &of_module; - - /* Setup Module List */ - for(i=1; irunning != 0) { - snk_modules[i]->term(); - } - snk_modules[i] = 0; - } -} - -snk_module_t * -get_module_by_type(int type) { - int i; - - for(i=0; itype == type) { - return snk_modules[i]; - } - } - return 0; -} diff --git a/clients/net-snk/kernel/modules.h b/clients/net-snk/kernel/modules.h deleted file mode 100644 index 489016a..0000000 --- a/clients/net-snk/kernel/modules.h +++ /dev/null @@ -1,15 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2011 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ - -extern void modules_init(void); -extern void modules_term(void); -extern snk_module_t *get_module_by_type(int type); diff --git a/clients/net-snk/kernel/systemcall.c b/clients/net-snk/kernel/systemcall.c index e0f6bbc..1cc4cdc 100644 --- a/clients/net-snk/kernel/systemcall.c +++ b/clients/net-snk/kernel/systemcall.c @@ -13,11 +13,10 @@ #include #include #include -#include -#include #include -#include -#include "modules.h" +#include +#include +#include extern int vsprintf(char *, const char *, va_list); extern void _exit(int status); @@ -27,108 +26,120 @@ int printk(const char*, ...); int open(const char* name, int flags) { - int fd, i; + int fd; /* search free file descriptor */ - for(fd=0; fdopen) { - continue; - } - - if(snk_modules[i]->running == 0) { - snk_modules[i]->init(); - } - - if(snk_modules[i]->open(&fd_array[fd], name, flags) == 0) - break; - } - - if(i==MODULES_MAX) { - /* file not found */ + fd_array[fd].ih = of_open(name); + if (fd_array[fd].ih == 0) return -1; - } + + fd_array[fd].type = FILEIO_TYPE_FILE; + + return fd; +} + +int pre_open_ih(int fd, ihandle_t ih) +{ + if (fd_array[fd].type != FILEIO_TYPE_EMPTY) + return -2; + fd_array[fd].ih = ih; + fd_array[fd].type = FILEIO_TYPE_FILE; return fd; } int socket(int domain, int type, int proto, char *mac_addr) { - snk_module_t *net_module; + uint8_t tmpbuf[8]; + int fd; + phandle_t ph; - net_module = get_module_by_type(MOD_TYPE_NETWORK); - if( !net_module || !net_module->init) { - printk("No net_init function available"); + /* search free file descriptor */ + for (fd=0; fdrunning == 0) { - net_module->init(); + ph = of_instance_to_package(fd_array[fd].ih); + if (ph == -1) { + printk ("Can not open socket, no parent package\n"); + return -1; } + if (of_get_mac(ph, mac_addr) < 0) { + printk ("Can not open socket, no MAC address\n"); + return -1; + } + fd_array[fd].type = FILEIO_TYPE_SOCKET; - if(net_module->running == 0) - return -2; - - memcpy(mac_addr, &net_module->mac_addr[0], 6); - return 0; + return fd; } int close(int fd) { - if(fd < 0 || fd >= FILEIO_MAX - || fd_array[fd].type == FILEIO_TYPE_EMPTY - || fd_array[fd].close == 0) + if (fd < 0 || fd >= FILEIO_MAX || + fd_array[fd].type == FILEIO_TYPE_EMPTY) return -1; - - return fd_array[fd].close(&fd_array[fd]); + if (fd_array[fd].type == FILEIO_TYPE_FILE) + of_close(fd_array[fd].ih); + fd_array[fd].type = FILEIO_TYPE_EMPTY; + return 0; } ssize_t read(int fd, void *buf, size_t len) { - if(fd < 0 || fd >= FILEIO_MAX - || fd_array[fd].type == FILEIO_TYPE_EMPTY - || fd_array[fd].read == 0) + if (fd < 0 || fd >= FILEIO_MAX || + fd_array[fd].type == FILEIO_TYPE_EMPTY) return -1; - return fd_array[fd].read(&fd_array[fd], buf, len); + return of_read(fd_array[fd].ih, buf, len); } ssize_t write (int fd, const void *buf, size_t len) { - char dest_buf[512]; - char *dest_buf_ptr; - const char *dbuf = buf; - int i; + char dest_buf[512]; + char *dest_buf_ptr; + const char *dbuf = buf; + int i; - if (fd == 1 || fd == 2) { - dest_buf_ptr = &dest_buf[0]; - for (i = 0; i < len && i < 256; i++) - { - *dest_buf_ptr++ = *dbuf++; - if (dbuf[-1] == '\n') - *dest_buf_ptr++ = '\r'; + if (fd == 1 || fd == 2) { + dest_buf_ptr = &dest_buf[0]; + for (i = 0; i < len && i < 256; i++) + { + *dest_buf_ptr++ = *dbuf++; + if (dbuf[-1] == '\n') + *dest_buf_ptr++ = '\r'; + } + len = dest_buf_ptr - &dest_buf[0]; + buf = &dest_buf[0]; } - len = dest_buf_ptr - &dest_buf[0]; - buf = &dest_buf[0]; - } - if(fd < 0 || fd >= FILEIO_MAX - || fd_array[fd].type == FILEIO_TYPE_EMPTY - || fd_array[fd].write == 0) + if(fd < 0 || fd >= FILEIO_MAX || + fd_array[fd].type == FILEIO_TYPE_EMPTY) return -1; - return fd_array[fd].write(&fd_array[fd], (void *)buf, len); + return of_write(fd_array[fd].ih, (void *)buf, len); } ssize_t lseek (int fd, long offset, int whence) @@ -144,51 +155,14 @@ ssize_t lseek (int fd, long offset, int whence) #endif } -int ioctl (int fd, int request, void* data) -{ - if (fd < 0 - || fd >= FILEIO_MAX - || fd_array[fd].type == FILEIO_TYPE_EMPTY) - return -1; - if (!fd_array[fd].ioctl) { /* for backwards compatibility with network modules */ - snk_module_t *net_module; - - net_module = get_module_by_type(MOD_TYPE_NETWORK); - if ( !net_module || !net_module->ioctl ) { - printk("No net_ioctl function available"); - return -1; - } - - return net_module->ioctl(request, data); - } - - return fd_array[fd].ioctl(&fd_array[fd], request, data); -} - int recv(int fd, void *packet, int packet_len, int flags) { - snk_module_t *net_module; - - net_module = get_module_by_type(MOD_TYPE_NETWORK); - if( !net_module || !net_module->read ) { - printk("No net_receive function available"); - return -1; - } - - return net_module->read(packet, packet_len); + return read(fd, packet, packet_len); } int send(int fd, const void *packet, int packet_len, int flags) { - snk_module_t *net_module; - - net_module = get_module_by_type(MOD_TYPE_NETWORK); - if( !net_module || !net_module->write ) { - printk("No net_xmit function available"); - return -1; - } - - return net_module->write((void *)packet, packet_len); + return write(fd, packet, packet_len); } int sendto(int fd, const void *packet, int packet_len, int flags, diff --git a/clients/net-snk/oflib/Makefile b/clients/net-snk/oflib/Makefile index 58c2fd8..aad3e89 100644 --- a/clients/net-snk/oflib/Makefile +++ b/clients/net-snk/oflib/Makefile @@ -17,7 +17,7 @@ ifndef TOP endif include $(TOP)/make.rules -OBJS = rtas.o of.o pci.o ci_device.o +OBJS = rtas.o of.o pci.o OBJS2 = entry.o all: oflib.o diff --git a/clients/net-snk/oflib/ci_device.c b/clients/net-snk/oflib/ci_device.c deleted file mode 100644 index 8b0636c..0000000 --- a/clients/net-snk/oflib/ci_device.c +++ /dev/null @@ -1,124 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2011 IBM Corporation - * All rights reserved. - * This program and the accompanying materials - * are made available under the terms of the BSD License - * which accompanies this distribution, and is available at - * http://www.opensource.org/licenses/bsd-license.php - * - * Contributors: - * IBM Corporation - initial implementation - *****************************************************************************/ -/* - * A pseudo-module that uses the the "write" and "read" functions via the - * client interface to handle the given device. - * Normally the net-snk uses the various net_xxx modules from the romfs to - * drive the network cards. However, in case we do not have a net-snk driver - * for the given card and it has been initialized via FCODE instead, we've - * got to use the Open Firmware Client Interface "write" and "read" functions - * to talk to the NIC. This is achieved via this pseudo-module here. - */ - -#include -#include -#include -#include -#include -#include - -#define DEBUG 0 -#if DEBUG -#define dprintf(str, ...) printk(str, ## __VA_ARGS__) -#else -#define dprintf(str, ...) do{}while(0) -#endif - -snk_module_t * cimod_check_and_install(void); -static int cimod_init(void); -static int cimod_term(void); -static int cimod_read(char *buffer, int len); -static int cimod_write(char *buffer, int len); -static int cimod_ioctl(int request, void *data); - -snk_module_t ci_module = { - .version = 1, - .type = MOD_TYPE_NETWORK, - .running = 0, - .link_addr = (char*) 1, - .init = cimod_init, - .term = cimod_term, - .write = cimod_write, - .read = cimod_read, - .ioctl = cimod_ioctl -}; - -static ihandle_t myself; - - -snk_module_t * -cimod_check_and_install(void) -{ - uint8_t tmpbuf[8]; - - dprintf("entered cimod_check_and_install!\n"); - - myself = of_interpret_1("my-parent", tmpbuf); - dprintf("cimod: myself=%lx\n", myself); - - /* Check whether "read" and "write" functions are provided by the - * device tree node: */ - if (of_read(myself, tmpbuf, 0) == -1 - || of_write(myself, tmpbuf, 0) == -1) { - dprintf("cimod: missing read or write!\n"); - return NULL; - } - - return &ci_module; -} - -static int -cimod_init(void) -{ - get_mac(&ci_module.mac_addr[0]); - ci_module.running = 1; - dprintf("client-interface module initialized!\n"); - return 0; -} - -static int -cimod_term(void) -{ - ci_module.running = 0; - dprintf("cimod term called!\n"); - return 0; -} - -static int -cimod_read(char *buffer, int len) -{ - int ret; - - ret = of_read(myself, buffer, len); - dprintf("cimod read returned: %i!\n", ret); - - return ret; -} - -static int -cimod_write(char *buffer, int len) -{ - int ret; - - ret = of_write(myself, buffer, len); - dprintf("cimod write returned: %i!\n", ret); - - return ret; -} - -static int -cimod_ioctl(int request, void *data) -{ - dprintf("cimod ioctl called!\n"); - - return 0; -} diff --git a/clients/net-snk/oflib/of.c b/clients/net-snk/oflib/of.c index 09f0be8..9133140 100644 --- a/clients/net-snk/oflib/of.c +++ b/clients/net-snk/oflib/of.c @@ -14,36 +14,11 @@ #include #include #include -#include -#include #include +#include extern void call_client_interface(of_arg_t *); -static int ofmod_init(void); -static int ofmod_term(void); -static int ofmod_open(snk_fileio_t*, const char* name, int flags); -static int ofmod_read(char *buffer, int len); -static int ofmod_write(char *buffer, int len); -static int ofmod_ioctl(int request, void *data); - -int glue_init(unsigned int *, size_t, size_t); -void glue_release(void); - -snk_module_t of_module = { - .version = 1, - .type = MOD_TYPE_OTHER, - .running = 1, - .link_addr = (char*) 1, - .init = ofmod_init, - .term = ofmod_term, - .open = ofmod_open, - .write = ofmod_write, - .read = ofmod_read, - .ioctl = ofmod_ioctl -}; - -static ihandle_t fd_ihandle_array[FILEIO_MAX]; static int claim_rc = 0; static void* client_start; static size_t client_size; @@ -283,6 +258,13 @@ of_parent(phandle_t phandle) return (phandle_t) of_1_1("parent", phandle); } +phandle_t +of_instance_to_package(ihandle_t ihandle) +{ + return (phandle_t) of_1_1("instance-to-package", ihandle); +} + + phandle_t of_finddevice(const char *name) { @@ -386,33 +368,6 @@ bootmsg_cp(short id) } */ -static long -of_fileio_read(snk_fileio_t *fileio, char *buf, long len) -{ - if(!fileio) - return -1; - return of_read( * (ihandle_t*) fileio->data, buf, len ); -} - -static long -of_fileio_write(snk_fileio_t *fileio, char *buf, long len) -{ - if(!fileio) - return -1; - return of_write( * (ihandle_t*) fileio->data, buf, len ); -} - -static int -of_fileio_close(snk_fileio_t *fileio) -{ - if(!fileio) - return -1; - - fileio->type = FILEIO_TYPE_EMPTY; - of_close( * (ihandle_t*) fileio->data ); - return 0; -} - #define CONFIG_SPACE 0 #define IO_SPACE 1 #define MEM_SPACE 2 @@ -690,19 +645,14 @@ get_puid(phandle_t node) return 0; } -void -get_mac(char *mac) +int of_get_mac(phandle_t device, char *mac) { uint8_t localmac[8]; int len; - phandle_t net = get_boot_device(); - if (net == -1) - return; - - len = of_getprop(net, "local-mac-address", localmac, 8); + len = of_getprop(device, "local-mac-address", localmac, 8); if (len <= 0) - return; + return -1; if (len == 8) { /* Some bad FDT nodes like veth use a 8-byte wide @@ -712,6 +662,7 @@ get_mac(char *mac) else { memcpy(mac, localmac, 6); } + return 0; } static void @@ -731,10 +682,11 @@ get_timebase(unsigned int *timebase) of_getprop(cpu, "timebase-frequency", timebase, 4); } -int glue_init(unsigned int * timebase, - size_t _client_start, size_t _client_size) +int of_glue_init(unsigned int * timebase, + size_t _client_start, size_t _client_size) { phandle_t chosen = of_finddevice("/chosen"); + ihandle_t stdin, stdout; client_start = (void *) (long) _client_start; client_size = _client_size; @@ -742,25 +694,10 @@ int glue_init(unsigned int * timebase, if (chosen == -1) return -1; - fd_array[0].type = FILEIO_TYPE_USED; - fd_array[0].read = of_fileio_read; - fd_array[0].write = of_fileio_write; - fd_array[0].ioctl = 0; - fd_array[0].close = of_fileio_close; - fd_array[0].data = &fd_ihandle_array[0]; - of_getprop(chosen, "stdin", fd_array[0].data, sizeof(ihandle_t)); - - fd_array[1].type = FILEIO_TYPE_USED; - fd_array[1].read = of_fileio_read; - fd_array[1].write = of_fileio_write; - fd_array[1].ioctl = 0; - fd_array[1].close = of_fileio_close; - fd_array[1].data = &fd_ihandle_array[1]; - of_getprop(chosen, "stdout", fd_array[1].data, sizeof(ihandle_t)); - - if (of_write(fd_ihandle_array[1], " ", 1) < 0) - return -2; - + of_getprop(chosen, "stdin", &stdin, sizeof(ihandle_t)); + of_getprop(chosen, "stdout", &stdout, sizeof(ihandle_t)); + pre_open_ih(0, stdin); + pre_open_ih(1, stdout); get_timebase(timebase); rtas_init(); @@ -769,60 +706,9 @@ int glue_init(unsigned int * timebase, return 0; } -void -glue_release(void) +void of_glue_release(void) { if (claim_rc >= 0) { of_release(client_start, client_size); } } - -static int -ofmod_init(void) -{ - of_module.running = 1; - return 0; -} - -static int -ofmod_term(void) -{ - of_module.running = 0; - return 0; -} - -static int -ofmod_open(snk_fileio_t *fileio, const char* name, int flags) -{ - if ((fd_ihandle_array[fileio->idx] = of_open (name)) == 0) - { - /* this module can not open this file */ - return -1; - } - - fileio->type = FILEIO_TYPE_USED; - fileio->read = of_fileio_read; - fileio->write = of_fileio_write; - fileio->close = of_fileio_close; - fileio->data = &fd_ihandle_array[fileio->idx]; - return 0; -} - -static int -ofmod_read(char *buffer, int len) -{ - return len; -} - -static int -ofmod_write(char *buffer, int len) -{ - return len; -} - -static int -ofmod_ioctl(int request, void *data) -{ - return 0; -} - diff --git a/clients/net-snk/oflib/rtas.c b/clients/net-snk/oflib/rtas.c index 1efb153..88d49c6 100644 --- a/clients/net-snk/oflib/rtas.c +++ b/clients/net-snk/oflib/rtas.c @@ -15,7 +15,6 @@ #include #include #include -#include #include typedef int rtas_arg_t;