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 <benh@kernel.crashing.org>
This commit is contained in:
Benjamin Herrenschmidt 2014-07-15 11:45:54 +10:00 committed by Nikunj A Dadhania
parent a7a11bcf51
commit 6495aef5b6
15 changed files with 121 additions and 639 deletions

View File

@ -12,40 +12,18 @@
#ifndef FILEIO_H
#define FILEIO_H
#include <sys/socket.h>
struct snk_fileio_type;
typedef struct snk_fileio_type snk_fileio_t;
#include <of.h>
#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];

View File

@ -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

View File

@ -15,6 +15,8 @@
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include <of.h>
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);

View File

@ -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 <stddef.h>
#include <unistd.h> /* ssize_t */
#include <fileio.h>
#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 */

View File

@ -14,6 +14,7 @@
#define OF_H
#include <stdint.h>
#include <stddef.h>
#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

View File

@ -13,7 +13,7 @@
#ifndef _PCI_H
#define _PCI_H
#include <netdriver_int.h>
#include <of.h>
int pci_calc_bar_size (long long puid, int bus, int devfn, int bar);

View File

@ -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

View File

@ -18,8 +18,6 @@
#include <kernel.h>
#include <cpu.h>
#include <fileio.h>
#include <ioctl.h> /* 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<FILEIO_MAX; ++rc) {
for(rc=0; rc<FILEIO_MAX; ++rc)
fd_array[rc].type = FILEIO_TYPE_EMPTY;
fd_array[rc].idx = rc;
}
/* this is step is e.g. resposible to initialize file descriptor 0 and 1 for STDIO */
rc = glue_init(&timebase, (size_t)(unsigned long)&__client_start,
(size_t)(unsigned long)&__client_end - (size_t)(unsigned long)&__client_start);
rc = of_glue_init(&timebase, (size_t)(unsigned long)&__client_start,
(size_t)(unsigned long)&__client_end - (size_t)(unsigned long)&__client_start);
if(rc < 0)
return -1;
tb_freq = (uint64_t) timebase;
modules_init();
rc = _start((unsigned char *) p0, p1);
modules_term();
glue_release();
of_glue_release();
return rc;
}

View File

@ -1,82 +0,0 @@
/******************************************************************************
* Copyright (c) 2004, 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
*****************************************************************************/
#include <netdriver_int.h>
#include <kernel.h>
#include <of.h>
#include <rtas.h>
#include <libelf.h>
#include <cpu.h> /* flush_cache */
#include <unistd.h> /* open, close, read, write */
#include <stdio.h>
#include <pci.h>
#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; i<MODULES_MAX; ++i) {
snk_modules[i] = 0;
}
/* Try to init client-interface module (it's built-in, not loadable) */
for(i=0; i<MODULES_MAX; ++i) {
if(snk_modules[i] == 0) {
snk_modules[i] = cimod_check_and_install();
break;
}
}
}
void
modules_term(void)
{
int i;
/* remove all modules */
for(i=0; i<MODULES_MAX; ++i) {
if(snk_modules[i] && snk_modules[i]->running != 0) {
snk_modules[i]->term();
}
snk_modules[i] = 0;
}
}
snk_module_t *
get_module_by_type(int type) {
int i;
for(i=0; i<MODULES_MAX; ++i) {
if(snk_modules[i] && snk_modules[i]->type == type) {
return snk_modules[i];
}
}
return 0;
}

View File

@ -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);

View File

@ -13,11 +13,10 @@
#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <of.h>
#include <netdriver_int.h>
#include <fileio.h>
#include <ioctl.h>
#include "modules.h"
#include <kernel.h>
#include <of.h>
#include <sys/socket.h>
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; fd<FILEIO_MAX; ++fd) {
for (fd=0; fd<FILEIO_MAX; ++fd) {
if(fd_array[fd].type == FILEIO_TYPE_EMPTY) {
break;
}
}
if(fd == FILEIO_MAX) {
if (fd == FILEIO_MAX) {
printk ("Can not open \"%s\" because file descriptor list is full\n", name);
/* there is no free file descriptor available */
return -2;
}
for(i=0; i<MODULES_MAX; ++i) {
if(!snk_modules[i] || !snk_modules[i]->open) {
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; fd<FILEIO_MAX; ++fd) {
if(fd_array[fd].type == FILEIO_TYPE_EMPTY) {
break;
}
}
if (fd == FILEIO_MAX) {
printk ("Can not open socket, file descriptor list is full\n");
/* there is no free file descriptor available */
return -2;
}
fd_array[fd].ih = of_interpret_1("my-parent", tmpbuf);
if (fd_array[fd].ih == 0) {
printk ("Can not open socket, no parent instance\n");
return -1;
}
/* Init net device driver */
if(net_module->running == 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,

View File

@ -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

View File

@ -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 <of.h>
#include <string.h>
#include <netdriver_int.h>
#include <fileio.h>
#include <stdint.h>
#include <kernel.h>
#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;
}

View File

@ -14,36 +14,11 @@
#include <of.h>
#include <rtas.h>
#include <string.h>
#include <netdriver_int.h>
#include <fileio.h>
#include <libbootmsg.h>
#include <kernel.h>
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;
}

View File

@ -15,7 +15,6 @@
#include <stdio.h>
#include <rtas.h>
#include <of.h>
#include <netdriver_int.h>
#include <kernel.h>
typedef int rtas_arg_t;