From 6956dd2b516c6d226afb5b4ae854532a02fcbd3d Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Wed, 5 Oct 2016 17:37:56 +0000 Subject: [PATCH 01/12] libc: bugfixes for minix's poll(3) wrapper - clear "revents" fields even when the call times out; - do not call FD_ISSET with a negative file descriptor number. Change-Id: I7aeaae79e73e39aed127a75495ea08256b18c182 --- minix/lib/libc/sys/poll.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/minix/lib/libc/sys/poll.c b/minix/lib/libc/sys/poll.c index 72fe6238e..8735833c2 100644 --- a/minix/lib/libc/sys/poll.c +++ b/minix/lib/libc/sys/poll.c @@ -57,6 +57,7 @@ poll(struct pollfd *p, nfds_t nfds, int timout) highfd = -1; for (i = 0; i < nfds; i++) { + p[i].revents = 0; if (p[i].fd < 0) continue; if (p[i].fd >= FD_SETSIZE) { @@ -83,7 +84,8 @@ poll(struct pollfd *p, nfds_t nfds, int timout) rval = 0; for (i = 0; i < nfds; i++) { - p[i].revents = 0; + if (p[i].fd < 0) + continue; if (FD_ISSET(p[i].fd, &rd)) p[i].revents |= POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI; if (FD_ISSET(p[i].fd, &wr)) From 4aa48abab95b2c3bef55ef84ec4b7c49368fb6f8 Mon Sep 17 00:00:00 2001 From: Richard Sailer Date: Tue, 4 Oct 2016 00:18:35 +0200 Subject: [PATCH 02/12] is: Convert K&R C -> ANSI C Aditionally this removes all trailing whitespaces using: sed -i 's/[[:space:]]*$//' *.c Change-Id: I274fccee9ec320e474ac26fbe19f3bd50bec271a --- minix/servers/is/dmp.c | 12 ++++----- minix/servers/is/dmp_ds.c | 3 ++- minix/servers/is/dmp_fs.c | 12 +++++---- minix/servers/is/dmp_kernel.c | 49 ++++++++++++++++++++--------------- minix/servers/is/dmp_pm.c | 18 +++++++------ minix/servers/is/dmp_rs.c | 5 ++-- minix/servers/is/dmp_vm.c | 5 ++-- minix/servers/is/main.c | 30 +++++++++++---------- 8 files changed, 76 insertions(+), 58 deletions(-) diff --git a/minix/servers/is/dmp.c b/minix/servers/is/dmp.c index 64e08b99e..487f97e6e 100644 --- a/minix/servers/is/dmp.c +++ b/minix/servers/is/dmp.c @@ -1,7 +1,7 @@ -/* This file contains information dump procedures. During the initialization +/* This file contains information dump procedures. During the initialization * of the Information Service 'known' function keys are registered at the TTY - * server in order to receive a notification if one is pressed. Here, the - * corresponding dump procedure is called. + * server in order to receive a notification if one is pressed. Here, the + * corresponding dump procedure is called. * * The entry points into this file are * map_unmap_fkeys: register or unregister function key maps with TTY @@ -42,8 +42,8 @@ struct hook_entry { /*===========================================================================* * map_unmap_keys * *===========================================================================*/ -void map_unmap_fkeys(map) -int map; +void +map_unmap_fkeys(int map) { int fkeys, sfkeys; int h, s; @@ -51,7 +51,7 @@ int map; fkeys = sfkeys = 0; for (h = 0; h < NHOOKS; h++) { - if (hooks[h].key >= F1 && hooks[h].key <= F12) + if (hooks[h].key >= F1 && hooks[h].key <= F12) bit_set(fkeys, hooks[h].key - F1 + 1); else if (hooks[h].key >= SF1 && hooks[h].key <= SF12) bit_set(sfkeys, hooks[h].key - SF1 + 1); diff --git a/minix/servers/is/dmp_ds.c b/minix/servers/is/dmp_ds.c index 795c52317..9f7b0e6db 100644 --- a/minix/servers/is/dmp_ds.c +++ b/minix/servers/is/dmp_ds.c @@ -5,7 +5,8 @@ static struct data_store noxfer_ds_store[NR_DS_KEYS]; -void data_store_dmp() +void +data_store_dmp(void) { struct data_store *p; static int prev_i = 0; diff --git a/minix/servers/is/dmp_fs.c b/minix/servers/is/dmp_fs.c index 5a9ad8fb3..0ed191736 100644 --- a/minix/servers/is/dmp_fs.c +++ b/minix/servers/is/dmp_fs.c @@ -1,8 +1,8 @@ /* This file contains procedures to dump to FS' data structures. * * The entry points into this file are - * dtab_dump: display device <-> driver mappings - * fproc_dump: display FS process table + * dtab_dump: display device <-> driver mappings + * fproc_dump: display FS process table * * Created: * Oct 01, 2004: by Jorrit N. Herder @@ -21,7 +21,8 @@ struct dmap dmap[NR_DEVICES]; /*===========================================================================* * fproc_dmp * *===========================================================================*/ -void fproc_dmp() +void +fproc_dmp(void) { struct fproc *fp; int i, j, nfds, n=0; @@ -61,7 +62,8 @@ void fproc_dmp() /*===========================================================================* * dtab_dmp * *===========================================================================*/ -void dtab_dmp() +void +dtab_dmp(void) { int i; @@ -69,7 +71,7 @@ void dtab_dmp() printf("Error obtaining table from VFS. Perhaps recompile IS?\n"); return; } - + printf("File System (FS) device <-> driver mappings\n"); printf(" Label Major Driver ept\n"); printf("------------- ----- ----------\n"); diff --git a/minix/servers/is/dmp_kernel.c b/minix/servers/is/dmp_kernel.c index ac35aea6d..3b0002de4 100644 --- a/minix/servers/is/dmp_kernel.c +++ b/minix/servers/is/dmp_kernel.c @@ -48,7 +48,7 @@ static char *s_traps_str(int flags); static char *s_flags_str(int flags); static char *p_rts_flags_str(int flags); -/* Some global data that is shared among several dumping procedures. +/* Some global data that is shared among several dumping procedures. * Note that the process table copy has the same name as in the kernel * so that most macros and definitions from proc.h also apply here. */ @@ -59,7 +59,8 @@ struct boot_image image[NR_BOOT_PROCS]; /*===========================================================================* * kmessages_dmp * *===========================================================================*/ -void kmessages_dmp() +void +kmessages_dmp(void) { struct kmessages *kmess; /* get copy of kernel messages */ static char print_buf[_KMESS_BUF_SIZE+1]; /* this one is used to print */ @@ -82,14 +83,15 @@ void kmessages_dmp() size--; } print_buf[r] = 0; /* make sure it terminates */ - printf("Dump of all messages generated by the kernel.\n\n"); + printf("Dump of all messages generated by the kernel.\n\n"); printf("%s", print_buf); /* print the messages */ } /*===========================================================================* * monparams_dmp * *===========================================================================*/ -void monparams_dmp() +void +monparams_dmp(void) { char val[MULTIBOOT_PARAM_BUF_SIZE]; char *e; @@ -106,7 +108,7 @@ void monparams_dmp() do { e += strlen(e); *e++ = '\n'; - } while (*e != 0); + } while (*e != 0); /* Finally, print the result. */ printf("Dump of kernel environment strings set by boot monitor.\n"); @@ -116,7 +118,8 @@ void monparams_dmp() /*===========================================================================* * irqtab_dmp * *===========================================================================*/ -void irqtab_dmp() +void +irqtab_dmp(void) { int i,r; struct irq_hook irq_hooks[NR_IRQ_HOOKS]; @@ -148,8 +151,8 @@ void irqtab_dmp() printf(" \n"); continue; } - printf("%10d ", e->proc_nr_e); - printf(" (%02d) ", e->irq); + printf("%10d ", e->proc_nr_e); + printf(" (%02d) ", e->irq); printf(" %s", (e->policy & IRQ_REENABLE) ? "reenable" : " - "); printf(" %4lu", e->notify_id); if (irq_actids[e->irq] & e->id) @@ -162,18 +165,19 @@ void irqtab_dmp() /*===========================================================================* * image_dmp * *===========================================================================*/ -void image_dmp() +void +image_dmp(void) { int m, r; struct boot_image *ip; - + if ((r = sys_getimage(image)) != OK) { printf("IS: warning: couldn't get copy of image table: %d\n", r); return; } printf("Image table dump showing all processes included in system image.\n"); printf("---name- -nr- flags -stack-\n"); - for (m=0; mproc_name, ip->proc_nr); } @@ -184,7 +188,8 @@ void image_dmp() /*===========================================================================* * kenv_dmp * *===========================================================================*/ -void kenv_dmp() +void +kenv_dmp(void) { struct kinfo kinfo; struct machine machine; @@ -200,10 +205,10 @@ void kenv_dmp() printf("Dump of kinfo structure.\n\n"); printf("Kernel info structure:\n"); - printf("- nr_procs: %3u\n", kinfo.nr_procs); - printf("- nr_tasks: %3u\n", kinfo.nr_tasks); - printf("- release: %.6s\n", kinfo.release); - printf("- version: %.6s\n", kinfo.version); + printf("- nr_procs: %3u\n", kinfo.nr_procs); + printf("- nr_tasks: %3u\n", kinfo.nr_tasks); + printf("- release: %.6s\n", kinfo.release); + printf("- version: %.6s\n", kinfo.version); printf("\n"); } @@ -244,7 +249,8 @@ static char *s_traps_str(int flags) /*===========================================================================* * privileges_dmp * *===========================================================================*/ -void privileges_dmp() +void +privileges_dmp(void) { register struct proc *rp; static struct proc *oldrp = BEG_PROC_ADDR; @@ -266,7 +272,7 @@ void privileges_dmp() PROCLOOP(rp, oldrp) r = -1; - for (sp = &priv[0]; sp < &priv[NR_SYS_PROCS]; sp++) + for (sp = &priv[0]; sp < &priv[NR_SYS_PROCS]; sp++) if (sp->s_proc_nr == rp->p_nr) { r ++; break; } if (r == -1 && !isemptyp(rp)) { sp = &priv[USER_PRIV_ID]; @@ -349,7 +355,8 @@ void proctab_dmp(void) /*===========================================================================* * procstack_dmp * *===========================================================================*/ -void procstack_dmp() +void +procstack_dmp(void) { /* Proc table dump, with stack */ @@ -375,8 +382,8 @@ void procstack_dmp() /*===========================================================================* * proc_name * *===========================================================================*/ -static char *proc_name(proc_nr) -int proc_nr; +static char * +proc_name(int proc_nr) { struct proc *p; if (proc_nr == ANY) return "ANY"; diff --git a/minix/servers/is/dmp_pm.c b/minix/servers/is/dmp_pm.c index a2c9d15fb..ae852b5e1 100644 --- a/minix/servers/is/dmp_pm.c +++ b/minix/servers/is/dmp_pm.c @@ -1,7 +1,7 @@ /* This file contains procedures to dump to PM' data structures. * * The entry points into this file are - * mproc_dmp: display PM process table + * mproc_dmp: display PM process table * * Created: * May 11, 2005: by Jorrit N. Herder @@ -10,8 +10,8 @@ #include "inc.h" #include "../pm/mproc.h" #include -#include -#include +#include +#include struct mproc mproc[NR_PROCS]; @@ -37,7 +37,8 @@ static char *flags_str(int flags) return str; } -void mproc_dmp() +void +mproc_dmp(void) { struct mproc *mp; int i, n=0; @@ -54,12 +55,12 @@ void mproc_dmp() mp = &mproc[i]; if (mp->mp_pid == 0 && i != PM_PROC_NR) continue; if (++n > 22) break; - printf("%8.8s %4d%4d%4d %5d %5d %5d ", + printf("%8.8s %4d%4d%4d %5d %5d %5d ", mp->mp_name, i, mp->mp_parent, mp->mp_tracer, mp->mp_pid, mproc[mp->mp_parent].mp_pid, mp->mp_procgrp); printf("%2d(%2d) %2d(%2d) ", mp->mp_realuid, mp->mp_effuid, mp->mp_realgid, mp->mp_effgid); - printf(" %3d %s ", - mp->mp_nice, flags_str(mp->mp_flags)); + printf(" %3d %s ", + mp->mp_nice, flags_str(mp->mp_flags)); printf("\n"); } if (i >= NR_PROCS) i = 0; @@ -70,7 +71,8 @@ void mproc_dmp() /*===========================================================================* * sigaction_dmp * *===========================================================================*/ -void sigaction_dmp() +void +sigaction_dmp(void) { struct mproc *mp; int i, n=0; diff --git a/minix/servers/is/dmp_rs.c b/minix/servers/is/dmp_rs.c index 1562590d7..091cccdbd 100644 --- a/minix/servers/is/dmp_rs.c +++ b/minix/servers/is/dmp_rs.c @@ -1,7 +1,7 @@ /* This file contains procedures to dump RS data structures. * * The entry points into this file are - * rproc_dump: display RS system process table + * rproc_dump: display RS system process table * * Created: * Oct 03, 2005: by Jorrit N. Herder @@ -22,7 +22,8 @@ static char *s_flags_str(int flags, int sys_flags); /*===========================================================================* * rproc_dmp * *===========================================================================*/ -void rproc_dmp() +void +rproc_dmp(void) { struct rproc *rp; struct rprocpub *rpub; diff --git a/minix/servers/is/dmp_vm.c b/minix/servers/is/dmp_vm.c index c94459935..bbfbbc8a7 100644 --- a/minix/servers/is/dmp_vm.c +++ b/minix/servers/is/dmp_vm.c @@ -17,7 +17,7 @@ static void print_region(struct vm_region_info *vri, int *n) /* part of a contiguous identical run? */ is_repeat = vri && - vri_prev_set && + vri_prev_set && vri->vri_prot == vri_prev.vri_prot && vri->vri_flags == vri_prev.vri_flags && vri->vri_length == vri_prev.vri_length && @@ -51,7 +51,8 @@ static void print_region(struct vm_region_info *vri, int *n) (*n)++; } -void vm_dmp() +void +vm_dmp(void) { static struct proc proc[NR_TASKS + NR_PROCS]; static struct vm_region_info vri[LINES]; diff --git a/minix/servers/is/main.c b/minix/servers/is/main.c index 759a4822d..d917b1fc5 100644 --- a/minix/servers/is/main.c +++ b/minix/servers/is/main.c @@ -1,8 +1,8 @@ -/* System Information Service. +/* System Information Service. * This service handles the various debugging dumps, such as the process - * table, so that these no longer directly touch kernel memory. Instead, the - * system task is asked to copy some table in local memory. - * + * table, so that these no longer directly touch kernel memory. Instead, the + * system task is asked to copy some table in local memory. + * * Created: * Apr 29, 2004 by Jorrit N. Herder */ @@ -30,18 +30,18 @@ static void sef_cb_signal_handler(int signo); *===========================================================================*/ int main(int argc, char **argv) { -/* This is the main routine of this service. The main loop consists of +/* This is the main routine of this service. The main loop consists of * three major activities: getting new work, processing the work, and * sending the reply. The loop never terminates, unless a panic occurs. */ - int result; + int result; /* SEF local startup. */ env_setargs(argc, argv); sef_local_startup(); - /* Main loop - get work and do it, forever. */ - while (TRUE) { + /* Main loop - get work and do it, forever. */ + while (TRUE) { /* Wait for incoming message, sets 'callnr' and 'who'. */ get_work(); @@ -73,7 +73,8 @@ int main(int argc, char **argv) /*===========================================================================* * sef_local_startup * *===========================================================================*/ -static void sef_local_startup() +static void +sef_local_startup(void) { /* Register init callbacks. */ sef_setcb_init_fresh(sef_cb_init_fresh); @@ -117,7 +118,8 @@ static void sef_cb_signal_handler(int signo) /*===========================================================================* * get_work * *===========================================================================*/ -static void get_work() +static void +get_work(void) { int status = 0; status = sef_receive(ANY, &m_in); /* this blocks until message arrives */ @@ -130,9 +132,11 @@ static void get_work() /*===========================================================================* * reply * *===========================================================================*/ -static void reply(who, result) -int who; /* destination */ -int result; /* report result to replyee */ +static void +reply( + int who, /* destination */ + int result /* report result to replyee */ +) { int send_status; m_out.m_type = result; /* build reply message */ From a0814afb2e128f52ed10c9a5d4c91bf6abc22290 Mon Sep 17 00:00:00 2001 From: Richard Sailer Date: Tue, 4 Oct 2016 00:27:02 +0200 Subject: [PATCH 03/12] VFS: Convert K&R C -> ANSI C Aditionally this removes all trailing whitespaces using: sed -i 's/[[:space:]]*$//' *.c Change-Id: I88451fdb6f6e79e61f8aae5bd5a7f2e3538f9944 --- minix/servers/vfs/exec.c | 6 +++--- minix/servers/vfs/filedes.c | 36 ++++++++++++++++--------------- minix/servers/vfs/link.c | 15 ++++++------- minix/servers/vfs/lock.c | 3 ++- minix/servers/vfs/main.c | 4 ++-- minix/servers/vfs/misc.c | 29 +++++++++++-------------- minix/servers/vfs/open.c | 5 ++--- minix/servers/vfs/path.c | 42 +++++++++++++------------------------ minix/servers/vfs/pipe.c | 5 ++--- minix/servers/vfs/protect.c | 6 ++++-- minix/servers/vfs/request.c | 34 +++++++++++------------------- minix/servers/vfs/select.c | 15 +++++++------ minix/servers/vfs/vmnt.c | 3 ++- minix/servers/vfs/vnode.c | 6 ++++-- 14 files changed, 93 insertions(+), 116 deletions(-) diff --git a/minix/servers/vfs/exec.c b/minix/servers/vfs/exec.c index 9f67a0e1d..24704f08a 100644 --- a/minix/servers/vfs/exec.c +++ b/minix/servers/vfs/exec.c @@ -295,7 +295,7 @@ int pm_exec(vir_bytes path, size_t path_len, vir_bytes frame, size_t frame_len, } /* ld.so is linked at 0, but it can relocate itself; we - * want it higher to trap NULL pointer dereferences. + * want it higher to trap NULL pointer dereferences. * Let's put it below the stack, and reserve 10MB for ld.so. */ execi.args.load_offset = @@ -435,12 +435,12 @@ static int stack_prepare_elf(struct vfs_exec_info *execi, char *frame, size_t *f return ENOEXEC; } - /* Find first Aux vector in the stack frame. */ + /* Find first Aux vector in the stack frame. */ vap = (vir_bytes)(psp->ps_envstr + (psp->ps_nenvstr + 1)); aux_vec = (AuxInfo *) (frame + (vap - *vsp)); aux_vec_end = aux_vec + PMEF_AUXVECTORS; - if (((char *)aux_vec < frame) || + if (((char *)aux_vec < frame) || ((char *)aux_vec > (frame + *frame_size))) { printf("VFS: malformed stack for exec(), first AuxVector is" " not on the stack.\n"); diff --git a/minix/servers/vfs/filedes.c b/minix/servers/vfs/filedes.c index 13bd6c8b6..1233dd9dd 100644 --- a/minix/servers/vfs/filedes.c +++ b/minix/servers/vfs/filedes.c @@ -137,9 +137,11 @@ int get_fd(struct fproc *rfp, int start, mode_t bits, int *k, struct filp **fpt) /*===========================================================================* * get_filp * *===========================================================================*/ -struct filp *get_filp(fild, locktype) -int fild; /* file descriptor */ -tll_access_t locktype; +struct filp * +get_filp( + int fild, /* file descriptor */ + tll_access_t locktype +) { /* See if 'fild' refers to a valid file descr. If so, return its filp ptr. */ @@ -150,10 +152,12 @@ tll_access_t locktype; /*===========================================================================* * get_filp2 * *===========================================================================*/ -struct filp *get_filp2(rfp, fild, locktype) -register struct fproc *rfp; -int fild; /* file descriptor */ -tll_access_t locktype; +struct filp * +get_filp2( + register struct fproc *rfp, + int fild, /* file descriptor */ + tll_access_t locktype +) { /* See if 'fild' refers to a valid file descr. If so, return its filp ptr. */ struct filp *filp; @@ -242,9 +246,8 @@ void invalidate_filp_by_endpt(endpoint_t proc_e) /*===========================================================================* * lock_filp * *===========================================================================*/ -void lock_filp(filp, locktype) -struct filp *filp; -tll_access_t locktype; +void +lock_filp(struct filp *filp, tll_access_t locktype) { struct worker_thread *org_self; struct vnode *vp; @@ -287,8 +290,8 @@ tll_access_t locktype; /*===========================================================================* * unlock_filp * *===========================================================================*/ -void unlock_filp(filp) -struct filp *filp; +void +unlock_filp(struct filp *filp) { /* If this filp holds a soft lock on the vnode, we must be the owner */ if (filp->filp_softlock != NULL) @@ -312,9 +315,8 @@ struct filp *filp; /*===========================================================================* * unlock_filps * *===========================================================================*/ -void unlock_filps(filp1, filp2) -struct filp *filp1; -struct filp *filp2; +void +unlock_filps(struct filp *filp1, struct filp *filp2) { /* Unlock two filps that are tied to the same vnode. As a thread can lock a * vnode only once, unlocking the vnode twice would result in an error. */ @@ -344,8 +346,8 @@ struct filp *filp2; /*===========================================================================* * close_filp * *===========================================================================*/ -void close_filp(f) -struct filp *f; +void +close_filp(struct filp *f) { /* Close a file. Will also unlock filp when done */ diff --git a/minix/servers/vfs/link.c b/minix/servers/vfs/link.c index ea6124c39..129a80595 100644 --- a/minix/servers/vfs/link.c +++ b/minix/servers/vfs/link.c @@ -362,9 +362,8 @@ int do_ftruncate(void) /*===========================================================================* * truncate_vnode * *===========================================================================*/ -int truncate_vnode(vp, newsize) -struct vnode *vp; -off_t newsize; +int +truncate_vnode(struct vnode *vp, off_t newsize) { /* Truncate a regular file or a pipe */ int r; @@ -427,10 +426,12 @@ int do_slink(void) /*===========================================================================* * rdlink_direct * *===========================================================================*/ -int rdlink_direct(orig_path, link_path, rfp) -char *orig_path; -char link_path[PATH_MAX]; /* should have length PATH_MAX */ -struct fproc *rfp; +int +rdlink_direct( + char *orig_path, + char link_path[PATH_MAX], /* should have length PATH_MAX */ + struct fproc *rfp +) { /* Perform a readlink()-like call from within the VFS */ int r; diff --git a/minix/servers/vfs/lock.c b/minix/servers/vfs/lock.c index 8cf341934..20d410265 100644 --- a/minix/servers/vfs/lock.c +++ b/minix/servers/vfs/lock.c @@ -169,7 +169,8 @@ int lock_op(int fd, int req, vir_bytes arg) /*===========================================================================* * lock_revive * *===========================================================================*/ -void lock_revive() +void +lock_revive(void) { /* Go find all the processes that are waiting for any kind of lock and * revive them all. The ones that are still blocked will block again when diff --git a/minix/servers/vfs/main.c b/minix/servers/vfs/main.c index b690ffd33..9be33245e 100644 --- a/minix/servers/vfs/main.c +++ b/minix/servers/vfs/main.c @@ -915,8 +915,8 @@ static void service_pm(void) /*===========================================================================* * unblock * *===========================================================================*/ -static int unblock(rfp) -struct fproc *rfp; +static int +unblock(struct fproc *rfp) { /* Unblock a process that was previously blocked on a pipe or a lock. This is * done by reconstructing the original request and continuing/repeating it. diff --git a/minix/servers/vfs/misc.c b/minix/servers/vfs/misc.c index d7e30bb94..54ed7ad0f 100644 --- a/minix/servers/vfs/misc.c +++ b/minix/servers/vfs/misc.c @@ -496,7 +496,8 @@ reqdone: /*===========================================================================* * pm_reboot * *===========================================================================*/ -void pm_reboot() +void +pm_reboot(void) { /* Perform the VFS side of the reboot call. This call is performed from the PM * process context. @@ -709,10 +710,8 @@ void pm_exit(void) /*===========================================================================* * pm_setgid * *===========================================================================*/ -void pm_setgid(proc_e, egid, rgid) -endpoint_t proc_e; -int egid; -int rgid; +void +pm_setgid(endpoint_t proc_e, int egid, int rgid) { register struct fproc *tfp; int slot; @@ -728,10 +727,8 @@ int rgid; /*===========================================================================* * pm_setgroups * *===========================================================================*/ -void pm_setgroups(proc_e, ngroups, groups) -endpoint_t proc_e; -int ngroups; -gid_t *groups; +void +pm_setgroups(endpoint_t proc_e, int ngroups, gid_t *groups) { struct fproc *rfp; int slot; @@ -751,10 +748,8 @@ gid_t *groups; /*===========================================================================* * pm_setuid * *===========================================================================*/ -void pm_setuid(proc_e, euid, ruid) -endpoint_t proc_e; -int euid; -int ruid; +void +pm_setuid(endpoint_t proc_e, int euid, int ruid) { struct fproc *tfp; int slot; @@ -973,11 +968,11 @@ ds_event(void) } /* A function to be called on panic(). */ -void panic_hook(void) -{ +void panic_hook(void) +{ printf("VFS mthread stacktraces:\n"); - mthread_stacktraces(); -} + mthread_stacktraces(); +} /*===========================================================================* * do_getrusage * diff --git a/minix/servers/vfs/open.c b/minix/servers/vfs/open.c index 4ace3b985..b5e3f8513 100644 --- a/minix/servers/vfs/open.c +++ b/minix/servers/vfs/open.c @@ -682,9 +682,8 @@ int do_close(void) /*===========================================================================* * close_fd * *===========================================================================*/ -int close_fd(rfp, fd_nr) -struct fproc *rfp; -int fd_nr; +int +close_fd(struct fproc *rfp, int fd_nr) { /* Perform the close(fd) system call. */ register struct filp *rfilp; diff --git a/minix/servers/vfs/path.c b/minix/servers/vfs/path.c index ffbc67d3d..21fab6f1a 100644 --- a/minix/servers/vfs/path.c +++ b/minix/servers/vfs/path.c @@ -39,10 +39,8 @@ static int check_perms(endpoint_t ep, cp_grant_id_t io_gr, size_t /*===========================================================================* * advance * *===========================================================================*/ -struct vnode *advance(dirp, resolve, rfp) -struct vnode *dirp; -struct lookup *resolve; -struct fproc *rfp; +struct vnode * +advance(struct vnode *dirp, struct lookup *resolve, struct fproc *rfp) { /* Resolve a path name starting at dirp to a vnode. */ int r; @@ -134,9 +132,8 @@ struct fproc *rfp; /*===========================================================================* * eat_path * *===========================================================================*/ -struct vnode *eat_path(resolve, rfp) -struct lookup *resolve; -struct fproc *rfp; +struct vnode * +eat_path(struct lookup *resolve, struct fproc *rfp) { /* Resolve path to a vnode. advance does the actual work. */ struct vnode *start_dir; @@ -148,9 +145,8 @@ struct fproc *rfp; /*===========================================================================* * last_dir * *===========================================================================*/ -struct vnode *last_dir(resolve, rfp) -struct lookup *resolve; -struct fproc *rfp; +struct vnode * +last_dir(struct lookup *resolve, struct fproc *rfp) { /* Parse a path, as far as the last directory, fetch the vnode * for the last directory into the vnode table, and return a pointer to the @@ -387,11 +383,8 @@ struct fproc *rfp; /*===========================================================================* * lookup * *===========================================================================*/ -static int lookup(start_node, resolve, result_node, rfp) -struct vnode *start_node; -struct lookup *resolve; -node_details_t *result_node; -struct fproc *rfp; +static int +lookup(struct vnode *start_node, struct lookup *resolve, node_details_t *result_node, struct fproc *rfp) { /* Resolve a path name relative to start_node. */ @@ -581,12 +574,8 @@ struct fproc *rfp; /*===========================================================================* * lookup_init * *===========================================================================*/ -void lookup_init(resolve, path, flags, vmp, vp) -struct lookup *resolve; -char *path; -int flags; -struct vmnt **vmp; -struct vnode **vp; +void +lookup_init(struct lookup *resolve, char *path, int flags, struct vmnt **vmp, struct vnode **vp) { assert(vmp != NULL); assert(vp != NULL); @@ -604,10 +593,8 @@ struct vnode **vp; /*===========================================================================* * get_name * *===========================================================================*/ -int get_name(dirp, entry, ename) -struct vnode *dirp; -struct vnode *entry; -char ename[NAME_MAX + 1]; +int +get_name(struct vnode *dirp, struct vnode *entry, char ename[NAME_MAX + 1]) { #define DIR_ENTRIES 8 #define DIR_ENTRY_SIZE (sizeof(struct dirent) + NAME_MAX) @@ -660,9 +647,8 @@ char ename[NAME_MAX + 1]; /*===========================================================================* * canonical_path * *===========================================================================*/ -int canonical_path(orig_path, rfp) -char orig_path[PATH_MAX]; -struct fproc *rfp; +int +canonical_path(char orig_path[PATH_MAX], struct fproc *rfp) { /* Find canonical path of a given path */ int len = 0; diff --git a/minix/servers/vfs/pipe.c b/minix/servers/vfs/pipe.c index 0b50c838a..bd89fedaa 100644 --- a/minix/servers/vfs/pipe.c +++ b/minix/servers/vfs/pipe.c @@ -147,9 +147,8 @@ static int create_pipe(int fil_des[2], int flags) /*===========================================================================* * map_vnode * *===========================================================================*/ -int map_vnode(vp, map_to_fs_e) -struct vnode *vp; -endpoint_t map_to_fs_e; +int +map_vnode(struct vnode *vp, endpoint_t map_to_fs_e) { int r; struct vmnt *vmp; diff --git a/minix/servers/vfs/protect.c b/minix/servers/vfs/protect.c index f36b71800..d94b98d5d 100644 --- a/minix/servers/vfs/protect.c +++ b/minix/servers/vfs/protect.c @@ -289,8 +289,10 @@ int forbidden(struct fproc *rfp, struct vnode *vp, mode_t access_desired) /*===========================================================================* * read_only * *===========================================================================*/ -int read_only(vp) -struct vnode *vp; /* ptr to inode whose file sys is to be cked */ +int +read_only( + struct vnode *vp /* ptr to inode whose file sys is to be cked */ +) { /* Check to see if the file system on which the inode 'ip' resides is mounted * read only. If so, return EROFS, else return OK. diff --git a/minix/servers/vfs/request.c b/minix/servers/vfs/request.c index e34874d35..19ae609b2 100644 --- a/minix/servers/vfs/request.c +++ b/minix/servers/vfs/request.c @@ -696,10 +696,8 @@ int req_newdriver( /*===========================================================================* * req_putnode * *===========================================================================*/ -int req_putnode(fs_e, inode_nr, count) -int fs_e; -ino_t inode_nr; -int count; +int +req_putnode(int fs_e, ino_t inode_nr, int count) { message m; @@ -925,12 +923,8 @@ int req_peek(endpoint_t fs_e, ino_t inode_nr, off_t pos, unsigned int bytes) /*===========================================================================* * req_rename * *===========================================================================*/ -int req_rename(fs_e, old_dir, old_name, new_dir, new_name) -endpoint_t fs_e; -ino_t old_dir; -char *old_name; -ino_t new_dir; -char *new_name; +int +req_rename(endpoint_t fs_e, ino_t old_dir, char *old_name, ino_t new_dir, char *new_name) { int r; cp_grant_id_t gid_old, gid_new; @@ -969,10 +963,8 @@ char *new_name; /*===========================================================================* * req_rmdir * *===========================================================================*/ -int req_rmdir(fs_e, inode_nr, lastc) -endpoint_t fs_e; -ino_t inode_nr; -char *lastc; +int +req_rmdir(endpoint_t fs_e, ino_t inode_nr, char *lastc) { int r; cp_grant_id_t grant_id; @@ -1138,8 +1130,8 @@ int req_stat(endpoint_t fs_e, ino_t inode_nr, endpoint_t proc_e, /*===========================================================================* * req_sync * *===========================================================================*/ -int req_sync(fs_e) -endpoint_t fs_e; +int +req_sync(endpoint_t fs_e) { message m; @@ -1154,10 +1146,8 @@ endpoint_t fs_e; /*===========================================================================* * req_unlink * *===========================================================================*/ -int req_unlink(fs_e, inode_nr, lastc) -endpoint_t fs_e; -ino_t inode_nr; -char *lastc; +int +req_unlink(endpoint_t fs_e, ino_t inode_nr, char *lastc) { cp_grant_id_t grant_id; size_t len; @@ -1186,8 +1176,8 @@ char *lastc; /*===========================================================================* * req_unmount * *===========================================================================*/ -int req_unmount(fs_e) -endpoint_t fs_e; +int +req_unmount(endpoint_t fs_e) { message m; diff --git a/minix/servers/vfs/select.c b/minix/servers/vfs/select.c index 92b852b54..c8347d0bb 100644 --- a/minix/servers/vfs/select.c +++ b/minix/servers/vfs/select.c @@ -582,7 +582,7 @@ static int copy_fdsets(struct selectentry *se, int nfds, int direction) src_fds = (direction == FROM_PROC) ? se->vir_readfds : &se->ready_readfds; dst_fds = (direction == FROM_PROC) ? &se->readfds : se->vir_readfds; if (se->vir_readfds) { - r = sys_datacopy_wrapper(src_e, (vir_bytes) src_fds, dst_e, + r = sys_datacopy_wrapper(src_e, (vir_bytes) src_fds, dst_e, (vir_bytes) dst_fds, fd_setsize); if (r != OK) return(r); } @@ -591,7 +591,7 @@ static int copy_fdsets(struct selectentry *se, int nfds, int direction) src_fds = (direction == FROM_PROC) ? se->vir_writefds : &se->ready_writefds; dst_fds = (direction == FROM_PROC) ? &se->writefds : se->vir_writefds; if (se->vir_writefds) { - r = sys_datacopy_wrapper(src_e, (vir_bytes) src_fds, dst_e, + r = sys_datacopy_wrapper(src_e, (vir_bytes) src_fds, dst_e, (vir_bytes) dst_fds, fd_setsize); if (r != OK) return(r); } @@ -600,7 +600,7 @@ static int copy_fdsets(struct selectentry *se, int nfds, int direction) src_fds = (direction == FROM_PROC) ? se->vir_errorfds : &se->ready_errorfds; dst_fds = (direction == FROM_PROC) ? &se->errorfds : se->vir_errorfds; if (se->vir_errorfds) { - r = sys_datacopy_wrapper(src_e, (vir_bytes) src_fds, dst_e, + r = sys_datacopy_wrapper(src_e, (vir_bytes) src_fds, dst_e, (vir_bytes) dst_fds, fd_setsize); if (r != OK) return(r); } @@ -1034,9 +1034,8 @@ static void select_restart_filps(void) /*===========================================================================* * filp_status * *===========================================================================*/ -static void filp_status(f, status) -struct filp *f; -int status; +static void +filp_status(struct filp *f, int status) { /* Tell processes that need to know about the status of this filp. This * function MUST NOT block its calling thread. @@ -1065,8 +1064,8 @@ int status; /*===========================================================================* * restart_proc * *===========================================================================*/ -static void restart_proc(se) -struct selectentry *se; +static void +restart_proc(struct selectentry *se) { /* Tell process about select results (if any) unless there are still results * pending. This function MUST NOT block its calling thread. diff --git a/minix/servers/vfs/vmnt.c b/minix/servers/vfs/vmnt.c index 7e17d204f..a262de167 100644 --- a/minix/servers/vfs/vmnt.c +++ b/minix/servers/vfs/vmnt.c @@ -41,7 +41,8 @@ void check_vmnt_locks_by_me(struct fproc *rfp) /*===========================================================================* * check_vmnt_locks * *===========================================================================*/ -void check_vmnt_locks() +void +check_vmnt_locks(void) { struct vmnt *vmp; int count = 0; diff --git a/minix/servers/vfs/vnode.c b/minix/servers/vfs/vnode.c index a45b3d885..73d63d2a5 100644 --- a/minix/servers/vfs/vnode.c +++ b/minix/servers/vfs/vnode.c @@ -61,7 +61,8 @@ void check_vnode_locks_by_me(struct fproc *rfp) /*===========================================================================* * check_vnode_locks * *===========================================================================*/ -void check_vnode_locks() +void +check_vnode_locks(void) { struct vnode *vp; int count = 0; @@ -80,7 +81,8 @@ void check_vnode_locks() /*===========================================================================* * get_free_vnode * *===========================================================================*/ -struct vnode *get_free_vnode() +struct vnode * +get_free_vnode(void) { /* Find a free vnode slot in the vnode table (it's not actually allocated) */ struct vnode *vp; From 702ec7400fb0580bac51ffbb217dd5d2b097d4d6 Mon Sep 17 00:00:00 2001 From: rlfnb Date: Fri, 14 Oct 2016 09:24:15 +0200 Subject: [PATCH 04/12] fixed git checkout and updated latest known changeset working for grub Change-Id: If4a1e8bfb42a20cf50d847105cc8f96c3cf1cd00 --- releasetools/image.functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasetools/image.functions b/releasetools/image.functions index de0c8c0d2..77e1d78e4 100644 --- a/releasetools/image.functions +++ b/releasetools/image.functions @@ -257,7 +257,7 @@ fetch_and_build_grub() git clone git://git.savannah.gnu.org/grub.git ${RELEASETOOLSDIR}/grub pushd ${RELEASETOOLSDIR}/grub # most recent known working commit at the time of writing - git clone b524fa27f56381bb0efa4944e36f50265113aee5 + git checkout a0bf403f66dbaca4edd8e667bfc397dd91c8d71c ./autogen.sh ./configure --with-platform=efi --target=i386 make clean From 022136b354f57076feaa8f0ae820cd578efdbad0 Mon Sep 17 00:00:00 2001 From: Jia-Ju Bai Date: Wed, 19 Oct 2016 10:11:26 +0000 Subject: [PATCH 05/12] Add the driver for VIA Technology 6105/6106S Ethernet card Change-Id: I690c34f0a37bcbb20a5b7748e3dd315707460caf --- distrib/sets/lists/minix-base/md.i386 | 2 + distrib/sets/lists/minix-debug/md.i386 | 1 + minix/drivers/net/Makefile | 1 + minix/drivers/net/vt6105/Makefile | 14 + minix/drivers/net/vt6105/vt6105.c | 807 +++++++++++++++++++++++++ minix/drivers/net/vt6105/vt6105.conf | 15 + minix/drivers/net/vt6105/vt6105.h | 194 ++++++ minix/fs/procfs/service.c | 1 + 8 files changed, 1035 insertions(+) create mode 100755 minix/drivers/net/vt6105/Makefile create mode 100644 minix/drivers/net/vt6105/vt6105.c create mode 100755 minix/drivers/net/vt6105/vt6105.conf create mode 100644 minix/drivers/net/vt6105/vt6105.h diff --git a/distrib/sets/lists/minix-base/md.i386 b/distrib/sets/lists/minix-base/md.i386 index 3280f85f5..52aa190aa 100644 --- a/distrib/sets/lists/minix-base/md.i386 +++ b/distrib/sets/lists/minix-base/md.i386 @@ -23,6 +23,7 @@ ./etc/system.conf.d/vbfs minix-base ./etc/system.conf.d/vbox minix-base ./etc/system.conf.d/virtio_net minix-base +./etc/system.conf.d/vt6105 minix-base ./service/3c90x minix-base ./service/acpi minix-base ./service/ahci minix-base @@ -53,6 +54,7 @@ ./service/vbox minix-base ./service/virtio_blk minix-base ./service/virtio_net minix-base +./service/vt6105 minix-base ./usr/lib/libhgfs.a minix-base ./usr/lib/libhgfs_pic.a minix-base ./usr/lib/libm387.a minix-base diff --git a/distrib/sets/lists/minix-debug/md.i386 b/distrib/sets/lists/minix-debug/md.i386 index 377a58e2c..ee66c819e 100644 --- a/distrib/sets/lists/minix-debug/md.i386 +++ b/distrib/sets/lists/minix-debug/md.i386 @@ -39,6 +39,7 @@ ./usr/libdata/debug/service/vbox.debug minix-debug debug ./usr/libdata/debug/service/virtio_blk.debug minix-debug debug ./usr/libdata/debug/service/virtio_net.debug minix-debug debug +./usr/libdata/debug/service/vt6105.debug minix-debug debug ./usr/libdata/debug/usr/lib/libm387.so.0.1.debug minix-debug debug ./usr/libdata/debug/usr/tests/minix-posix/test47.debug minix-debug debug ./usr/libdata/debug/usr/tests/minix-posix/test51.debug minix-debug debug diff --git a/minix/drivers/net/Makefile b/minix/drivers/net/Makefile index 51cf094f0..b8c4e479b 100644 --- a/minix/drivers/net/Makefile +++ b/minix/drivers/net/Makefile @@ -12,6 +12,7 @@ SUBDIR+= lance SUBDIR+= rtl8139 SUBDIR+= rtl8169 SUBDIR+= virtio_net +SUBDIR+= vt6105 .endif # ${MACHINE_ARCH} == "i386" .if ${MACHINE_ARCH} == "earm" diff --git a/minix/drivers/net/vt6105/Makefile b/minix/drivers/net/vt6105/Makefile new file mode 100755 index 000000000..8ac42452f --- /dev/null +++ b/minix/drivers/net/vt6105/Makefile @@ -0,0 +1,14 @@ +# Makefile for the VIA Technology 6105/6106S Ethernet driver (vt6105) +PROG= vt6105 +SRCS= vt6105.c + +FILES=${PROG}.conf +FILESNAME=${PROG} +FILESDIR= /etc/system.conf.d + +DPADD+= ${LIBNETDRIVER} ${LIBSYS} +LDADD+= -lnetdriver -lsys + +CPPFLAGS+= -I${NETBSDSRCDIR}/minix + +.include diff --git a/minix/drivers/net/vt6105/vt6105.c b/minix/drivers/net/vt6105/vt6105.c new file mode 100644 index 000000000..92b628977 --- /dev/null +++ b/minix/drivers/net/vt6105/vt6105.c @@ -0,0 +1,807 @@ +#include "vt6105.h" + +/* global value */ +static vt_driver g_driver; +static int g_instance; + +/* I/O function */ +static u8_t my_inb(u16_t port) { + u32_t value; + int r; + if ((r = sys_inb(port, &value)) != OK) + printf("VT6105: sys_inb failed: %d\n", r); + return (u8_t)value; +} +#define vt_inb(port, offset) (my_inb((port) + (offset))) + +static u16_t my_inw(u16_t port) { + u32_t value; + int r; + if ((r = sys_inw(port, &value)) != OK) + printf("VT6105: sys_inw failed: %d\n", r); + return (u16_t)value; +} +#define vt_inw(port, offset) (my_inw((port) + (offset))) + +static u32_t my_inl(u16_t port) { + u32_t value; + int r; + if ((r = sys_inl(port, &value)) != OK) + printf("VT6105: sys_inl failed: %d\n", r); + return value; +} +#define vt_inl(port, offset) (my_inl((port) + (offset))) + +static void my_outb(u16_t port, u8_t value) { + int r; + if ((r = sys_outb(port, value)) != OK) + printf("VT6105: sys_outb failed: %d\n", r); +} +#define vt_outb(port, offset, value) (my_outb((port) + (offset), (value))) + +static void my_outw(u16_t port, u16_t value) { + int r; + if ((r = sys_outw(port, value)) != OK) + printf("VT6105: sys_outw failed: %d\n", r); +} +#define vt_outw(port, offset, value) (my_outw((port) + (offset), (value))) + +static void my_outl(u16_t port, u32_t value) { + int r; + if ((r = sys_outl(port, value)) != OK) + printf("VT6105: sys_outl failed: %d\n", r); +} +#define vt_outl(port, offset, value) (my_outl((port) + (offset), (value))) + +/* driver interface */ +static int vt_init(unsigned int instance, ether_addr_t *addr); +static void vt_stop(void); +static void vt_mode(unsigned int mode); +static ssize_t vt_recv(struct netdriver_data *data, size_t max); +static int vt_send(struct netdriver_data *data, size_t size); +static void vt_intr(unsigned int mask); +static void vt_stat(eth_stat_t *stat); +static void vt_alarm(clock_t stamp); + +static int vt_probe(vt_driver *pdev, int instance); +static int vt_init_buf(vt_driver *pdev); +static int vt_init_hw(vt_driver *pdev, ether_addr_t *addr); +static void vt_reset_hw(vt_driver *pdev); +static void vt_power_init(vt_driver *pdev); +static void vt_conf_addr(vt_driver *pdev, ether_addr_t *addr); +static void vt_check_link(vt_driver *pdev); +static void vt_handler(vt_driver *pdev); +static void vt_check_ints(vt_driver *pdev); + +static const struct netdriver vt_table = { + .ndr_init = vt_init, + .ndr_stop = vt_stop, + .ndr_mode = vt_mode, + .ndr_recv = vt_recv, + .ndr_send = vt_send, + .ndr_stat = vt_stat, + .ndr_intr = vt_intr, + .ndr_alarm = vt_alarm +}; + +int main(int argc, char *argv[]) { + env_setargs(argc, argv); + netdriver_task(&vt_table); +} + +/* Initialize the driver */ +static int vt_init(unsigned int instance, ether_addr_t *addr) { + int ret = 0; + + /* Intialize driver data structure */ + memset(&g_driver, 0, sizeof(g_driver)); + g_driver.vt_link = VT_LINK_UNKNOWN; + strcpy(g_driver.vt_name, "vt6105#0"); + g_driver.vt_name[7] += instance; + g_instance = instance; + + /* Probe the device */ + if (vt_probe(&g_driver, instance)) { + printf("VT6105: Device is not found!\n"); + ret = -ENODEV; + goto err_probe; + } + + /* Allocate and initialize buffer */ + if (vt_init_buf(&g_driver)) { + printf("VT6105: Device is not found!\n"); + ret = -ENODEV; + goto err_init_buf; + } + + /* Intialize hardware */ + if (vt_init_hw(&g_driver, addr)) { + printf("VT6105: Find to initialize hardware!\n"); + ret = -EIO; + goto err_init_hw; + } + + /* Use a synchronous alarm instead of a watchdog timer */ + sys_setalarm(sys_hz(), 0); + + /* Clear send and recv flag */ + g_driver.vt_send_flag = FALSE; + g_driver.vt_recv_flag = FALSE; + + return 0; + +err_init_hw: + free_contig(g_driver.vt_buf, g_driver.vt_buf_size); +err_init_buf: +err_probe: + return ret; +} + +/* Match the device and get base address */ +static int vt_probe(vt_driver *pdev, int instance) { + int devind; + u16_t cr, vid, did; + u32_t bar; + u8_t irq, rev; + + /* Find pci device */ + pci_init(); + if (!pci_first_dev(&devind, &vid, &did)) + return -EIO; + while (instance--) { + if (!pci_next_dev(&devind, &vid, &did)) + return -EIO; + } + pci_reserve(devind); + + /* Enable bus mastering */ + cr = pci_attr_r16(devind, PCI_CR); + if (!(cr & PCI_CR_MAST_EN)) + pci_attr_w16(devind, PCI_CR, cr | PCI_CR_MAST_EN); + + /* Get base address */ + bar = pci_attr_r32(devind, PCI_BAR) & 0xffffffe0; + if (bar < 0x400) { + printf("VT6105: base address is not properly configured!\n"); + return -EIO; + } + pdev->vt_base_addr = bar; + + /* Get irq number */ + irq = pci_attr_r8(devind, PCI_ILR); + pdev->vt_irq = irq; + + /* Get revision ID */ + rev = pci_attr_r8(devind, PCI_REV); + pdev->vt_revision = rev; + +#ifdef VT6105_DEBUG + printf("VT6105: Base address is 0x%08x\n", pdev->vt_base_addr); + printf("VT6105: IRQ number is 0x%08x\n", pdev->vt_irq); + printf("VT6105: Revision ID is 0x%08x\n", pdev->vt_revision); +#endif + + return 0; +} + +/* Allocate and initialize buffer */ +static int vt_init_buf(vt_driver *pdev) { + size_t rx_desc_size, tx_desc_size, rx_buf_size, tx_buf_size, tot_buf_size; + vt_desc *desc; + phys_bytes buf_dma, next; + char *buf; + int i; + + /* Build Rx and Tx descriptor buffer */ + rx_desc_size = VT_RX_DESC_NUM * sizeof(vt_desc); + tx_desc_size = VT_TX_DESC_NUM * sizeof(vt_desc); + + /* Allocate Rx and Tx buffer */ + tx_buf_size = VT_TX_BUF_SIZE; + if (tx_buf_size % 4) + tx_buf_size += 4 - (tx_buf_size % 4); + rx_buf_size = VT_RX_BUF_SIZE; + tot_buf_size = rx_desc_size + tx_desc_size; + tot_buf_size += VT_TX_DESC_NUM * tx_buf_size + VT_RX_DESC_NUM * rx_buf_size; + if (tot_buf_size % 4096) + tot_buf_size += 4096 - (tot_buf_size % 4096); + + if (!(buf = alloc_contig(tot_buf_size, 0, &buf_dma))) { + printf("VT6105: Fail to allocate memory!\n"); + return -ENOMEM; + } + pdev->vt_buf_size = tot_buf_size; + pdev->vt_buf = buf; + + /* Rx descriptor */ + pdev->vt_rx_desc = (vt_desc *)buf; + pdev->vt_rx_desc_dma = buf_dma; + memset(buf, 0, rx_desc_size); + buf += rx_desc_size; + buf_dma += rx_desc_size; + + /* Tx descriptor */ + pdev->vt_tx_desc = (vt_desc *)buf; + pdev->vt_tx_desc_dma = buf_dma; + memset(buf, 0, tx_desc_size); + buf += tx_desc_size; + buf_dma += tx_desc_size; + + /* Rx buffer assignment */ + desc = pdev->vt_rx_desc; + next = pdev->vt_rx_desc_dma; + for (i = 0; i < VT_RX_DESC_NUM; i++) { + /* Set Rx buffer */ + pdev->vt_rx[i].buf_dma = buf_dma; + pdev->vt_rx[i].buf = buf; + buf_dma += rx_buf_size; + buf += rx_buf_size; + + /* Set Rx descriptor */ + desc->status = VT_DESC_OWN | + ((VT_RX_BUF_SIZE << 16) & VT_DESC_RX_LENMASK); + desc->addr = pdev->vt_rx[i].buf_dma; + desc->length = VT_RX_BUF_SIZE; + if (i == (VT_RX_DESC_NUM - 1)) + desc->next_desc = pdev->vt_rx_desc_dma; + else { + next += sizeof(vt_desc); + desc->next_desc = next; + desc++; + } + } + + /* Tx buffer assignment */ + desc = pdev->vt_tx_desc; + next = pdev->vt_tx_desc_dma; + for (i = 0; i < VT_TX_DESC_NUM; i++) { + /* Set Tx buffer */ + pdev->vt_tx[i].busy = 0; + pdev->vt_tx[i].buf_dma = buf_dma; + pdev->vt_tx[i].buf = buf; + buf_dma += tx_buf_size; + buf += tx_buf_size; + + /* Set Rx descriptor */ + desc->addr = pdev->vt_tx[i].buf_dma; + desc->length = VT_TX_BUF_SIZE; + if (i == (VT_TX_DESC_NUM - 1)) + desc->next_desc = pdev->vt_tx_desc_dma; + else { + next += sizeof(vt_desc); + desc->next_desc = next; + desc++; + } + } + pdev->vt_tx_busy_num = 0; + pdev->vt_tx_head = 0; + pdev->vt_tx_tail = 0; + pdev->vt_rx_head = 0; + pdev->vt_tx_alive = FALSE; + + return 0; +} + +/* Intialize hardware */ +static int vt_init_hw(vt_driver *pdev, ether_addr_t *addr) { + int r, ret; + + /* Set the interrupt handler */ + pdev->vt_hook = pdev->vt_irq; + if ((r = sys_irqsetpolicy(pdev->vt_irq, 0, &pdev->vt_hook)) != OK) { + printf("VT6105: Fail to set IRQ policy: %d!\n", r); + ret = -EFAULT; + goto err_irq_policy; + } + + /* Reset hardware */ + vt_reset_hw(pdev); + + /* Enable IRQ */ + if ((r = sys_irqenable(&pdev->vt_hook)) != OK) { + printf("VT6105: Fail to enable IRQ: %d!\n", r); + ret = -EFAULT; + goto err_irq_enable; + } + + /* Configure MAC address */ + vt_conf_addr(pdev, addr); + + /* Detect link status */ + vt_check_link(pdev); +#ifdef VT6105_DEBUG + if (pdev->vt_link) + printf("VT6105: Link up!\n"); + else + printf("VT6105: Link down!\n"); +#endif + + return 0; + +err_irq_enable: +err_irq_policy: + return ret; +} + +/* Reset hardware */ +static void vt_reset_hw(vt_driver *pdev) { + u16_t base = pdev->vt_base_addr; + u8_t db; + u16_t dw; + u32_t dl; + + /* Let power registers into sane state */ + vt_power_init(pdev); + + /* Reset the chip */ + vt_outw(base, VT_REG_CR, VT_CMD_RESET); + vt_inb(base, VT_REG_ADDR); + +#ifdef VT6105_DEBUG + if (vt_inw(base, VT_REG_CR) & VT_CMD_RESET) { + vt_outb(base, VT_REG_MCR1, 0x40); + usleep(100000); + if (vt_inw(base, VT_REG_CR) & VT_CMD_RESET) + printf("VT6105: Fail to completely reset!\n"); + } + else + printf("VT6105: Reset successfully!\n"); +#endif + + /* Initialize regsiters */ + vt_outw(base, VT_REG_BCR0, 0x0006); + vt_outb(base, VT_REG_TCR, 0x20); /* Tx threshold is 256 bytes */ + vt_outb(base, VT_REG_RCR, 0x78); /* Rx threshold is 256 bytes */ + vt_outl(base, VT_REG_RD_BASE, pdev->vt_rx_desc_dma); /* Set Rx descriptor base address */ + vt_outl(base, VT_REG_TD_BASE, pdev->vt_tx_desc_dma); /* Set Tx descriptor base address */ + +#ifdef VT6105_DEBUG + dl = vt_inl(base, VT_REG_RD_BASE); + printf("VT6105: Rx descriptor DMA address is: 0x%08x\n", dl); + dl = vt_inl(base, VT_REG_TD_BASE); + printf("VT6105: Tx descriptor DMA address is: 0x%08x\n", dl); +#endif + + /* Enable interrupts */ + vt_outw(base, VT_REG_IMR, 0xfeff); + + /* Start the device, Rx and Tx */ + dw = VT_CMD_START | VT_CMD_RX_ON | VT_CMD_TX_ON | VT_CMD_NO_POLL | VT_CMD_FDUPLEX; + vt_outw(base, VT_REG_CR, dw); + dw = vt_inw(base, VT_REG_CR); + +#ifdef VT6105_DEBUG + dw = vt_inw(base, VT_REG_CR); + printf("VT6105: Control status is 0x%04x\n", dw); +#endif +} + +/* Initialize power registers */ +static void vt_power_init(vt_driver *pdev) { + u8_t db, wolstat; + u16_t dw, base = pdev->vt_base_addr; + u32_t dl; + + /* Make sure chip is in power state D0 */ + db = vt_inb(base, VT_REG_STICK); + vt_outb(base, VT_REG_STICK, db & 0xfc); + + /* Disable "force PME-enable" */ + vt_outb(base, VT_REG_WOLC_SET, 0x80); + + /* Clear power-event config bits (WOL) */ + vt_outb(base, VT_REG_WOL_SET, 0xff); + + /* Save power-event status bits */ + wolstat = vt_inb(base, VT_REG_WOLS_SET); + + /* Clear power-event status bits */ + vt_outb(base, VT_REG_WOLS_CLR, 0xff); + +#ifdef VT6105_DEBUG + if (wolstat) { + char reason[50]; + switch (wolstat) { + case VT_WOL_MAGIC: + strcpy(reason, "Magic packet"); + break; + case VT_WOL_LINK_UP: + strcpy(reason, "Link up"); + break; + case VT_WOL_LINK_DOWN: + strcpy(reason, "Link down"); + break; + case VT_WOL_UCAST: + strcpy(reason, "Unicast packet"); + break; + case VT_WOL_MCAST: + strcpy(reason, "Multicast/Broadcast packet"); + break; + default: + strcpy(reason, "Unknown"); + } + printf("VT6105: Wake system up: %s\n", reason); + } +#endif +} + +static void vt_conf_addr(vt_driver *pdev, ether_addr_t *addr) { + u16_t dw, base = pdev->vt_base_addr; + int i; + + for (i=0; i<6; i++) + addr->ea_addr[i] = vt_inb(base, VT_REG_ADDR + i); + +#ifdef VT6105_DEBUG + printf("VT6105: Ethernet address is %02x:%02x:%02x:%02x:%02x:%02x\n", + addr->ea_addr[0], addr->ea_addr[1], addr->ea_addr[2], + addr->ea_addr[3], addr->ea_addr[4], addr->ea_addr[5]); +#endif +} + +/* Detect link status (MII interface) */ +static void vt_check_link(vt_driver *pdev) { + u16_t base = pdev->vt_base_addr; + u32_t res; + + vt_outb(base, VT_REG_MII_CFG, 0x01); + vt_outb(base, VT_REG_MII_ADDR, 0x01); + vt_outb(base, VT_REG_MII_CR, 0x40); + usleep(10000); + res = vt_inw(base, VT_REG_MII_DATA); + if (res & 0x0004) + pdev->vt_link = TRUE; + else + pdev->vt_link = FALSE; +} + +/* Stop the driver */ +static void vt_stop(void) { + u16_t base = g_driver.vt_base_addr; + + /* Free Rx and Tx buffer*/ + free_contig(g_driver.vt_buf, g_driver.vt_buf_size); + + /* Stop IRQ and device */ + vt_outw(base, VT_REG_IMR, 0x0000); + vt_outw(base, VT_REG_CR, VT_CMD_STOP); +} + +/* Set driver mode */ +static void vt_mode(unsigned int mode) { + vt_driver *pdev = &g_driver; + u16_t base = pdev->vt_base_addr; + u8_t rcr; + + pdev->vt_mode = mode; + vt_outl(base, VT_REG_MAR0, 0xffffffff); + vt_outl(base, VT_REG_MAR1, 0xffffffff); + + rcr = vt_inb(base, VT_REG_RCR); + rcr &= ~(VT_RCR_AB | VT_RCR_AM | VT_RCR_AP | VT_RCR_AE | VT_RCR_AR); + if (pdev->vt_mode & NDEV_PROMISC) + rcr |= VT_RCR_AB | VT_RCR_AM | VT_RCR_AE | VT_RCR_AR; + if (pdev->vt_mode & NDEV_BROAD) + rcr |= VT_RCR_AB; + if (pdev->vt_mode & NDEV_MULTI) + rcr |= VT_RCR_AM; + rcr |= VT_RCR_AP; + vt_outb(base, VT_REG_RCR, 0x60 | rcr); +} + +/* Receive data */ +static ssize_t vt_recv(struct netdriver_data *data, size_t max) { + vt_driver *pdev = &g_driver; + u32_t rxstat, totlen, packlen; + vt_desc *desc; + int index, i; + + index = pdev->vt_rx_head; + desc = pdev->vt_rx_desc; + desc += index; + + /* Manage Rx buffer */ + for (;;) { + rxstat = desc->status; + + if (rxstat & VT_DESC_OWN) + return SUSPEND; + + if (rxstat & VT_DESC_RX_ALL_ERR) { +#ifdef VT6105_DEBUG + printf("VT6105: Rx error: 0x%08x\n", rxstat); +#endif + if (rxstat & VT_DESC_RX_FOV) { +#ifdef VT6105_DEBUG + printf("VT6105: Rx buffer overflow\n"); +#endif + pdev->vt_stat.ets_fifoOver++; + } + if (rxstat & VT_DESC_RX_FAE) { +#ifdef VT6105_DEBUG + printf("VT6105: Rx frames not align\n"); +#endif + pdev->vt_stat.ets_frameAll++; + } + if (rxstat & VT_DESC_RX_CRCE) { +#ifdef VT6105_DEBUG + printf("VT6105: Rx CRC error\n"); +#endif + pdev->vt_stat.ets_CRCerr++; + } + } + + /* Normal packet */ + if ((rxstat & VT_DESC_RX_PACK) == VT_DESC_RX_PACK) + break; + + /* Other packet */ + if (index == VT_RX_DESC_NUM - 1) { + desc->status = VT_DESC_OWN | + ((VT_RX_BUF_SIZE << 16) & VT_DESC_RX_LENMASK); + index = 0; + desc = pdev->vt_rx_desc; + } + else { + desc->status = VT_DESC_OWN | + ((VT_RX_BUF_SIZE << 16) & VT_DESC_RX_LENMASK); + index++; + desc++; + } + } + + /* Get data length */ + totlen = (rxstat & VT_DESC_RX_LENMASK) >> 16; + if (totlen < 8 || totlen > 2 * ETH_MAX_PACK_SIZE) { + printf("VT6105: Bad data length: %d\n", totlen); + panic(NULL); + } + + /* Substract CRC to get packet */ + packlen = totlen - ETH_CRC_SIZE; + if (packlen > max) + packlen = max; + + /* Copy data to user */ + netdriver_copyout(data, 0, pdev->vt_rx[index].buf, packlen); + pdev->vt_stat.ets_packetR++; + + /* Set Rx descriptor status */ + if (index == VT_RX_DESC_NUM - 1) { + desc->status = VT_DESC_OWN | + ((VT_RX_BUF_SIZE << 16) & VT_DESC_RX_LENMASK); + index = 0; + } + else { + desc->status = VT_DESC_OWN | + ((VT_RX_BUF_SIZE << 16) & VT_DESC_RX_LENMASK); + index++; + } + pdev->vt_rx_head = index; + +#ifdef VT6105_DEBUG + printf("VT6105: Successfully receive a packet, length = %d\n", packlen); +#endif + + return packlen; +} + +/* Transmit data */ +static int vt_send(struct netdriver_data *data, size_t size) { + vt_driver *pdev = &g_driver; + vt_desc *desc; + int tx_head, i; + u8_t db; + u16_t base = pdev->vt_base_addr; + + tx_head = pdev->vt_tx_head; + desc = pdev->vt_tx_desc; + desc += tx_head; + + if (pdev->vt_tx[tx_head].busy) + return SUSPEND; + + /* Copy data from user */ + netdriver_copyin(data, 0, pdev->vt_tx[tx_head].buf, size); + + /* Set busy */ + pdev->vt_tx[tx_head].busy = TRUE; + pdev->vt_tx_busy_num++; + + /* Set Tx descriptor status */ + desc->status = VT_DESC_OWN | VT_DESC_FIRST | VT_DESC_LAST; + desc->length = 0x00e08000 | (size >= 60 ? size : 60); + if (tx_head == VT_TX_DESC_NUM - 1) + tx_head = 0; + else + tx_head++; + pdev->vt_tx_head = tx_head; + + /* Wake up transmit channel */ + db = vt_inb(base, VT_REG_CR); + db |= VT_CMD_TX_DEMAND; + vt_outb(base, VT_REG_CR, db); + + return 0; +} + +/* Handle Interrupt */ +static void vt_intr(unsigned int mask) { + int s; + + /* Run interrupt handler at driver level */ + vt_handler(&g_driver); + + /* Reenable interrupts for this hook */ + if ((s = sys_irqenable(&g_driver.vt_hook)) != OK) + printf("VT6105: Cannot enable interrupts: %d\n", s); + + /* Perform tasks based on the flagged conditions */ + vt_check_ints(&g_driver); +} + +/* Real handler interrupt */ +static void vt_handler(vt_driver *pdev) { + u16_t base = pdev->vt_base_addr; + int intr_status; + u8_t db; + u16_t dw; + u32_t dl, txstat; + int flag = 0, tx_head, tx_tail; + vt_desc *desc; + + /* Get interrupt status */ + intr_status = vt_inw(base, VT_REG_ISR); + + /* Clear interrupt */ + dw = intr_status & ~(VT_INTR_PCI_ERR | VT_INTR_PORT_CHANGE); + vt_outw(base, VT_REG_ISR, dw); + + /* Check link status */ + if (intr_status & VT_INTR_PORT_CHANGE) + printf("VT6105: Port state change!\n"); + + /* Check interrupt status */ + if (intr_status & VT_INTR_RX_DONE) { + pdev->vt_recv_flag = TRUE; + flag++; + + if (intr_status & VT_INTR_RX_ERR) { + pdev->vt_stat.ets_recvErr++; + printf("VT6105: Rx error in interrupt: 0x%04x\n", intr_status); + } + if (intr_status & VT_INTR_RX_NOBUF) + printf("VT6105: Rx no buffer in interrupt: 0x%04x\n", intr_status); + if (intr_status & VT_INTR_RX_EMPTY) + printf("VT6105: Rx buffer empty in interrupt: 0x%04x\n", intr_status); + if (intr_status & VT_INTR_RX_OVERFLOW) + printf("VT6105: Rx buffer overflow in interrupt: 0x%04x\n", intr_status); + if (intr_status & VT_INTR_RX_DROPPED) + printf("VT6105: Rx buffer dropped in interrupt: 0x%04x\n", intr_status); + } + if (intr_status & VT_INTR_TX_DONE) { + pdev->vt_send_flag = TRUE; + flag++; + + if (intr_status & VT_INTR_TX_ERR) { + pdev->vt_stat.ets_sendErr++; + printf("VT6105: Tx error in interrupt: 0x%04x\n", intr_status); + } + if (intr_status & VT_INTR_TX_UNDER_RUN) + printf("VT6105: Tx buffer underflow in interrupt: 0x%04x\n", intr_status); + if (intr_status & VT_INTR_TX_ABORT) + printf("VT6105: Tx abort in interrupt: 0x%04x\n", intr_status); + + /* Manage Tx Buffer */ + tx_head = pdev->vt_tx_head; + tx_tail = pdev->vt_tx_tail; + while (tx_tail != tx_head) { + desc = pdev->vt_tx_desc; + desc += tx_tail; + if (!pdev->vt_tx[tx_tail].busy) + printf("VT6105: Strange, buffer not busy?\n"); + txstat = desc->status; + + /* Check whether the buffer is ready */ + if (txstat & VT_DESC_OWN) { + break; + } + + if (txstat & VT_DESC_TX_ERR) { +#ifdef VT6105_DEBUG + printf("VT6105: Tx error: 0x%08x\n", txstat); +#endif + if (txstat & VT_DESC_TX_UDF) { +#ifdef VT6105_DEBUG + printf("VT6105: Tx buffer underflow\n"); +#endif + pdev->vt_stat.ets_fifoUnder++; + } + if (txstat & VT_DESC_TX_CRS) { +#ifdef VT6105_DEBUG + printf("VT6105: Tx carrier sense lost\n"); +#endif + pdev->vt_stat.ets_carrSense++; + } + if (txstat & VT_DESC_TX_CDH) { +#ifdef VT6105_DEBUG + printf("VT6105: Tx collision detect\n"); +#endif + pdev->vt_stat.ets_collision++; + } + if (txstat & VT_DESC_TX_OWC) { +#ifdef VT6105_DEBUG + printf("VT6105: Tx buffer out of winidow\n"); +#endif + pdev->vt_stat.ets_OWC++; + } + } + + pdev->vt_stat.ets_packetT++; + pdev->vt_tx[tx_tail].busy = FALSE; + pdev->vt_tx_busy_num--; + + if (++tx_tail >= VT_TX_DESC_NUM) + tx_tail = 0; + + pdev->vt_send_flag = TRUE; + pdev->vt_recv_flag = TRUE; + pdev->vt_tx_alive = TRUE; + +#ifdef VT6105_DEBUG + printf("VT6105: Successfully send a packet\n"); +#endif + } + pdev->vt_tx_tail = tx_tail; + } + if (!flag) { + printf("VT6105: Unknown error in interrupt: 0x%04x\n", intr_status); + return; + } + + /* Perform tasks based on the flagged condition */ + vt_check_ints(pdev); +} + +/* Check interrupt and perform */ +static void vt_check_ints(vt_driver *pdev) { + if (!pdev->vt_recv_flag) + return; + pdev->vt_recv_flag = FALSE; + + /* Handle data receive */ + netdriver_recv(); + + /* Handle data transmit */ + if (pdev->vt_send_flag) { + pdev->vt_send_flag = FALSE; + netdriver_send(); + } +} + +static void vt_stat(eth_stat_t *stat) { + memcpy(stat, &g_driver.vt_stat, sizeof(*stat)); +} + +static void vt_alarm(clock_t stamp) { + vt_driver *pdev = &g_driver; + + /* Use a synchronous alarm instead of a watchdog timer */ + sys_setalarm(sys_hz(), 0); + + /* Assume the an idle system is alive */ + if (!pdev->vt_tx_busy_num) { + pdev->vt_tx_alive = TRUE; + return; + } + if (pdev->vt_tx_alive) { + pdev->vt_tx_alive = FALSE; + return; + } + + printf("VT6105: Resetting the driver\n"); + vt_reset_hw(pdev); + pdev->vt_recv_flag = TRUE; + + vt_check_ints(pdev); +} diff --git a/minix/drivers/net/vt6105/vt6105.conf b/minix/drivers/net/vt6105/vt6105.conf new file mode 100755 index 000000000..887aa4257 --- /dev/null +++ b/minix/drivers/net/vt6105/vt6105.conf @@ -0,0 +1,15 @@ +service vt6105 +{ + type net; + descr "VIA Technology 6105/6106S Ethernet Card"; + system + UMAP # 14 + IRQCTL # 19 + DEVIO # 21 + ; + pci device 1106:3106; + ipc + SYSTEM pm rs log tty ds vm + pci inet lwip amddev + ; +}; diff --git a/minix/drivers/net/vt6105/vt6105.h b/minix/drivers/net/vt6105/vt6105.h new file mode 100644 index 000000000..51c842724 --- /dev/null +++ b/minix/drivers/net/vt6105/vt6105.h @@ -0,0 +1,194 @@ +#include +#include +#include +#include +#include + +/* PCI Register */ +#define VT_PCI_VID 0x00 /* Vendor ID */ +#define VT_PCI_DID 0x02 /* Device ID */ +#define VT_PCI_CMD 0x04 /* Command */ +#define VT_PCI_STS 0x06 /* Status */ +#define VT_PCI_RID 0x08 /* Revision ID */ +#define VT_PCI_CC 0x09 /* Class Code */ +#define VT_PCI_CLS 0x0c /* Cache Line Size */ +#define VT_PCI_LT 0x0d /* Latency Timer */ +#define VT_PCI_HT 0x0e /* Header Type */ + +/* Internal Register */ +#define VT_REG_ADDR 0x00 /* Ethernet Address */ +#define VT_REG_RCR 0x06 /* Receive Configure Request */ +#define VT_REG_TCR 0x07 /* Transmit Configure Request */ +#define VT_REG_CR 0x08 /* Control 0 */ +#define VT_REG_ISR 0x0c /* Interrupt Status */ +#define VT_REG_IMR 0x0e /* Interrupt Mask */ +#define VT_REG_MAR0 0x10 /* Multicast Address 0 */ +#define VT_REG_MAR1 0x14 /* Multicast Address 1 */ +#define VT_REG_RD_BASE 0x18 /* Receive Descriptor Base Address */ +#define VT_REG_TD_BASE 0x1c /* Transmit Descriptor Base Address */ +#define VT_REG_MII_CFG 0x6c /* MII Configuration */ +#define VT_REG_MII_STS 0x6d /* MII Status */ +#define VT_REG_BCR0 0x6e /* Bus Control 0 */ +#define VT_REG_BCR1 0x6f /* Bus Control 1 */ +#define VT_REG_MII_CR 0x70 /* MII Control */ +#define VT_REG_MII_ADDR 0x71 /* MII Interface Address*/ +#define VT_REG_MII_DATA 0x72 /* MII Data Port */ +#define VT_REG_EECSR 0x74 /* EEPROM Control/Status */ +#define VT_REG_CFG_A 0x78 /* Chip Configuration A */ +#define VT_REG_CFG_B 0x79 /* Chip Configuration B */ +#define VT_REG_CFG_C 0x7a /* Chip Configuration C */ +#define VT_REG_CFG_D 0x7b /* Chip Configuration D */ +#define VT_REG_MCR0 0x80 /* Miscellaneous Control 0 */ +#define VT_REG_MCR1 0x81 /* Miscellaneous Control 1 */ +#define VT_REG_STICK 0x83 /* Sticky Hardware Control */ +#define VT_REG_MISR 0x84 /* MII Interrupt Status */ +#define VT_REG_MIMR 0x86 /* MII Interrupt Mask */ +#define VT_REG_FCR0 0x98 /* Flow Control 0 */ +#define VT_REG_FCR1 0x99 /* Flow Control 1 */ +#define VT_REG_WOL_SET 0xA4 /* Wake On LAN Set */ +#define VT_REG_WOL_CLR 0xA0 /* Wake On LAN Clear */ +#define VT_REG_PCS_CLR 0xA5 /* Power Configuration Set */ +#define VT_REG_PCS_SET 0xA1 /* Power Configuration Clear */ +#define VT_REG_WOLC_SET 0xA7 /* WOL Configuration Set */ +#define VT_REG_WOLC_CLR 0xA3 /* WOL Configuration Clear */ +#define VT_REG_WOLS_SET 0xA8 /* WOL Status Clear */ +#define VT_REG_WOLS_CLR 0xAC /* WOL Status Set */ + +/* Interrupt Status/Mask Register */ +#define VT_INTR_RX_DONE 0x0001 +#define VT_INTR_TX_DONE 0x0002 +#define VT_INTR_RX_ERR 0x0004 +#define VT_INTR_TX_ERR 0x0008 +#define VT_INTR_RX_EMPTY 0x0020 +#define VT_INTR_PCI_ERR 0x0040 +#define VT_INTR_STS_MAX 0x0080 +#define VT_INTR_RX_EARLY 0x0100 +#define VT_INTR_TX_UNDER_RUN 0x0210 +#define VT_INTR_RX_OVERFLOW 0x0400 +#define VT_INTR_RX_DROPPED 0x0800 +#define VT_INTR_RX_NOBUF 0x1000 +#define VT_INTR_TX_ABORT 0x2000 +#define VT_INTR_PORT_CHANGE 0x4000 +#define VT_INTR_RX_WAKE_UP 0x8000 + +/* Control Register Command */ +#define VT_CMD_START 0x0002 +#define VT_CMD_STOP 0x0004 +#define VT_CMD_RX_ON 0x0008 +#define VT_CMD_TX_ON 0x0010 +#define VT_CMD_TX_DEMAND 0x0020 +#define VT_CMD_RX_DEMAND 0x0040 +#define VT_CMD_EARLY_RX 0x0100 +#define VT_CMD_EARLY_TX 0x0200 +#define VT_CMD_FDUPLEX 0x0400 +#define VT_CMD_NO_POLL 0x0800 +#define VT_CMD_RESET 0x8000 + +/* Receive Configure Mode */ +#define VT_RCR_AP 0x10 +#define VT_RCR_AB 0x08 +#define VT_RCR_AM 0x04 +#define VT_RCR_AR 0x02 +#define VT_RCR_AE 0x01 + +/* General Descriptor Flag */ +#define VT_DESC_OWN 0x80000000 /* Ownership */ +#define VT_DESC_FIRST 0x00000200 /* First Descriptor */ +#define VT_DESC_LAST 0x00000100 /* Last Descriptor */ + +/* Rx Descriptor Flag */ +#define VT_DESC_RX_LENMASK 0x7fff0000 /* Receive Frame Length Mask */ +#define VT_DESC_RX_OK 0x00008000 /* Receive OK */ +#define VT_DESC_RX_MAR 0x00002000 /* Multicast Address Received */ +#define VT_DESC_RX_BAR 0x00001000 /* Broadcast Address Received */ +#define VT_DESC_RX_PHY 0x00000800 /* Physical Address Received */ +#define VT_DESC_RX_LINK_ERR 0x00000080 /* Descriptor Link Structure Error */ +#define VT_DESC_RX_RUNT 0x00000020 /* Runt Packet */ +#define VT_DESC_RX_LONG 0x00000010 /* Long Packet */ +#define VT_DESC_RX_FOV 0x00000008 /* FIFO Overflow */ +#define VT_DESC_RX_FAE 0x00000004 /* Frame Align Error */ +#define VT_DESC_RX_CRCE 0x00000002 /* CRC Error */ +#define VT_DESC_RX_ERR 0x00000001 /* Receive Error */ +#define VT_DESC_RX_ALL_ERR (VT_DESC_RX_LINK_ERR | VT_DESC_RX_RUNT | \ + VT_DESC_RX_LONG | VT_DESC_RX_FOV | \ + VT_DESC_RX_FAE | VT_DESC_RX_CRCE | VT_DESC_RX_ERR) +#define VT_DESC_RX_PACK (VT_DESC_FIRST | VT_DESC_LAST) + +/* Tx Descriptor Flag */ +#define VT_DESC_TX_ERR 0x00008000 /* Transmit Error */ +#define VT_DESC_TX_UDF 0x00000800 /* FIFO Underflow */ +#define VT_DESC_TX_CRS 0x00000400 /* Carrier Sense Lost Detect */ +#define VT_DESC_TX_OWC 0x00000200 /* Out of Window Collision */ +#define VT_DESC_TX_ABT 0x00000100 /* Excessive Collision Abort */ +#define VT_DESC_TX_CDH 0x00000010 /* Collision Detect */ + +/* WOL status */ +#define VT_WOL_UCAST 0x10 +#define VT_WOL_MAGIC 0x20 +#define VT_WOL_MCAST 0x30 +#define VT_WOL_LINK_UP 0x40 +#define VT_WOL_LINK_DOWN 0x80 + +/* Link status */ +#define VT_LINK_UP 1 +#define VT_LINK_DOWN 0 +#define VT_LINK_UNKNOWN -1 + +#define VT_RX_BUF_SIZE 1536 +#define VT_TX_BUF_SIZE 1536 +#define VT_RX_DESC_NUM 64 +#define VT_TX_DESC_NUM 64 + +/* #define VT6105_DEBUG */ + +/* Data Descriptor */ +typedef struct vt_desc { + u32_t status; /* command/status */ + u32_t length; /* Buffer/Frame length */ + u32_t addr; /* DMA buffer address */ + u32_t next_desc; /* Next descriptor */ +} vt_desc; + +/* Driver Data Structure */ +typedef struct vt_driver { + u16_t vt_base_addr; /* Base address */ + int vt_revision; /* Revision ID */ + int vt_irq; /* IRQ number */ + int vt_mode; + int vt_link; /* Whether link-up */ + int vt_recv_flag; /* Receive flag */ + int vt_send_flag; /* Send flag */ + int vt_report_link; + int vt_tx_alive; + int vt_tx_busy; + + /* Buffer */ + size_t vt_buf_size; + char *vt_buf; + + /* Rx data */ + int vt_rx_head; + struct { + phys_bytes buf_dma; + char *buf; + } vt_rx[VT_RX_DESC_NUM]; + vt_desc *vt_rx_desc; /* Rx descriptor buffer */ + phys_bytes vt_rx_desc_dma; /* Rx descriptor DMA buffer */ + + /* Tx data */ + int vt_tx_head; + int vt_tx_tail; + struct { + int busy; + phys_bytes buf_dma; + char *buf; + } vt_tx[VT_TX_DESC_NUM]; + vt_desc *vt_tx_desc; /* Tx descriptor buffer */ + phys_bytes vt_tx_desc_dma; /* Tx descriptor DMA buffer */ + int vt_tx_busy_num; /* Number of busy Tx descriptors */ + + int vt_hook; /* IRQ hook id at kernel */ + eth_stat_t vt_stat; + + char vt_name[20]; +} vt_driver; diff --git a/minix/fs/procfs/service.c b/minix/fs/procfs/service.c index bb2606e65..e8b06eef5 100644 --- a/minix/fs/procfs/service.c +++ b/minix/fs/procfs/service.c @@ -73,6 +73,7 @@ service_get_policies(struct policies * pol, index_t slot) { .label = "rtl8169", .policy_str = "reset" }, { .label = "uds", .policy_str = "reset" }, { .label = "virtio_net", .policy_str = "reset" }, + { .label = "vt6105", .policy_str = "reset" }, /* power */ { .label = "acpi", .policy_str = "" }, { .label = "tps65217", .policy_str = "" }, From 9f11521a37bfb95426e4373d3586c13902e4517f Mon Sep 17 00:00:00 2001 From: io12 Date: Wed, 19 Oct 2016 17:37:53 -0400 Subject: [PATCH 06/12] Fix grammar errors in a comment Change-Id: I0ad2b6a28afb44e42d1830f1b0944579dc032261 --- minix/kernel/arch/earm/bsp/ti/omap_serial.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/minix/kernel/arch/earm/bsp/ti/omap_serial.c b/minix/kernel/arch/earm/bsp/ti/omap_serial.c index 48408073e..3ca7f57ca 100644 --- a/minix/kernel/arch/earm/bsp/ti/omap_serial.c +++ b/minix/kernel/arch/earm/bsp/ti/omap_serial.c @@ -26,21 +26,21 @@ static struct omap_serial omap_serial = { static kern_phys_map serial_phys_map; /* - * In kernel serial for the omap. The serial driver like most other - * drivers needs to be started early and even before the MMU is turned on. + * In kernel serial for the omap. The serial driver, like most other + * drivers, needs to be started early and even before the MMU is turned on. * We start by directly accessing the hardware memory address. Later on - * a when the MMU is turned on we still use a 1:1 mapping for these addresses. + * when the MMU is turned on we still use a 1:1 mapping for these addresses. * - * Pretty soon we are going to remap these addresses at later stage. And this + * Pretty soon we are going to remap these addresses at a later stage. And this * requires us to use a dynamic base address. The idea is to receive a callback * from VM with the new address to use. * - * We also anticipate on the beaglebone port an try to keep the differences between - * the drivers to a minimum by initializing a struct here and not using (to much) + * We also try on the BeagleBone port to keep the differences between the + * drivers to a minimum by initializing a struct here and not using (too many) * constants in the code. * * The serial driver also gets used in the "pre_init" stage before the kernel is loaded - * in high memory so keep in mind there are two copies of this code in the kernel. + * in high memory, so keep in mind there are two copies of this code in the kernel. */ void bsp_ser_init(void) From f221d2ce4807b04c41fa17e999402ee7bc5bf19c Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Thu, 20 Oct 2016 11:07:25 +0000 Subject: [PATCH 07/12] RMIB: add support for vector copy-out Change-Id: I9e9b4b8d6eed39fdb511c6bd2a375ddf898064a5 --- minix/include/minix/rmib.h | 8 ++++++ minix/lib/libsys/rmib.c | 54 ++++++++++++++++++++++++++++++++++++++ minix/net/inet/rtinfo.c | 26 ------------------ minix/net/lwip/rtinfo.c | 26 ------------------ 4 files changed, 62 insertions(+), 52 deletions(-) diff --git a/minix/include/minix/rmib.h b/minix/include/minix/rmib.h index 0e055a404..06b403d8f 100644 --- a/minix/include/minix/rmib.h +++ b/minix/include/minix/rmib.h @@ -9,6 +9,12 @@ #include +/* + * The maximum number of I/O vector elements that can be passed to the + * rmib_vcopyout function. + */ +#define RMIB_IOV_MAX SCPVEC_NR + /* * This structure contains a number of less heavily used parameters for handler * functions, mainly to provide extensibility while limiting argument clutter. @@ -145,6 +151,8 @@ int rmib_inrange(struct rmib_oldp *, size_t); size_t rmib_getoldlen(struct rmib_oldp *); ssize_t rmib_copyout(struct rmib_oldp *, size_t, const void * __restrict, size_t); +ssize_t rmib_vcopyout(struct rmib_oldp *, size_t, const iovec_t *, + unsigned int); int rmib_copyin(struct rmib_newp * __restrict, void * __restrict, size_t); ssize_t rmib_readwrite(struct rmib_call *, struct rmib_node *, struct rmib_oldp *, struct rmib_newp *); diff --git a/minix/lib/libsys/rmib.c b/minix/lib/libsys/rmib.c index d14287efc..ad96e8644 100644 --- a/minix/lib/libsys/rmib.c +++ b/minix/lib/libsys/rmib.c @@ -110,6 +110,60 @@ rmib_copyout(struct rmib_oldp * __restrict oldp, size_t off, return size; } +/* + * Copy out (partial) data to the user, from a vector of up to RMIB_IOV_MAX + * local buffers. The copy is automatically limited to the range of data + * requested by the user. Return the total requested length on success or an + * error code on failure. + */ +ssize_t +rmib_vcopyout(struct rmib_oldp * oldp, size_t off, const iovec_t * iov, + unsigned int iovcnt) +{ + static struct vscp_vec vec[RMIB_IOV_MAX]; + size_t size, chunk; + unsigned int i; + ssize_t r; + + assert(iov != NULL); + assert(iovcnt <= __arraycount(vec)); + + /* Take a shortcut for single-vector elements, saving a kernel copy. */ + if (iovcnt == 1) + return rmib_copyout(oldp, off, (const void *)iov->iov_addr, + iov->iov_size); + + /* + * Iterate through the full vector even if we cannot copy out all of + * it, because we need to compute the total length. + */ + for (size = i = 0; iovcnt > 0; iov++, iovcnt--) { + if (oldp != NULL && off < oldp->oldp_len) { + chunk = oldp->oldp_len - off; + if (chunk > iov->iov_size) + chunk = iov->iov_size; + + vec[i].v_from = SELF; + vec[i].v_to = MIB_PROC_NR; + vec[i].v_gid = oldp->oldp_grant; + vec[i].v_offset = off; + vec[i].v_addr = iov->iov_addr; + vec[i].v_bytes = chunk; + + off += chunk; + i++; + } + + size += iov->iov_size; + } + + /* Perform the copy, if there is anything to copy, that is. */ + if (i > 0 && (r = sys_vsafecopy(vec, i)) != OK) + return r; + + return size; +} + /* * Copy in data from the user. The given length must match exactly the length * given by the user. Return OK or an error code. diff --git a/minix/net/inet/rtinfo.c b/minix/net/inet/rtinfo.c index 62f3880b0..7235abfa4 100644 --- a/minix/net/inet/rtinfo.c +++ b/minix/net/inet/rtinfo.c @@ -26,32 +26,6 @@ static const char padbuf[RT_ROUNDUP(0)] = { 0 }; -/* - * Copy out a vector of data to the sysctl(2) caller. TODO: decide what to do - * with this. We could implement this as a vectored-safecopy operation in - * RMIB. We could also copy everything into a single buffer first. The - * current implementation is probably the worst among the possibilities. - */ -static ssize_t -rmib_vcopyout(struct rmib_oldp * oldp, size_t off, const iovec_t * iov, - unsigned int iovcnt) -{ - unsigned int i; - ssize_t r, len; - - len = 0; - - for (i = 0; i < iovcnt; i++) { - if ((r = rmib_copyout(oldp, off + len, - (const void *)iov[i].iov_addr, iov[i].iov_size)) < 0) - return r; - - len += r; - } - - return len; -} - /* * Compute the length for, and possibly copy out, an interface information or * interface address record with an associated set of zero or more routing diff --git a/minix/net/lwip/rtinfo.c b/minix/net/lwip/rtinfo.c index 878fb3875..add6609a6 100644 --- a/minix/net/lwip/rtinfo.c +++ b/minix/net/lwip/rtinfo.c @@ -23,32 +23,6 @@ static const char padbuf[RT_ROUNDUP(0)] = { 0 }; -/* - * Copy out a vector of data to the sysctl(2) caller. TODO: decide what to do - * with this. We could implement this as a vectored-safecopy operation in - * RMIB. We could also copy everything into a single buffer first. The - * current implementation is probably the worst among the possibilities. - */ -static ssize_t -rmib_vcopyout(struct rmib_oldp * oldp, size_t off, const iovec_t * iov, - unsigned int iovcnt) -{ - unsigned int i; - ssize_t r, len; - - len = 0; - - for (i = 0; i < iovcnt; i++) { - if ((r = rmib_copyout(oldp, off + len, - (const void *)iov[i].iov_addr, iov[i].iov_size)) < 0) - return r; - - len += r; - } - - return len; -} - /* * Compute the length for, and possibly copy out, an interface information or * interface address record with an associated set of zero or more routing From dd41186aac5f9c05e657f127b7e5d33f375d1686 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Fri, 21 Oct 2016 23:42:31 +0000 Subject: [PATCH 08/12] libc: remove MINIX3 restrictions from getnameinfo(3) Change-Id: I4679f6804f229520d6399a06a5da0655f2bfd899 --- distrib/sets/lists/minix-comp/mi | 1 + lib/libc/net/getnameinfo.c | 12 ---- sys/net/Makefile | 2 +- sys/net/if_ieee1394.h | 120 +++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 sys/net/if_ieee1394.h diff --git a/distrib/sets/lists/minix-comp/mi b/distrib/sets/lists/minix-comp/mi index f20b52784..e621bb447 100644 --- a/distrib/sets/lists/minix-comp/mi +++ b/distrib/sets/lists/minix-comp/mi @@ -1312,6 +1312,7 @@ ./usr/include/net/if_arp.h minix-comp ./usr/include/net/if_dl.h minix-comp ./usr/include/net/if_ether.h minix-comp +./usr/include/net/if_ieee1394.h minix-comp ./usr/include/net/if_media.h minix-comp ./usr/include/net/if_pflog.h minix-comp ./usr/include/net/if_types.h minix-comp diff --git a/lib/libc/net/getnameinfo.c b/lib/libc/net/getnameinfo.c index 43ef52131..c7186a181 100644 --- a/lib/libc/net/getnameinfo.c +++ b/lib/libc/net/getnameinfo.c @@ -57,12 +57,10 @@ __RCSID("$NetBSD: getnameinfo.c,v 1.59 2015/09/22 16:15:08 christos Exp $"); #include #include #include -#if !defined(__minix) #include #include #include #include -#endif /* !defined(__minix) */ #include #include #include @@ -110,7 +108,6 @@ static int ip6_parsenumeric(const struct sockaddr *, const char *, char *, socklen_t, int); static int ip6_sa2str(const struct sockaddr_in6 *, char *, size_t, int); #endif -#if !defined(__minix) static int getnameinfo_atalk(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int); static int getnameinfo_local(const struct sockaddr *, socklen_t, char *, @@ -119,7 +116,6 @@ static int getnameinfo_local(const struct sockaddr *, socklen_t, char *, static int getnameinfo_link(const struct sockaddr *, socklen_t, char *, socklen_t, char *, socklen_t, int); static int hexname(const uint8_t *, size_t, char *, socklen_t); -#endif /* !defined(__minix) */ /* * Top-level getnameinfo() code. Look at the address family, and pick an @@ -133,29 +129,24 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, { switch (sa->sa_family) { -#if !defined(__minix) case AF_APPLETALK: return getnameinfo_atalk(sa, salen, host, hostlen, serv, servlen, flags); -#endif /* !defined(__minix) */ case AF_INET: case AF_INET6: return getnameinfo_inet(sa, salen, host, hostlen, serv, servlen, flags); -#if !defined(__minix) case AF_LINK: return getnameinfo_link(sa, salen, host, hostlen, serv, servlen, flags); case AF_LOCAL: return getnameinfo_local(sa, salen, host, hostlen, serv, servlen, flags); -#endif /* !defined(__minix) */ default: return EAI_FAMILY; } } -#if !defined(__minix) /* * getnameinfo_atalk(): * Format an AppleTalk address into a printable format. @@ -238,7 +229,6 @@ getnameinfo_local(const struct sockaddr *sa, socklen_t salen, return 0; } -#endif /* !defined(__minix) */ /* * getnameinfo_inet(): @@ -538,7 +528,6 @@ ip6_sa2str(const struct sockaddr_in6 *sa6, char *buf, size_t bufsiz, int flags) #endif /* INET6 */ -#if !defined(__minix) /* * getnameinfo_link(): * Format a link-layer address into a printable format, paying attention to @@ -635,4 +624,3 @@ hexname(const uint8_t *cp, size_t len, char *host, socklen_t hostlen) } return 0; } -#endif /* !defined(__minix) */ diff --git a/sys/net/Makefile b/sys/net/Makefile index c0d230345..b2d92bbf9 100644 --- a/sys/net/Makefile +++ b/sys/net/Makefile @@ -4,7 +4,7 @@ INCSDIR= /usr/include/net INCS= bpf.h bpfdesc.h bpfjit.h dlt.h ethertypes.h if.h if_arp.h \ if_dl.h if_ether.h \ - if_media.h \ + if_ieee1394.h if_media.h \ if_pflog.h \ if_types.h \ pfil.h pfkeyv2.h pfvar.h radix.h \ diff --git a/sys/net/if_ieee1394.h b/sys/net/if_ieee1394.h new file mode 100644 index 000000000..4e86c18f1 --- /dev/null +++ b/sys/net/if_ieee1394.h @@ -0,0 +1,120 @@ +/* $NetBSD: if_ieee1394.h,v 1.9 2008/04/28 20:24:09 martin Exp $ */ + +/* + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Atsushi Onoe. + * + * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _NET_IF_IEEE1394_H_ +#define _NET_IF_IEEE1394_H_ + +/* hardware address information for arp / nd */ +struct ieee1394_hwaddr { + uint8_t iha_uid[8]; /* node unique ID */ + uint8_t iha_maxrec; /* max_rec in the config ROM */ + uint8_t iha_speed; /* min of link/PHY speed */ + uint8_t iha_offset[6]; /* unicast FIFO address */ +}; + +/* + * BPF wants to see one of these. + */ +struct ieee1394_bpfhdr { + uint8_t ibh_dhost[8]; + uint8_t ibh_shost[8]; + uint16_t ibh_type; +}; + +#ifdef _KERNEL + +/* pseudo header */ +struct ieee1394_header { + uint8_t ih_uid[8]; /* dst/src uid */ + uint8_t ih_maxrec; /* dst maxrec for tx */ + uint8_t ih_speed; /* speed */ + uint8_t ih_offset[6]; /* dst offset */ +}; + +/* unfragment encapsulation header */ +struct ieee1394_unfraghdr { + uint16_t iuh_ft; /* fragment type == 0 */ + uint16_t iuh_etype; /* ether_type */ +}; + +/* fragmented encapsulation header */ +struct ieee1394_fraghdr { + uint16_t ifh_ft_size; /* fragment type, data size-1 */ + uint16_t ifh_etype_off; /* etype for first fragment */ + /* offset for subseq frag */ + uint16_t ifh_dgl; /* datagram label */ + uint16_t ifh_reserved; +}; + +#define IEEE1394_FT_SUBSEQ 0x8000 +#define IEEE1394_FT_MORE 0x4000 + +#define IEEE1394MTU 1500 + +#define IEEE1394_GASP_LEN 8 /* GASP header for Stream */ +#define IEEE1394_ADDR_LEN 8 +#define IEEE1394_CRC_LEN 4 + +struct ieee1394_reass_pkt { + LIST_ENTRY(ieee1394_reass_pkt) rp_next; + struct mbuf *rp_m; + uint16_t rp_size; + uint16_t rp_etype; + uint16_t rp_off; + uint16_t rp_dgl; + uint16_t rp_len; + uint16_t rp_ttl; +}; + +struct ieee1394_reassq { + LIST_ENTRY(ieee1394_reassq) rq_node; + LIST_HEAD(, ieee1394_reass_pkt) rq_pkt; + uint32_t fr_id; +}; + +struct ieee1394com { + struct ifnet fc_if; + struct ieee1394_hwaddr ic_hwaddr; + uint16_t ic_dgl; + LIST_HEAD(, ieee1394_reassq) ic_reassq; +}; + +const char *ieee1394_sprintf(const uint8_t *); +void ieee1394_input(struct ifnet *, struct mbuf *, uint16_t); +void ieee1394_ifattach(struct ifnet *, const struct ieee1394_hwaddr *); +void ieee1394_ifdetach(struct ifnet *); +int ieee1394_ioctl(struct ifnet *, u_long, void *); +struct mbuf * ieee1394_fragment(struct ifnet *, struct mbuf *, int, uint16_t); +void ieee1394_drain(struct ifnet *); +void ieee1394_watchdog(struct ifnet *); +#endif /* _KERNEL */ + +#endif /* !_NET_IF_IEEE1394_H_ */ From 286d266fd0c2c6853131c62e77f8edab8f6dc2bb Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sat, 22 Oct 2016 11:46:28 +0000 Subject: [PATCH 09/12] PM: fix alarm signal delivery As of change git-87c599d, when processing CLOCK notifications, PM no longer set the current process pointer 'mp'. That pointer is however used when delivering signals through check_sig(), to see whether the current process may deliver a signal to the target process. As a result, delivering SIGALARM signals used a previous pointer in these checks, causing alarm signals not to be delivered in some cases. This patch ensures that alarm signals are again delivered with PM as current process. Change-Id: I94ccbe8b71289df0e1d6d67928e55297bbc28360 --- minix/servers/pm/alarm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/minix/servers/pm/alarm.c b/minix/servers/pm/alarm.c index e10f84dca..560a1b279 100644 --- a/minix/servers/pm/alarm.c +++ b/minix/servers/pm/alarm.c @@ -338,5 +338,7 @@ cause_sigalrm(int arg) set_alarm(rmp, rmp->mp_interval[ITIMER_REAL]); else rmp->mp_flags &= ~ALARM_ON; + mp = &mproc[0]; /* pretend the signal comes from PM */ + check_sig(rmp->mp_pid, SIGALRM, FALSE /* ksig */); } From 9784113fda0dc424347489f1b8e8e77961d4e756 Mon Sep 17 00:00:00 2001 From: Jia-Ju Bai Date: Fri, 21 Oct 2016 02:15:50 +0000 Subject: [PATCH 10/12] vt6105: add a README file Change-Id: I8dbb122afc130f2f2504743fa4fcbada5c97dff5 --- minix/drivers/net/vt6105/README | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 minix/drivers/net/vt6105/README diff --git a/minix/drivers/net/vt6105/README b/minix/drivers/net/vt6105/README new file mode 100644 index 000000000..be49e63e8 --- /dev/null +++ b/minix/drivers/net/vt6105/README @@ -0,0 +1,17 @@ +The vt6105 driver is for VIA Technology 6105/6106S Ethernet card. + +This driver is referred to Minix(3.4.0) rtl8169 driver, +Linux(4.2.1) via-rhine driver and VT6105 Rhine III Specification(Rev 1.2). + +The supported PCI number is 1106:3106:1186:1403. +Maybe other PCI numbers for VIA Rhine III can be supported. + +Revision 1.0 2016/10/18 +Authored by Jia-Ju Bai + +Something can be improved: +1. MII, WOL functions are not adequately defined and used. +2. Link status report does not work well. +3. Ethernet address can not be modified at present. +4. Programming PHY registers and EEPROM are not adequately used. +5. Dump interfaces are not provided. From e154914956380951cb5da405c38cd6d15f7e532a Mon Sep 17 00:00:00 2001 From: rlfnb Date: Fri, 21 Oct 2016 12:47:39 +0200 Subject: [PATCH 11/12] Added vendor- and device id for Via Rhine III The device id added is used by ALIX boards. Change-Id: I78d1ce9f2fa0ee121e68d2c84818f669eeab3092 --- minix/drivers/net/vt6105/vt6105.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/minix/drivers/net/vt6105/vt6105.conf b/minix/drivers/net/vt6105/vt6105.conf index 887aa4257..00076ca69 100755 --- a/minix/drivers/net/vt6105/vt6105.conf +++ b/minix/drivers/net/vt6105/vt6105.conf @@ -7,7 +7,8 @@ service vt6105 IRQCTL # 19 DEVIO # 21 ; - pci device 1106:3106; + pci device 1106:3053; + pci device 1106:3106; ipc SYSTEM pm rs log tty ds vm pci inet lwip amddev From fee60e45e67240c6c98101a60bf7abc705899333 Mon Sep 17 00:00:00 2001 From: rlfnb Date: Thu, 8 Sep 2016 20:03:12 +0200 Subject: [PATCH 12/12] introducing libacpi Change-Id: I0808545fefaefc9a8fc8d1101bd85b676467fea0 --- distrib/sets/lists/minix-base/md.i386 | 2 + distrib/sets/lists/minix-comp/mi | 1 + lib/Makefile | 3 +- minix/drivers/bus/pci/Makefile | 3 + minix/drivers/bus/pci/pci.c | 48 +-------------- minix/include/minix/acpi.h | 10 +++- minix/lib/Makefile | 1 + minix/lib/libacpi/Makefile | 9 +++ minix/lib/libacpi/acpi.c | 85 +++++++++++++++++++++++++++ 9 files changed, 111 insertions(+), 51 deletions(-) create mode 100644 minix/lib/libacpi/Makefile create mode 100644 minix/lib/libacpi/acpi.c diff --git a/distrib/sets/lists/minix-base/md.i386 b/distrib/sets/lists/minix-base/md.i386 index 52aa190aa..c3f049cc2 100644 --- a/distrib/sets/lists/minix-base/md.i386 +++ b/distrib/sets/lists/minix-base/md.i386 @@ -55,6 +55,8 @@ ./service/virtio_blk minix-base ./service/virtio_net minix-base ./service/vt6105 minix-base +./usr/lib/libacpi.a minix-base +./usr/lib/libacpi_pic.a minix-base ./usr/lib/libhgfs.a minix-base ./usr/lib/libhgfs_pic.a minix-base ./usr/lib/libm387.a minix-base diff --git a/distrib/sets/lists/minix-comp/mi b/distrib/sets/lists/minix-comp/mi index e621bb447..16afb47d6 100644 --- a/distrib/sets/lists/minix-comp/mi +++ b/distrib/sets/lists/minix-comp/mi @@ -1867,6 +1867,7 @@ ./usr/include/zlib.h minix-comp ./usr/lib minix-comp ./usr/lib/bc minix-comp +./usr/lib/bc/libacpi.a minix-comp bitcode ./usr/lib/bc/libarchive.a minix-comp bitcode ./usr/lib/bc/libasyn.a minix-comp bitcode ./usr/lib/bc/libaudiodriver.a minix-comp bitcode diff --git a/lib/Makefile b/lib/Makefile index dec0fa079..bb090de11 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -50,7 +50,8 @@ SUBDIR+= ../minix/lib/liblwip \ .endif .if (${MACHINE_ARCH} == "i386") -SUBDIR+= ../minix/lib/libhgfs \ +SUBDIR+= ../minix/lib/libacpi \ + ../minix/lib/libhgfs \ ../minix/lib/libvassert \ ../minix/lib/libvboxfs \ ../minix/lib/libvirtio diff --git a/minix/drivers/bus/pci/Makefile b/minix/drivers/bus/pci/Makefile index 71e63fc1e..94c4dccfb 100644 --- a/minix/drivers/bus/pci/Makefile +++ b/minix/drivers/bus/pci/Makefile @@ -18,6 +18,9 @@ CWARNFLAGS.clang=-Wno-unused DPADD+= ${LIBCHARDRIVER} LDADD+= -lchardriver +DPADD+= ${LIBACPI} +LDADD+= -lacpi + WARNS= 3 .include diff --git a/minix/drivers/bus/pci/pci.c b/minix/drivers/bus/pci/pci.c index ceb5d1d24..833e46156 100644 --- a/minix/drivers/bus/pci/pci.c +++ b/minix/drivers/bus/pci/pci.c @@ -8,7 +8,6 @@ Created: Jan 2000 by Philip Homburg #include #include #include -#include #include #include @@ -94,7 +93,6 @@ static struct pcidev static int nr_pcidev= 0; static struct machine machine; -static endpoint_t acpi_ep; /*===========================================================================* * helper functions for I/O * @@ -890,26 +888,6 @@ do_isabridge(int busind) return 0; } -/*===========================================================================* - * IRQ handling * - *===========================================================================*/ -static int -acpi_get_irq(unsigned bus, unsigned dev, unsigned pin) -{ - int err; - message m; - - ((struct acpi_get_irq_req *)&m)->hdr.request = ACPI_REQ_GET_IRQ; - ((struct acpi_get_irq_req *)&m)->bus = bus; - ((struct acpi_get_irq_req *)&m)->dev = dev; - ((struct acpi_get_irq_req *)&m)->pin = pin; - - if ((err = ipc_sendrec(acpi_ep, &m)) != OK) - panic("PCI: error %d while receiveing from ACPI\n", err); - - return ((struct acpi_get_irq_resp *)&m)->irq; -} - static int derive_irq(struct pcidev * dev, int pin) { @@ -1801,30 +1779,6 @@ complete_bridges(void) } } -/* - * tells acpi which two busses are connected by this bridge. The primary bus - * (pbnr) must be already known to acpi and it must map dev as the connection to - * the secondary (sbnr) bus - */ -static void -acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr) -{ - int err; - message m; - - ((struct acpi_map_bridge_req *)&m)->hdr.request = ACPI_REQ_MAP_BRIDGE; - ((struct acpi_map_bridge_req *)&m)->primary_bus = pbnr; - ((struct acpi_map_bridge_req *)&m)->secondary_bus = sbnr; - ((struct acpi_map_bridge_req *)&m)->device = dev; - - if ((err = ipc_sendrec(acpi_ep, &m)) != OK) - panic("PCI: error %d while receiveing from ACPI\n", err); - - if (((struct acpi_map_bridge_resp *)&m)->err != OK) - printf("PCI: acpi failed to map pci (%d) to pci (%d) bridge\n", - pbnr, sbnr); -} - static void do_pcibridge(int busind) { @@ -2148,7 +2102,7 @@ sef_cb_init(int type, sef_init_info_t *info) return ENODEV; } if (machine.apic_enabled && - ds_retrieve_label_endpt("acpi", &acpi_ep) != OK) { + acpi_init() != OK) { panic("PCI: Cannot use APIC mode without ACPI!\n"); } diff --git a/minix/include/minix/acpi.h b/minix/include/minix/acpi.h index 618339d1f..98e447d2a 100644 --- a/minix/include/minix/acpi.h +++ b/minix/include/minix/acpi.h @@ -1,15 +1,15 @@ #include #include -#define ACPI_REQ_GET_IRQ 1 -#define ACPI_REQ_MAP_BRIDGE 2 +#define ACPI_REQ_GET_IRQ 1 +#define ACPI_REQ_MAP_BRIDGE 2 struct acpi_request_hdr { endpoint_t m_source; /* message header */ u32_t request; }; -/* +/* * Message to request dev/pin translation to IRQ by acpi using the acpi routing * tables */ @@ -42,3 +42,7 @@ struct acpi_map_bridge_resp { int err; u32_t __padding[7]; }; + +int acpi_init(void); +int acpi_get_irq(unsigned bus, unsigned dev, unsigned pin); +void acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr); diff --git a/minix/lib/Makefile b/minix/lib/Makefile index c0325a2f0..ff8094050 100644 --- a/minix/lib/Makefile +++ b/minix/lib/Makefile @@ -32,6 +32,7 @@ SUBDIR+= libnetsock .endif .if (${MACHINE_ARCH} == "i386") +SUBDIR+= libacpi SUBDIR+= libhgfs SUBDIR+= libvassert SUBDIR+= libvboxfs diff --git a/minix/lib/libacpi/Makefile b/minix/lib/libacpi/Makefile new file mode 100644 index 000000000..37c328590 --- /dev/null +++ b/minix/lib/libacpi/Makefile @@ -0,0 +1,9 @@ +# Makefile for libacpi + +CPPFLAGS+= -D_MINIX_SYSTEM + +LIB = acpi + +SRCS = acpi.c + +.include diff --git a/minix/lib/libacpi/acpi.c b/minix/lib/libacpi/acpi.c new file mode 100644 index 000000000..5675ee8f4 --- /dev/null +++ b/minix/lib/libacpi/acpi.c @@ -0,0 +1,85 @@ +#define _SYSTEM + +#include +#include + +#include +#include +#include +#include +#include +#include + +static struct log log = +{ .name = "libacpi", .log_level = LEVEL_TRACE, .log_func = default_log }; + +static endpoint_t acpi_ep = NONE; + +int +acpi_init(void) +{ + int res; + res = ds_retrieve_label_endpt("acpi", &acpi_ep); + return res; +} + +/*===========================================================================* + * IRQ handling * + *===========================================================================*/ +int +acpi_get_irq(unsigned bus, unsigned dev, unsigned pin) +{ + int err; + message m; + + if (acpi_ep == NONE) { + err = acpi_init(); + if (OK != err) { + panic("libacpi: ds_retrieve_label_endpt failed for 'acpi': %d", err); + } + else { + log_info(&log, "resolved acpi to endpoint: %d\n", acpi_ep); + } + } + + ((struct acpi_get_irq_req *)&m)->hdr.request = ACPI_REQ_GET_IRQ; + ((struct acpi_get_irq_req *)&m)->bus = bus; + ((struct acpi_get_irq_req *)&m)->dev = dev; + ((struct acpi_get_irq_req *)&m)->pin = pin; + + if ((err = ipc_sendrec(acpi_ep, &m)) != OK) + panic("libacpi: error %d while receiving from ACPI\n", err); + + return ((struct acpi_get_irq_resp *)&m)->irq; +} + +/* + * tells acpi which two busses are connected by this bridge. The primary bus + * (pbnr) must be already known to acpi and it must map dev as the connection to + * the secondary (sbnr) bus + */ +void +acpi_map_bridge(unsigned int pbnr, unsigned int dev, unsigned int sbnr) +{ + int err; + message m; + + if (acpi_ep == NONE) { + err = acpi_init(); + if (OK != err) { + panic("libacpi: ds_retrieve_label_endpt failed for 'acpi': %d", err); + } + } + + ((struct acpi_map_bridge_req *)&m)->hdr.request = ACPI_REQ_MAP_BRIDGE; + ((struct acpi_map_bridge_req *)&m)->primary_bus = pbnr; + ((struct acpi_map_bridge_req *)&m)->secondary_bus = sbnr; + ((struct acpi_map_bridge_req *)&m)->device = dev; + + if ((err = ipc_sendrec(acpi_ep, &m)) != OK) + panic("libacpi: error %d while receiving from ACPI\n", err); + + if (((struct acpi_map_bridge_resp *)&m)->err != OK) + printf("libacpi: acpi failed to map pci (%d) to pci (%d) bridge\n", + pbnr, sbnr); +}