From 5b1f20b73f410544f06353d4e81d5097c21ceac9 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 6 May 2016 21:22:38 +0200 Subject: Rename files for kernel namespace script This makes it easier to create the kernel namespace header. --- create-kernel-namespace.sh | 41 +-- libbsd.py | 76 ++-- libbsd_waf.py | 72 ++-- rtemsbsd/rtems/rtems-bsd-assert.c | 57 --- rtemsbsd/rtems/rtems-bsd-autoconf.c | 69 ---- rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c | 129 ------- rtemsbsd/rtems/rtems-bsd-bus-dma.c | 436 ---------------------- rtemsbsd/rtems/rtems-bsd-bus-root.c | 91 ----- rtemsbsd/rtems/rtems-bsd-cam.c | 504 -------------------------- rtemsbsd/rtems/rtems-bsd-chunk.c | 150 -------- rtemsbsd/rtems/rtems-bsd-conf.c | 65 ---- rtemsbsd/rtems/rtems-bsd-configintrhook.c | 58 --- rtemsbsd/rtems/rtems-bsd-delay.c | 53 --- rtemsbsd/rtems/rtems-bsd-get-file.c | 59 --- rtemsbsd/rtems/rtems-bsd-init.c | 120 ------ rtemsbsd/rtems/rtems-bsd-irqs.c | 63 ---- rtemsbsd/rtems/rtems-bsd-jail.c | 317 ---------------- rtemsbsd/rtems/rtems-bsd-malloc.c | 127 ------- rtemsbsd/rtems/rtems-bsd-mbuf.c | 68 ---- rtemsbsd/rtems/rtems-bsd-mutex.c | 227 ------------ rtemsbsd/rtems/rtems-bsd-muteximpl.c | 95 ----- rtemsbsd/rtems/rtems-bsd-newproc.c | 116 ------ rtemsbsd/rtems/rtems-bsd-nexus.c | 365 ------------------- rtemsbsd/rtems/rtems-bsd-page.c | 157 -------- rtemsbsd/rtems/rtems-bsd-panic.c | 64 ---- rtemsbsd/rtems/rtems-bsd-pci_bus.c | 78 ---- rtemsbsd/rtems/rtems-bsd-pci_cfgreg.c | 122 ------- rtemsbsd/rtems/rtems-bsd-program.c | 216 ----------- rtemsbsd/rtems/rtems-bsd-rwlock.c | 293 --------------- rtemsbsd/rtems/rtems-bsd-signal.c | 50 --- rtemsbsd/rtems/rtems-bsd-sx.c | 276 -------------- rtemsbsd/rtems/rtems-bsd-sysctl.c | 84 ----- rtemsbsd/rtems/rtems-bsd-sysctlbyname.c | 44 --- rtemsbsd/rtems/rtems-bsd-sysctlnametomib.c | 68 ---- rtemsbsd/rtems/rtems-bsd-thread.c | 370 ------------------- rtemsbsd/rtems/rtems-bsd-timesupport.c | 54 --- rtemsbsd/rtems/rtems-bsd-vprintf.c | 119 ------ rtemsbsd/rtems/rtems-bsdnet-rtrequest.c | 55 --- rtemsbsd/rtems/rtems-kernel-assert.c | 57 +++ rtemsbsd/rtems/rtems-kernel-autoconf.c | 69 ++++ rtemsbsd/rtems/rtems-kernel-bus-dma-mbuf.c | 129 +++++++ rtemsbsd/rtems/rtems-kernel-bus-dma.c | 436 ++++++++++++++++++++++ rtemsbsd/rtems/rtems-kernel-bus-root.c | 91 +++++ rtemsbsd/rtems/rtems-kernel-cam.c | 504 ++++++++++++++++++++++++++ rtemsbsd/rtems/rtems-kernel-chunk.c | 150 ++++++++ rtemsbsd/rtems/rtems-kernel-conf.c | 65 ++++ rtemsbsd/rtems/rtems-kernel-configintrhook.c | 58 +++ rtemsbsd/rtems/rtems-kernel-delay.c | 53 +++ rtemsbsd/rtems/rtems-kernel-get-file.c | 59 +++ rtemsbsd/rtems/rtems-kernel-init.c | 120 ++++++ rtemsbsd/rtems/rtems-kernel-irqs.c | 63 ++++ rtemsbsd/rtems/rtems-kernel-jail.c | 317 ++++++++++++++++ rtemsbsd/rtems/rtems-kernel-malloc.c | 127 +++++++ rtemsbsd/rtems/rtems-kernel-mbuf.c | 68 ++++ rtemsbsd/rtems/rtems-kernel-mutex.c | 227 ++++++++++++ rtemsbsd/rtems/rtems-kernel-muteximpl.c | 95 +++++ rtemsbsd/rtems/rtems-kernel-nexus.c | 365 +++++++++++++++++++ rtemsbsd/rtems/rtems-kernel-page.c | 157 ++++++++ rtemsbsd/rtems/rtems-kernel-panic.c | 64 ++++ rtemsbsd/rtems/rtems-kernel-pci_bus.c | 78 ++++ rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c | 122 +++++++ rtemsbsd/rtems/rtems-kernel-program.c | 216 +++++++++++ rtemsbsd/rtems/rtems-kernel-rwlock.c | 293 +++++++++++++++ rtemsbsd/rtems/rtems-kernel-signal.c | 50 +++ rtemsbsd/rtems/rtems-kernel-sx.c | 276 ++++++++++++++ rtemsbsd/rtems/rtems-kernel-sysctl.c | 84 +++++ rtemsbsd/rtems/rtems-kernel-sysctlbyname.c | 44 +++ rtemsbsd/rtems/rtems-kernel-sysctlnametomib.c | 68 ++++ rtemsbsd/rtems/rtems-kernel-thread.c | 370 +++++++++++++++++++ rtemsbsd/rtems/rtems-kernel-timesupport.c | 54 +++ rtemsbsd/rtems/rtems-kernel-vprintf.c | 119 ++++++ rtemsbsd/rtems/rtems-legacy-mii.c | 254 +++++++++++++ rtemsbsd/rtems/rtems-legacy-newproc.c | 116 ++++++ rtemsbsd/rtems/rtems-legacy-rtrequest.c | 55 +++ rtemsbsd/rtems/rtems_mii_ioctl_kern.c | 254 ------------- 75 files changed, 5551 insertions(+), 5584 deletions(-) delete mode 100644 rtemsbsd/rtems/rtems-bsd-assert.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-autoconf.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-bus-dma.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-bus-root.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-cam.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-chunk.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-conf.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-configintrhook.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-delay.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-get-file.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-init.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-irqs.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-jail.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-malloc.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-mbuf.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-mutex.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-muteximpl.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-newproc.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-nexus.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-page.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-panic.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-pci_bus.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-pci_cfgreg.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-program.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-rwlock.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-signal.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-sx.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-sysctl.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-sysctlbyname.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-sysctlnametomib.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-thread.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-timesupport.c delete mode 100644 rtemsbsd/rtems/rtems-bsd-vprintf.c delete mode 100644 rtemsbsd/rtems/rtems-bsdnet-rtrequest.c create mode 100644 rtemsbsd/rtems/rtems-kernel-assert.c create mode 100644 rtemsbsd/rtems/rtems-kernel-autoconf.c create mode 100644 rtemsbsd/rtems/rtems-kernel-bus-dma-mbuf.c create mode 100644 rtemsbsd/rtems/rtems-kernel-bus-dma.c create mode 100644 rtemsbsd/rtems/rtems-kernel-bus-root.c create mode 100644 rtemsbsd/rtems/rtems-kernel-cam.c create mode 100644 rtemsbsd/rtems/rtems-kernel-chunk.c create mode 100644 rtemsbsd/rtems/rtems-kernel-conf.c create mode 100644 rtemsbsd/rtems/rtems-kernel-configintrhook.c create mode 100644 rtemsbsd/rtems/rtems-kernel-delay.c create mode 100644 rtemsbsd/rtems/rtems-kernel-get-file.c create mode 100644 rtemsbsd/rtems/rtems-kernel-init.c create mode 100644 rtemsbsd/rtems/rtems-kernel-irqs.c create mode 100644 rtemsbsd/rtems/rtems-kernel-jail.c create mode 100644 rtemsbsd/rtems/rtems-kernel-malloc.c create mode 100644 rtemsbsd/rtems/rtems-kernel-mbuf.c create mode 100644 rtemsbsd/rtems/rtems-kernel-mutex.c create mode 100644 rtemsbsd/rtems/rtems-kernel-muteximpl.c create mode 100644 rtemsbsd/rtems/rtems-kernel-nexus.c create mode 100644 rtemsbsd/rtems/rtems-kernel-page.c create mode 100644 rtemsbsd/rtems/rtems-kernel-panic.c create mode 100644 rtemsbsd/rtems/rtems-kernel-pci_bus.c create mode 100644 rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c create mode 100644 rtemsbsd/rtems/rtems-kernel-program.c create mode 100644 rtemsbsd/rtems/rtems-kernel-rwlock.c create mode 100644 rtemsbsd/rtems/rtems-kernel-signal.c create mode 100644 rtemsbsd/rtems/rtems-kernel-sx.c create mode 100644 rtemsbsd/rtems/rtems-kernel-sysctl.c create mode 100644 rtemsbsd/rtems/rtems-kernel-sysctlbyname.c create mode 100644 rtemsbsd/rtems/rtems-kernel-sysctlnametomib.c create mode 100644 rtemsbsd/rtems/rtems-kernel-thread.c create mode 100644 rtemsbsd/rtems/rtems-kernel-timesupport.c create mode 100644 rtemsbsd/rtems/rtems-kernel-vprintf.c create mode 100644 rtemsbsd/rtems/rtems-legacy-mii.c create mode 100644 rtemsbsd/rtems/rtems-legacy-newproc.c create mode 100644 rtemsbsd/rtems/rtems-legacy-rtrequest.c delete mode 100644 rtemsbsd/rtems/rtems_mii_ioctl_kern.c diff --git a/create-kernel-namespace.sh b/create-kernel-namespace.sh index a30df850..0524c747 100755 --- a/create-kernel-namespace.sh +++ b/create-kernel-namespace.sh @@ -36,43 +36,10 @@ # . # -objdump --syms `for i in build/*rtems* ; do find $i/freebsd/sys/ -name '*.o' ; echo \ - $i/rtemsbsd/rtems/rtems-bsd-assert*.o \ - $i/rtemsbsd/rtems/rtems-bsd-autoconf*.o \ - $i/rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf*.o \ - $i/rtemsbsd/rtems/rtems-bsd-bus-dma*.o \ - $i/rtemsbsd/rtems/rtems-bsd-bus-root*.o \ - $i/rtemsbsd/rtems/rtems-bsd-cam*.o \ - $i/rtemsbsd/rtems/rtems-bsd-chunk*.o \ - $i/rtemsbsd/rtems/rtems-bsd-configintrhook*.o \ - $i/rtemsbsd/rtems/rtems-bsd-conf*.o \ - $i/rtemsbsd/rtems/rtems-bsd-delay*.o \ - $i/rtemsbsd/rtems/rtems-bsd-get-file*.o \ - $i/rtemsbsd/rtems/rtems-bsd-init*.o \ - $i/rtemsbsd/rtems/rtems-bsd-irqs*.o \ - $i/rtemsbsd/rtems/rtems-bsd-jail*.o \ - $i/rtemsbsd/rtems/rtems-bsd-log*.o \ - $i/rtemsbsd/rtems/rtems-bsd-malloc*.o \ - $i/rtemsbsd/rtems/rtems-bsd-mbuf*.o \ - $i/rtemsbsd/rtems/rtems-bsd-muteximpl*.o \ - $i/rtemsbsd/rtems/rtems-bsd-mutex*.o \ - $i/rtemsbsd/rtems/rtems-bsdnet-rtrequest*.o \ - $i/rtemsbsd/rtems/rtems-bsd-nexus*.o \ - $i/rtemsbsd/rtems/rtems-bsd-page*.o \ - $i/rtemsbsd/rtems/rtems-bsd-panic*.o \ - $i/rtemsbsd/rtems/rtems-bsd-pci_bus*.o \ - $i/rtemsbsd/rtems/rtems-bsd-pci_cfgreg*.o \ - $i/rtemsbsd/rtems/rtems-bsd-program*.o \ - $i/rtemsbsd/rtems/rtems-bsd-rwlock*.o \ - $i/rtemsbsd/rtems/rtems-bsd-shell*.o \ - $i/rtemsbsd/rtems/rtems-bsd-signal*.o \ - $i/rtemsbsd/rtems/rtems-bsd-sx*.o \ - $i/rtemsbsd/rtems/rtems-bsd-sysctlbyname*.o \ - $i/rtemsbsd/rtems/rtems-bsd-sysctlnametomib*.o \ - $i/rtemsbsd/rtems/rtems-bsd-sysctl*.o \ - $i/rtemsbsd/rtems/rtems-bsd-thread*.o \ - $i/rtemsbsd/rtems/rtems-bsd-timesupport*.o \ - $i/rtemsbsd/rtems/rtems_mii_ioctl_kern*.o ; done` \ +objdump --syms `for i in build/*rtems* ; do \ + find $i/freebsd/sys/ -name '*.o' ; \ + echo $i/rtemsbsd/rtems/rtems-kernel-*.o ; \ + done` \ | awk '/^[0-9a-f]+[[:blank:]]+g/ {print $6}' \ | sed 's/^_bsd_//' \ | sed '/^accept$/d' \ diff --git a/libbsd.py b/libbsd.py index a53e8d9b..194662c9 100755 --- a/libbsd.py +++ b/libbsd.py @@ -1,7 +1,7 @@ # # Copyright (c) 2015-2016 Chris Johns . All rights reserved. # -# Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. +# Copyright (c) 2009, 2016 embedded brains GmbH. All rights reserved. # # embedded brains GmbH # Dornierstr. 4 @@ -57,52 +57,52 @@ def rtems(mm): 'local/mmcbus_if.c', 'local/mmcbr_if.c', 'rtems/ipsec_get_policylen.c', - 'rtems/rtems-bsd-assert.c', 'rtems/rtems-bsd-arp-processor.c', - 'rtems/rtems-bsd-autoconf.c', - 'rtems/rtems-bsd-bus-dma.c', - 'rtems/rtems-bsd-bus-dma-mbuf.c', - 'rtems/rtems-bsd-bus-root.c', - 'rtems/rtems-bsd-cam.c', - 'rtems/rtems-bsd-chunk.c', - 'rtems/rtems-bsd-conf.c', - 'rtems/rtems-bsd-configintrhook.c', - 'rtems/rtems-bsd-delay.c', + 'rtems/rtems-bsd-get-allocator-domain-size.c', 'rtems/rtems-bsd-get-ethernet-addr.c', - 'rtems/rtems-bsd-get-file.c', 'rtems/rtems-bsd-get-mac-address.c', - 'rtems/rtems-bsd-get-allocator-domain-size.c', 'rtems/rtems-bsd-get-task-priority.c', 'rtems/rtems-bsd-get-task-stack-size.c', - 'rtems/rtems-bsd-init.c', - 'rtems/rtems-bsd-irqs.c', - 'rtems/rtems-bsd-jail.c', - 'rtems/rtems-bsd-malloc.c', - 'rtems/rtems-bsd-mbuf.c', - 'rtems/rtems-bsd-mutex.c', - 'rtems/rtems-bsd-muteximpl.c', - 'rtems/rtems-bsd-newproc.c', - 'rtems/rtems-bsd-nexus.c', - 'rtems/rtems-bsd-page.c', - 'rtems/rtems-bsd-panic.c', - 'rtems/rtems-bsd-pci_bus.c', - 'rtems/rtems-bsd-pci_cfgreg.c', - 'rtems/rtems-bsd-program.c', - 'rtems/rtems-bsd-rwlock.c', 'rtems/rtems-bsd-shell.c', 'rtems/rtems-bsd-shell-netcmds.c', - 'rtems/rtems-bsd-signal.c', - 'rtems/rtems-bsd-sx.c', 'rtems/rtems-bsd-syscall-api.c', - 'rtems/rtems-bsd-sysctlbyname.c', - 'rtems/rtems-bsd-sysctl.c', - 'rtems/rtems-bsd-sysctlnametomib.c', - 'rtems/rtems-bsd-thread.c', - 'rtems/rtems-bsd-timesupport.c', - 'rtems/rtems-bsd-vprintf.c', - 'rtems/rtems-bsdnet-rtrequest.c', + 'rtems/rtems-kernel-assert.c', + 'rtems/rtems-kernel-autoconf.c', + 'rtems/rtems-kernel-bus-dma.c', + 'rtems/rtems-kernel-bus-dma-mbuf.c', + 'rtems/rtems-kernel-bus-root.c', + 'rtems/rtems-kernel-cam.c', + 'rtems/rtems-kernel-chunk.c', + 'rtems/rtems-kernel-conf.c', + 'rtems/rtems-kernel-configintrhook.c', + 'rtems/rtems-kernel-delay.c', + 'rtems/rtems-kernel-get-file.c', + 'rtems/rtems-kernel-init.c', + 'rtems/rtems-kernel-irqs.c', + 'rtems/rtems-kernel-jail.c', + 'rtems/rtems-kernel-malloc.c', + 'rtems/rtems-kernel-mbuf.c', + 'rtems/rtems-kernel-mutex.c', + 'rtems/rtems-kernel-muteximpl.c', + 'rtems/rtems-kernel-nexus.c', + 'rtems/rtems-kernel-page.c', + 'rtems/rtems-kernel-panic.c', + 'rtems/rtems-kernel-pci_bus.c', + 'rtems/rtems-kernel-pci_cfgreg.c', + 'rtems/rtems-kernel-program.c', + 'rtems/rtems-kernel-rwlock.c', + 'rtems/rtems-kernel-signal.c', + 'rtems/rtems-kernel-sx.c', + 'rtems/rtems-kernel-sysctlbyname.c', + 'rtems/rtems-kernel-sysctl.c', + 'rtems/rtems-kernel-sysctlnametomib.c', + 'rtems/rtems-kernel-thread.c', + 'rtems/rtems-kernel-timesupport.c', + 'rtems/rtems-kernel-vprintf.c', + 'rtems/rtems-legacy-rtrequest.c', + 'rtems/rtems-legacy-newproc.c', + 'rtems/rtems-legacy-mii.c', 'rtems/rtems-kvm.c', - 'rtems/rtems_mii_ioctl_kern.c', 'rtems/syslog.c', 'ftpd/ftpd.c', 'mdns/mdns.c', diff --git a/libbsd_waf.py b/libbsd_waf.py index 36e39426..3f6fa12f 100644 --- a/libbsd_waf.py +++ b/libbsd_waf.py @@ -972,52 +972,52 @@ def build(bld): 'rtemsbsd/pppd/utils.c', 'rtemsbsd/rtems/ipsec_get_policylen.c', 'rtemsbsd/rtems/rtems-bsd-arp-processor.c', - 'rtemsbsd/rtems/rtems-bsd-assert.c', - 'rtemsbsd/rtems/rtems-bsd-autoconf.c', - 'rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c', - 'rtemsbsd/rtems/rtems-bsd-bus-dma.c', - 'rtemsbsd/rtems/rtems-bsd-bus-root.c', - 'rtemsbsd/rtems/rtems-bsd-cam.c', - 'rtemsbsd/rtems/rtems-bsd-chunk.c', - 'rtemsbsd/rtems/rtems-bsd-conf.c', - 'rtemsbsd/rtems/rtems-bsd-configintrhook.c', - 'rtemsbsd/rtems/rtems-bsd-delay.c', 'rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c', 'rtemsbsd/rtems/rtems-bsd-get-ethernet-addr.c', - 'rtemsbsd/rtems/rtems-bsd-get-file.c', 'rtemsbsd/rtems/rtems-bsd-get-mac-address.c', 'rtemsbsd/rtems/rtems-bsd-get-task-priority.c', 'rtemsbsd/rtems/rtems-bsd-get-task-stack-size.c', - 'rtemsbsd/rtems/rtems-bsd-init.c', - 'rtemsbsd/rtems/rtems-bsd-irqs.c', - 'rtemsbsd/rtems/rtems-bsd-jail.c', - 'rtemsbsd/rtems/rtems-bsd-malloc.c', - 'rtemsbsd/rtems/rtems-bsd-mbuf.c', - 'rtemsbsd/rtems/rtems-bsd-mutex.c', - 'rtemsbsd/rtems/rtems-bsd-muteximpl.c', - 'rtemsbsd/rtems/rtems-bsd-newproc.c', - 'rtemsbsd/rtems/rtems-bsd-nexus.c', - 'rtemsbsd/rtems/rtems-bsd-page.c', - 'rtemsbsd/rtems/rtems-bsd-panic.c', - 'rtemsbsd/rtems/rtems-bsd-pci_bus.c', - 'rtemsbsd/rtems/rtems-bsd-pci_cfgreg.c', - 'rtemsbsd/rtems/rtems-bsd-program.c', - 'rtemsbsd/rtems/rtems-bsd-rwlock.c', 'rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c', 'rtemsbsd/rtems/rtems-bsd-shell-netcmds.c', 'rtemsbsd/rtems/rtems-bsd-shell.c', - 'rtemsbsd/rtems/rtems-bsd-signal.c', - 'rtemsbsd/rtems/rtems-bsd-sx.c', 'rtemsbsd/rtems/rtems-bsd-syscall-api.c', - 'rtemsbsd/rtems/rtems-bsd-sysctl.c', - 'rtemsbsd/rtems/rtems-bsd-sysctlbyname.c', - 'rtemsbsd/rtems/rtems-bsd-sysctlnametomib.c', - 'rtemsbsd/rtems/rtems-bsd-thread.c', - 'rtemsbsd/rtems/rtems-bsd-timesupport.c', - 'rtemsbsd/rtems/rtems-bsd-vprintf.c', - 'rtemsbsd/rtems/rtems-bsdnet-rtrequest.c', + 'rtemsbsd/rtems/rtems-kernel-assert.c', + 'rtemsbsd/rtems/rtems-kernel-autoconf.c', + 'rtemsbsd/rtems/rtems-kernel-bus-dma-mbuf.c', + 'rtemsbsd/rtems/rtems-kernel-bus-dma.c', + 'rtemsbsd/rtems/rtems-kernel-bus-root.c', + 'rtemsbsd/rtems/rtems-kernel-cam.c', + 'rtemsbsd/rtems/rtems-kernel-chunk.c', + 'rtemsbsd/rtems/rtems-kernel-conf.c', + 'rtemsbsd/rtems/rtems-kernel-configintrhook.c', + 'rtemsbsd/rtems/rtems-kernel-delay.c', + 'rtemsbsd/rtems/rtems-kernel-get-file.c', + 'rtemsbsd/rtems/rtems-kernel-init.c', + 'rtemsbsd/rtems/rtems-kernel-irqs.c', + 'rtemsbsd/rtems/rtems-kernel-jail.c', + 'rtemsbsd/rtems/rtems-kernel-malloc.c', + 'rtemsbsd/rtems/rtems-kernel-mbuf.c', + 'rtemsbsd/rtems/rtems-kernel-mutex.c', + 'rtemsbsd/rtems/rtems-kernel-muteximpl.c', + 'rtemsbsd/rtems/rtems-kernel-nexus.c', + 'rtemsbsd/rtems/rtems-kernel-page.c', + 'rtemsbsd/rtems/rtems-kernel-panic.c', + 'rtemsbsd/rtems/rtems-kernel-pci_bus.c', + 'rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c', + 'rtemsbsd/rtems/rtems-kernel-program.c', + 'rtemsbsd/rtems/rtems-kernel-rwlock.c', + 'rtemsbsd/rtems/rtems-kernel-signal.c', + 'rtemsbsd/rtems/rtems-kernel-sx.c', + 'rtemsbsd/rtems/rtems-kernel-sysctl.c', + 'rtemsbsd/rtems/rtems-kernel-sysctlbyname.c', + 'rtemsbsd/rtems/rtems-kernel-sysctlnametomib.c', + 'rtemsbsd/rtems/rtems-kernel-thread.c', + 'rtemsbsd/rtems/rtems-kernel-timesupport.c', + 'rtemsbsd/rtems/rtems-kernel-vprintf.c', 'rtemsbsd/rtems/rtems-kvm.c', - 'rtemsbsd/rtems/rtems_mii_ioctl_kern.c', + 'rtemsbsd/rtems/rtems-legacy-mii.c', + 'rtemsbsd/rtems/rtems-legacy-newproc.c', + 'rtemsbsd/rtems/rtems-legacy-rtrequest.c', 'rtemsbsd/rtems/syslog.c', 'rtemsbsd/sys/dev/dw_mmc/dw_mmc.c', 'rtemsbsd/sys/dev/ffec/if_ffec_mcf548x.c', diff --git a/rtemsbsd/rtems/rtems-bsd-assert.c b/rtemsbsd/rtems/rtems-bsd-assert.c deleted file mode 100644 index 3ebe19e7..00000000 --- a/rtemsbsd/rtems/rtems-bsd-assert.c +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009, 2010 embedded brains GmbH. - * All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include - -void -rtems_bsd_assert_func(const char *file, int line, const char *func, const char *expr) -{ - panic( - "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", - expr, - file, - line, - (func != NULL) ? ", function: " : "", - (func != NULL) ? func : "" - ); -} diff --git a/rtemsbsd/rtems/rtems-bsd-autoconf.c b/rtemsbsd/rtems/rtems-bsd-autoconf.c deleted file mode 100644 index ea250c05..00000000 --- a/rtemsbsd/rtems/rtems-bsd-autoconf.c +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009, 2010 embedded brains GmbH. - * All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include -#include -#include -#include - -static void -configure_first(void *dummy) -{ - device_add_child(root_bus, "nexus", 0); -} - -static void -configure(void *dummy) -{ - root_bus_configure(); -} - -static void -configure_final(void *dummy) -{ - /* Do nothing */ -} - -SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL); -SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL); -SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL); diff --git a/rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c b/rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c deleted file mode 100644 index c435fd74..00000000 --- a/rtemsbsd/rtems/rtems-bsd-bus-dma-mbuf.c +++ /dev/null @@ -1,129 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - * - * File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c". - */ - -/*- - * Copyright (c) 2012 embedded brains GmbH. - * All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Copyright (c) 1997, 1998 Justin T. Gibbs. - * All rights reserved. - * - * 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, - * without modification, immediately at the beginning of the file. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include - -/* - * Like bus_dmamap_load(), but for mbufs. - */ -int -bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *m0, - bus_dmamap_callback2_t *callback, void *callback_arg, - int flags) -{ - bus_dma_segment_t dm_segments[dmat->nsegments]; - int nsegs, error; - - M_ASSERTPKTHDR(m0); - - flags |= BUS_DMA_NOWAIT; - nsegs = 0; - error = 0; - if (m0->m_pkthdr.len <= dmat->maxsize) { - int first = 1; - bus_addr_t lastaddr = 0; - struct mbuf *m; - - for (m = m0; m != NULL && error == 0; m = m->m_next) { - if (m->m_len > 0) { - error = bus_dmamap_load_buffer(dmat, dm_segments, - m->m_data, m->m_len, - NULL, flags, &lastaddr, - &nsegs, first); - first = 0; - } - } - } else { - error = EINVAL; - } - - if (error) { - /* force "no valid mappings" in callback */ - (*callback)(callback_arg, dm_segments, 0, 0, error); - } else { - (*callback)(callback_arg, dm_segments, - nsegs+1, m0->m_pkthdr.len, error); - } - return (error); -} - -int -bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, - struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs, - int flags) -{ - int error; - - M_ASSERTPKTHDR(m0); - - flags |= BUS_DMA_NOWAIT; - *nsegs = 0; - error = 0; - if (m0->m_pkthdr.len <= dmat->maxsize) { - int first = 1; - bus_addr_t lastaddr = 0; - struct mbuf *m; - - for (m = m0; m != NULL && error == 0; m = m->m_next) { - if (m->m_len > 0) { - error = bus_dmamap_load_buffer(dmat, segs, - m->m_data, m->m_len, - NULL, flags, &lastaddr, - nsegs, first); - first = 0; - } - } - } else { - error = EINVAL; - } - - /* XXX FIXME: Having to increment nsegs is really annoying */ - ++*nsegs; - return (error); -} diff --git a/rtemsbsd/rtems/rtems-bsd-bus-dma.c b/rtemsbsd/rtems/rtems-bsd-bus-dma.c deleted file mode 100644 index c7cc8724..00000000 --- a/rtemsbsd/rtems/rtems-bsd-bus-dma.c +++ /dev/null @@ -1,436 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - * - * File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c". - */ - -/* - * Copyright (c) 2009-2012 embedded brains GmbH. - * All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Copyright (c) 2004 Olivier Houchard - * Copyright (c) 2002 Peter Grehan - * Copyright (c) 1997, 1998 Justin T. Gibbs. - * All rights reserved. - * - * 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, - * without modification, immediately at the beginning of the file. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include - -#include -#include - -#ifdef CPU_DATA_CACHE_ALIGNMENT - #define CLSZ ((uintptr_t) CPU_DATA_CACHE_ALIGNMENT) - #define CLMASK (CLSZ - (uintptr_t) 1) -#endif - -/* - * Convenience function for manipulating driver locks from busdma (during - * busdma_swi, for example). Drivers that don't provide their own locks - * should specify &Giant to dmat->lockfuncarg. Drivers that use their own - * non-mutex locking scheme don't have to use this at all. - */ -void -busdma_lock_mutex(void *arg, bus_dma_lock_op_t op) -{ - struct mtx *dmtx; - - dmtx = (struct mtx *)arg; - switch (op) { - case BUS_DMA_LOCK: - mtx_lock(dmtx); - break; - case BUS_DMA_UNLOCK: - mtx_unlock(dmtx); - break; - default: - panic("Unknown operation 0x%x for busdma_lock_mutex!", op); - } -} - -/* - * dflt_lock should never get called. It gets put into the dma tag when - * lockfunc == NULL, which is only valid if the maps that are associated - * with the tag are meant to never be defered. - * XXX Should have a way to identify which driver is responsible here. - */ -static void -dflt_lock(void *arg, bus_dma_lock_op_t op) -{ - panic("driver error: busdma dflt_lock called"); -} - -/* - * Allocate a device specific dma_tag. - */ -int -bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, - bus_size_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, - bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, - int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, - void *lockfuncarg, bus_dma_tag_t *dmat) -{ - bus_dma_tag_t newtag; - int error = 0; - - /* Return a NULL tag on failure */ - *dmat = NULL; - - newtag = malloc(sizeof(*newtag), M_DEVBUF, M_NOWAIT | M_ZERO); - if (newtag == NULL) - return (ENOMEM); - - newtag->parent = parent; - newtag->alignment = alignment; - newtag->boundary = boundary; - newtag->lowaddr = lowaddr; - newtag->highaddr = highaddr; - newtag->filter = filter; - newtag->filterarg = filterarg; - newtag->maxsize = maxsize; - newtag->nsegments = nsegments; - newtag->maxsegsz = maxsegsz; - newtag->flags = flags; - newtag->ref_count = 1; /* Count ourself */ - newtag->map_count = 0; - if (lockfunc != NULL) { - newtag->lockfunc = lockfunc; - newtag->lockfuncarg = lockfuncarg; - } else { - newtag->lockfunc = dflt_lock; - newtag->lockfuncarg = NULL; - } - - /* - * Take into account any restrictions imposed by our parent tag - */ - if (parent != NULL) { - newtag->lowaddr = min(parent->lowaddr, newtag->lowaddr); - newtag->highaddr = max(parent->highaddr, newtag->highaddr); - if (newtag->boundary == 0) - newtag->boundary = parent->boundary; - else if (parent->boundary != 0) - newtag->boundary = MIN(parent->boundary, - newtag->boundary); - if (newtag->filter == NULL) { - /* - * Short circuit looking at our parent directly - * since we have encapsulated all of its information - */ - newtag->filter = parent->filter; - newtag->filterarg = parent->filterarg; - newtag->parent = parent->parent; - } - if (newtag->parent != NULL) - atomic_add_int(&parent->ref_count, 1); - } - - *dmat = newtag; - return (error); -} - -int -bus_dma_tag_destroy(bus_dma_tag_t dmat) -{ - if (dmat != NULL) { - - if (dmat->map_count != 0) - return (EBUSY); - - while (dmat != NULL) { - bus_dma_tag_t parent; - - parent = dmat->parent; - atomic_subtract_int(&dmat->ref_count, 1); - if (dmat->ref_count == 0) { - free(dmat, M_DEVBUF); - /* - * Last reference count, so - * release our reference - * count on our parent. - */ - dmat = parent; - } else - dmat = NULL; - } - } - return (0); -} - -/* - * Allocate a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int -bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) -{ - *mapp = malloc(sizeof(**mapp), M_DEVBUF, M_NOWAIT | M_ZERO); - if (*mapp == NULL) { - return ENOMEM; - } - - dmat->map_count++; - - return (0); -} - -/* - * Destroy a handle for mapping from kva/uva/physical - * address space into bus device space. - */ -int -bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) -{ - free(map, M_DEVBUF); - - dmat->map_count--; - - return (0); -} - -/* - * Allocate a piece of memory that can be efficiently mapped into - * bus device space based on the constraints lited in the dma tag. - * A dmamap to for use with dmamap_load is also allocated. - */ -int -bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, - bus_dmamap_t *mapp) -{ - *mapp = malloc(sizeof(**mapp), M_DEVBUF, M_NOWAIT | M_ZERO); - if (*mapp == NULL) { - return ENOMEM; - } - - if ((flags & BUS_DMA_COHERENT) != 0) { - *vaddr = rtems_cache_coherent_allocate( - dmat->maxsize, dmat->alignment, dmat->boundary); - } else { - *vaddr = rtems_heap_allocate_aligned_with_boundary( - dmat->maxsize, dmat->alignment, dmat->boundary); - } - - if (*vaddr == NULL) { - free(*mapp, M_DEVBUF); - - return ENOMEM; - } - - (*mapp)->buffer_begin = *vaddr; - (*mapp)->buffer_size = dmat->maxsize; - - if ((flags & BUS_DMA_ZERO) != 0) { - memset(*vaddr, 0, dmat->maxsize); - } - - return (0); -} - -/* - * Free a piece of memory and it's allocated dmamap, that was allocated - * via bus_dmamem_alloc. Make the same choice for free/contigfree. - */ -void -bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) -{ - rtems_cache_coherent_free(vaddr); - free(map, M_DEVBUF); -} - -/* - * Utility function to load a linear buffer. lastaddrp holds state - * between invocations (for multiple-buffer loads). segp contains - * the starting segment on entrance, and the ending segment on exit. - * first indicates if this is the first invocation of this function. - */ -int -bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dma_segment_t segs[], - void *buf, bus_size_t buflen, struct thread *td, int flags, - vm_offset_t *lastaddrp, int *segp, int first) -{ - bus_size_t sgsize; - bus_addr_t curaddr, lastaddr, baddr, bmask; - vm_offset_t vaddr = (vm_offset_t)buf; - int seg; - - lastaddr = *lastaddrp; - bmask = ~(dmat->boundary - 1); - - for (seg = *segp; buflen > 0 ; ) { - /* - * Get the physical address for this segment. - */ - curaddr = vaddr; - - /* - * Compute the segment size, and adjust counts. - */ - sgsize = PAGE_SIZE - ((u_long)curaddr & PAGE_MASK); - if (sgsize > dmat->maxsegsz) - sgsize = dmat->maxsegsz; - if (buflen < sgsize) - sgsize = buflen; - - /* - * Make sure we don't cross any boundaries. - */ - if (dmat->boundary > 0) { - baddr = (curaddr + dmat->boundary) & bmask; - if (sgsize > (baddr - curaddr)) - sgsize = (baddr - curaddr); - } - - /* - * Insert chunk into a segment, coalescing with - * the previous segment if possible. - */ - if (first) { - segs[seg].ds_addr = curaddr; - segs[seg].ds_len = sgsize; - first = 0; - } else { - if (curaddr == lastaddr && - (segs[seg].ds_len + sgsize) <= dmat->maxsegsz && - (dmat->boundary == 0 || - (segs[seg].ds_addr & bmask) == (curaddr & bmask))) - segs[seg].ds_len += sgsize; - else { - if (++seg >= dmat->nsegments) - break; - segs[seg].ds_addr = curaddr; - segs[seg].ds_len = sgsize; - } - } - - lastaddr = curaddr + sgsize; - vaddr += sgsize; - buflen -= sgsize; - } - - *segp = seg; - *lastaddrp = lastaddr; - - /* - * Did we fit? - */ - return (buflen != 0 ? EFBIG : 0); /* XXX better return value here? */ -} - -/* - * Map the buffer buf into bus space using the dmamap map. - */ -int -bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, - bus_size_t buflen, bus_dmamap_callback_t *callback, - void *callback_arg, int flags) -{ - bus_dma_segment_t dm_segments[dmat->nsegments]; - vm_offset_t lastaddr; - int error, nsegs; - - map->buffer_begin = buf; - map->buffer_size = buflen; - - lastaddr = (vm_offset_t)0; - nsegs = 0; - error = bus_dmamap_load_buffer(dmat, dm_segments, buf, buflen, - NULL, flags, &lastaddr, &nsegs, 1); - - if (error == 0) - (*callback)(callback_arg, dm_segments, nsegs + 1, 0); - else - (*callback)(callback_arg, NULL, 0, error); - - return (0); -} - -/* - * Release the mapping held by map. A no-op on PowerPC. - */ -void -_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) -{ - - return; -} - -void -_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op) -{ -#ifdef CPU_DATA_CACHE_ALIGNMENT - uintptr_t size = map->buffer_size; - uintptr_t begin = (uintptr_t) map->buffer_begin; - uintptr_t end = begin + size; - - if ((op & BUS_DMASYNC_PREWRITE) != 0 && (op & BUS_DMASYNC_PREREAD) == 0) { - rtems_cache_flush_multiple_data_lines((void *) begin, size); - } - if ((op & BUS_DMASYNC_PREREAD) != 0) { - if ((op & BUS_DMASYNC_PREWRITE) != 0 || ((begin | size) & CLMASK) != 0) { - rtems_cache_flush_multiple_data_lines((void *) begin, size); - } - rtems_cache_invalidate_multiple_data_lines((void *) begin, size); - } - if ((op & BUS_DMASYNC_POSTREAD) != 0) { - char first_buf [CLSZ]; - char last_buf [CLSZ]; - bool first_is_aligned = (begin & CLMASK) == 0; - bool last_is_aligned = (end & CLMASK) == 0; - void *first_begin = (void *) (begin & ~CLMASK); - size_t first_size = begin & CLMASK; - void *last_begin = (void *) end; - size_t last_size = CLSZ - (end & CLMASK); - - if (!first_is_aligned) { - memcpy(first_buf, first_begin, first_size); - } - if (!last_is_aligned) { - memcpy(last_buf, last_begin, last_size); - } - - rtems_cache_invalidate_multiple_data_lines((void *) begin, size); - - if (!first_is_aligned) { - memcpy(first_begin, first_buf, first_size); - } - if (!last_is_aligned) { - memcpy(last_begin, last_buf, last_size); - } - } -#endif /* CPU_DATA_CACHE_ALIGNMENT */ -} diff --git a/rtemsbsd/rtems/rtems-bsd-bus-root.c b/rtemsbsd/rtems/rtems-bsd-bus-root.c deleted file mode 100644 index f444f512..00000000 --- a/rtemsbsd/rtems/rtems-bsd-bus-root.c +++ /dev/null @@ -1,91 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/*- - * Copyright (c) 2012-2013 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * 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, - * without modification, immediately at the beginning of the file. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include - -#include - -int -rtems_bsd_bus_root_attach(void) -{ - int err; - device_t dev; - - dev = device_find_child(root_bus, "nexus", 0); - if (dev != NULL) { - err = device_probe_and_attach(dev); - } else { - err = ENOENT; - } - - return (err); -} - -int -rtems_bsd_bus_root_suspend(void) -{ - - return (DEVICE_SUSPEND(root_bus)); -} - -int -rtems_bsd_bus_root_resume(void) -{ - - return (DEVICE_RESUME(root_bus)); -} - -int -rtems_bsd_bus_root_detach(void) -{ - int err; - device_t dev; - - dev = device_find_child(root_bus, "nexus", 0); - if (dev != NULL) { - err = device_detach(dev); - } else { - err = ENOENT; - } - - return (err); -} diff --git a/rtemsbsd/rtems/rtems-bsd-cam.c b/rtemsbsd/rtems/rtems-bsd-cam.c deleted file mode 100644 index 0f518586..00000000 --- a/rtemsbsd/rtems/rtems-bsd-cam.c +++ /dev/null @@ -1,504 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2012 embedded brains GmbH. - * All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#define BSD_CAM_DEVQ_DUMMY ((struct cam_devq *) 0xdeadbeef) - -#define BSD_SCSI_TAG 0 - -#define BSD_SCSI_RETRIES 4 - -#define BSD_SCSI_TIMEOUT (60 * 1000) - -#define BSD_SCSI_MIN_COMMAND_SIZE 10 - -MALLOC_DEFINE(M_CAMSIM, "CAM SIM", "CAM SIM buffers"); - -static void -rtems_bsd_sim_set_state(struct cam_sim *sim, enum bsd_sim_state state) -{ - sim->state = state; -} - -static void -rtems_bsd_sim_set_state_and_notify(struct cam_sim *sim, enum bsd_sim_state state) -{ - sim->state = state; - cv_broadcast(&sim->state_changed); -} - -static void -rtems_bsd_sim_wait_for_state(struct cam_sim *sim, enum bsd_sim_state state) -{ - while (sim->state != state) { - cv_wait(&sim->state_changed, sim->mtx); - } -} - -static void -rtems_bsd_sim_wait_for_state_and_cancel_ccb(struct cam_sim *sim, enum bsd_sim_state state) -{ - while (sim->state != state) { - if (sim->state != BSD_SIM_BUSY) { - cv_wait(&sim->state_changed, sim->mtx); - } else { - sim->ccb.ccb_h.status = CAM_SEL_TIMEOUT; - (*sim->ccb.ccb_h.cbfcnp)(NULL, &sim->ccb); - } - } -} - -static void -rtems_bsd_ccb_callback(struct cam_periph *periph, union ccb *ccb) -{ - struct cam_sim *sim = ccb->ccb_h.sim; - - BSD_ASSERT(periph == NULL && sim->state == BSD_SIM_INIT_BUSY); - - rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_INIT_READY); -} - -static rtems_status_code -rtems_bsd_ccb_action(union ccb *ccb) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - struct cam_sim *sim = ccb->ccb_h.sim; - - mtx_lock(sim->mtx); - - BSD_ASSERT(sim->state == BSD_SIM_INIT); - rtems_bsd_sim_set_state(sim, BSD_SIM_INIT_BUSY); - (*sim->sim_action)(sim, ccb); - rtems_bsd_sim_wait_for_state(sim, BSD_SIM_INIT_READY); - if (ccb->ccb_h.status != CAM_REQ_CMP) { - sc = RTEMS_IO_ERROR; - } - rtems_bsd_sim_set_state(sim, BSD_SIM_INIT); - - mtx_unlock(sim->mtx); - - return sc; -} - -static rtems_status_code -rtems_bsd_scsi_inquiry(union ccb *ccb, struct scsi_inquiry_data *inq_data) -{ - memset(inq_data, 0, sizeof(*inq_data)); - - scsi_inquiry( - &ccb->csio, - BSD_SCSI_RETRIES, - rtems_bsd_ccb_callback, - BSD_SCSI_TAG, - (u_int8_t *) inq_data, - SHORT_INQUIRY_LENGTH, - FALSE, - 0, - SSD_MIN_SIZE, - BSD_SCSI_TIMEOUT - ); - - return rtems_bsd_ccb_action(ccb); -} - -static rtems_status_code -rtems_bsd_scsi_test_unit_ready(union ccb *ccb) -{ - scsi_test_unit_ready( - &ccb->csio, - BSD_SCSI_RETRIES, - rtems_bsd_ccb_callback, - BSD_SCSI_TAG, - SSD_FULL_SIZE, - BSD_SCSI_TIMEOUT - ); - - return rtems_bsd_ccb_action(ccb); -} - -static rtems_status_code -rtems_bsd_scsi_read_capacity(union ccb *ccb, uint32_t *block_count, uint32_t *block_size) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - struct scsi_read_capacity_data rdcap; - - memset(&rdcap, 0, sizeof(rdcap)); - - scsi_read_capacity( - &ccb->csio, - BSD_SCSI_RETRIES, - rtems_bsd_ccb_callback, - BSD_SCSI_TAG, - &rdcap, - SSD_FULL_SIZE, - BSD_SCSI_TIMEOUT - ); - - sc = rtems_bsd_ccb_action(ccb); - if (sc != RTEMS_SUCCESSFUL) { - return RTEMS_IO_ERROR; - } - - *block_size = scsi_4btoul(rdcap.length); - *block_count = scsi_4btoul(rdcap.addr) + 1; - - return RTEMS_SUCCESSFUL; -} - -static void -rtems_bsd_csio_callback(struct cam_periph *periph, union ccb *ccb) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - bool done = false; - struct cam_sim *sim = ccb->ccb_h.sim; - - BSD_ASSERT(periph == NULL && sim->state == BSD_SIM_BUSY); - - if (ccb->ccb_h.status == CAM_REQ_CMP) { - rtems_blkdev_sg_buffer *sg = ccb->csio.sg_current; - - if (sg != ccb->csio.sg_end) { - scsi_read_write( - &ccb->csio, - BSD_SCSI_RETRIES, - rtems_bsd_csio_callback, - BSD_SCSI_TAG, - ccb->csio.readop, - 0, - BSD_SCSI_MIN_COMMAND_SIZE, - sg->block, - sg->length / 512, /* FIXME */ - sg->buffer, - sg->length, - SSD_FULL_SIZE, - BSD_SCSI_TIMEOUT - ); - ccb->csio.sg_current = sg + 1; - (*sim->sim_action)(sim, ccb); - } else { - done = true; - } - } else if (ccb->ccb_h.status == CAM_SEL_TIMEOUT) { - sc = RTEMS_UNSATISFIED; - done = true; - } else { - sc = RTEMS_IO_ERROR; - done = true; - } - - if (done) { - rtems_blkdev_request_done(ccb->csio.req, sc); - rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_IDLE); - } -} - -static int rtems_bsd_sim_disk_read_write(struct cam_sim *sim, rtems_blkdev_request *req) -{ - mtx_lock(sim->mtx); - - rtems_bsd_sim_wait_for_state(sim, BSD_SIM_IDLE); - rtems_bsd_sim_set_state(sim, BSD_SIM_BUSY); - - switch (req->req) { - case RTEMS_BLKDEV_REQ_READ: - sim->ccb.csio.readop = TRUE; - break; - case RTEMS_BLKDEV_REQ_WRITE: - sim->ccb.csio.readop = FALSE; - break; - default: - mtx_unlock(sim->mtx); - return -1; - } - - sim->ccb.csio.sg_current = req->bufs; - sim->ccb.csio.sg_end = req->bufs + req->bufnum; - sim->ccb.csio.req = req; - - sim->ccb.ccb_h.status = CAM_REQ_CMP; - - rtems_bsd_csio_callback(NULL, &sim->ccb); - - mtx_unlock(sim->mtx); - - return 0; -} - -static int rtems_bsd_sim_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg) -{ - struct cam_sim *sim = rtems_disk_get_driver_data(dd); - - if (req == RTEMS_BLKIO_REQUEST) { - rtems_blkdev_request *r = arg; - - return rtems_bsd_sim_disk_read_write(sim, r); - } else if (req == RTEMS_BLKIO_DELETED) { - mtx_lock(sim->mtx); - - free(sim->disk, M_RTEMS_HEAP); - sim->disk = NULL; - rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_DELETED); - - mtx_unlock(sim->mtx); - - return 0; - } else { - return rtems_blkdev_ioctl(dd, req, arg); - } -} - -static void -rtems_bsd_sim_disk_initialized(struct cam_sim *sim, char *disk) -{ - mtx_lock(sim->mtx); - - sim->disk = disk; - rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_IDLE); - - mtx_unlock(sim->mtx); -} - -static rtems_status_code -rtems_bsd_sim_attach_worker(rtems_media_state state, const char *src, char **dest, void *arg) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - struct cam_sim *sim = arg; - char *disk = NULL; - - if (state == RTEMS_MEDIA_STATE_READY) { - unsigned retries = 0; - - struct scsi_inquiry_data inq_data; - uint32_t block_count = 0; - uint32_t block_size = 0; - - disk = rtems_media_create_path("/dev", src, cam_sim_unit(sim)); - if (disk == NULL) { - BSD_PRINTF("OOPS: create path failed\n"); - goto error; - } - - sc = rtems_bsd_scsi_inquiry(&sim->ccb, &inq_data); - if (sc == RTEMS_SUCCESSFUL) { - scsi_print_inquiry(&inq_data); - } else { - BSD_PRINTF("OOPS: inquiry failed\n"); - } - - for (retries = 0; retries <= 3; ++retries) { - sc = rtems_bsd_scsi_test_unit_ready(&sim->ccb); - if (sc == RTEMS_SUCCESSFUL) { - break; - } - } - if (sc != RTEMS_SUCCESSFUL) { - BSD_PRINTF("OOPS: test unit ready failed\n"); - } - - for (retries = 0; retries <= 3; ++retries) { - sc = rtems_bsd_scsi_read_capacity(&sim->ccb, &block_count, &block_size); - if (sc == RTEMS_SUCCESSFUL) { - break; - } - } - if (sc != RTEMS_SUCCESSFUL) { - BSD_PRINTF("OOPS: read capacity failed\n"); - goto error; - } - - BSD_PRINTF("read capacity: block count %u, block size %u\n", block_count, block_size); - - sc = rtems_blkdev_create(disk, block_size, block_count, rtems_bsd_sim_disk_ioctl, sim); - if (sc != RTEMS_SUCCESSFUL) { - goto error; - } - - /* FIXME */ -#if 0 - rtems_disk_device *dd = rtems_disk_obtain(dev); - dd->block_size *= 64; - rtems_disk_release(dd); -#endif - - rtems_bsd_sim_disk_initialized(sim, disk); - - *dest = strdup(disk, M_RTEMS_HEAP); - } - - return RTEMS_SUCCESSFUL; - -error: - - free(disk, M_RTEMS_HEAP); - - rtems_bsd_sim_disk_initialized(sim, NULL); - - return RTEMS_IO_ERROR; -} - -struct cam_sim * -cam_sim_alloc( - sim_action_func sim_action, - sim_poll_func sim_poll, - const char *sim_name, - void *softc, - u_int32_t unit, - struct mtx *mtx, - int max_dev_transactions, - int max_tagged_dev_transactions, - struct cam_devq *queue -) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - struct cam_sim *sim = NULL; - - if (mtx == NULL) { - return NULL; - } - - sim = malloc(sizeof(*sim), M_CAMSIM, M_NOWAIT | M_ZERO); - if (sim == NULL) { - return NULL; - } - - sim->sim_action = sim_action; - sim->sim_poll = sim_poll; - sim->sim_name = sim_name; - sim->softc = softc; - sim->mtx = mtx; - sim->unit_number = unit; - sim->ccb.ccb_h.sim = sim; - - cv_init(&sim->state_changed, "SIM state changed"); - - sc = rtems_media_server_disk_attach(sim_name, rtems_bsd_sim_attach_worker, sim); - BSD_ASSERT_SC(sc); - - return sim; -} - -void -cam_sim_free(struct cam_sim *sim, int free_devq) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - - /* - * The umass_detach() cancels all transfers via - * usbd_transfer_unsetup(). This prevents also the start of new - * transfers since the transfer descriptors will be removed. Started - * transfers that are not in the transferring state will be canceled - * and the callbacks will be not called. Thus it is necessary to do - * this here if we are in the BUSY state. - */ - rtems_bsd_sim_wait_for_state_and_cancel_ccb(sim, BSD_SIM_IDLE); - - if (sim->disk != NULL) { - sc = rtems_media_server_disk_detach(sim->disk); - BSD_ASSERT_SC(sc); - - rtems_bsd_sim_wait_for_state(sim, BSD_SIM_DELETED); - } - - cv_destroy(&sim->state_changed); - free(sim, M_CAMSIM); -} - -struct cam_devq * -cam_simq_alloc(u_int32_t max_sim_transactions) -{ - return BSD_CAM_DEVQ_DUMMY; -} - -void -cam_simq_free(struct cam_devq *devq) -{ - BSD_ASSERT(devq == BSD_CAM_DEVQ_DUMMY); -} - -void -xpt_done(union ccb *done_ccb) -{ - (*done_ccb->ccb_h.cbfcnp)(NULL, done_ccb); -} - -int32_t -xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus) -{ - /* - * We ignore this bus stuff completely. This is easier than removing - * the calls from "umass.c". - */ - - return CAM_SUCCESS; -} - -int32_t -xpt_bus_deregister(path_id_t pathid) -{ - /* - * We ignore this bus stuff completely. This is easier than removing - * the calls from "umass.c". - */ - - return CAM_REQ_CMP; -} diff --git a/rtemsbsd/rtems/rtems-bsd-chunk.c b/rtemsbsd/rtems/rtems-bsd-chunk.c deleted file mode 100644 index a327fe5e..00000000 --- a/rtemsbsd/rtems/rtems-bsd-chunk.c +++ /dev/null @@ -1,150 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2013-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include - -#include -#include - -#define chunk_of_node(n) ((rtems_bsd_chunk_info *) n) - -static rtems_rbtree_compare_result -chunk_compare(const rtems_rbtree_node *a, const rtems_rbtree_node *b) -{ - const rtems_bsd_chunk_info *left = chunk_of_node(a); - const rtems_bsd_chunk_info *right = chunk_of_node(b); - - if (left->begin < right->begin) { - return -1; - } else if (left->begin < right->end) { - return 0; - } else { - return 1; - } -} - -void -rtems_bsd_chunk_init(rtems_bsd_chunk_control *self, uintptr_t info_size, - rtems_bsd_chunk_info_ctor info_ctor, rtems_bsd_chunk_info_dtor info_dtor) -{ - uintptr_t align = rtems_cache_get_data_line_size(); - - if (align < CPU_HEAP_ALIGNMENT) - align = CPU_HEAP_ALIGNMENT; - - info_size = roundup(info_size, align); - - self->info_size = info_size; - self->info_ctor = info_ctor; - self->info_dtor = info_dtor; - rtems_rbtree_initialize_empty(&self->chunks); -} - -void * -rtems_bsd_chunk_alloc(rtems_bsd_chunk_control *self, uintptr_t chunk_size) -{ - char *p = rtems_cache_aligned_malloc(chunk_size + self->info_size); - - if (p != NULL) { - rtems_bsd_chunk_info *info = (rtems_bsd_chunk_info *) p; - - p += self->info_size; - - info->begin = (uintptr_t) p; - info->end = (uintptr_t) p + chunk_size; - - (*self->info_ctor)(self, info); - - _RTEMS_Lock_allocator(); - rtems_rbtree_insert(&self->chunks, &info->node, chunk_compare, true); - _RTEMS_Unlock_allocator(); - } - - return p; -} - -void -rtems_bsd_chunk_free(rtems_bsd_chunk_control *self, - void *some_addr_in_chunk) -{ - rtems_bsd_chunk_info *info = rtems_bsd_chunk_get_info(self, - some_addr_in_chunk); - - _RTEMS_Lock_allocator(); - rtems_rbtree_extract(&self->chunks, &info->node); - _RTEMS_Unlock_allocator(); - - (*self->info_dtor)(self, info); - - free(info, M_RTEMS_HEAP); -} - -rtems_bsd_chunk_info * -rtems_bsd_chunk_get_info(rtems_bsd_chunk_control *self, - void *some_addr_in_chunk) -{ - rtems_bsd_chunk_info find_me = { - .begin = (uintptr_t) some_addr_in_chunk - }; - - return chunk_of_node(rtems_rbtree_find(&self->chunks, - &find_me.node, chunk_compare, true)); -} - -void * -rtems_bsd_chunk_get_begin(rtems_bsd_chunk_control *self, - void *some_addr_in_chunk) -{ - rtems_bsd_chunk_info *info = rtems_bsd_chunk_get_info(self, - some_addr_in_chunk); - - return (void *) info->begin; -} - -void -rtems_bsd_chunk_info_dtor_default(rtems_bsd_chunk_control *self, - rtems_bsd_chunk_info *info) -{ - (void) self; - (void) info; -} diff --git a/rtemsbsd/rtems/rtems-bsd-conf.c b/rtemsbsd/rtems/rtems-bsd-conf.c deleted file mode 100644 index d52ad198..00000000 --- a/rtemsbsd/rtems/rtems-bsd-conf.c +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief This file is an rtems representation of needed methods from - * the FreeBSD file kern_conf.c - */ - -/* - * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -__FBSDID("$FreeBSD$"); - -#include -#include - -struct cdev * -make_dev(struct cdevsw *devsw, int unit, uid_t uid, gid_t gid, int mode, - const char *fmt, ...) -{ - struct cdev *dev; - dev = malloc( sizeof(struct cdev) ); - - /* Initialize the elements that rtems uses. */ - dev->si_flags = 0; - dev->si_drv0 = unit; - dev->si_drv1 = NULL; - dev->si_drv2 = NULL; - - return (dev); -} - -void -destroy_dev(struct cdev *dev) -{ - free (dev); -} diff --git a/rtemsbsd/rtems/rtems-bsd-configintrhook.c b/rtemsbsd/rtems/rtems-bsd-configintrhook.c deleted file mode 100644 index baf737e1..00000000 --- a/rtemsbsd/rtems/rtems-bsd-configintrhook.c +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2011 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * 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 COPYRIGHT HOLDERS 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 COPYRIGHT - * OWNER 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. - */ - -#include - -#include -#include -#include - -int -config_intrhook_establish(struct intr_config_hook *hook) -{ - (*hook->ich_func)(hook->ich_arg); - - return (0); -} - -void -config_intrhook_disestablish(struct intr_config_hook *hook) -{ - /* Do nothing */ -} diff --git a/rtemsbsd/rtems/rtems-bsd-delay.c b/rtemsbsd/rtems/rtems-bsd-delay.c deleted file mode 100644 index 1faa9265..00000000 --- a/rtemsbsd/rtems/rtems-bsd-delay.c +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009, 2015 embedded brains GmbH - * All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include -#include - -void -DELAY(int usec) -{ - uint32_t ns = 1000 * (uint32_t)usec; - BSD_ASSERT((uint32_t)usec <= UINT32_MAX / 1000); - rtems_counter_delay_nanoseconds(ns); -} diff --git a/rtemsbsd/rtems/rtems-bsd-get-file.c b/rtemsbsd/rtems/rtems-bsd-get-file.c deleted file mode 100644 index 6d321c30..00000000 --- a/rtemsbsd/rtems/rtems-bsd-get-file.c +++ /dev/null @@ -1,59 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2013 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include - -struct file * -rtems_bsd_get_file(int fd) -{ - struct file *fp; - - if ((uint32_t) fd < rtems_libio_number_iops) { - fp = rtems_bsd_fd_to_fp(fd); - if ((fp->f_io.flags & LIBIO_FLAGS_OPEN) != LIBIO_FLAGS_OPEN) { - fp = NULL; - } - } else { - fp = NULL; - } - - return fp; -} diff --git a/rtemsbsd/rtems/rtems-bsd-init.c b/rtemsbsd/rtems/rtems-bsd-init.c deleted file mode 100644 index 085b5a9e..00000000 --- a/rtemsbsd/rtems/rtems-bsd-init.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -SYSINIT_REFERENCE(configure1); -SYSINIT_REFERENCE(module); -SYSINIT_REFERENCE(kobj); -SYSINIT_REFERENCE(linker_kernel); -SYSINIT_MODULE_REFERENCE(rootbus); -SYSINIT_DRIVER_REFERENCE(nexus, root); - -RTEMS_BSD_DEFINE_SET(modmetadata_set, struct mod_metadata *); -RTEMS_BSD_DEFINE_SET(sysctl_set, struct sysctl_oid *); - -RTEMS_BSD_DEFINE_RWSET(sysinit_set, struct sysinit *); - -/* In FreeBSD this is a local function */ -void mi_startup(void); - -int hz; -int tick; -int maxusers; /* base tunable */ - -static SYSCTL_NODE(_kern, OID_AUTO, smp, CTLFLAG_RD|CTLFLAG_CAPRD, NULL, - "Kernel SMP"); - -static int maxid_maxcpus; - -SYSCTL_INT(_kern_smp, OID_AUTO, maxid, CTLFLAG_RD|CTLFLAG_CAPRD, - &maxid_maxcpus, 0, "Max CPU ID."); - -SYSCTL_INT(_kern_smp, OID_AUTO, maxcpus, CTLFLAG_RD|CTLFLAG_CAPRD, - &maxid_maxcpus, 0, "Max number of CPUs that the system was compiled for."); - -#undef _bsd_ticks - -RTEMS_STATIC_ASSERT(sizeof(int) == sizeof(int32_t), ticks); - -volatile uint32_t _Watchdog_Ticks_since_boot; - -extern volatile int32_t _bsd_ticks - __attribute__ ((__alias__("_Watchdog_Ticks_since_boot"))); - -rtems_status_code -rtems_bsd_initialize(void) -{ - static const char name[] = "TIME"; - rtems_status_code sc; - - hz = (int) rtems_clock_get_ticks_per_second(); - tick = 1000000 / hz; - maxusers = 1; - maxid_maxcpus = (int) rtems_get_processor_count(); - - mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO); - - sc = rtems_timer_initiate_server( - rtems_bsd_get_task_priority(name), - rtems_bsd_get_task_stack_size(name), - RTEMS_DEFAULT_ATTRIBUTES - ); - if (sc != RTEMS_SUCCESSFUL) { - return RTEMS_UNSATISFIED; - } - - mutex_init(); - mi_startup(); - - return RTEMS_SUCCESSFUL; -} diff --git a/rtemsbsd/rtems/rtems-bsd-irqs.c b/rtemsbsd/rtems/rtems-bsd-irqs.c deleted file mode 100644 index e558d1f5..00000000 --- a/rtemsbsd/rtems/rtems-bsd-irqs.c +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include - -#include -#include - -static void -irqs_sysinit(void) -{ - static const char name[] = "IRQS"; - rtems_status_code status; - - status = rtems_interrupt_server_initialize( - rtems_bsd_get_task_priority(name), - rtems_bsd_get_task_stack_size(name), - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, - NULL - ); - BSD_ASSERT(status == RTEMS_SUCCESSFUL); -} -SYSINIT(irqs, SI_SUB_SETTINGS, SI_ORDER_ANY, irqs_sysinit, NULL); diff --git a/rtemsbsd/rtems/rtems-bsd-jail.c b/rtemsbsd/rtems/rtems-bsd-jail.c deleted file mode 100644 index 0c7ab4f9..00000000 --- a/rtemsbsd/rtems/rtems-bsd-jail.c +++ /dev/null @@ -1,317 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief This object is an minimal rtems implementation of kern_jail.c. - */ - -/* - * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -/*#include -#include -#include -#include -#include -#include */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" - -/* Keep struct prison prison0 and some code in kern_jail_set() readable. */ -#ifdef INET -#ifdef INET6 -#define _PR_IP_SADDRSEL PR_IP4_SADDRSEL|PR_IP6_SADDRSEL -#else -#define _PR_IP_SADDRSEL PR_IP4_SADDRSEL -#endif -#else /* !INET */ -#ifdef INET6 -#define _PR_IP_SADDRSEL PR_IP6_SADDRSEL -#else -#define _PR_IP_SADDRSEL 0 -#endif -#endif - -/* prison0 describes what is "real" about the system. */ -struct prison prison0 = { - .pr_id = 0, - .pr_name = "0", - .pr_ref = 1, - .pr_uref = 1, - .pr_path = "/", - .pr_securelevel = -1, - .pr_childmax = JAIL_MAX, - .pr_hostuuid = DEFAULT_HOSTUUID, - .pr_children = LIST_HEAD_INITIALIZER(prison0.pr_children), -#ifdef VIMAGE - .pr_flags = PR_HOST|PR_VNET|_PR_IP_SADDRSEL, -#else - .pr_flags = PR_HOST|_PR_IP_SADDRSEL, -#endif - .pr_allow = PR_ALLOW_ALL, -}; -MTX_SYSINIT(prison0, &prison0.pr_mtx, "jail mutex", MTX_DEF); - -/* - * See if a prison has the specific flag set. - */ -int -prison_flag(struct ucred *cred, unsigned flag) -{ - /* This is an atomic read, so no locking is necessary. */ - return (prison0.pr_flags & flag); -} - -void -prison_free(struct prison *pr) -{ -} - -void -prison_hold(struct prison *pr) -{ -} - -/* - * Check if given address belongs to the jail referenced by cred (wrapper to - * prison_check_ip[46]). - * - * Returns 0 if jail doesn't restrict the address family or if address belongs - * to jail, EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if - * the jail doesn't allow the address family. IPv4 Address passed in in NBO. - */ -int -prison_if(struct ucred *cred, struct sockaddr *sa) -{ - return 0; -} - -/* - * Return 1 if we should do proper source address selection or are not jailed. - * We will return 0 if we should bypass source address selection in favour - * of the primary jail IPv6 address. Only in this case *ia will be updated and - * returned in NBO. - * Return EAFNOSUPPORT, in case this jail does not allow IPv6. - */ -int -prison_saddrsel_ip6(struct ucred *cred, struct in6_addr *ia6) -{ - return EAFNOSUPPORT; -} - -/* - * Check if given address belongs to the jail referenced by cred/prison. - * - * Returns 0 if jail doesn't restrict IPv4 or if address belongs to jail, - * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail - * doesn't allow IPv4. Address passed in in NBO. - */ -int -prison_check_ip4(struct ucred *cred, struct in_addr *ia) -{ - return 0; -} - -/* - * Assuming 0 means no restrictions. - * - * NOTE: RTEMS does not restrict via a jail so return 0. - */ -int -prison_check_ip6(struct ucred *cred, struct in6_addr *ia6) -{ - return 0; -} - -/* - * Make sure our (source) address is set to something meaningful to this - * jail. - * - * Returns 0 if jail doesn't restrict IPv4 or if address belongs to jail, - * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail - * doesn't allow IPv4. Address passed in in NBO and returned in NBO. - */ -int -prison_local_ip4(struct ucred *cred, struct in_addr *ia) -{ - return 0; -} - -/* - * Rewrite destination address in case we will connect to loopback address. - * - * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv4. - * Address passed in in NBO and returned in NBO. - */ -int -prison_remote_ip4(struct ucred *cred, struct in_addr *ia) -{ - return 0; -} - -/* - * Make sure our (source) address is set to something meaningful to this jail. - * - * v6only should be set based on (inp->inp_flags & IN6P_IPV6_V6ONLY != 0) - * when needed while binding. - * - * Returns 0 if jail doesn't restrict IPv6 or if address belongs to jail, - * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail - * doesn't allow IPv6. - * - * NOTE: RTEMS does not restrict via a jail so return 0. - */ -int -prison_local_ip6(struct ucred *cred, struct in6_addr *ia6, int v6only) -{ - return 0; -} - -/* - * Rewrite destination address in case we will connect to loopback address. - * - * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. - * - * NOTE: RTEMS does not restrict via a jail so return 0. - */ -int -prison_remote_ip6(struct ucred *cred, struct in6_addr *ia6) -{ - return 0; -} - -/* - * Return 1 if we should do proper source address selection or are not jailed. - * We will return 0 if we should bypass source address selection in favour - * of the primary jail IPv4 address. Only in this case *ia will be updated and - * returned in NBO. - * Return EAFNOSUPPORT, in case this jail does not allow IPv4. - */ -int -prison_saddrsel_ip4(struct ucred *cred, struct in_addr *ia) -{ - return 1; -} - -/* - * Pass back primary IPv4 address of this jail. - * - * If not restricted return success but do not alter the address. Caller has - * to make sure to initialize it correctly (e.g. INADDR_ANY). - * - * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv4. - * Address returned in NBO. - */ -int -prison_get_ip4(struct ucred *cred, struct in_addr *ia) -{ - return 0; -} - -/* - * Return 1 if the passed credential is in a jail and that jail does not - * have its own virtual network stack, otherwise 0. - */ -int -jailed_without_vnet(struct ucred *cred) -{ - return 0; -} - -/* - * Pass back primary IPv6 address for this jail. - * - * If not restricted return success but do not alter the address. Caller has - * to make sure to initialize it correctly (e.g. IN6ADDR_ANY_INIT). - * - * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. - */ -int -prison_get_ip6(struct ucred *cred, struct in6_addr *ia6) -{ - return 0; -} -/* - * Return 0 if jails permit p1 to frob p2, otherwise ESRCH. - */ -int -prison_check(struct ucred *cred1, struct ucred *cred2) -{ - return 0; -} - -/* - * Check if a jail supports the given address family. - * - * Returns 0 if not jailed or the address family is supported, EAFNOSUPPORT - * if not. - */ -int -prison_check_af(struct ucred *cred, int af) -{ - return 0; -} - -/* - * Return 1 if the passed credential is in a jail, otherwise 0. - */ -int -jailed(struct ucred *cred) -{ - return 0; -} diff --git a/rtemsbsd/rtems/rtems-bsd-malloc.c b/rtemsbsd/rtems/rtems-bsd-malloc.c deleted file mode 100644 index fe0d01db..00000000 --- a/rtemsbsd/rtems/rtems-bsd-malloc.c +++ /dev/null @@ -1,127 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include - -MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory"); - -MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers"); - -MALLOC_DEFINE(M_IP6OPT, "ip6opt", "IPv6 options"); -MALLOC_DEFINE(M_IP6NDP, "ip6ndp", "IPv6 Neighbor Discovery"); - -MALLOC_DEFINE(M_IOV, "iov", "large iov's"); - -void -malloc_init(void *data) -{ - struct malloc_type *mtp = data; -} - -void -malloc_uninit(void *data) -{ - struct malloc_type *mtp = data; - - BSD_PRINTF( "desc = %s\n", mtp->ks_shortdesc); -} - -#undef malloc - -void * -_bsd_malloc(unsigned long size, struct malloc_type *mtp, int flags) -{ - void *p = malloc(size > 0 ? size : 1); - - if ((flags & M_ZERO) != 0 && p != NULL) { - memset(p, 0, size); - } - - return p; -} - -#undef realloc -void * -_bsd_realloc( void *addr, unsigned long size, - struct malloc_type *type, int flags) -{ - void *p = realloc(addr, size > 0 ? size : 1); - - if ((flags & M_ZERO) != 0 && p != NULL) { - memset(p, 0, size); - } - - return p; -} - -#undef reallocf -void * -_bsd_reallocf( void *addr, unsigned long size, - struct malloc_type *type, int flags) -{ - void *p = realloc(addr, size > 0 ? size : 1); - - if (p == NULL) { - free(addr,NULL); - } - - return p; -} - -#undef free -void -_bsd_free(void *addr, struct malloc_type *mtp) -{ - free(addr); -} - -#undef strdup - -char * -_bsd_strdup(const char *__restrict s, struct malloc_type *type) -{ - return strdup(s); -} diff --git a/rtemsbsd/rtems/rtems-bsd-mbuf.c b/rtemsbsd/rtems/rtems-bsd-mbuf.c deleted file mode 100644 index a1429d86..00000000 --- a/rtemsbsd/rtems/rtems-bsd-mbuf.c +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include - -struct mbuf * -rtems_bsd_m_get(int how, short type) -{ - return (m_get(how, type)); -} - -struct mbuf * -rtems_bsd_m_gethdr(int how, short type) -{ - return (m_gethdr(how, type)); -} - -void -rtems_bsd_m_extaddref(struct mbuf *m, void *buf, size_t size, - u_int *ref_cnt, void (*freef)(void *, void *), void *arg1, - void *arg2) -{ - m_extaddref(m, buf, size, ref_cnt, freef, arg1, arg2); -} - -void -rtems_bsd_m_free(struct mbuf *m) -{ - m_free(m); -} diff --git a/rtemsbsd/rtems/rtems-bsd-mutex.c b/rtemsbsd/rtems/rtems-bsd-mutex.c deleted file mode 100644 index 5931a7e5..00000000 --- a/rtemsbsd/rtems/rtems-bsd-mutex.c +++ /dev/null @@ -1,227 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static void assert_mtx(struct lock_object *lock, int what); -static void lock_mtx(struct lock_object *lock, int how); -#ifdef KDTRACE_HOOKS -static int owner_mtx(struct lock_object *lock, struct thread **owner); -#endif -static int unlock_mtx(struct lock_object *lock); - -/* - * Lock classes for sleep and spin mutexes. - */ -struct lock_class lock_class_mtx_sleep = { - .lc_name = "sleep mutex", - .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, - .lc_assert = assert_mtx, -#ifdef DDB - .lc_ddb_show = db_show_mtx, -#endif - .lc_lock = lock_mtx, - .lc_unlock = unlock_mtx, -#ifdef KDTRACE_HOOKS - .lc_owner = owner_mtx, -#endif -}; - -struct lock_class lock_class_mtx_spin = { - .lc_name = "spin mutex", - .lc_flags = LC_SPINLOCK | LC_RECURSABLE, - .lc_assert = assert_mtx, -#ifdef DDB - .lc_ddb_show = db_show_mtx, -#endif - .lc_lock = lock_mtx, - .lc_unlock = unlock_mtx, -#ifdef KDTRACE_HOOKS - .lc_owner = owner_mtx, -#endif -}; - -struct mtx Giant; - -void -assert_mtx(struct lock_object *lock, int what) -{ - mtx_assert((struct mtx *)lock, what); -} - -void -lock_mtx(struct lock_object *lock, int how) -{ - mtx_lock((struct mtx *)lock); -} - -int -unlock_mtx(struct lock_object *lock) -{ - mtx_unlock((struct mtx *)lock); - - return (0); -} - - -#ifdef KDTRACE_HOOKS -int -owner_mtx(struct lock_object *lock, struct thread **owner) -{ - struct mtx *m = (struct mtx *)lock; - - *owner = mtx_owner(m); - return (mtx_unowned(m) == 0); -} -#endif - -void -mtx_init(struct mtx *m, const char *name, const char *type, int opts) -{ - struct lock_class *class; - int flags; - - /* Determine lock class and lock flags. */ - if (opts & MTX_SPIN) - class = &lock_class_mtx_spin; - else - class = &lock_class_mtx_sleep; - flags = 0; - if (opts & MTX_RECURSE) - flags |= LO_RECURSABLE; - - rtems_bsd_mutex_init(&m->lock_object, &m->mutex, class, name, type, - flags); -} - -void -_mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) -{ - rtems_bsd_mutex_lock(&m->lock_object, &m->mutex); -} - -int -_mtx_trylock(struct mtx *m, int opts, const char *file, int line) -{ - return (rtems_bsd_mutex_trylock(&m->lock_object, &m->mutex)); -} - -void -_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) -{ - rtems_bsd_mutex_unlock(&m->mutex); -} - -/* - * The backing function for the INVARIANTS-enabled mtx_assert() - */ -#ifdef INVARIANT_SUPPORT -void -_mtx_assert(struct mtx *m, int what, const char *file, int line) -{ - - if (panicstr != NULL || dumping) - return; - switch (what) { - case MA_OWNED: - case MA_OWNED | MA_RECURSED: - case MA_OWNED | MA_NOTRECURSED: - if (!mtx_owned(m)) - panic("mutex %s not owned at %s:%d", - m->lock_object.lo_name, file, line); - if (mtx_recursed(m)) { - if ((what & MA_NOTRECURSED) != 0) - panic("mutex %s recursed at %s:%d", - m->lock_object.lo_name, file, line); - } else if ((what & MA_RECURSED) != 0) { - panic("mutex %s unrecursed at %s:%d", - m->lock_object.lo_name, file, line); - } - break; - case MA_NOTOWNED: - if (mtx_owned(m)) - panic("mutex %s owned at %s:%d", - m->lock_object.lo_name, file, line); - break; - default: - panic("unknown mtx_assert at %s:%d", file, line); - } -} -#endif - -int mtx_owned(struct mtx *m) -{ - return (rtems_bsd_mutex_owned(&m->mutex)); -} - -int mtx_recursed(struct mtx *m) -{ - return (rtems_bsd_mutex_recursed(&m->mutex)); -} - -void -mtx_sysinit(void *arg) -{ - struct mtx_args *margs = arg; - - mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts); -} - -void -mtx_destroy(struct mtx *m) -{ - - rtems_bsd_mutex_destroy(&m->lock_object, &m->mutex); -} - -void -mutex_init(void) -{ - mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE); - mtx_lock(&Giant); -} diff --git a/rtemsbsd/rtems/rtems-bsd-muteximpl.c b/rtemsbsd/rtems/rtems-bsd-muteximpl.c deleted file mode 100644 index ff54365e..00000000 --- a/rtemsbsd/rtems/rtems-bsd-muteximpl.c +++ /dev/null @@ -1,95 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2014, 2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include - -#define BSD_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority - -void -rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m, - Thread_Control *owner, Thread_Control *executing, - ISR_lock_Context *lock_context) -{ - if (owner == executing) { - BSD_ASSERT(lock->lo_flags & LO_RECURSABLE); - ++m->nest_level; - - _Thread_queue_Release(&m->queue, lock_context); - } else { - /* Priority inheritance */ - _Thread_Raise_priority(owner, executing->current_priority); - - ++executing->resource_count; - _Thread_queue_Enqueue_critical(&m->queue, - BSD_MUTEX_TQ_OPERATIONS, executing, - STATES_WAITING_FOR_MUTEX, WATCHDOG_NO_TIMEOUT, 0, - lock_context); - } -} - -void -rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner, - int keep_priority, Thread_queue_Heads *heads, - ISR_lock_Context *lock_context) -{ - if (heads != NULL) { - const Thread_queue_Operations *operations; - Thread_Control *new_owner; - - operations = BSD_MUTEX_TQ_OPERATIONS; - new_owner = ( *operations->first )( heads ); - m->owner = new_owner; - _Thread_queue_Extract_critical(&m->queue, operations, - new_owner, NULL, 0, lock_context); - } else { - _Thread_queue_Release(&m->queue, lock_context); - } - - if (!keep_priority) { - Per_CPU_Control *cpu_self; - - cpu_self = _Thread_Dispatch_disable(); - _Thread_Restore_priority(owner); - _Thread_Dispatch_enable(cpu_self); - } -} diff --git a/rtemsbsd/rtems/rtems-bsd-newproc.c b/rtemsbsd/rtems/rtems-bsd-newproc.c deleted file mode 100644 index c01b41d2..00000000 --- a/rtemsbsd/rtems/rtems-bsd-newproc.c +++ /dev/null @@ -1,116 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * COPYRIGHT (c) 2012. - * On-Line Applications Research Corporation (OAR). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include - -/* - * Structure passed to task-start stub - */ -struct newtask { - void (*entry)(void *); - void *arg; -}; - -/* - * Task-start stub - */ -static void -taskEntry (rtems_task_argument arg) -{ - struct newtask t; - - /* - * Pick up task information and free - * the memory allocated to pass the - * information to this task. - */ - t = *(struct newtask *)arg; - free ((struct newtask *)arg); - - /* - * XXX If we need a semaphore it should be added here - */ - - /* - * Enter the task - */ - (*t.entry)(t.arg); - rtems_panic ("Network task returned!\n"); -} - -/* - * Start a network task - */ -rtems_id -rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg) -{ - struct newtask *t; - char nm[4]; - rtems_id tid; - rtems_status_code sc; - - strncpy (nm, name, 4); - sc = rtems_task_create (rtems_build_name(nm[0], nm[1], nm[2], nm[3]), - rtems_bsd_get_task_priority(name), - stacksize, - RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), - RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, - &tid - ); - if (sc != RTEMS_SUCCESSFUL) - rtems_panic ("Can't create network daemon `%s': `%s'\n", name, rtems_status_text (sc)); - - /* - * Set up task arguments - */ - t = malloc (sizeof *t); - t->entry = entry; - t->arg = arg; - - /* - * Start the task - */ - sc = rtems_task_start (tid, taskEntry, (rtems_task_argument)t); - if (sc != RTEMS_SUCCESSFUL) - rtems_panic ("Can't start network daemon `%s': `%s'\n", name, rtems_status_text (sc)); - - /* - * Let our caller know the i.d. of the new task - */ - return tid; -} diff --git a/rtemsbsd/rtems/rtems-bsd-nexus.c b/rtemsbsd/rtems/rtems-bsd-nexus.c deleted file mode 100644 index d8afebc2..00000000 --- a/rtemsbsd/rtems/rtems-bsd-nexus.c +++ /dev/null @@ -1,365 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/* #define DISABLE_INTERRUPT_EXTENSION */ - -RTEMS_BSD_DECLARE_SET(nexus, rtems_bsd_device); - -RTEMS_BSD_DEFINE_SET(nexus, rtems_bsd_device); - -RTEMS_STATIC_ASSERT(SYS_RES_MEMORY == RTEMS_BSD_RES_MEMORY, RTEMS_BSD_RES_MEMORY); - -RTEMS_STATIC_ASSERT(SYS_RES_IRQ == RTEMS_BSD_RES_IRQ, RTEMS_BSD_RES_IRQ); - -static struct rman mem_rman; - -static struct rman irq_rman; - -#ifdef __i386__ -static struct rman port_rman; -#endif - -#ifndef DISABLE_INTERRUPT_EXTENSION -SYSINIT_REFERENCE(irqs); -#endif - -static int -nexus_probe(device_t dev) -{ - int err; - const rtems_bsd_device *nd; - - device_set_desc(dev, "RTEMS Nexus device"); - - mem_rman.rm_start = 0; - mem_rman.rm_end = ~0UL; - mem_rman.rm_type = RMAN_ARRAY; - mem_rman.rm_descr = "I/O memory addresses"; - err = rman_init(&mem_rman) != 0; - BSD_ASSERT(err == 0); - err = rman_manage_region(&mem_rman, mem_rman.rm_start, mem_rman.rm_end); - BSD_ASSERT(err == 0); - - irq_rman.rm_start = 0; - irq_rman.rm_end = ~0UL; - irq_rman.rm_type = RMAN_ARRAY; - irq_rman.rm_descr = "Interrupt vectors"; - err = rman_init(&irq_rman) != 0; - BSD_ASSERT(err == 0); - err = rman_manage_region(&irq_rman, irq_rman.rm_start, irq_rman.rm_end); - BSD_ASSERT(err == 0); - -#ifdef __i386__ - port_rman.rm_start = 0; - port_rman.rm_end = 0xffff; - port_rman.rm_type = RMAN_ARRAY; - port_rman.rm_descr = "I/O ports"; - err = rman_init(&port_rman) != 0; - BSD_ASSERT(err == 0); - err = rman_manage_region(&port_rman, port_rman.rm_start, - port_rman.rm_end); - BSD_ASSERT(err == 0); -#endif - - SET_FOREACH(nd, nexus) { - device_add_child(dev, nd->name, nd->unit); - } - - return (0); -} - -static bool -nexus_get_start(const rtems_bsd_device *nd, int type, u_long *start) -{ - u_long sr = *start; - size_t i; - - for (i = 0; i < nd->resource_count; ++i) { - const rtems_bsd_device_resource *dr = &nd->resources[i]; - - if (dr->type == type && dr->start_request == sr) { - *start = dr->start_actual; - - return (true); - } - } - - return (false); -} - -static struct resource * -nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, - u_long start, u_long end, u_long count, u_int flags) -{ - struct resource *res = NULL; - struct rman *rm; - const rtems_bsd_device *nd; - - switch (type) { - case SYS_RES_MEMORY: - rm = &mem_rman; - break; - case SYS_RES_IRQ: - rm = &irq_rman; - break; -#ifdef __i386__ - case SYS_RES_IOPORT: - rm = &port_rman; - break; -#endif - default: - return (res); - } - - SET_FOREACH(nd, nexus) { - if (strcmp(device_get_name(child), nd->name) == 0 - && device_get_unit(child) == nd->unit) { - if (nexus_get_start(nd, type, &start)) { - res = rman_reserve_resource(rm, start, end, - count, flags, child); - if (res != NULL) { - rman_set_rid(res, *rid); - rman_set_bushandle(res, - rman_get_start(res)); - } - }; - - return (res); - } - } - -#ifdef __i386__ - /* - * FIXME: This is a quick and dirty hack. Simply reserve resources of - * this kind. See also pci_reserve_map(). - */ - if (start + count - end <= 1UL) { - res = rman_reserve_resource(rm, start, end, count, flags, - child); - if (res != NULL) { - rman_set_rid(res, *rid); - rman_set_bushandle(res, rman_get_start(res)); - } - } -#endif - - return (res); -} - -static int -nexus_release_resource(device_t bus, device_t child, int type, int rid, - struct resource *res) -{ - return (rman_release_resource(res)); -} - -#ifdef __i386__ -static int -nexus_activate_resource(device_t bus, device_t child, int type, int rid, - struct resource *res) -{ - switch (type) { - case SYS_RES_IOPORT: - rman_set_bustag(res, X86_BUS_SPACE_IO); - break; - case SYS_RES_MEMORY: - rman_set_bustag(res, X86_BUS_SPACE_MEM); - break; - } - return (rman_activate_resource(res)); -} - -static int -nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, - struct resource *res) -{ - - return (rman_deactivate_resource(res)); -} -#endif - -struct nexus_intr { - driver_filter_t *filt; - driver_intr_t *intr; - void *arg; -}; - -static void -nexus_intr_with_filter(void *arg) -{ - struct nexus_intr *ni; - int status; - - ni = arg; - - status = (*ni->filt)(ni->arg); - if ((status & FILTER_SCHEDULE_THREAD) != 0) { - (*ni->intr)(ni->arg); - } -} - -static int -nexus_setup_intr(device_t dev, device_t child, struct resource *res, int flags, - driver_filter_t *filt, driver_intr_t *intr, void *arg, void **cookiep) -{ - int err; -#ifndef DISABLE_INTERRUPT_EXTENSION - struct nexus_intr *ni; - - ni = malloc(sizeof(*ni), M_TEMP, M_WAITOK); - if (ni != NULL) { - rtems_status_code sc; - rtems_interrupt_handler rh; - void *ra; - - ni->filt = filt; - ni->intr = intr; - ni->arg = arg; - - *cookiep = ni; - - if (filt == NULL) { - rh = intr; - ra = arg; - } else { - rh = nexus_intr_with_filter; - ra = ni; - } - - sc = rtems_interrupt_server_handler_install(RTEMS_ID_NONE, - rman_get_start(res), device_get_nameunit(child), - RTEMS_INTERRUPT_UNIQUE, rh, ra); - if (sc == RTEMS_SUCCESSFUL) { - err = 0; - } else { - free(ni, M_TEMP); - - err = EINVAL; - } - } else { - err = ENOMEM; - } -#else - err = EINVAL; -#endif - - return (err); -} - -static int -nexus_teardown_intr(device_t dev, device_t child, struct resource *res, - void *cookie) -{ - int err; -#ifndef DISABLE_INTERRUPT_EXTENSION - struct nexus_intr *ni; - rtems_status_code sc; - rtems_interrupt_handler rh; - void *ra; - - ni = cookie; - - if (ni->filt == NULL) { - rh = ni->intr; - ra = ni->arg; - } else { - rh = nexus_intr_with_filter; - ra = ni->arg; - } - - sc = rtems_interrupt_server_handler_install(RTEMS_ID_NONE, - rman_get_start(res), device_get_nameunit(child), - RTEMS_INTERRUPT_UNIQUE, rh, ra); - err = sc == RTEMS_SUCCESSFUL ? 0 : EINVAL; -#else - err = EINVAL; -#endif - - return (err); -} - -static device_method_t nexus_methods[] = { - /* Device interface */ - DEVMETHOD(device_probe, nexus_probe), - DEVMETHOD(device_attach, bus_generic_attach), - DEVMETHOD(device_detach, bus_generic_detach), - DEVMETHOD(device_shutdown, bus_generic_shutdown), - DEVMETHOD(device_suspend, bus_generic_suspend), - DEVMETHOD(device_resume, bus_generic_resume), - - /* Bus interface */ - DEVMETHOD(bus_print_child, bus_generic_print_child), - DEVMETHOD(bus_add_child, bus_generic_add_child), - DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), - DEVMETHOD(bus_release_resource, nexus_release_resource), -#ifdef __i386__ - DEVMETHOD(bus_activate_resource, nexus_activate_resource), - DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), -#endif - DEVMETHOD(bus_setup_intr, nexus_setup_intr), - DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), - - { 0, 0 } -}; - -static driver_t nexus_driver = { - .name = "nexus", - .methods = nexus_methods, - .size = 0 -}; - -static devclass_t nexus_devclass; - -DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0); diff --git a/rtemsbsd/rtems/rtems-bsd-page.c b/rtemsbsd/rtems/rtems-bsd-page.c deleted file mode 100644 index b3f4325d..00000000 --- a/rtemsbsd/rtems/rtems-bsd-page.c +++ /dev/null @@ -1,157 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -void **rtems_bsd_page_object_table; - -uintptr_t rtems_bsd_page_area_begin; - -static rtems_rbheap_control page_heap; - -struct mtx page_heap_mtx; - -void * -rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait) -{ - void *addr; - - mtx_lock(&page_heap_mtx); - - addr = rtems_rbheap_allocate(&page_heap, size_in_bytes); - if (addr == NULL && wait) { - int i; - - for (i = 0; i < 8; i++) { - mtx_unlock(&page_heap_mtx); - uma_reclaim(); - mtx_lock(&page_heap_mtx); - - addr = rtems_rbheap_allocate(&page_heap, size_in_bytes); - if (addr != NULL) - break; - - msleep(&page_heap, &page_heap_mtx, 0, - "page alloc", (hz / 4) * (i + 1)); - } - - if (i == 8) { - panic("rtems_bsd_page_alloc: page starvation"); - } - } - - mtx_unlock(&page_heap_mtx); - -#ifdef INVARIANTS - if (addr != NULL) { - memset(addr, 0, size_in_bytes); - } -#endif - - return (addr); -} - -void -rtems_bsd_page_free(void *addr) -{ - mtx_lock(&page_heap_mtx); - rtems_rbheap_free(&page_heap, addr); - wakeup(&page_heap); - mtx_unlock(&page_heap_mtx); -} - -static void -rtems_bsd_page_init(void *arg) -{ - rtems_status_code sc; - void *area; - void **obj_table; - rtems_rbheap_chunk *chunks; - size_t i; - size_t n; - uintptr_t heap_size; - - mtx_init(&page_heap_mtx, "page heap", NULL, MTX_DEF); - - heap_size = rtems_bsd_get_allocator_domain_size( - RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE); - - area = rtems_heap_allocate_aligned_with_boundary(heap_size, PAGE_SIZE, - 0); - BSD_ASSERT(area != NULL); - - sc = rtems_rbheap_initialize(&page_heap, area, heap_size, PAGE_SIZE, - rtems_rbheap_extend_descriptors_with_malloc, NULL); - BSD_ASSERT(sc == RTEMS_SUCCESSFUL); - - rtems_rbheap_set_extend_descriptors(&page_heap, - rtems_rbheap_extend_descriptors_never); - - n = heap_size / PAGE_SIZE; - - chunks = malloc(n * sizeof(*chunks), M_RTEMS_HEAP, M_NOWAIT); - BSD_ASSERT(chunks != NULL); - - for (i = 0; i < n; ++i) { - rtems_rbheap_add_to_spare_descriptor_chain(&page_heap, - &chunks[i]); - } - - obj_table = calloc(n, sizeof(*obj_table)); - - rtems_bsd_page_area_begin = (uintptr_t)area; - rtems_bsd_page_object_table = obj_table; -} - -SYSINIT(rtems_bsd_page, SI_SUB_VM, SI_ORDER_FIRST, rtems_bsd_page_init, NULL); diff --git a/rtemsbsd/rtems/rtems-bsd-panic.c b/rtemsbsd/rtems/rtems-bsd-panic.c deleted file mode 100644 index 1fc65f08..00000000 --- a/rtemsbsd/rtems/rtems-bsd-panic.c +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include - -void -panic(const char *fmt, ...) -{ - va_list ap; - - printf("\n*** BSD PANIC *** "); - - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); - - printf("\n"); - - rtems_task_suspend(RTEMS_SELF); - - /* FIXME */ - rtems_fatal_error_occurred(0xdeadbeef); -} diff --git a/rtemsbsd/rtems/rtems-bsd-pci_bus.c b/rtemsbsd/rtems/rtems-bsd-pci_bus.c deleted file mode 100644 index f687e0f5..00000000 --- a/rtemsbsd/rtems/rtems-bsd-pci_bus.c +++ /dev/null @@ -1,78 +0,0 @@ -#include - -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief This file contains methods that are rtems specific implementation - * of methods in pci_bus.c. - */ - -/* - * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#define pci_find_device rtems_pci_find_device -#if HAVE_RTEMS_PCI_H -#include -#endif -#include - -int -pcibios_pcib_route_interrupt(device_t pcib, device_t dev, int pin) -{ -#if HAVE_RTEMS_PCI_H - int bus; - int slot; - int func; - uint8_t irq; - - bus = pci_get_bus(dev); - slot = pci_get_slot(dev); - func = pci_get_function(dev); - - pci_read_config_byte(bus, slot, func, PCI_INTERRUPT_LINE, &irq); - return irq; -#else - return 0; -#endif -} diff --git a/rtemsbsd/rtems/rtems-bsd-pci_cfgreg.c b/rtemsbsd/rtems/rtems-bsd-pci_cfgreg.c deleted file mode 100644 index b9bdd31b..00000000 --- a/rtemsbsd/rtems/rtems-bsd-pci_cfgreg.c +++ /dev/null @@ -1,122 +0,0 @@ -#include - -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief This is the rtems version for the FreeBSD cpu specific - * file pci_cfgreg.c. Please note that the Ether Express is not - * supported in this version. - */ - -/* - * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define pci_find_device rtems_pci_find_device -#if HAVE_RTEMS_PCI_H -#include -#endif - -/* - * Initialise access to PCI configuration space - */ -int -pci_cfgregopen(void) -{ - return(1); -} - -/* - * Read configuration space register - */ -u_int32_t -pci_cfgregread(int bus, int slot, int func, int reg, int bytes) -{ -#if HAVE_RTEMS_PCI_H - u_int32_t value; - uint8_t v8; - uint16_t v16; - uint32_t v32; - int data; - - switch (bytes) { - case 1: - data = pci_read_config_byte( bus, slot, func, reg, &v8 ); - value = v8; - break; - case 2: - data = pci_read_config_word( bus, slot, func, reg, &v16 ); - value = v16; - break; - case 4: - data = pci_read_config_dword( bus, slot, func, reg, &v32 ); - value = v32; - break; - } - - return value; -#else - return 0; -#endif -} - -/* - * Write configuration space register - */ -void -pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes) -{ -#if HAVE_RTEMS_PCI_H - uint8_t v8 = data & 0xff; - uint16_t v16 = data & 0xffff; - uint32_t v32 = data; - - switch (bytes) { - case 1: - pci_write_config_byte( bus, slot, func, reg, v8 ); - break; - case 2: - pci_write_config_word( bus, slot, func, reg, v16 ); - break; - case 4: - pci_write_config_dword( bus, slot, func, reg, v32 ); - break; - } -#endif -} diff --git a/rtemsbsd/rtems/rtems-bsd-program.c b/rtemsbsd/rtems/rtems-bsd-program.c deleted file mode 100644 index 18b9a627..00000000 --- a/rtemsbsd/rtems/rtems-bsd-program.c +++ /dev/null @@ -1,216 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2013 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#undef printf -#include - -struct rtems_bsd_program_control { - void *context; - int exit_code; - const char *name; - jmp_buf return_context; -}; - -int -rtems_bsd_program_call(const char *name, int (*prog)(void *), void *context) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - int exit_code = EXIT_FAILURE; - - if (td != NULL) { - struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; - - if (prog_ctrl == NULL) { - prog_ctrl = malloc(sizeof(*prog_ctrl), M_TEMP, 0); - - if (prog_ctrl != NULL) { - td->td_prog_ctrl = prog_ctrl; - - prog_ctrl->context = context; - prog_ctrl->name = name; - prog_ctrl->exit_code = exit_code; - - if (setjmp(prog_ctrl->return_context) == 0) { - exit_code = (*prog)(context); - } else { - exit_code = prog_ctrl->exit_code; - } - - td->td_prog_ctrl = NULL; - free(prog_ctrl, M_TEMP); - } else { - errno = ENOMEM; - } - } else { - panic("unexpected BSD program state"); - } - } else { - errno = ENOMEM; - } - - return exit_code; -} - -void -rtems_bsd_program_exit(int exit_code) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - - if (td != NULL) { - struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; - - if (prog_ctrl != NULL) { - prog_ctrl->exit_code = exit_code; - longjmp(prog_ctrl->return_context, 1); - } - } - - panic("unexpected BSD program exit"); -} - -void -rtems_bsd_program_error(const char *fmt, ...) -{ - va_list list; - va_start(list, fmt); - vfprintf(stderr, fmt, list); - fprintf(stderr, "\n"); - va_end(list); - rtems_bsd_program_exit(1); -} - -const char * -rtems_bsd_program_get_name(void) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - const char *name = "?"; - - if (td != NULL) { - struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; - - if (prog_ctrl != NULL) { - name = prog_ctrl->name; - } - } - - return name; -} - -void * -rtems_bsd_program_get_context(void) -{ - struct thread *td = rtems_bsd_get_curthread_or_null(); - void *context = NULL; - - if (td != NULL) { - struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; - - if (prog_ctrl != NULL) { - context = prog_ctrl->context; - } - } - - return context; -} - -struct main_context { - int argc; - char **argv; - int (*main)(int, char **); -}; - -static int -call_main(void *ctx) -{ - const struct main_context *mc = ctx; - - return (*mc->main)(mc->argc, mc->argv); -} - -int -rtems_bsd_program_call_main(const char *name, int (*main)(int, char **), - int argc, char **argv) -{ - struct main_context mc = { - .argc = argc, - .argv = argv, - .main = main - }; - int exit_code; - - if (argv[argc] == NULL) { - exit_code = rtems_bsd_program_call(name, call_main, &mc); - } else { - errno = EFAULT; - exit_code = EXIT_FAILURE; - } - - return exit_code; -} - -static struct mtx program_mtx; - -MTX_SYSINIT(rtems_bsd_program, &program_mtx, "BSD program", MTX_DEF); - -void -rtems_bsd_program_lock(void) -{ - mtx_lock(&program_mtx); -} - -void -rtems_bsd_program_unlock(void) -{ - mtx_unlock(&program_mtx); -} diff --git a/rtemsbsd/rtems/rtems-bsd-rwlock.c b/rtemsbsd/rtems/rtems-bsd-rwlock.c deleted file mode 100644 index d0b911d5..00000000 --- a/rtemsbsd/rtems/rtems-bsd-rwlock.c +++ /dev/null @@ -1,293 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2011 OPTI Medical. All rights reserved. - * - * OPTI Medical - * 235 Hembree Park Drive - * Roswell, GA 30076 - * USA - * - * - * Copyright (c) 2013-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include -#include - -#ifndef INVARIANTS -#define _rw_assert(rw, what, file, line) -#endif - -static void assert_rw(struct lock_object *lock, int what); -static void lock_rw(struct lock_object *lock, int how); -#ifdef KDTRACE_HOOKS -static int owner_rw(struct lock_object *lock, struct thread **owner); -#endif -static int unlock_rw(struct lock_object *lock); - -struct lock_class lock_class_rw = { - .lc_name = "rw", - .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, - .lc_assert = assert_rw, -#ifdef DDB - .lc_ddb_show = db_show_rwlock, -#endif - .lc_lock = lock_rw, - .lc_unlock = unlock_rw, -#ifdef KDTRACE_HOOKS - .lc_owner = owner_rw, -#endif -}; - -#define rw_wowner(rw) ((rw)->mutex.owner) - -#define rw_recursed(rw) ((rw)->mutex.nest_level != 0) - -void -assert_rw(struct lock_object *lock, int what) -{ - rw_assert((struct rwlock *)lock, what); -} - -void -lock_rw(struct lock_object *lock, int how) -{ - rw_wlock((struct rwlock *)lock); -} - -int -unlock_rw(struct lock_object *lock) -{ - rw_unlock((struct rwlock *)lock); - - return (0); -} - -#ifdef KDTRACE_HOOKS -int -owner_rw(struct lock_object *lock, struct thread **owner) -{ - struct rwlock *rw = (struct rwlock *)lock; - uintptr_t x = rw->rw_lock; - - *owner = rw_wowner(rw); - return ((x & RW_LOCK_READ) != 0 ? (RW_READERS(x) != 0) : - (*owner != NULL)); -} -#endif - -void -rw_init_flags(struct rwlock *rw, const char *name, int opts) -{ - int flags; - - flags = LO_UPGRADABLE; - if (opts & RW_RECURSE) - flags |= LO_RECURSABLE; - - rtems_bsd_mutex_init(&rw->lock_object, &rw->mutex, &lock_class_rw, - name, NULL, flags); -} - -void -rw_destroy(struct rwlock *rw) -{ - - rtems_bsd_mutex_destroy(&rw->lock_object, &rw->mutex); -} - -void -rw_sysinit(void *arg) -{ - struct rw_args *args = arg; - - rw_init(args->ra_rw, args->ra_desc); -} - -void -rw_sysinit_flags(void *arg) -{ - struct rw_args_flags *args = arg; - - rw_init_flags(args->ra_rw, args->ra_desc, args->ra_flags); -} - -int -rw_wowned(struct rwlock *rw) -{ - return (rtems_bsd_mutex_owned(&rw->mutex)); -} - -void -_rw_wlock(struct rwlock *rw, const char *file, int line) -{ - rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex); -} - -int -_rw_try_wlock(struct rwlock *rw, const char *file, int line) -{ - return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex)); -} - -void -_rw_wunlock(struct rwlock *rw, const char *file, int line) -{ - rtems_bsd_mutex_unlock(&rw->mutex); -} - -void -_rw_rlock(struct rwlock *rw, const char *file, int line) -{ - rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex); -} - -int -_rw_try_rlock(struct rwlock *rw, const char *file, int line) -{ - return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex)); -} - -void -_rw_runlock(struct rwlock *rw, const char *file, int line) -{ - rtems_bsd_mutex_unlock(&rw->mutex); -} - -int -_rw_try_upgrade(struct rwlock *rw, const char *file, int line) -{ - return (1); -} - -void -_rw_downgrade(struct rwlock *rw, const char *file, int line) -{ - /* Nothing to do */ -} - -#ifdef INVARIANT_SUPPORT -#ifndef INVARIANTS -#undef _rw_assert -#endif - -/* - * In the non-WITNESS case, rw_assert() can only detect that at least - * *some* thread owns an rlock, but it cannot guarantee that *this* - * thread owns an rlock. - */ -void -_rw_assert(struct rwlock *rw, int what, const char *file, int line) -{ - - if (panicstr != NULL) - return; - switch (what) { - case RA_LOCKED: - case RA_LOCKED | RA_RECURSED: - case RA_LOCKED | RA_NOTRECURSED: - case RA_RLOCKED: -#ifndef __rtems__ -#ifdef WITNESS - witness_assert(&rw->lock_object, what, file, line); -#else - /* - * If some other thread has a write lock or we have one - * and are asserting a read lock, fail. Also, if no one - * has a lock at all, fail. - */ - if (rw->rw_lock == RW_UNLOCKED || - (!(rw->rw_lock & RW_LOCK_READ) && (what == RA_RLOCKED || - rw_wowner(rw) != curthread))) - panic("Lock %s not %slocked @ %s:%d\n", - rw->lock_object.lo_name, (what == RA_RLOCKED) ? - "read " : "", file, line); - - if (!(rw->rw_lock & RW_LOCK_READ)) { - if (rw_recursed(rw)) { - if (what & RA_NOTRECURSED) - panic("Lock %s recursed @ %s:%d\n", - rw->lock_object.lo_name, file, - line); - } else if (what & RA_RECURSED) - panic("Lock %s not recursed @ %s:%d\n", - rw->lock_object.lo_name, file, line); - } -#endif - break; -#else /* __rtems__ */ - /* FALLTHROUGH */ -#endif /* __rtems__ */ - case RA_WLOCKED: - case RA_WLOCKED | RA_RECURSED: - case RA_WLOCKED | RA_NOTRECURSED: - if (rw_wowner(rw) != _Thread_Get_executing()) - panic("Lock %s not exclusively locked @ %s:%d\n", - rw->lock_object.lo_name, file, line); - if (rw_recursed(rw)) { - if (what & RA_NOTRECURSED) - panic("Lock %s recursed @ %s:%d\n", - rw->lock_object.lo_name, file, line); - } else if (what & RA_RECURSED) - panic("Lock %s not recursed @ %s:%d\n", - rw->lock_object.lo_name, file, line); - break; - case RA_UNLOCKED: -#ifdef WITNESS - witness_assert(&rw->lock_object, what, file, line); -#else - /* - * If we hold a write lock fail. We can't reliably check - * to see if we hold a read lock or not. - */ - if (rw_wowner(rw) == _Thread_Get_executing()) - panic("Lock %s exclusively locked @ %s:%d\n", - rw->lock_object.lo_name, file, line); -#endif - break; - default: - panic("Unknown rw lock assertion: %d @ %s:%d", what, file, - line); - } -} -#endif /* INVARIANT_SUPPORT */ diff --git a/rtemsbsd/rtems/rtems-bsd-signal.c b/rtemsbsd/rtems/rtems-bsd-signal.c deleted file mode 100644 index 44fa8167..00000000 --- a/rtemsbsd/rtems/rtems-bsd-signal.c +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include -#include - -void pgsigio(struct sigio **sigiop, int sig, int checkctty) -{ - - BSD_ASSERT(0); -} diff --git a/rtemsbsd/rtems/rtems-bsd-sx.c b/rtemsbsd/rtems/rtems-bsd-sx.c deleted file mode 100644 index dcf3a009..00000000 --- a/rtemsbsd/rtems/rtems-bsd-sx.c +++ /dev/null @@ -1,276 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifndef INVARIANTS -#define _sx_assert(sx, what, file, line) -#endif - -static void assert_sx(struct lock_object *lock, int what); -static void lock_sx(struct lock_object *lock, int how); -#ifdef KDTRACE_HOOKS -static int owner_sx(struct lock_object *lock, struct thread **owner); -#endif -static int unlock_sx(struct lock_object *lock); - -struct lock_class lock_class_sx = { - .lc_name = "sx", - .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, - .lc_assert = assert_sx, -#ifdef DDB - .lc_ddb_show = db_show_sx, -#endif - .lc_lock = lock_sx, - .lc_unlock = unlock_sx, -#ifdef KDTRACE_HOOKS - .lc_owner = owner_sx, -#endif -}; - -#define sx_xholder(sx) ((sx)->mutex.owner) - -#define sx_recursed(sx) ((sx)->mutex.nest_level != 0) - -void -assert_sx(struct lock_object *lock, int what) -{ - sx_assert((struct sx *)lock, what); -} - -void -lock_sx(struct lock_object *lock, int how) -{ - sx_xlock((struct sx *)lock); -} - -int -unlock_sx(struct lock_object *lock) -{ - sx_xunlock((struct sx *)lock); - - return (0); -} - -#ifdef KDTRACE_HOOKS -int -owner_sx(struct lock_object *lock, struct thread **owner) -{ - struct sx *sx = (struct sx *)lock; - uintptr_t x = sx->sx_lock; - - *owner = (struct thread *)SX_OWNER(x); - return ((x & SX_LOCK_SHARED) != 0 ? (SX_SHARERS(x) != 0) : - (*owner != NULL)); -} -#endif - -void -sx_sysinit(void *arg) -{ - struct sx_args *sargs = arg; - - sx_init(sargs->sa_sx, sargs->sa_desc); -} - -void -sx_init_flags(struct sx *sx, const char *description, int opts) -{ - int flags; - - flags = LO_SLEEPABLE | LO_UPGRADABLE; - if (opts & SX_RECURSE) - flags |= LO_RECURSABLE; - - rtems_bsd_mutex_init(&sx->lock_object, &sx->mutex, &lock_class_sx, - description, NULL, flags); -} - -void -sx_destroy(struct sx *sx) -{ - - rtems_bsd_mutex_destroy(&sx->lock_object, &sx->mutex); -} - -int -_sx_xlock(struct sx *sx, int opts, const char *file, int line) -{ - rtems_bsd_mutex_lock(&sx->lock_object, &sx->mutex); - - return (0); -} - -int -_sx_try_xlock(struct sx *sx, const char *file, int line) -{ - return (rtems_bsd_mutex_trylock(&sx->lock_object, &sx->mutex)); -} - -void -_sx_xunlock(struct sx *sx, const char *file, int line) -{ - rtems_bsd_mutex_unlock(&sx->mutex); -} - -int -_sx_try_upgrade(struct sx *sx, const char *file, int line) -{ - return (1); -} - -void -_sx_downgrade(struct sx *sx, const char *file, int line) -{ - /* Do nothing */ -} - -#ifdef INVARIANT_SUPPORT -#ifndef INVARIANTS -#undef _sx_assert -#endif - -/* - * In the non-WITNESS case, sx_assert() can only detect that at least - * *some* thread owns an slock, but it cannot guarantee that *this* - * thread owns an slock. - */ -void -_sx_assert(struct sx *sx, int what, const char *file, int line) -{ -#ifndef __rtems__ -#ifndef WITNESS - int slocked = 0; -#endif -#endif /* __rtems__ */ - - if (panicstr != NULL) - return; - switch (what) { - case SA_SLOCKED: - case SA_SLOCKED | SA_NOTRECURSED: - case SA_SLOCKED | SA_RECURSED: -#ifndef __rtems__ -#ifndef WITNESS - slocked = 1; - /* FALLTHROUGH */ -#endif -#endif /* __rtems__ */ - case SA_LOCKED: - case SA_LOCKED | SA_NOTRECURSED: - case SA_LOCKED | SA_RECURSED: -#ifndef __rtems__ -#ifdef WITNESS - witness_assert(&sx->lock_object, what, file, line); -#else - /* - * If some other thread has an exclusive lock or we - * have one and are asserting a shared lock, fail. - * Also, if no one has a lock at all, fail. - */ - if (sx->sx_lock == SX_LOCK_UNLOCKED || - (!(sx->sx_lock & SX_LOCK_SHARED) && (slocked || - sx_xholder(sx) != curthread))) - panic("Lock %s not %slocked @ %s:%d\n", - sx->lock_object.lo_name, slocked ? "share " : "", - file, line); - - if (!(sx->sx_lock & SX_LOCK_SHARED)) { - if (sx_recursed(sx)) { - if (what & SA_NOTRECURSED) - panic("Lock %s recursed @ %s:%d\n", - sx->lock_object.lo_name, file, - line); - } else if (what & SA_RECURSED) - panic("Lock %s not recursed @ %s:%d\n", - sx->lock_object.lo_name, file, line); - } -#endif - break; -#else /* __rtems__ */ - /* FALLTHROUGH */ -#endif /* __rtems__ */ - case SA_XLOCKED: - case SA_XLOCKED | SA_NOTRECURSED: - case SA_XLOCKED | SA_RECURSED: - if (sx_xholder(sx) != _Thread_Get_executing()) - panic("Lock %s not exclusively locked @ %s:%d\n", - sx->lock_object.lo_name, file, line); - if (sx_recursed(sx)) { - if (what & SA_NOTRECURSED) - panic("Lock %s recursed @ %s:%d\n", - sx->lock_object.lo_name, file, line); - } else if (what & SA_RECURSED) - panic("Lock %s not recursed @ %s:%d\n", - sx->lock_object.lo_name, file, line); - break; - case SA_UNLOCKED: -#ifdef WITNESS - witness_assert(&sx->lock_object, what, file, line); -#else - /* - * If we hold an exclusve lock fail. We can't - * reliably check to see if we hold a shared lock or - * not. - */ - if (sx_xholder(sx) == _Thread_Get_executing()) - panic("Lock %s exclusively locked @ %s:%d\n", - sx->lock_object.lo_name, file, line); -#endif - break; - default: - panic("Unknown sx lock assertion: %d @ %s:%d", what, file, - line); - } -} -#endif /* INVARIANT_SUPPORT */ - -int -sx_xlocked(struct sx *sx) -{ - return (rtems_bsd_mutex_owned(&sx->mutex)); -} diff --git a/rtemsbsd/rtems/rtems-bsd-sysctl.c b/rtemsbsd/rtems/rtems-bsd-sysctl.c deleted file mode 100644 index 7e087385..00000000 --- a/rtemsbsd/rtems/rtems-bsd-sysctl.c +++ /dev/null @@ -1,84 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2010 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Obere Lagerstr. 30 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include - -#include -#include -#include -#include - -int sysctl( - const int *name, - u_int namelen, - void *oldp, - size_t *oldlenp, - const void *newp, - size_t newlen -) -{ - int eno = EINVAL; - - if (namelen <= CTL_MAXNAME) { - int namedup [CTL_MAXNAME]; - - memcpy(namedup, name, namelen * sizeof(*name)); - - eno = kernel_sysctl( - NULL, - namedup, - namelen, - oldp, - oldlenp, - newp, - newlen, - oldlenp, - 0 - ); - } - - if (eno == 0) { - return 0; - } else { - errno = eno; - - return -1; - } -} diff --git a/rtemsbsd/rtems/rtems-bsd-sysctlbyname.c b/rtemsbsd/rtems/rtems-bsd-sysctlbyname.c deleted file mode 100644 index ab3e8083..00000000 --- a/rtemsbsd/rtems/rtems-bsd-sysctlbyname.c +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - * - * File origin from FreeBSD 'lib/libc/gen/sysctlbyname.c'. - */ - -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - */ - -#include -#include - -#include -__FBSDID("$FreeBSD$"); - -#include -#include - -int -sysctlbyname(const char *name, void *oldp, size_t *oldlenp, - const void *newp, size_t newlen) -{ - int real_oid[CTL_MAXNAME+2]; - int error; - size_t oidlen; - - oidlen = sizeof(real_oid) / sizeof(int); - error = sysctlnametomib(name, real_oid, &oidlen); - if (error < 0) - return (error); - error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); - return (error); -} diff --git a/rtemsbsd/rtems/rtems-bsd-sysctlnametomib.c b/rtemsbsd/rtems/rtems-bsd-sysctlnametomib.c deleted file mode 100644 index 62ce6b80..00000000 --- a/rtemsbsd/rtems/rtems-bsd-sysctlnametomib.c +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - * - * File origin from FreeBSD 'lib/libc/gen/sysctlnametomib.c'. - */ - -/* - * Copyright 2001 The FreeBSD Project. All Rights Reserved. - * - * 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 FREEBSD PROJECT ``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 FREEBSD PROJECT 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. - */ - -#include -#include - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -/* - * This function uses a presently undocumented interface to the kernel - * to walk the tree and get the type so it can print the value. - * This interface is under work and consideration, and should probably - * be killed with a big axe by the first person who can find the time. - * (be aware though, that the proper interface isn't as obvious as it - * may seem, there are various conflicting requirements. - */ -int -sysctlnametomib(const char *name, int *mibp, size_t *sizep) -{ - int oid[2]; - int error; - - oid[0] = 0; - oid[1] = 3; - - *sizep *= sizeof(int); - error = sysctl(oid, 2, mibp, sizep, name, strlen(name)); - *sizep /= sizeof(int); - return (error); -} diff --git a/rtemsbsd/rtems/rtems-bsd-thread.c b/rtemsbsd/rtems/rtems-bsd-thread.c deleted file mode 100644 index fe213201..00000000 --- a/rtemsbsd/rtems/rtems-bsd-thread.c +++ /dev/null @@ -1,370 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#undef ticks - -#include -#include -#include -#include -#include -#include - -static size_t rtems_bsd_extension_index; - -static CHAIN_DEFINE_EMPTY(rtems_bsd_thread_delay_start_chain); - -static bool rtems_bsd_thread_ready_to_start; - -struct thread * -rtems_bsd_get_thread(const Thread_Control *thread) -{ - return thread->extensions[rtems_bsd_extension_index]; -} - -static Thread_Control * -rtems_bsd_get_thread_by_id(rtems_id task_id) -{ - Thread_Control *thread; - Objects_Locations location; - - thread = _Thread_Get(task_id, &location); - switch (location) { - case OBJECTS_LOCAL: - _Objects_Put(&thread->Object); - break; -#if defined(RTEMS_MULTIPROCESSING) - case OBJECTS_REMOTE: - _Thread_Dispatch(); - thread = NULL; - break; -#endif - default: - thread = NULL; - break; - } - - return thread; -} - -struct thread * -rtems_bsd_thread_create(Thread_Control *thread, int wait) -{ - struct thread *td = malloc(sizeof(*td), M_TEMP, M_ZERO | wait); - struct sleepqueue *sq = sleepq_alloc(); - - if (td != NULL && sq != NULL) { - td->td_thread = thread; - td->td_sleepqueue = sq; - } else { - free(td, M_TEMP); - sleepq_free(sq); - td = NULL; - } - - thread->extensions[rtems_bsd_extension_index] = td; - - return td; -} - -static struct thread * -rtems_bsd_get_curthread(int wait) -{ - Thread_Control *executing = _Thread_Get_executing(); - struct thread *td = rtems_bsd_get_thread(executing); - - if (td == NULL) { - td = rtems_bsd_thread_create(executing, wait); - } - - return td; -} - -struct thread * -rtems_bsd_get_curthread_or_wait_forever(void) -{ - return rtems_bsd_get_curthread(M_WAITOK); -} - -struct thread * -rtems_bsd_get_curthread_or_null(void) -{ - return rtems_bsd_get_curthread(0); -} - -static bool -rtems_bsd_is_bsd_thread(Thread_Control *thread) -{ - return thread->Object.name.name_u32 == BSD_TASK_NAME; -} - -static bool -rtems_bsd_extension_thread_create( - Thread_Control *executing, - Thread_Control *created -) -{ - bool ok; - - if (rtems_bsd_is_bsd_thread(created)) { - struct thread *td = rtems_bsd_thread_create(created, 0); - - ok = td != NULL; - } else { - ok = true; - } - - return ok; -} - -static void -rtems_bsd_extension_thread_delete( - Thread_Control *executing, - Thread_Control *deleted -) -{ - struct thread *td = rtems_bsd_get_thread(deleted); - - if (td != NULL) { - seltdfini(td); - sleepq_free(td->td_sleepqueue); - free(td, M_TEMP); - } -} - -static const rtems_extensions_table rtems_bsd_extensions = { - .thread_create = rtems_bsd_extension_thread_create, - .thread_delete = rtems_bsd_extension_thread_delete -}; - -static void -rtems_bsd_threads_init_early(void *arg) -{ - rtems_id ext_id; - rtems_status_code sc; - - (void) arg; - - sc = rtems_extension_create( - BSD_TASK_NAME, - &rtems_bsd_extensions, - &ext_id - ); - if (sc != RTEMS_SUCCESSFUL) { - BSD_PANIC("cannot create extension"); - } - - rtems_bsd_extension_index = rtems_object_id_get_index(ext_id); -} - -static void -rtems_bsd_threads_init_late(void *arg) -{ - Chain_Control *chain = &rtems_bsd_thread_delay_start_chain; - Chain_Node *node; - - (void) arg; - - while ((node = _Chain_Get_unprotected(chain)) != NULL) { - Thread_Control *thread = (Thread_Control *) node; - rtems_status_code sc; - - sc = rtems_task_start(thread->Object.id, - thread->Start.Entry.Kinds.Numeric.entry, - thread->Start.Entry.Kinds.Numeric.argument); - BSD_ASSERT(sc == RTEMS_SUCCESSFUL); - } - - rtems_bsd_thread_ready_to_start = true; -} - -SYSINIT(rtems_bsd_threads_early, SI_SUB_INTRINSIC, SI_ORDER_ANY, - rtems_bsd_threads_init_early, NULL); - -SYSINIT(rtems_bsd_threads_late, SI_SUB_LAST, SI_ORDER_ANY, - rtems_bsd_threads_init_late, NULL); - -static int -rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg, - int flags, int pages, const char *fmt, va_list ap) -{ - int eno = 0; - rtems_status_code sc; - rtems_id task_id; - struct thread *td; - char name[sizeof(td->td_name)]; - - BSD_ASSERT(pages >= 0); - - vsnprintf(name, sizeof(name), fmt, ap); - - sc = rtems_task_create( - BSD_TASK_NAME, - rtems_bsd_get_task_priority(name), - rtems_bsd_get_task_stack_size(name) - + (size_t) pages * PAGE_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, - &task_id - ); - if (sc == RTEMS_SUCCESSFUL) { - Thread_Control *thread = rtems_bsd_get_thread_by_id(task_id); - - BSD_ASSERT(thread != NULL); - - td = rtems_bsd_get_thread(thread); - BSD_ASSERT(td != NULL); - - memcpy(td->td_name, name, sizeof(name)); - - if (rtems_bsd_thread_ready_to_start) { - sc = rtems_task_start(task_id, (rtems_task_entry) func, - (rtems_task_argument) arg); - BSD_ASSERT(sc == RTEMS_SUCCESSFUL); - } else { - thread->Start.Entry.Kinds.Numeric.entry = - (void (*)(Thread_Entry_numeric_type))func; - thread->Start.Entry.Kinds.Numeric.argument = - (Thread_Entry_numeric_type)arg; - _Chain_Append_unprotected( - &rtems_bsd_thread_delay_start_chain, - &thread->Object.Node); - } - - if (td_ptr != NULL) { - *td_ptr = td; - } - } else { - eno = ENOMEM; - } - - return eno; -} - -static __dead2 void -rtems_bsd_thread_delete(void) -{ - rtems_task_delete(RTEMS_SELF); - BSD_PANIC("delete self failed"); -} - -void -kproc_start(const void *udata) -{ - const struct kproc_desc *pd = udata; - int eno = kproc_create((void (*)(void *))pd->func, NULL, pd->global_procpp, 0, 0, "%s", pd->arg0); - - BSD_ASSERT(eno == 0); -} - -int -kproc_create(void (*func)(void *), void *arg, struct proc **newpp, int flags, int pages, const char *fmt, ...) -{ - int eno = 0; - va_list ap; - - va_start(ap, fmt); - eno = rtems_bsd_thread_start(newpp, func, arg, flags, pages, fmt, ap); - va_end(ap); - - return eno; -} - -void -kproc_exit(int ecode) -{ - rtems_bsd_thread_delete(); -} - -void -kthread_start(const void *udata) -{ - const struct kthread_desc *td = udata; - int eno = kthread_add((void (*)(void *)) td->func, NULL, NULL, td->global_threadpp, 0, 0, "%s", td->arg0); - - BSD_ASSERT(eno == 0); -} - -int -kthread_add(void (*func)(void *), void *arg, struct proc *p, struct thread **newtdp, int flags, int pages, const char *fmt, ...) -{ - int eno = 0; - va_list ap; - - va_start(ap, fmt); - eno = rtems_bsd_thread_start(newtdp, func, arg, flags, pages, fmt, ap); - va_end(ap); - - return eno; -} - -void -kthread_exit(void) -{ - rtems_bsd_thread_delete(); -} - -int -kproc_kthread_add(void (*func)(void *), void *arg, struct proc **procptr, struct thread **tdptr, int flags, int pages, const char * procname, const char *fmt, ...) -{ - int eno = 0; - va_list ap; - - va_start(ap, fmt); - eno = rtems_bsd_thread_start(tdptr, func, arg, flags, pages, fmt, ap); - va_end(ap); - - return eno; -} diff --git a/rtemsbsd/rtems/rtems-bsd-timesupport.c b/rtemsbsd/rtems/rtems-bsd-timesupport.c deleted file mode 100644 index ef14d1fa..00000000 --- a/rtemsbsd/rtems/rtems-bsd-timesupport.c +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * COPYRIGHT (c) 2012. - * On-Line Applications Research Corporation (OAR). - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include - -#include - -/* - * Compute number of ticks in the specified amount of time. - */ -int -tvtohz(struct timeval *tv) -{ - struct timespec ts; - - ts.tv_sec = tv->tv_sec; - ts.tv_nsec = tv->tv_usec * 1000; - - return (int) _Timespec_To_ticks( &ts ); -} diff --git a/rtemsbsd/rtems/rtems-bsd-vprintf.c b/rtemsbsd/rtems/rtems-bsd-vprintf.c deleted file mode 100644 index 36f0c59c..00000000 --- a/rtemsbsd/rtems/rtems-bsd-vprintf.c +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @file - * - * @ingroup rtems_bsd_rtems - * - * @brief TODO. - */ - -/* - * Copyright (c) 2014, 2016 embedded brains GmbH. All rights reserved. - * - * embedded brains GmbH - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include -#include -#include - -#include - -#include - -#undef printf - -#define VPRINTF_LOCK() _Mutex_Acquire(&vprintf_mtx) -#define VPRINTF_UNLOCK() _Mutex_Release(&vprintf_mtx) - -static const char * const log_priorities[] = { - [LOG_EMERG] = "emerg", - [LOG_ALERT] = "alert", - [LOG_CRIT] = "crit", - [LOG_ERR] = "err", - [LOG_WARNING] = "warning", - [LOG_NOTICE] = "notice", - [LOG_INFO] = "info", - [LOG_DEBUG] = "debug" -}; - -/* Use a mutex due to the static initialization capability */ -static struct _Mutex_Control vprintf_mtx = _MUTEX_INITIALIZER; - -static void -vprintf_putchar(int c, void *arg) -{ - int *last; - - last = arg; - *last = c; - putchar(c); -} - -static int -default_vprintf_handler(int level, const char *fmt, va_list ap) -{ - int n; - int last; - - VPRINTF_LOCK(); - - if (level != LOG_PRINTF) { - printf("%s: ", log_priorities[LOG_PRI(level)]); - } - - last = -1; - n = kvprintf(fmt, vprintf_putchar, &last, 10, ap); - - if (level != LOG_PRINTF && last != '\n') { - putchar('\n'); - } - - VPRINTF_UNLOCK(); - return (n); -} - -static int (*vprintf_handler)(int, const char *, va_list) = - default_vprintf_handler; - -void -rtems_bsd_set_vprintf_handler(int (*new_vprintf_handler) - (int, const char *, va_list)) -{ - - vprintf_handler = new_vprintf_handler; -} - -int -rtems_bsd_vprintf(int level, const char *fmt, va_list ap) -{ - - return ((*vprintf_handler)(level, fmt, ap)); -} diff --git a/rtemsbsd/rtems/rtems-bsdnet-rtrequest.c b/rtemsbsd/rtems/rtems-bsdnet-rtrequest.c deleted file mode 100644 index e1269be9..00000000 --- a/rtemsbsd/rtems/rtems-bsdnet-rtrequest.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014 embedded brains GmbH. All rights reserved. - * - * Dornierstr. 4 - * 82178 Puchheim - * Germany - * - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include - -#include - -#include - -#include - -int -rtems_bsdnet_rtrequest(int req, struct sockaddr *dst, struct sockaddr *gateway, - struct sockaddr *netmask, int flags, struct rtentry **net_nrt) -{ - int error; - - error = rtrequest(req, dst, gateway, netmask, flags, net_nrt); - if (error != 0) { - errno = error; - - return (-1); - } else { - return (0); - } -} diff --git a/rtemsbsd/rtems/rtems-kernel-assert.c b/rtemsbsd/rtems/rtems-kernel-assert.c new file mode 100644 index 00000000..3ebe19e7 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-assert.c @@ -0,0 +1,57 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009, 2010 embedded brains GmbH. + * All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +void +rtems_bsd_assert_func(const char *file, int line, const char *func, const char *expr) +{ + panic( + "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", + expr, + file, + line, + (func != NULL) ? ", function: " : "", + (func != NULL) ? func : "" + ); +} diff --git a/rtemsbsd/rtems/rtems-kernel-autoconf.c b/rtemsbsd/rtems/rtems-kernel-autoconf.c new file mode 100644 index 00000000..ea250c05 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-autoconf.c @@ -0,0 +1,69 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009, 2010 embedded brains GmbH. + * All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include +#include + +static void +configure_first(void *dummy) +{ + device_add_child(root_bus, "nexus", 0); +} + +static void +configure(void *dummy) +{ + root_bus_configure(); +} + +static void +configure_final(void *dummy) +{ + /* Do nothing */ +} + +SYSINIT(configure1, SI_SUB_CONFIGURE, SI_ORDER_FIRST, configure_first, NULL); +SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL); +SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL); diff --git a/rtemsbsd/rtems/rtems-kernel-bus-dma-mbuf.c b/rtemsbsd/rtems/rtems-kernel-bus-dma-mbuf.c new file mode 100644 index 00000000..c435fd74 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-bus-dma-mbuf.c @@ -0,0 +1,129 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + * + * File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c". + */ + +/*- + * Copyright (c) 2012 embedded brains GmbH. + * All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Copyright (c) 1997, 1998 Justin T. Gibbs. + * All rights reserved. + * + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include + +/* + * Like bus_dmamap_load(), but for mbufs. + */ +int +bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *m0, + bus_dmamap_callback2_t *callback, void *callback_arg, + int flags) +{ + bus_dma_segment_t dm_segments[dmat->nsegments]; + int nsegs, error; + + M_ASSERTPKTHDR(m0); + + flags |= BUS_DMA_NOWAIT; + nsegs = 0; + error = 0; + if (m0->m_pkthdr.len <= dmat->maxsize) { + int first = 1; + bus_addr_t lastaddr = 0; + struct mbuf *m; + + for (m = m0; m != NULL && error == 0; m = m->m_next) { + if (m->m_len > 0) { + error = bus_dmamap_load_buffer(dmat, dm_segments, + m->m_data, m->m_len, + NULL, flags, &lastaddr, + &nsegs, first); + first = 0; + } + } + } else { + error = EINVAL; + } + + if (error) { + /* force "no valid mappings" in callback */ + (*callback)(callback_arg, dm_segments, 0, 0, error); + } else { + (*callback)(callback_arg, dm_segments, + nsegs+1, m0->m_pkthdr.len, error); + } + return (error); +} + +int +bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map, + struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs, + int flags) +{ + int error; + + M_ASSERTPKTHDR(m0); + + flags |= BUS_DMA_NOWAIT; + *nsegs = 0; + error = 0; + if (m0->m_pkthdr.len <= dmat->maxsize) { + int first = 1; + bus_addr_t lastaddr = 0; + struct mbuf *m; + + for (m = m0; m != NULL && error == 0; m = m->m_next) { + if (m->m_len > 0) { + error = bus_dmamap_load_buffer(dmat, segs, + m->m_data, m->m_len, + NULL, flags, &lastaddr, + nsegs, first); + first = 0; + } + } + } else { + error = EINVAL; + } + + /* XXX FIXME: Having to increment nsegs is really annoying */ + ++*nsegs; + return (error); +} diff --git a/rtemsbsd/rtems/rtems-kernel-bus-dma.c b/rtemsbsd/rtems/rtems-kernel-bus-dma.c new file mode 100644 index 00000000..c7cc8724 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-bus-dma.c @@ -0,0 +1,436 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + * + * File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c". + */ + +/* + * Copyright (c) 2009-2012 embedded brains GmbH. + * All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Copyright (c) 2004 Olivier Houchard + * Copyright (c) 2002 Peter Grehan + * Copyright (c) 1997, 1998 Justin T. Gibbs. + * All rights reserved. + * + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include + +#include +#include + +#ifdef CPU_DATA_CACHE_ALIGNMENT + #define CLSZ ((uintptr_t) CPU_DATA_CACHE_ALIGNMENT) + #define CLMASK (CLSZ - (uintptr_t) 1) +#endif + +/* + * Convenience function for manipulating driver locks from busdma (during + * busdma_swi, for example). Drivers that don't provide their own locks + * should specify &Giant to dmat->lockfuncarg. Drivers that use their own + * non-mutex locking scheme don't have to use this at all. + */ +void +busdma_lock_mutex(void *arg, bus_dma_lock_op_t op) +{ + struct mtx *dmtx; + + dmtx = (struct mtx *)arg; + switch (op) { + case BUS_DMA_LOCK: + mtx_lock(dmtx); + break; + case BUS_DMA_UNLOCK: + mtx_unlock(dmtx); + break; + default: + panic("Unknown operation 0x%x for busdma_lock_mutex!", op); + } +} + +/* + * dflt_lock should never get called. It gets put into the dma tag when + * lockfunc == NULL, which is only valid if the maps that are associated + * with the tag are meant to never be defered. + * XXX Should have a way to identify which driver is responsible here. + */ +static void +dflt_lock(void *arg, bus_dma_lock_op_t op) +{ + panic("driver error: busdma dflt_lock called"); +} + +/* + * Allocate a device specific dma_tag. + */ +int +bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, + bus_size_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, + bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, + int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat) +{ + bus_dma_tag_t newtag; + int error = 0; + + /* Return a NULL tag on failure */ + *dmat = NULL; + + newtag = malloc(sizeof(*newtag), M_DEVBUF, M_NOWAIT | M_ZERO); + if (newtag == NULL) + return (ENOMEM); + + newtag->parent = parent; + newtag->alignment = alignment; + newtag->boundary = boundary; + newtag->lowaddr = lowaddr; + newtag->highaddr = highaddr; + newtag->filter = filter; + newtag->filterarg = filterarg; + newtag->maxsize = maxsize; + newtag->nsegments = nsegments; + newtag->maxsegsz = maxsegsz; + newtag->flags = flags; + newtag->ref_count = 1; /* Count ourself */ + newtag->map_count = 0; + if (lockfunc != NULL) { + newtag->lockfunc = lockfunc; + newtag->lockfuncarg = lockfuncarg; + } else { + newtag->lockfunc = dflt_lock; + newtag->lockfuncarg = NULL; + } + + /* + * Take into account any restrictions imposed by our parent tag + */ + if (parent != NULL) { + newtag->lowaddr = min(parent->lowaddr, newtag->lowaddr); + newtag->highaddr = max(parent->highaddr, newtag->highaddr); + if (newtag->boundary == 0) + newtag->boundary = parent->boundary; + else if (parent->boundary != 0) + newtag->boundary = MIN(parent->boundary, + newtag->boundary); + if (newtag->filter == NULL) { + /* + * Short circuit looking at our parent directly + * since we have encapsulated all of its information + */ + newtag->filter = parent->filter; + newtag->filterarg = parent->filterarg; + newtag->parent = parent->parent; + } + if (newtag->parent != NULL) + atomic_add_int(&parent->ref_count, 1); + } + + *dmat = newtag; + return (error); +} + +int +bus_dma_tag_destroy(bus_dma_tag_t dmat) +{ + if (dmat != NULL) { + + if (dmat->map_count != 0) + return (EBUSY); + + while (dmat != NULL) { + bus_dma_tag_t parent; + + parent = dmat->parent; + atomic_subtract_int(&dmat->ref_count, 1); + if (dmat->ref_count == 0) { + free(dmat, M_DEVBUF); + /* + * Last reference count, so + * release our reference + * count on our parent. + */ + dmat = parent; + } else + dmat = NULL; + } + } + return (0); +} + +/* + * Allocate a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int +bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp) +{ + *mapp = malloc(sizeof(**mapp), M_DEVBUF, M_NOWAIT | M_ZERO); + if (*mapp == NULL) { + return ENOMEM; + } + + dmat->map_count++; + + return (0); +} + +/* + * Destroy a handle for mapping from kva/uva/physical + * address space into bus device space. + */ +int +bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + free(map, M_DEVBUF); + + dmat->map_count--; + + return (0); +} + +/* + * Allocate a piece of memory that can be efficiently mapped into + * bus device space based on the constraints lited in the dma tag. + * A dmamap to for use with dmamap_load is also allocated. + */ +int +bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, + bus_dmamap_t *mapp) +{ + *mapp = malloc(sizeof(**mapp), M_DEVBUF, M_NOWAIT | M_ZERO); + if (*mapp == NULL) { + return ENOMEM; + } + + if ((flags & BUS_DMA_COHERENT) != 0) { + *vaddr = rtems_cache_coherent_allocate( + dmat->maxsize, dmat->alignment, dmat->boundary); + } else { + *vaddr = rtems_heap_allocate_aligned_with_boundary( + dmat->maxsize, dmat->alignment, dmat->boundary); + } + + if (*vaddr == NULL) { + free(*mapp, M_DEVBUF); + + return ENOMEM; + } + + (*mapp)->buffer_begin = *vaddr; + (*mapp)->buffer_size = dmat->maxsize; + + if ((flags & BUS_DMA_ZERO) != 0) { + memset(*vaddr, 0, dmat->maxsize); + } + + return (0); +} + +/* + * Free a piece of memory and it's allocated dmamap, that was allocated + * via bus_dmamem_alloc. Make the same choice for free/contigfree. + */ +void +bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) +{ + rtems_cache_coherent_free(vaddr); + free(map, M_DEVBUF); +} + +/* + * Utility function to load a linear buffer. lastaddrp holds state + * between invocations (for multiple-buffer loads). segp contains + * the starting segment on entrance, and the ending segment on exit. + * first indicates if this is the first invocation of this function. + */ +int +bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dma_segment_t segs[], + void *buf, bus_size_t buflen, struct thread *td, int flags, + vm_offset_t *lastaddrp, int *segp, int first) +{ + bus_size_t sgsize; + bus_addr_t curaddr, lastaddr, baddr, bmask; + vm_offset_t vaddr = (vm_offset_t)buf; + int seg; + + lastaddr = *lastaddrp; + bmask = ~(dmat->boundary - 1); + + for (seg = *segp; buflen > 0 ; ) { + /* + * Get the physical address for this segment. + */ + curaddr = vaddr; + + /* + * Compute the segment size, and adjust counts. + */ + sgsize = PAGE_SIZE - ((u_long)curaddr & PAGE_MASK); + if (sgsize > dmat->maxsegsz) + sgsize = dmat->maxsegsz; + if (buflen < sgsize) + sgsize = buflen; + + /* + * Make sure we don't cross any boundaries. + */ + if (dmat->boundary > 0) { + baddr = (curaddr + dmat->boundary) & bmask; + if (sgsize > (baddr - curaddr)) + sgsize = (baddr - curaddr); + } + + /* + * Insert chunk into a segment, coalescing with + * the previous segment if possible. + */ + if (first) { + segs[seg].ds_addr = curaddr; + segs[seg].ds_len = sgsize; + first = 0; + } else { + if (curaddr == lastaddr && + (segs[seg].ds_len + sgsize) <= dmat->maxsegsz && + (dmat->boundary == 0 || + (segs[seg].ds_addr & bmask) == (curaddr & bmask))) + segs[seg].ds_len += sgsize; + else { + if (++seg >= dmat->nsegments) + break; + segs[seg].ds_addr = curaddr; + segs[seg].ds_len = sgsize; + } + } + + lastaddr = curaddr + sgsize; + vaddr += sgsize; + buflen -= sgsize; + } + + *segp = seg; + *lastaddrp = lastaddr; + + /* + * Did we fit? + */ + return (buflen != 0 ? EFBIG : 0); /* XXX better return value here? */ +} + +/* + * Map the buffer buf into bus space using the dmamap map. + */ +int +bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf, + bus_size_t buflen, bus_dmamap_callback_t *callback, + void *callback_arg, int flags) +{ + bus_dma_segment_t dm_segments[dmat->nsegments]; + vm_offset_t lastaddr; + int error, nsegs; + + map->buffer_begin = buf; + map->buffer_size = buflen; + + lastaddr = (vm_offset_t)0; + nsegs = 0; + error = bus_dmamap_load_buffer(dmat, dm_segments, buf, buflen, + NULL, flags, &lastaddr, &nsegs, 1); + + if (error == 0) + (*callback)(callback_arg, dm_segments, nsegs + 1, 0); + else + (*callback)(callback_arg, NULL, 0, error); + + return (0); +} + +/* + * Release the mapping held by map. A no-op on PowerPC. + */ +void +_bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map) +{ + + return; +} + +void +_bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op) +{ +#ifdef CPU_DATA_CACHE_ALIGNMENT + uintptr_t size = map->buffer_size; + uintptr_t begin = (uintptr_t) map->buffer_begin; + uintptr_t end = begin + size; + + if ((op & BUS_DMASYNC_PREWRITE) != 0 && (op & BUS_DMASYNC_PREREAD) == 0) { + rtems_cache_flush_multiple_data_lines((void *) begin, size); + } + if ((op & BUS_DMASYNC_PREREAD) != 0) { + if ((op & BUS_DMASYNC_PREWRITE) != 0 || ((begin | size) & CLMASK) != 0) { + rtems_cache_flush_multiple_data_lines((void *) begin, size); + } + rtems_cache_invalidate_multiple_data_lines((void *) begin, size); + } + if ((op & BUS_DMASYNC_POSTREAD) != 0) { + char first_buf [CLSZ]; + char last_buf [CLSZ]; + bool first_is_aligned = (begin & CLMASK) == 0; + bool last_is_aligned = (end & CLMASK) == 0; + void *first_begin = (void *) (begin & ~CLMASK); + size_t first_size = begin & CLMASK; + void *last_begin = (void *) end; + size_t last_size = CLSZ - (end & CLMASK); + + if (!first_is_aligned) { + memcpy(first_buf, first_begin, first_size); + } + if (!last_is_aligned) { + memcpy(last_buf, last_begin, last_size); + } + + rtems_cache_invalidate_multiple_data_lines((void *) begin, size); + + if (!first_is_aligned) { + memcpy(first_begin, first_buf, first_size); + } + if (!last_is_aligned) { + memcpy(last_begin, last_buf, last_size); + } + } +#endif /* CPU_DATA_CACHE_ALIGNMENT */ +} diff --git a/rtemsbsd/rtems/rtems-kernel-bus-root.c b/rtemsbsd/rtems/rtems-kernel-bus-root.c new file mode 100644 index 00000000..f444f512 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-bus-root.c @@ -0,0 +1,91 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/*- + * Copyright (c) 2012-2013 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include + +int +rtems_bsd_bus_root_attach(void) +{ + int err; + device_t dev; + + dev = device_find_child(root_bus, "nexus", 0); + if (dev != NULL) { + err = device_probe_and_attach(dev); + } else { + err = ENOENT; + } + + return (err); +} + +int +rtems_bsd_bus_root_suspend(void) +{ + + return (DEVICE_SUSPEND(root_bus)); +} + +int +rtems_bsd_bus_root_resume(void) +{ + + return (DEVICE_RESUME(root_bus)); +} + +int +rtems_bsd_bus_root_detach(void) +{ + int err; + device_t dev; + + dev = device_find_child(root_bus, "nexus", 0); + if (dev != NULL) { + err = device_detach(dev); + } else { + err = ENOENT; + } + + return (err); +} diff --git a/rtemsbsd/rtems/rtems-kernel-cam.c b/rtemsbsd/rtems/rtems-kernel-cam.c new file mode 100644 index 00000000..0f518586 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-cam.c @@ -0,0 +1,504 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2012 embedded brains GmbH. + * All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#define BSD_CAM_DEVQ_DUMMY ((struct cam_devq *) 0xdeadbeef) + +#define BSD_SCSI_TAG 0 + +#define BSD_SCSI_RETRIES 4 + +#define BSD_SCSI_TIMEOUT (60 * 1000) + +#define BSD_SCSI_MIN_COMMAND_SIZE 10 + +MALLOC_DEFINE(M_CAMSIM, "CAM SIM", "CAM SIM buffers"); + +static void +rtems_bsd_sim_set_state(struct cam_sim *sim, enum bsd_sim_state state) +{ + sim->state = state; +} + +static void +rtems_bsd_sim_set_state_and_notify(struct cam_sim *sim, enum bsd_sim_state state) +{ + sim->state = state; + cv_broadcast(&sim->state_changed); +} + +static void +rtems_bsd_sim_wait_for_state(struct cam_sim *sim, enum bsd_sim_state state) +{ + while (sim->state != state) { + cv_wait(&sim->state_changed, sim->mtx); + } +} + +static void +rtems_bsd_sim_wait_for_state_and_cancel_ccb(struct cam_sim *sim, enum bsd_sim_state state) +{ + while (sim->state != state) { + if (sim->state != BSD_SIM_BUSY) { + cv_wait(&sim->state_changed, sim->mtx); + } else { + sim->ccb.ccb_h.status = CAM_SEL_TIMEOUT; + (*sim->ccb.ccb_h.cbfcnp)(NULL, &sim->ccb); + } + } +} + +static void +rtems_bsd_ccb_callback(struct cam_periph *periph, union ccb *ccb) +{ + struct cam_sim *sim = ccb->ccb_h.sim; + + BSD_ASSERT(periph == NULL && sim->state == BSD_SIM_INIT_BUSY); + + rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_INIT_READY); +} + +static rtems_status_code +rtems_bsd_ccb_action(union ccb *ccb) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + struct cam_sim *sim = ccb->ccb_h.sim; + + mtx_lock(sim->mtx); + + BSD_ASSERT(sim->state == BSD_SIM_INIT); + rtems_bsd_sim_set_state(sim, BSD_SIM_INIT_BUSY); + (*sim->sim_action)(sim, ccb); + rtems_bsd_sim_wait_for_state(sim, BSD_SIM_INIT_READY); + if (ccb->ccb_h.status != CAM_REQ_CMP) { + sc = RTEMS_IO_ERROR; + } + rtems_bsd_sim_set_state(sim, BSD_SIM_INIT); + + mtx_unlock(sim->mtx); + + return sc; +} + +static rtems_status_code +rtems_bsd_scsi_inquiry(union ccb *ccb, struct scsi_inquiry_data *inq_data) +{ + memset(inq_data, 0, sizeof(*inq_data)); + + scsi_inquiry( + &ccb->csio, + BSD_SCSI_RETRIES, + rtems_bsd_ccb_callback, + BSD_SCSI_TAG, + (u_int8_t *) inq_data, + SHORT_INQUIRY_LENGTH, + FALSE, + 0, + SSD_MIN_SIZE, + BSD_SCSI_TIMEOUT + ); + + return rtems_bsd_ccb_action(ccb); +} + +static rtems_status_code +rtems_bsd_scsi_test_unit_ready(union ccb *ccb) +{ + scsi_test_unit_ready( + &ccb->csio, + BSD_SCSI_RETRIES, + rtems_bsd_ccb_callback, + BSD_SCSI_TAG, + SSD_FULL_SIZE, + BSD_SCSI_TIMEOUT + ); + + return rtems_bsd_ccb_action(ccb); +} + +static rtems_status_code +rtems_bsd_scsi_read_capacity(union ccb *ccb, uint32_t *block_count, uint32_t *block_size) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + struct scsi_read_capacity_data rdcap; + + memset(&rdcap, 0, sizeof(rdcap)); + + scsi_read_capacity( + &ccb->csio, + BSD_SCSI_RETRIES, + rtems_bsd_ccb_callback, + BSD_SCSI_TAG, + &rdcap, + SSD_FULL_SIZE, + BSD_SCSI_TIMEOUT + ); + + sc = rtems_bsd_ccb_action(ccb); + if (sc != RTEMS_SUCCESSFUL) { + return RTEMS_IO_ERROR; + } + + *block_size = scsi_4btoul(rdcap.length); + *block_count = scsi_4btoul(rdcap.addr) + 1; + + return RTEMS_SUCCESSFUL; +} + +static void +rtems_bsd_csio_callback(struct cam_periph *periph, union ccb *ccb) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + bool done = false; + struct cam_sim *sim = ccb->ccb_h.sim; + + BSD_ASSERT(periph == NULL && sim->state == BSD_SIM_BUSY); + + if (ccb->ccb_h.status == CAM_REQ_CMP) { + rtems_blkdev_sg_buffer *sg = ccb->csio.sg_current; + + if (sg != ccb->csio.sg_end) { + scsi_read_write( + &ccb->csio, + BSD_SCSI_RETRIES, + rtems_bsd_csio_callback, + BSD_SCSI_TAG, + ccb->csio.readop, + 0, + BSD_SCSI_MIN_COMMAND_SIZE, + sg->block, + sg->length / 512, /* FIXME */ + sg->buffer, + sg->length, + SSD_FULL_SIZE, + BSD_SCSI_TIMEOUT + ); + ccb->csio.sg_current = sg + 1; + (*sim->sim_action)(sim, ccb); + } else { + done = true; + } + } else if (ccb->ccb_h.status == CAM_SEL_TIMEOUT) { + sc = RTEMS_UNSATISFIED; + done = true; + } else { + sc = RTEMS_IO_ERROR; + done = true; + } + + if (done) { + rtems_blkdev_request_done(ccb->csio.req, sc); + rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_IDLE); + } +} + +static int rtems_bsd_sim_disk_read_write(struct cam_sim *sim, rtems_blkdev_request *req) +{ + mtx_lock(sim->mtx); + + rtems_bsd_sim_wait_for_state(sim, BSD_SIM_IDLE); + rtems_bsd_sim_set_state(sim, BSD_SIM_BUSY); + + switch (req->req) { + case RTEMS_BLKDEV_REQ_READ: + sim->ccb.csio.readop = TRUE; + break; + case RTEMS_BLKDEV_REQ_WRITE: + sim->ccb.csio.readop = FALSE; + break; + default: + mtx_unlock(sim->mtx); + return -1; + } + + sim->ccb.csio.sg_current = req->bufs; + sim->ccb.csio.sg_end = req->bufs + req->bufnum; + sim->ccb.csio.req = req; + + sim->ccb.ccb_h.status = CAM_REQ_CMP; + + rtems_bsd_csio_callback(NULL, &sim->ccb); + + mtx_unlock(sim->mtx); + + return 0; +} + +static int rtems_bsd_sim_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg) +{ + struct cam_sim *sim = rtems_disk_get_driver_data(dd); + + if (req == RTEMS_BLKIO_REQUEST) { + rtems_blkdev_request *r = arg; + + return rtems_bsd_sim_disk_read_write(sim, r); + } else if (req == RTEMS_BLKIO_DELETED) { + mtx_lock(sim->mtx); + + free(sim->disk, M_RTEMS_HEAP); + sim->disk = NULL; + rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_DELETED); + + mtx_unlock(sim->mtx); + + return 0; + } else { + return rtems_blkdev_ioctl(dd, req, arg); + } +} + +static void +rtems_bsd_sim_disk_initialized(struct cam_sim *sim, char *disk) +{ + mtx_lock(sim->mtx); + + sim->disk = disk; + rtems_bsd_sim_set_state_and_notify(sim, BSD_SIM_IDLE); + + mtx_unlock(sim->mtx); +} + +static rtems_status_code +rtems_bsd_sim_attach_worker(rtems_media_state state, const char *src, char **dest, void *arg) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + struct cam_sim *sim = arg; + char *disk = NULL; + + if (state == RTEMS_MEDIA_STATE_READY) { + unsigned retries = 0; + + struct scsi_inquiry_data inq_data; + uint32_t block_count = 0; + uint32_t block_size = 0; + + disk = rtems_media_create_path("/dev", src, cam_sim_unit(sim)); + if (disk == NULL) { + BSD_PRINTF("OOPS: create path failed\n"); + goto error; + } + + sc = rtems_bsd_scsi_inquiry(&sim->ccb, &inq_data); + if (sc == RTEMS_SUCCESSFUL) { + scsi_print_inquiry(&inq_data); + } else { + BSD_PRINTF("OOPS: inquiry failed\n"); + } + + for (retries = 0; retries <= 3; ++retries) { + sc = rtems_bsd_scsi_test_unit_ready(&sim->ccb); + if (sc == RTEMS_SUCCESSFUL) { + break; + } + } + if (sc != RTEMS_SUCCESSFUL) { + BSD_PRINTF("OOPS: test unit ready failed\n"); + } + + for (retries = 0; retries <= 3; ++retries) { + sc = rtems_bsd_scsi_read_capacity(&sim->ccb, &block_count, &block_size); + if (sc == RTEMS_SUCCESSFUL) { + break; + } + } + if (sc != RTEMS_SUCCESSFUL) { + BSD_PRINTF("OOPS: read capacity failed\n"); + goto error; + } + + BSD_PRINTF("read capacity: block count %u, block size %u\n", block_count, block_size); + + sc = rtems_blkdev_create(disk, block_size, block_count, rtems_bsd_sim_disk_ioctl, sim); + if (sc != RTEMS_SUCCESSFUL) { + goto error; + } + + /* FIXME */ +#if 0 + rtems_disk_device *dd = rtems_disk_obtain(dev); + dd->block_size *= 64; + rtems_disk_release(dd); +#endif + + rtems_bsd_sim_disk_initialized(sim, disk); + + *dest = strdup(disk, M_RTEMS_HEAP); + } + + return RTEMS_SUCCESSFUL; + +error: + + free(disk, M_RTEMS_HEAP); + + rtems_bsd_sim_disk_initialized(sim, NULL); + + return RTEMS_IO_ERROR; +} + +struct cam_sim * +cam_sim_alloc( + sim_action_func sim_action, + sim_poll_func sim_poll, + const char *sim_name, + void *softc, + u_int32_t unit, + struct mtx *mtx, + int max_dev_transactions, + int max_tagged_dev_transactions, + struct cam_devq *queue +) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + struct cam_sim *sim = NULL; + + if (mtx == NULL) { + return NULL; + } + + sim = malloc(sizeof(*sim), M_CAMSIM, M_NOWAIT | M_ZERO); + if (sim == NULL) { + return NULL; + } + + sim->sim_action = sim_action; + sim->sim_poll = sim_poll; + sim->sim_name = sim_name; + sim->softc = softc; + sim->mtx = mtx; + sim->unit_number = unit; + sim->ccb.ccb_h.sim = sim; + + cv_init(&sim->state_changed, "SIM state changed"); + + sc = rtems_media_server_disk_attach(sim_name, rtems_bsd_sim_attach_worker, sim); + BSD_ASSERT_SC(sc); + + return sim; +} + +void +cam_sim_free(struct cam_sim *sim, int free_devq) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + + /* + * The umass_detach() cancels all transfers via + * usbd_transfer_unsetup(). This prevents also the start of new + * transfers since the transfer descriptors will be removed. Started + * transfers that are not in the transferring state will be canceled + * and the callbacks will be not called. Thus it is necessary to do + * this here if we are in the BUSY state. + */ + rtems_bsd_sim_wait_for_state_and_cancel_ccb(sim, BSD_SIM_IDLE); + + if (sim->disk != NULL) { + sc = rtems_media_server_disk_detach(sim->disk); + BSD_ASSERT_SC(sc); + + rtems_bsd_sim_wait_for_state(sim, BSD_SIM_DELETED); + } + + cv_destroy(&sim->state_changed); + free(sim, M_CAMSIM); +} + +struct cam_devq * +cam_simq_alloc(u_int32_t max_sim_transactions) +{ + return BSD_CAM_DEVQ_DUMMY; +} + +void +cam_simq_free(struct cam_devq *devq) +{ + BSD_ASSERT(devq == BSD_CAM_DEVQ_DUMMY); +} + +void +xpt_done(union ccb *done_ccb) +{ + (*done_ccb->ccb_h.cbfcnp)(NULL, done_ccb); +} + +int32_t +xpt_bus_register(struct cam_sim *sim, device_t parent, u_int32_t bus) +{ + /* + * We ignore this bus stuff completely. This is easier than removing + * the calls from "umass.c". + */ + + return CAM_SUCCESS; +} + +int32_t +xpt_bus_deregister(path_id_t pathid) +{ + /* + * We ignore this bus stuff completely. This is easier than removing + * the calls from "umass.c". + */ + + return CAM_REQ_CMP; +} diff --git a/rtemsbsd/rtems/rtems-kernel-chunk.c b/rtemsbsd/rtems/rtems-kernel-chunk.c new file mode 100644 index 00000000..a327fe5e --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-chunk.c @@ -0,0 +1,150 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2013-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include + +#include +#include + +#define chunk_of_node(n) ((rtems_bsd_chunk_info *) n) + +static rtems_rbtree_compare_result +chunk_compare(const rtems_rbtree_node *a, const rtems_rbtree_node *b) +{ + const rtems_bsd_chunk_info *left = chunk_of_node(a); + const rtems_bsd_chunk_info *right = chunk_of_node(b); + + if (left->begin < right->begin) { + return -1; + } else if (left->begin < right->end) { + return 0; + } else { + return 1; + } +} + +void +rtems_bsd_chunk_init(rtems_bsd_chunk_control *self, uintptr_t info_size, + rtems_bsd_chunk_info_ctor info_ctor, rtems_bsd_chunk_info_dtor info_dtor) +{ + uintptr_t align = rtems_cache_get_data_line_size(); + + if (align < CPU_HEAP_ALIGNMENT) + align = CPU_HEAP_ALIGNMENT; + + info_size = roundup(info_size, align); + + self->info_size = info_size; + self->info_ctor = info_ctor; + self->info_dtor = info_dtor; + rtems_rbtree_initialize_empty(&self->chunks); +} + +void * +rtems_bsd_chunk_alloc(rtems_bsd_chunk_control *self, uintptr_t chunk_size) +{ + char *p = rtems_cache_aligned_malloc(chunk_size + self->info_size); + + if (p != NULL) { + rtems_bsd_chunk_info *info = (rtems_bsd_chunk_info *) p; + + p += self->info_size; + + info->begin = (uintptr_t) p; + info->end = (uintptr_t) p + chunk_size; + + (*self->info_ctor)(self, info); + + _RTEMS_Lock_allocator(); + rtems_rbtree_insert(&self->chunks, &info->node, chunk_compare, true); + _RTEMS_Unlock_allocator(); + } + + return p; +} + +void +rtems_bsd_chunk_free(rtems_bsd_chunk_control *self, + void *some_addr_in_chunk) +{ + rtems_bsd_chunk_info *info = rtems_bsd_chunk_get_info(self, + some_addr_in_chunk); + + _RTEMS_Lock_allocator(); + rtems_rbtree_extract(&self->chunks, &info->node); + _RTEMS_Unlock_allocator(); + + (*self->info_dtor)(self, info); + + free(info, M_RTEMS_HEAP); +} + +rtems_bsd_chunk_info * +rtems_bsd_chunk_get_info(rtems_bsd_chunk_control *self, + void *some_addr_in_chunk) +{ + rtems_bsd_chunk_info find_me = { + .begin = (uintptr_t) some_addr_in_chunk + }; + + return chunk_of_node(rtems_rbtree_find(&self->chunks, + &find_me.node, chunk_compare, true)); +} + +void * +rtems_bsd_chunk_get_begin(rtems_bsd_chunk_control *self, + void *some_addr_in_chunk) +{ + rtems_bsd_chunk_info *info = rtems_bsd_chunk_get_info(self, + some_addr_in_chunk); + + return (void *) info->begin; +} + +void +rtems_bsd_chunk_info_dtor_default(rtems_bsd_chunk_control *self, + rtems_bsd_chunk_info *info) +{ + (void) self; + (void) info; +} diff --git a/rtemsbsd/rtems/rtems-kernel-conf.c b/rtemsbsd/rtems/rtems-kernel-conf.c new file mode 100644 index 00000000..d52ad198 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-conf.c @@ -0,0 +1,65 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief This file is an rtems representation of needed methods from + * the FreeBSD file kern_conf.c + */ + +/* + * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +__FBSDID("$FreeBSD$"); + +#include +#include + +struct cdev * +make_dev(struct cdevsw *devsw, int unit, uid_t uid, gid_t gid, int mode, + const char *fmt, ...) +{ + struct cdev *dev; + dev = malloc( sizeof(struct cdev) ); + + /* Initialize the elements that rtems uses. */ + dev->si_flags = 0; + dev->si_drv0 = unit; + dev->si_drv1 = NULL; + dev->si_drv2 = NULL; + + return (dev); +} + +void +destroy_dev(struct cdev *dev) +{ + free (dev); +} diff --git a/rtemsbsd/rtems/rtems-kernel-configintrhook.c b/rtemsbsd/rtems/rtems-kernel-configintrhook.c new file mode 100644 index 00000000..baf737e1 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-configintrhook.c @@ -0,0 +1,58 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2011 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 COPYRIGHT HOLDERS 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 COPYRIGHT + * OWNER 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. + */ + +#include + +#include +#include +#include + +int +config_intrhook_establish(struct intr_config_hook *hook) +{ + (*hook->ich_func)(hook->ich_arg); + + return (0); +} + +void +config_intrhook_disestablish(struct intr_config_hook *hook) +{ + /* Do nothing */ +} diff --git a/rtemsbsd/rtems/rtems-kernel-delay.c b/rtemsbsd/rtems/rtems-kernel-delay.c new file mode 100644 index 00000000..1faa9265 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-delay.c @@ -0,0 +1,53 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009, 2015 embedded brains GmbH + * All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include + +void +DELAY(int usec) +{ + uint32_t ns = 1000 * (uint32_t)usec; + BSD_ASSERT((uint32_t)usec <= UINT32_MAX / 1000); + rtems_counter_delay_nanoseconds(ns); +} diff --git a/rtemsbsd/rtems/rtems-kernel-get-file.c b/rtemsbsd/rtems/rtems-kernel-get-file.c new file mode 100644 index 00000000..6d321c30 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-get-file.c @@ -0,0 +1,59 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2013 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include + +struct file * +rtems_bsd_get_file(int fd) +{ + struct file *fp; + + if ((uint32_t) fd < rtems_libio_number_iops) { + fp = rtems_bsd_fd_to_fp(fd); + if ((fp->f_io.flags & LIBIO_FLAGS_OPEN) != LIBIO_FLAGS_OPEN) { + fp = NULL; + } + } else { + fp = NULL; + } + + return fp; +} diff --git a/rtemsbsd/rtems/rtems-kernel-init.c b/rtemsbsd/rtems/rtems-kernel-init.c new file mode 100644 index 00000000..085b5a9e --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-init.c @@ -0,0 +1,120 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +SYSINIT_REFERENCE(configure1); +SYSINIT_REFERENCE(module); +SYSINIT_REFERENCE(kobj); +SYSINIT_REFERENCE(linker_kernel); +SYSINIT_MODULE_REFERENCE(rootbus); +SYSINIT_DRIVER_REFERENCE(nexus, root); + +RTEMS_BSD_DEFINE_SET(modmetadata_set, struct mod_metadata *); +RTEMS_BSD_DEFINE_SET(sysctl_set, struct sysctl_oid *); + +RTEMS_BSD_DEFINE_RWSET(sysinit_set, struct sysinit *); + +/* In FreeBSD this is a local function */ +void mi_startup(void); + +int hz; +int tick; +int maxusers; /* base tunable */ + +static SYSCTL_NODE(_kern, OID_AUTO, smp, CTLFLAG_RD|CTLFLAG_CAPRD, NULL, + "Kernel SMP"); + +static int maxid_maxcpus; + +SYSCTL_INT(_kern_smp, OID_AUTO, maxid, CTLFLAG_RD|CTLFLAG_CAPRD, + &maxid_maxcpus, 0, "Max CPU ID."); + +SYSCTL_INT(_kern_smp, OID_AUTO, maxcpus, CTLFLAG_RD|CTLFLAG_CAPRD, + &maxid_maxcpus, 0, "Max number of CPUs that the system was compiled for."); + +#undef _bsd_ticks + +RTEMS_STATIC_ASSERT(sizeof(int) == sizeof(int32_t), ticks); + +volatile uint32_t _Watchdog_Ticks_since_boot; + +extern volatile int32_t _bsd_ticks + __attribute__ ((__alias__("_Watchdog_Ticks_since_boot"))); + +rtems_status_code +rtems_bsd_initialize(void) +{ + static const char name[] = "TIME"; + rtems_status_code sc; + + hz = (int) rtems_clock_get_ticks_per_second(); + tick = 1000000 / hz; + maxusers = 1; + maxid_maxcpus = (int) rtems_get_processor_count(); + + mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO); + + sc = rtems_timer_initiate_server( + rtems_bsd_get_task_priority(name), + rtems_bsd_get_task_stack_size(name), + RTEMS_DEFAULT_ATTRIBUTES + ); + if (sc != RTEMS_SUCCESSFUL) { + return RTEMS_UNSATISFIED; + } + + mutex_init(); + mi_startup(); + + return RTEMS_SUCCESSFUL; +} diff --git a/rtemsbsd/rtems/rtems-kernel-irqs.c b/rtemsbsd/rtems/rtems-kernel-irqs.c new file mode 100644 index 00000000..e558d1f5 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-irqs.c @@ -0,0 +1,63 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include +#include + +static void +irqs_sysinit(void) +{ + static const char name[] = "IRQS"; + rtems_status_code status; + + status = rtems_interrupt_server_initialize( + rtems_bsd_get_task_priority(name), + rtems_bsd_get_task_stack_size(name), + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + NULL + ); + BSD_ASSERT(status == RTEMS_SUCCESSFUL); +} +SYSINIT(irqs, SI_SUB_SETTINGS, SI_ORDER_ANY, irqs_sysinit, NULL); diff --git a/rtemsbsd/rtems/rtems-kernel-jail.c b/rtemsbsd/rtems/rtems-kernel-jail.c new file mode 100644 index 00000000..0c7ab4f9 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-jail.c @@ -0,0 +1,317 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief This object is an minimal rtems implementation of kern_jail.c. + */ + +/* + * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/*#include +#include +#include +#include +#include +#include */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_HOSTUUID "00000000-0000-0000-0000-000000000000" + +/* Keep struct prison prison0 and some code in kern_jail_set() readable. */ +#ifdef INET +#ifdef INET6 +#define _PR_IP_SADDRSEL PR_IP4_SADDRSEL|PR_IP6_SADDRSEL +#else +#define _PR_IP_SADDRSEL PR_IP4_SADDRSEL +#endif +#else /* !INET */ +#ifdef INET6 +#define _PR_IP_SADDRSEL PR_IP6_SADDRSEL +#else +#define _PR_IP_SADDRSEL 0 +#endif +#endif + +/* prison0 describes what is "real" about the system. */ +struct prison prison0 = { + .pr_id = 0, + .pr_name = "0", + .pr_ref = 1, + .pr_uref = 1, + .pr_path = "/", + .pr_securelevel = -1, + .pr_childmax = JAIL_MAX, + .pr_hostuuid = DEFAULT_HOSTUUID, + .pr_children = LIST_HEAD_INITIALIZER(prison0.pr_children), +#ifdef VIMAGE + .pr_flags = PR_HOST|PR_VNET|_PR_IP_SADDRSEL, +#else + .pr_flags = PR_HOST|_PR_IP_SADDRSEL, +#endif + .pr_allow = PR_ALLOW_ALL, +}; +MTX_SYSINIT(prison0, &prison0.pr_mtx, "jail mutex", MTX_DEF); + +/* + * See if a prison has the specific flag set. + */ +int +prison_flag(struct ucred *cred, unsigned flag) +{ + /* This is an atomic read, so no locking is necessary. */ + return (prison0.pr_flags & flag); +} + +void +prison_free(struct prison *pr) +{ +} + +void +prison_hold(struct prison *pr) +{ +} + +/* + * Check if given address belongs to the jail referenced by cred (wrapper to + * prison_check_ip[46]). + * + * Returns 0 if jail doesn't restrict the address family or if address belongs + * to jail, EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if + * the jail doesn't allow the address family. IPv4 Address passed in in NBO. + */ +int +prison_if(struct ucred *cred, struct sockaddr *sa) +{ + return 0; +} + +/* + * Return 1 if we should do proper source address selection or are not jailed. + * We will return 0 if we should bypass source address selection in favour + * of the primary jail IPv6 address. Only in this case *ia will be updated and + * returned in NBO. + * Return EAFNOSUPPORT, in case this jail does not allow IPv6. + */ +int +prison_saddrsel_ip6(struct ucred *cred, struct in6_addr *ia6) +{ + return EAFNOSUPPORT; +} + +/* + * Check if given address belongs to the jail referenced by cred/prison. + * + * Returns 0 if jail doesn't restrict IPv4 or if address belongs to jail, + * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail + * doesn't allow IPv4. Address passed in in NBO. + */ +int +prison_check_ip4(struct ucred *cred, struct in_addr *ia) +{ + return 0; +} + +/* + * Assuming 0 means no restrictions. + * + * NOTE: RTEMS does not restrict via a jail so return 0. + */ +int +prison_check_ip6(struct ucred *cred, struct in6_addr *ia6) +{ + return 0; +} + +/* + * Make sure our (source) address is set to something meaningful to this + * jail. + * + * Returns 0 if jail doesn't restrict IPv4 or if address belongs to jail, + * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail + * doesn't allow IPv4. Address passed in in NBO and returned in NBO. + */ +int +prison_local_ip4(struct ucred *cred, struct in_addr *ia) +{ + return 0; +} + +/* + * Rewrite destination address in case we will connect to loopback address. + * + * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv4. + * Address passed in in NBO and returned in NBO. + */ +int +prison_remote_ip4(struct ucred *cred, struct in_addr *ia) +{ + return 0; +} + +/* + * Make sure our (source) address is set to something meaningful to this jail. + * + * v6only should be set based on (inp->inp_flags & IN6P_IPV6_V6ONLY != 0) + * when needed while binding. + * + * Returns 0 if jail doesn't restrict IPv6 or if address belongs to jail, + * EADDRNOTAVAIL if the address doesn't belong, or EAFNOSUPPORT if the jail + * doesn't allow IPv6. + * + * NOTE: RTEMS does not restrict via a jail so return 0. + */ +int +prison_local_ip6(struct ucred *cred, struct in6_addr *ia6, int v6only) +{ + return 0; +} + +/* + * Rewrite destination address in case we will connect to loopback address. + * + * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. + * + * NOTE: RTEMS does not restrict via a jail so return 0. + */ +int +prison_remote_ip6(struct ucred *cred, struct in6_addr *ia6) +{ + return 0; +} + +/* + * Return 1 if we should do proper source address selection or are not jailed. + * We will return 0 if we should bypass source address selection in favour + * of the primary jail IPv4 address. Only in this case *ia will be updated and + * returned in NBO. + * Return EAFNOSUPPORT, in case this jail does not allow IPv4. + */ +int +prison_saddrsel_ip4(struct ucred *cred, struct in_addr *ia) +{ + return 1; +} + +/* + * Pass back primary IPv4 address of this jail. + * + * If not restricted return success but do not alter the address. Caller has + * to make sure to initialize it correctly (e.g. INADDR_ANY). + * + * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv4. + * Address returned in NBO. + */ +int +prison_get_ip4(struct ucred *cred, struct in_addr *ia) +{ + return 0; +} + +/* + * Return 1 if the passed credential is in a jail and that jail does not + * have its own virtual network stack, otherwise 0. + */ +int +jailed_without_vnet(struct ucred *cred) +{ + return 0; +} + +/* + * Pass back primary IPv6 address for this jail. + * + * If not restricted return success but do not alter the address. Caller has + * to make sure to initialize it correctly (e.g. IN6ADDR_ANY_INIT). + * + * Returns 0 on success, EAFNOSUPPORT if the jail doesn't allow IPv6. + */ +int +prison_get_ip6(struct ucred *cred, struct in6_addr *ia6) +{ + return 0; +} +/* + * Return 0 if jails permit p1 to frob p2, otherwise ESRCH. + */ +int +prison_check(struct ucred *cred1, struct ucred *cred2) +{ + return 0; +} + +/* + * Check if a jail supports the given address family. + * + * Returns 0 if not jailed or the address family is supported, EAFNOSUPPORT + * if not. + */ +int +prison_check_af(struct ucred *cred, int af) +{ + return 0; +} + +/* + * Return 1 if the passed credential is in a jail, otherwise 0. + */ +int +jailed(struct ucred *cred) +{ + return 0; +} diff --git a/rtemsbsd/rtems/rtems-kernel-malloc.c b/rtemsbsd/rtems/rtems-kernel-malloc.c new file mode 100644 index 00000000..fe0d01db --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-malloc.c @@ -0,0 +1,127 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include + +MALLOC_DEFINE(M_DEVBUF, "devbuf", "device driver memory"); + +MALLOC_DEFINE(M_TEMP, "temp", "misc temporary data buffers"); + +MALLOC_DEFINE(M_IP6OPT, "ip6opt", "IPv6 options"); +MALLOC_DEFINE(M_IP6NDP, "ip6ndp", "IPv6 Neighbor Discovery"); + +MALLOC_DEFINE(M_IOV, "iov", "large iov's"); + +void +malloc_init(void *data) +{ + struct malloc_type *mtp = data; +} + +void +malloc_uninit(void *data) +{ + struct malloc_type *mtp = data; + + BSD_PRINTF( "desc = %s\n", mtp->ks_shortdesc); +} + +#undef malloc + +void * +_bsd_malloc(unsigned long size, struct malloc_type *mtp, int flags) +{ + void *p = malloc(size > 0 ? size : 1); + + if ((flags & M_ZERO) != 0 && p != NULL) { + memset(p, 0, size); + } + + return p; +} + +#undef realloc +void * +_bsd_realloc( void *addr, unsigned long size, + struct malloc_type *type, int flags) +{ + void *p = realloc(addr, size > 0 ? size : 1); + + if ((flags & M_ZERO) != 0 && p != NULL) { + memset(p, 0, size); + } + + return p; +} + +#undef reallocf +void * +_bsd_reallocf( void *addr, unsigned long size, + struct malloc_type *type, int flags) +{ + void *p = realloc(addr, size > 0 ? size : 1); + + if (p == NULL) { + free(addr,NULL); + } + + return p; +} + +#undef free +void +_bsd_free(void *addr, struct malloc_type *mtp) +{ + free(addr); +} + +#undef strdup + +char * +_bsd_strdup(const char *__restrict s, struct malloc_type *type) +{ + return strdup(s); +} diff --git a/rtemsbsd/rtems/rtems-kernel-mbuf.c b/rtemsbsd/rtems/rtems-kernel-mbuf.c new file mode 100644 index 00000000..a1429d86 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-mbuf.c @@ -0,0 +1,68 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include + +struct mbuf * +rtems_bsd_m_get(int how, short type) +{ + return (m_get(how, type)); +} + +struct mbuf * +rtems_bsd_m_gethdr(int how, short type) +{ + return (m_gethdr(how, type)); +} + +void +rtems_bsd_m_extaddref(struct mbuf *m, void *buf, size_t size, + u_int *ref_cnt, void (*freef)(void *, void *), void *arg1, + void *arg2) +{ + m_extaddref(m, buf, size, ref_cnt, freef, arg1, arg2); +} + +void +rtems_bsd_m_free(struct mbuf *m) +{ + m_free(m); +} diff --git a/rtemsbsd/rtems/rtems-kernel-mutex.c b/rtemsbsd/rtems/rtems-kernel-mutex.c new file mode 100644 index 00000000..5931a7e5 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-mutex.c @@ -0,0 +1,227 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static void assert_mtx(struct lock_object *lock, int what); +static void lock_mtx(struct lock_object *lock, int how); +#ifdef KDTRACE_HOOKS +static int owner_mtx(struct lock_object *lock, struct thread **owner); +#endif +static int unlock_mtx(struct lock_object *lock); + +/* + * Lock classes for sleep and spin mutexes. + */ +struct lock_class lock_class_mtx_sleep = { + .lc_name = "sleep mutex", + .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, +#ifdef DDB + .lc_ddb_show = db_show_mtx, +#endif + .lc_lock = lock_mtx, + .lc_unlock = unlock_mtx, +#ifdef KDTRACE_HOOKS + .lc_owner = owner_mtx, +#endif +}; + +struct lock_class lock_class_mtx_spin = { + .lc_name = "spin mutex", + .lc_flags = LC_SPINLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, +#ifdef DDB + .lc_ddb_show = db_show_mtx, +#endif + .lc_lock = lock_mtx, + .lc_unlock = unlock_mtx, +#ifdef KDTRACE_HOOKS + .lc_owner = owner_mtx, +#endif +}; + +struct mtx Giant; + +void +assert_mtx(struct lock_object *lock, int what) +{ + mtx_assert((struct mtx *)lock, what); +} + +void +lock_mtx(struct lock_object *lock, int how) +{ + mtx_lock((struct mtx *)lock); +} + +int +unlock_mtx(struct lock_object *lock) +{ + mtx_unlock((struct mtx *)lock); + + return (0); +} + + +#ifdef KDTRACE_HOOKS +int +owner_mtx(struct lock_object *lock, struct thread **owner) +{ + struct mtx *m = (struct mtx *)lock; + + *owner = mtx_owner(m); + return (mtx_unowned(m) == 0); +} +#endif + +void +mtx_init(struct mtx *m, const char *name, const char *type, int opts) +{ + struct lock_class *class; + int flags; + + /* Determine lock class and lock flags. */ + if (opts & MTX_SPIN) + class = &lock_class_mtx_spin; + else + class = &lock_class_mtx_sleep; + flags = 0; + if (opts & MTX_RECURSE) + flags |= LO_RECURSABLE; + + rtems_bsd_mutex_init(&m->lock_object, &m->mutex, class, name, type, + flags); +} + +void +_mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) +{ + rtems_bsd_mutex_lock(&m->lock_object, &m->mutex); +} + +int +_mtx_trylock(struct mtx *m, int opts, const char *file, int line) +{ + return (rtems_bsd_mutex_trylock(&m->lock_object, &m->mutex)); +} + +void +_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) +{ + rtems_bsd_mutex_unlock(&m->mutex); +} + +/* + * The backing function for the INVARIANTS-enabled mtx_assert() + */ +#ifdef INVARIANT_SUPPORT +void +_mtx_assert(struct mtx *m, int what, const char *file, int line) +{ + + if (panicstr != NULL || dumping) + return; + switch (what) { + case MA_OWNED: + case MA_OWNED | MA_RECURSED: + case MA_OWNED | MA_NOTRECURSED: + if (!mtx_owned(m)) + panic("mutex %s not owned at %s:%d", + m->lock_object.lo_name, file, line); + if (mtx_recursed(m)) { + if ((what & MA_NOTRECURSED) != 0) + panic("mutex %s recursed at %s:%d", + m->lock_object.lo_name, file, line); + } else if ((what & MA_RECURSED) != 0) { + panic("mutex %s unrecursed at %s:%d", + m->lock_object.lo_name, file, line); + } + break; + case MA_NOTOWNED: + if (mtx_owned(m)) + panic("mutex %s owned at %s:%d", + m->lock_object.lo_name, file, line); + break; + default: + panic("unknown mtx_assert at %s:%d", file, line); + } +} +#endif + +int mtx_owned(struct mtx *m) +{ + return (rtems_bsd_mutex_owned(&m->mutex)); +} + +int mtx_recursed(struct mtx *m) +{ + return (rtems_bsd_mutex_recursed(&m->mutex)); +} + +void +mtx_sysinit(void *arg) +{ + struct mtx_args *margs = arg; + + mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts); +} + +void +mtx_destroy(struct mtx *m) +{ + + rtems_bsd_mutex_destroy(&m->lock_object, &m->mutex); +} + +void +mutex_init(void) +{ + mtx_init(&Giant, "Giant", NULL, MTX_DEF | MTX_RECURSE); + mtx_lock(&Giant); +} diff --git a/rtemsbsd/rtems/rtems-kernel-muteximpl.c b/rtemsbsd/rtems/rtems-kernel-muteximpl.c new file mode 100644 index 00000000..ff54365e --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-muteximpl.c @@ -0,0 +1,95 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2014, 2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include + +#define BSD_MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority + +void +rtems_bsd_mutex_lock_more(struct lock_object *lock, rtems_bsd_mutex *m, + Thread_Control *owner, Thread_Control *executing, + ISR_lock_Context *lock_context) +{ + if (owner == executing) { + BSD_ASSERT(lock->lo_flags & LO_RECURSABLE); + ++m->nest_level; + + _Thread_queue_Release(&m->queue, lock_context); + } else { + /* Priority inheritance */ + _Thread_Raise_priority(owner, executing->current_priority); + + ++executing->resource_count; + _Thread_queue_Enqueue_critical(&m->queue, + BSD_MUTEX_TQ_OPERATIONS, executing, + STATES_WAITING_FOR_MUTEX, WATCHDOG_NO_TIMEOUT, 0, + lock_context); + } +} + +void +rtems_bsd_mutex_unlock_more(rtems_bsd_mutex *m, Thread_Control *owner, + int keep_priority, Thread_queue_Heads *heads, + ISR_lock_Context *lock_context) +{ + if (heads != NULL) { + const Thread_queue_Operations *operations; + Thread_Control *new_owner; + + operations = BSD_MUTEX_TQ_OPERATIONS; + new_owner = ( *operations->first )( heads ); + m->owner = new_owner; + _Thread_queue_Extract_critical(&m->queue, operations, + new_owner, NULL, 0, lock_context); + } else { + _Thread_queue_Release(&m->queue, lock_context); + } + + if (!keep_priority) { + Per_CPU_Control *cpu_self; + + cpu_self = _Thread_Dispatch_disable(); + _Thread_Restore_priority(owner); + _Thread_Dispatch_enable(cpu_self); + } +} diff --git a/rtemsbsd/rtems/rtems-kernel-nexus.c b/rtemsbsd/rtems/rtems-kernel-nexus.c new file mode 100644 index 00000000..d8afebc2 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-nexus.c @@ -0,0 +1,365 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* #define DISABLE_INTERRUPT_EXTENSION */ + +RTEMS_BSD_DECLARE_SET(nexus, rtems_bsd_device); + +RTEMS_BSD_DEFINE_SET(nexus, rtems_bsd_device); + +RTEMS_STATIC_ASSERT(SYS_RES_MEMORY == RTEMS_BSD_RES_MEMORY, RTEMS_BSD_RES_MEMORY); + +RTEMS_STATIC_ASSERT(SYS_RES_IRQ == RTEMS_BSD_RES_IRQ, RTEMS_BSD_RES_IRQ); + +static struct rman mem_rman; + +static struct rman irq_rman; + +#ifdef __i386__ +static struct rman port_rman; +#endif + +#ifndef DISABLE_INTERRUPT_EXTENSION +SYSINIT_REFERENCE(irqs); +#endif + +static int +nexus_probe(device_t dev) +{ + int err; + const rtems_bsd_device *nd; + + device_set_desc(dev, "RTEMS Nexus device"); + + mem_rman.rm_start = 0; + mem_rman.rm_end = ~0UL; + mem_rman.rm_type = RMAN_ARRAY; + mem_rman.rm_descr = "I/O memory addresses"; + err = rman_init(&mem_rman) != 0; + BSD_ASSERT(err == 0); + err = rman_manage_region(&mem_rman, mem_rman.rm_start, mem_rman.rm_end); + BSD_ASSERT(err == 0); + + irq_rman.rm_start = 0; + irq_rman.rm_end = ~0UL; + irq_rman.rm_type = RMAN_ARRAY; + irq_rman.rm_descr = "Interrupt vectors"; + err = rman_init(&irq_rman) != 0; + BSD_ASSERT(err == 0); + err = rman_manage_region(&irq_rman, irq_rman.rm_start, irq_rman.rm_end); + BSD_ASSERT(err == 0); + +#ifdef __i386__ + port_rman.rm_start = 0; + port_rman.rm_end = 0xffff; + port_rman.rm_type = RMAN_ARRAY; + port_rman.rm_descr = "I/O ports"; + err = rman_init(&port_rman) != 0; + BSD_ASSERT(err == 0); + err = rman_manage_region(&port_rman, port_rman.rm_start, + port_rman.rm_end); + BSD_ASSERT(err == 0); +#endif + + SET_FOREACH(nd, nexus) { + device_add_child(dev, nd->name, nd->unit); + } + + return (0); +} + +static bool +nexus_get_start(const rtems_bsd_device *nd, int type, u_long *start) +{ + u_long sr = *start; + size_t i; + + for (i = 0; i < nd->resource_count; ++i) { + const rtems_bsd_device_resource *dr = &nd->resources[i]; + + if (dr->type == type && dr->start_request == sr) { + *start = dr->start_actual; + + return (true); + } + } + + return (false); +} + +static struct resource * +nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, + u_long start, u_long end, u_long count, u_int flags) +{ + struct resource *res = NULL; + struct rman *rm; + const rtems_bsd_device *nd; + + switch (type) { + case SYS_RES_MEMORY: + rm = &mem_rman; + break; + case SYS_RES_IRQ: + rm = &irq_rman; + break; +#ifdef __i386__ + case SYS_RES_IOPORT: + rm = &port_rman; + break; +#endif + default: + return (res); + } + + SET_FOREACH(nd, nexus) { + if (strcmp(device_get_name(child), nd->name) == 0 + && device_get_unit(child) == nd->unit) { + if (nexus_get_start(nd, type, &start)) { + res = rman_reserve_resource(rm, start, end, + count, flags, child); + if (res != NULL) { + rman_set_rid(res, *rid); + rman_set_bushandle(res, + rman_get_start(res)); + } + }; + + return (res); + } + } + +#ifdef __i386__ + /* + * FIXME: This is a quick and dirty hack. Simply reserve resources of + * this kind. See also pci_reserve_map(). + */ + if (start + count - end <= 1UL) { + res = rman_reserve_resource(rm, start, end, count, flags, + child); + if (res != NULL) { + rman_set_rid(res, *rid); + rman_set_bushandle(res, rman_get_start(res)); + } + } +#endif + + return (res); +} + +static int +nexus_release_resource(device_t bus, device_t child, int type, int rid, + struct resource *res) +{ + return (rman_release_resource(res)); +} + +#ifdef __i386__ +static int +nexus_activate_resource(device_t bus, device_t child, int type, int rid, + struct resource *res) +{ + switch (type) { + case SYS_RES_IOPORT: + rman_set_bustag(res, X86_BUS_SPACE_IO); + break; + case SYS_RES_MEMORY: + rman_set_bustag(res, X86_BUS_SPACE_MEM); + break; + } + return (rman_activate_resource(res)); +} + +static int +nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, + struct resource *res) +{ + + return (rman_deactivate_resource(res)); +} +#endif + +struct nexus_intr { + driver_filter_t *filt; + driver_intr_t *intr; + void *arg; +}; + +static void +nexus_intr_with_filter(void *arg) +{ + struct nexus_intr *ni; + int status; + + ni = arg; + + status = (*ni->filt)(ni->arg); + if ((status & FILTER_SCHEDULE_THREAD) != 0) { + (*ni->intr)(ni->arg); + } +} + +static int +nexus_setup_intr(device_t dev, device_t child, struct resource *res, int flags, + driver_filter_t *filt, driver_intr_t *intr, void *arg, void **cookiep) +{ + int err; +#ifndef DISABLE_INTERRUPT_EXTENSION + struct nexus_intr *ni; + + ni = malloc(sizeof(*ni), M_TEMP, M_WAITOK); + if (ni != NULL) { + rtems_status_code sc; + rtems_interrupt_handler rh; + void *ra; + + ni->filt = filt; + ni->intr = intr; + ni->arg = arg; + + *cookiep = ni; + + if (filt == NULL) { + rh = intr; + ra = arg; + } else { + rh = nexus_intr_with_filter; + ra = ni; + } + + sc = rtems_interrupt_server_handler_install(RTEMS_ID_NONE, + rman_get_start(res), device_get_nameunit(child), + RTEMS_INTERRUPT_UNIQUE, rh, ra); + if (sc == RTEMS_SUCCESSFUL) { + err = 0; + } else { + free(ni, M_TEMP); + + err = EINVAL; + } + } else { + err = ENOMEM; + } +#else + err = EINVAL; +#endif + + return (err); +} + +static int +nexus_teardown_intr(device_t dev, device_t child, struct resource *res, + void *cookie) +{ + int err; +#ifndef DISABLE_INTERRUPT_EXTENSION + struct nexus_intr *ni; + rtems_status_code sc; + rtems_interrupt_handler rh; + void *ra; + + ni = cookie; + + if (ni->filt == NULL) { + rh = ni->intr; + ra = ni->arg; + } else { + rh = nexus_intr_with_filter; + ra = ni->arg; + } + + sc = rtems_interrupt_server_handler_install(RTEMS_ID_NONE, + rman_get_start(res), device_get_nameunit(child), + RTEMS_INTERRUPT_UNIQUE, rh, ra); + err = sc == RTEMS_SUCCESSFUL ? 0 : EINVAL; +#else + err = EINVAL; +#endif + + return (err); +} + +static device_method_t nexus_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, nexus_probe), + DEVMETHOD(device_attach, bus_generic_attach), + DEVMETHOD(device_detach, bus_generic_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD(device_suspend, bus_generic_suspend), + DEVMETHOD(device_resume, bus_generic_resume), + + /* Bus interface */ + DEVMETHOD(bus_print_child, bus_generic_print_child), + DEVMETHOD(bus_add_child, bus_generic_add_child), + DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), + DEVMETHOD(bus_release_resource, nexus_release_resource), +#ifdef __i386__ + DEVMETHOD(bus_activate_resource, nexus_activate_resource), + DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), +#endif + DEVMETHOD(bus_setup_intr, nexus_setup_intr), + DEVMETHOD(bus_teardown_intr, nexus_teardown_intr), + + { 0, 0 } +}; + +static driver_t nexus_driver = { + .name = "nexus", + .methods = nexus_methods, + .size = 0 +}; + +static devclass_t nexus_devclass; + +DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0); diff --git a/rtemsbsd/rtems/rtems-kernel-page.c b/rtemsbsd/rtems/rtems-kernel-page.c new file mode 100644 index 00000000..b3f4325d --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-page.c @@ -0,0 +1,157 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +void **rtems_bsd_page_object_table; + +uintptr_t rtems_bsd_page_area_begin; + +static rtems_rbheap_control page_heap; + +struct mtx page_heap_mtx; + +void * +rtems_bsd_page_alloc(uintptr_t size_in_bytes, int wait) +{ + void *addr; + + mtx_lock(&page_heap_mtx); + + addr = rtems_rbheap_allocate(&page_heap, size_in_bytes); + if (addr == NULL && wait) { + int i; + + for (i = 0; i < 8; i++) { + mtx_unlock(&page_heap_mtx); + uma_reclaim(); + mtx_lock(&page_heap_mtx); + + addr = rtems_rbheap_allocate(&page_heap, size_in_bytes); + if (addr != NULL) + break; + + msleep(&page_heap, &page_heap_mtx, 0, + "page alloc", (hz / 4) * (i + 1)); + } + + if (i == 8) { + panic("rtems_bsd_page_alloc: page starvation"); + } + } + + mtx_unlock(&page_heap_mtx); + +#ifdef INVARIANTS + if (addr != NULL) { + memset(addr, 0, size_in_bytes); + } +#endif + + return (addr); +} + +void +rtems_bsd_page_free(void *addr) +{ + mtx_lock(&page_heap_mtx); + rtems_rbheap_free(&page_heap, addr); + wakeup(&page_heap); + mtx_unlock(&page_heap_mtx); +} + +static void +rtems_bsd_page_init(void *arg) +{ + rtems_status_code sc; + void *area; + void **obj_table; + rtems_rbheap_chunk *chunks; + size_t i; + size_t n; + uintptr_t heap_size; + + mtx_init(&page_heap_mtx, "page heap", NULL, MTX_DEF); + + heap_size = rtems_bsd_get_allocator_domain_size( + RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE); + + area = rtems_heap_allocate_aligned_with_boundary(heap_size, PAGE_SIZE, + 0); + BSD_ASSERT(area != NULL); + + sc = rtems_rbheap_initialize(&page_heap, area, heap_size, PAGE_SIZE, + rtems_rbheap_extend_descriptors_with_malloc, NULL); + BSD_ASSERT(sc == RTEMS_SUCCESSFUL); + + rtems_rbheap_set_extend_descriptors(&page_heap, + rtems_rbheap_extend_descriptors_never); + + n = heap_size / PAGE_SIZE; + + chunks = malloc(n * sizeof(*chunks), M_RTEMS_HEAP, M_NOWAIT); + BSD_ASSERT(chunks != NULL); + + for (i = 0; i < n; ++i) { + rtems_rbheap_add_to_spare_descriptor_chain(&page_heap, + &chunks[i]); + } + + obj_table = calloc(n, sizeof(*obj_table)); + + rtems_bsd_page_area_begin = (uintptr_t)area; + rtems_bsd_page_object_table = obj_table; +} + +SYSINIT(rtems_bsd_page, SI_SUB_VM, SI_ORDER_FIRST, rtems_bsd_page_init, NULL); diff --git a/rtemsbsd/rtems/rtems-kernel-panic.c b/rtemsbsd/rtems/rtems-kernel-panic.c new file mode 100644 index 00000000..1fc65f08 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-panic.c @@ -0,0 +1,64 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include + +void +panic(const char *fmt, ...) +{ + va_list ap; + + printf("\n*** BSD PANIC *** "); + + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + + printf("\n"); + + rtems_task_suspend(RTEMS_SELF); + + /* FIXME */ + rtems_fatal_error_occurred(0xdeadbeef); +} diff --git a/rtemsbsd/rtems/rtems-kernel-pci_bus.c b/rtemsbsd/rtems/rtems-kernel-pci_bus.c new file mode 100644 index 00000000..f687e0f5 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-pci_bus.c @@ -0,0 +1,78 @@ +#include + +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief This file contains methods that are rtems specific implementation + * of methods in pci_bus.c. + */ + +/* + * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#define pci_find_device rtems_pci_find_device +#if HAVE_RTEMS_PCI_H +#include +#endif +#include + +int +pcibios_pcib_route_interrupt(device_t pcib, device_t dev, int pin) +{ +#if HAVE_RTEMS_PCI_H + int bus; + int slot; + int func; + uint8_t irq; + + bus = pci_get_bus(dev); + slot = pci_get_slot(dev); + func = pci_get_function(dev); + + pci_read_config_byte(bus, slot, func, PCI_INTERRUPT_LINE, &irq); + return irq; +#else + return 0; +#endif +} diff --git a/rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c b/rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c new file mode 100644 index 00000000..b9bdd31b --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-pci_cfgreg.c @@ -0,0 +1,122 @@ +#include + +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief This is the rtems version for the FreeBSD cpu specific + * file pci_cfgreg.c. Please note that the Ether Express is not + * supported in this version. + */ + +/* + * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define pci_find_device rtems_pci_find_device +#if HAVE_RTEMS_PCI_H +#include +#endif + +/* + * Initialise access to PCI configuration space + */ +int +pci_cfgregopen(void) +{ + return(1); +} + +/* + * Read configuration space register + */ +u_int32_t +pci_cfgregread(int bus, int slot, int func, int reg, int bytes) +{ +#if HAVE_RTEMS_PCI_H + u_int32_t value; + uint8_t v8; + uint16_t v16; + uint32_t v32; + int data; + + switch (bytes) { + case 1: + data = pci_read_config_byte( bus, slot, func, reg, &v8 ); + value = v8; + break; + case 2: + data = pci_read_config_word( bus, slot, func, reg, &v16 ); + value = v16; + break; + case 4: + data = pci_read_config_dword( bus, slot, func, reg, &v32 ); + value = v32; + break; + } + + return value; +#else + return 0; +#endif +} + +/* + * Write configuration space register + */ +void +pci_cfgregwrite(int bus, int slot, int func, int reg, u_int32_t data, int bytes) +{ +#if HAVE_RTEMS_PCI_H + uint8_t v8 = data & 0xff; + uint16_t v16 = data & 0xffff; + uint32_t v32 = data; + + switch (bytes) { + case 1: + pci_write_config_byte( bus, slot, func, reg, v8 ); + break; + case 2: + pci_write_config_word( bus, slot, func, reg, v16 ); + break; + case 4: + pci_write_config_dword( bus, slot, func, reg, v32 ); + break; + } +#endif +} diff --git a/rtemsbsd/rtems/rtems-kernel-program.c b/rtemsbsd/rtems/rtems-kernel-program.c new file mode 100644 index 00000000..18b9a627 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-program.c @@ -0,0 +1,216 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2013 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#undef printf +#include + +struct rtems_bsd_program_control { + void *context; + int exit_code; + const char *name; + jmp_buf return_context; +}; + +int +rtems_bsd_program_call(const char *name, int (*prog)(void *), void *context) +{ + struct thread *td = rtems_bsd_get_curthread_or_null(); + int exit_code = EXIT_FAILURE; + + if (td != NULL) { + struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; + + if (prog_ctrl == NULL) { + prog_ctrl = malloc(sizeof(*prog_ctrl), M_TEMP, 0); + + if (prog_ctrl != NULL) { + td->td_prog_ctrl = prog_ctrl; + + prog_ctrl->context = context; + prog_ctrl->name = name; + prog_ctrl->exit_code = exit_code; + + if (setjmp(prog_ctrl->return_context) == 0) { + exit_code = (*prog)(context); + } else { + exit_code = prog_ctrl->exit_code; + } + + td->td_prog_ctrl = NULL; + free(prog_ctrl, M_TEMP); + } else { + errno = ENOMEM; + } + } else { + panic("unexpected BSD program state"); + } + } else { + errno = ENOMEM; + } + + return exit_code; +} + +void +rtems_bsd_program_exit(int exit_code) +{ + struct thread *td = rtems_bsd_get_curthread_or_null(); + + if (td != NULL) { + struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; + + if (prog_ctrl != NULL) { + prog_ctrl->exit_code = exit_code; + longjmp(prog_ctrl->return_context, 1); + } + } + + panic("unexpected BSD program exit"); +} + +void +rtems_bsd_program_error(const char *fmt, ...) +{ + va_list list; + va_start(list, fmt); + vfprintf(stderr, fmt, list); + fprintf(stderr, "\n"); + va_end(list); + rtems_bsd_program_exit(1); +} + +const char * +rtems_bsd_program_get_name(void) +{ + struct thread *td = rtems_bsd_get_curthread_or_null(); + const char *name = "?"; + + if (td != NULL) { + struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; + + if (prog_ctrl != NULL) { + name = prog_ctrl->name; + } + } + + return name; +} + +void * +rtems_bsd_program_get_context(void) +{ + struct thread *td = rtems_bsd_get_curthread_or_null(); + void *context = NULL; + + if (td != NULL) { + struct rtems_bsd_program_control *prog_ctrl = td->td_prog_ctrl; + + if (prog_ctrl != NULL) { + context = prog_ctrl->context; + } + } + + return context; +} + +struct main_context { + int argc; + char **argv; + int (*main)(int, char **); +}; + +static int +call_main(void *ctx) +{ + const struct main_context *mc = ctx; + + return (*mc->main)(mc->argc, mc->argv); +} + +int +rtems_bsd_program_call_main(const char *name, int (*main)(int, char **), + int argc, char **argv) +{ + struct main_context mc = { + .argc = argc, + .argv = argv, + .main = main + }; + int exit_code; + + if (argv[argc] == NULL) { + exit_code = rtems_bsd_program_call(name, call_main, &mc); + } else { + errno = EFAULT; + exit_code = EXIT_FAILURE; + } + + return exit_code; +} + +static struct mtx program_mtx; + +MTX_SYSINIT(rtems_bsd_program, &program_mtx, "BSD program", MTX_DEF); + +void +rtems_bsd_program_lock(void) +{ + mtx_lock(&program_mtx); +} + +void +rtems_bsd_program_unlock(void) +{ + mtx_unlock(&program_mtx); +} diff --git a/rtemsbsd/rtems/rtems-kernel-rwlock.c b/rtemsbsd/rtems/rtems-kernel-rwlock.c new file mode 100644 index 00000000..d0b911d5 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-rwlock.c @@ -0,0 +1,293 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2011 OPTI Medical. All rights reserved. + * + * OPTI Medical + * 235 Hembree Park Drive + * Roswell, GA 30076 + * USA + * + * + * Copyright (c) 2013-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include +#include + +#ifndef INVARIANTS +#define _rw_assert(rw, what, file, line) +#endif + +static void assert_rw(struct lock_object *lock, int what); +static void lock_rw(struct lock_object *lock, int how); +#ifdef KDTRACE_HOOKS +static int owner_rw(struct lock_object *lock, struct thread **owner); +#endif +static int unlock_rw(struct lock_object *lock); + +struct lock_class lock_class_rw = { + .lc_name = "rw", + .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_rw, +#ifdef DDB + .lc_ddb_show = db_show_rwlock, +#endif + .lc_lock = lock_rw, + .lc_unlock = unlock_rw, +#ifdef KDTRACE_HOOKS + .lc_owner = owner_rw, +#endif +}; + +#define rw_wowner(rw) ((rw)->mutex.owner) + +#define rw_recursed(rw) ((rw)->mutex.nest_level != 0) + +void +assert_rw(struct lock_object *lock, int what) +{ + rw_assert((struct rwlock *)lock, what); +} + +void +lock_rw(struct lock_object *lock, int how) +{ + rw_wlock((struct rwlock *)lock); +} + +int +unlock_rw(struct lock_object *lock) +{ + rw_unlock((struct rwlock *)lock); + + return (0); +} + +#ifdef KDTRACE_HOOKS +int +owner_rw(struct lock_object *lock, struct thread **owner) +{ + struct rwlock *rw = (struct rwlock *)lock; + uintptr_t x = rw->rw_lock; + + *owner = rw_wowner(rw); + return ((x & RW_LOCK_READ) != 0 ? (RW_READERS(x) != 0) : + (*owner != NULL)); +} +#endif + +void +rw_init_flags(struct rwlock *rw, const char *name, int opts) +{ + int flags; + + flags = LO_UPGRADABLE; + if (opts & RW_RECURSE) + flags |= LO_RECURSABLE; + + rtems_bsd_mutex_init(&rw->lock_object, &rw->mutex, &lock_class_rw, + name, NULL, flags); +} + +void +rw_destroy(struct rwlock *rw) +{ + + rtems_bsd_mutex_destroy(&rw->lock_object, &rw->mutex); +} + +void +rw_sysinit(void *arg) +{ + struct rw_args *args = arg; + + rw_init(args->ra_rw, args->ra_desc); +} + +void +rw_sysinit_flags(void *arg) +{ + struct rw_args_flags *args = arg; + + rw_init_flags(args->ra_rw, args->ra_desc, args->ra_flags); +} + +int +rw_wowned(struct rwlock *rw) +{ + return (rtems_bsd_mutex_owned(&rw->mutex)); +} + +void +_rw_wlock(struct rwlock *rw, const char *file, int line) +{ + rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex); +} + +int +_rw_try_wlock(struct rwlock *rw, const char *file, int line) +{ + return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex)); +} + +void +_rw_wunlock(struct rwlock *rw, const char *file, int line) +{ + rtems_bsd_mutex_unlock(&rw->mutex); +} + +void +_rw_rlock(struct rwlock *rw, const char *file, int line) +{ + rtems_bsd_mutex_lock(&rw->lock_object, &rw->mutex); +} + +int +_rw_try_rlock(struct rwlock *rw, const char *file, int line) +{ + return (rtems_bsd_mutex_trylock(&rw->lock_object, &rw->mutex)); +} + +void +_rw_runlock(struct rwlock *rw, const char *file, int line) +{ + rtems_bsd_mutex_unlock(&rw->mutex); +} + +int +_rw_try_upgrade(struct rwlock *rw, const char *file, int line) +{ + return (1); +} + +void +_rw_downgrade(struct rwlock *rw, const char *file, int line) +{ + /* Nothing to do */ +} + +#ifdef INVARIANT_SUPPORT +#ifndef INVARIANTS +#undef _rw_assert +#endif + +/* + * In the non-WITNESS case, rw_assert() can only detect that at least + * *some* thread owns an rlock, but it cannot guarantee that *this* + * thread owns an rlock. + */ +void +_rw_assert(struct rwlock *rw, int what, const char *file, int line) +{ + + if (panicstr != NULL) + return; + switch (what) { + case RA_LOCKED: + case RA_LOCKED | RA_RECURSED: + case RA_LOCKED | RA_NOTRECURSED: + case RA_RLOCKED: +#ifndef __rtems__ +#ifdef WITNESS + witness_assert(&rw->lock_object, what, file, line); +#else + /* + * If some other thread has a write lock or we have one + * and are asserting a read lock, fail. Also, if no one + * has a lock at all, fail. + */ + if (rw->rw_lock == RW_UNLOCKED || + (!(rw->rw_lock & RW_LOCK_READ) && (what == RA_RLOCKED || + rw_wowner(rw) != curthread))) + panic("Lock %s not %slocked @ %s:%d\n", + rw->lock_object.lo_name, (what == RA_RLOCKED) ? + "read " : "", file, line); + + if (!(rw->rw_lock & RW_LOCK_READ)) { + if (rw_recursed(rw)) { + if (what & RA_NOTRECURSED) + panic("Lock %s recursed @ %s:%d\n", + rw->lock_object.lo_name, file, + line); + } else if (what & RA_RECURSED) + panic("Lock %s not recursed @ %s:%d\n", + rw->lock_object.lo_name, file, line); + } +#endif + break; +#else /* __rtems__ */ + /* FALLTHROUGH */ +#endif /* __rtems__ */ + case RA_WLOCKED: + case RA_WLOCKED | RA_RECURSED: + case RA_WLOCKED | RA_NOTRECURSED: + if (rw_wowner(rw) != _Thread_Get_executing()) + panic("Lock %s not exclusively locked @ %s:%d\n", + rw->lock_object.lo_name, file, line); + if (rw_recursed(rw)) { + if (what & RA_NOTRECURSED) + panic("Lock %s recursed @ %s:%d\n", + rw->lock_object.lo_name, file, line); + } else if (what & RA_RECURSED) + panic("Lock %s not recursed @ %s:%d\n", + rw->lock_object.lo_name, file, line); + break; + case RA_UNLOCKED: +#ifdef WITNESS + witness_assert(&rw->lock_object, what, file, line); +#else + /* + * If we hold a write lock fail. We can't reliably check + * to see if we hold a read lock or not. + */ + if (rw_wowner(rw) == _Thread_Get_executing()) + panic("Lock %s exclusively locked @ %s:%d\n", + rw->lock_object.lo_name, file, line); +#endif + break; + default: + panic("Unknown rw lock assertion: %d @ %s:%d", what, file, + line); + } +} +#endif /* INVARIANT_SUPPORT */ diff --git a/rtemsbsd/rtems/rtems-kernel-signal.c b/rtemsbsd/rtems/rtems-kernel-signal.c new file mode 100644 index 00000000..44fa8167 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-signal.c @@ -0,0 +1,50 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include + +void pgsigio(struct sigio **sigiop, int sig, int checkctty) +{ + + BSD_ASSERT(0); +} diff --git a/rtemsbsd/rtems/rtems-kernel-sx.c b/rtemsbsd/rtems/rtems-kernel-sx.c new file mode 100644 index 00000000..dcf3a009 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-sx.c @@ -0,0 +1,276 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef INVARIANTS +#define _sx_assert(sx, what, file, line) +#endif + +static void assert_sx(struct lock_object *lock, int what); +static void lock_sx(struct lock_object *lock, int how); +#ifdef KDTRACE_HOOKS +static int owner_sx(struct lock_object *lock, struct thread **owner); +#endif +static int unlock_sx(struct lock_object *lock); + +struct lock_class lock_class_sx = { + .lc_name = "sx", + .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_sx, +#ifdef DDB + .lc_ddb_show = db_show_sx, +#endif + .lc_lock = lock_sx, + .lc_unlock = unlock_sx, +#ifdef KDTRACE_HOOKS + .lc_owner = owner_sx, +#endif +}; + +#define sx_xholder(sx) ((sx)->mutex.owner) + +#define sx_recursed(sx) ((sx)->mutex.nest_level != 0) + +void +assert_sx(struct lock_object *lock, int what) +{ + sx_assert((struct sx *)lock, what); +} + +void +lock_sx(struct lock_object *lock, int how) +{ + sx_xlock((struct sx *)lock); +} + +int +unlock_sx(struct lock_object *lock) +{ + sx_xunlock((struct sx *)lock); + + return (0); +} + +#ifdef KDTRACE_HOOKS +int +owner_sx(struct lock_object *lock, struct thread **owner) +{ + struct sx *sx = (struct sx *)lock; + uintptr_t x = sx->sx_lock; + + *owner = (struct thread *)SX_OWNER(x); + return ((x & SX_LOCK_SHARED) != 0 ? (SX_SHARERS(x) != 0) : + (*owner != NULL)); +} +#endif + +void +sx_sysinit(void *arg) +{ + struct sx_args *sargs = arg; + + sx_init(sargs->sa_sx, sargs->sa_desc); +} + +void +sx_init_flags(struct sx *sx, const char *description, int opts) +{ + int flags; + + flags = LO_SLEEPABLE | LO_UPGRADABLE; + if (opts & SX_RECURSE) + flags |= LO_RECURSABLE; + + rtems_bsd_mutex_init(&sx->lock_object, &sx->mutex, &lock_class_sx, + description, NULL, flags); +} + +void +sx_destroy(struct sx *sx) +{ + + rtems_bsd_mutex_destroy(&sx->lock_object, &sx->mutex); +} + +int +_sx_xlock(struct sx *sx, int opts, const char *file, int line) +{ + rtems_bsd_mutex_lock(&sx->lock_object, &sx->mutex); + + return (0); +} + +int +_sx_try_xlock(struct sx *sx, const char *file, int line) +{ + return (rtems_bsd_mutex_trylock(&sx->lock_object, &sx->mutex)); +} + +void +_sx_xunlock(struct sx *sx, const char *file, int line) +{ + rtems_bsd_mutex_unlock(&sx->mutex); +} + +int +_sx_try_upgrade(struct sx *sx, const char *file, int line) +{ + return (1); +} + +void +_sx_downgrade(struct sx *sx, const char *file, int line) +{ + /* Do nothing */ +} + +#ifdef INVARIANT_SUPPORT +#ifndef INVARIANTS +#undef _sx_assert +#endif + +/* + * In the non-WITNESS case, sx_assert() can only detect that at least + * *some* thread owns an slock, but it cannot guarantee that *this* + * thread owns an slock. + */ +void +_sx_assert(struct sx *sx, int what, const char *file, int line) +{ +#ifndef __rtems__ +#ifndef WITNESS + int slocked = 0; +#endif +#endif /* __rtems__ */ + + if (panicstr != NULL) + return; + switch (what) { + case SA_SLOCKED: + case SA_SLOCKED | SA_NOTRECURSED: + case SA_SLOCKED | SA_RECURSED: +#ifndef __rtems__ +#ifndef WITNESS + slocked = 1; + /* FALLTHROUGH */ +#endif +#endif /* __rtems__ */ + case SA_LOCKED: + case SA_LOCKED | SA_NOTRECURSED: + case SA_LOCKED | SA_RECURSED: +#ifndef __rtems__ +#ifdef WITNESS + witness_assert(&sx->lock_object, what, file, line); +#else + /* + * If some other thread has an exclusive lock or we + * have one and are asserting a shared lock, fail. + * Also, if no one has a lock at all, fail. + */ + if (sx->sx_lock == SX_LOCK_UNLOCKED || + (!(sx->sx_lock & SX_LOCK_SHARED) && (slocked || + sx_xholder(sx) != curthread))) + panic("Lock %s not %slocked @ %s:%d\n", + sx->lock_object.lo_name, slocked ? "share " : "", + file, line); + + if (!(sx->sx_lock & SX_LOCK_SHARED)) { + if (sx_recursed(sx)) { + if (what & SA_NOTRECURSED) + panic("Lock %s recursed @ %s:%d\n", + sx->lock_object.lo_name, file, + line); + } else if (what & SA_RECURSED) + panic("Lock %s not recursed @ %s:%d\n", + sx->lock_object.lo_name, file, line); + } +#endif + break; +#else /* __rtems__ */ + /* FALLTHROUGH */ +#endif /* __rtems__ */ + case SA_XLOCKED: + case SA_XLOCKED | SA_NOTRECURSED: + case SA_XLOCKED | SA_RECURSED: + if (sx_xholder(sx) != _Thread_Get_executing()) + panic("Lock %s not exclusively locked @ %s:%d\n", + sx->lock_object.lo_name, file, line); + if (sx_recursed(sx)) { + if (what & SA_NOTRECURSED) + panic("Lock %s recursed @ %s:%d\n", + sx->lock_object.lo_name, file, line); + } else if (what & SA_RECURSED) + panic("Lock %s not recursed @ %s:%d\n", + sx->lock_object.lo_name, file, line); + break; + case SA_UNLOCKED: +#ifdef WITNESS + witness_assert(&sx->lock_object, what, file, line); +#else + /* + * If we hold an exclusve lock fail. We can't + * reliably check to see if we hold a shared lock or + * not. + */ + if (sx_xholder(sx) == _Thread_Get_executing()) + panic("Lock %s exclusively locked @ %s:%d\n", + sx->lock_object.lo_name, file, line); +#endif + break; + default: + panic("Unknown sx lock assertion: %d @ %s:%d", what, file, + line); + } +} +#endif /* INVARIANT_SUPPORT */ + +int +sx_xlocked(struct sx *sx) +{ + return (rtems_bsd_mutex_owned(&sx->mutex)); +} diff --git a/rtemsbsd/rtems/rtems-kernel-sysctl.c b/rtemsbsd/rtems/rtems-kernel-sysctl.c new file mode 100644 index 00000000..7e087385 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-sysctl.c @@ -0,0 +1,84 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2010 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include +#include +#include +#include + +int sysctl( + const int *name, + u_int namelen, + void *oldp, + size_t *oldlenp, + const void *newp, + size_t newlen +) +{ + int eno = EINVAL; + + if (namelen <= CTL_MAXNAME) { + int namedup [CTL_MAXNAME]; + + memcpy(namedup, name, namelen * sizeof(*name)); + + eno = kernel_sysctl( + NULL, + namedup, + namelen, + oldp, + oldlenp, + newp, + newlen, + oldlenp, + 0 + ); + } + + if (eno == 0) { + return 0; + } else { + errno = eno; + + return -1; + } +} diff --git a/rtemsbsd/rtems/rtems-kernel-sysctlbyname.c b/rtemsbsd/rtems/rtems-kernel-sysctlbyname.c new file mode 100644 index 00000000..ab3e8083 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-sysctlbyname.c @@ -0,0 +1,44 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + * + * File origin from FreeBSD 'lib/libc/gen/sysctlbyname.c'. + */ + +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + */ + +#include +#include + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +int +sysctlbyname(const char *name, void *oldp, size_t *oldlenp, + const void *newp, size_t newlen) +{ + int real_oid[CTL_MAXNAME+2]; + int error; + size_t oidlen; + + oidlen = sizeof(real_oid) / sizeof(int); + error = sysctlnametomib(name, real_oid, &oidlen); + if (error < 0) + return (error); + error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen); + return (error); +} diff --git a/rtemsbsd/rtems/rtems-kernel-sysctlnametomib.c b/rtemsbsd/rtems/rtems-kernel-sysctlnametomib.c new file mode 100644 index 00000000..62ce6b80 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-sysctlnametomib.c @@ -0,0 +1,68 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + * + * File origin from FreeBSD 'lib/libc/gen/sysctlnametomib.c'. + */ + +/* + * Copyright 2001 The FreeBSD Project. All Rights Reserved. + * + * 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 FREEBSD PROJECT ``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 FREEBSD PROJECT 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. + */ + +#include +#include + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +/* + * This function uses a presently undocumented interface to the kernel + * to walk the tree and get the type so it can print the value. + * This interface is under work and consideration, and should probably + * be killed with a big axe by the first person who can find the time. + * (be aware though, that the proper interface isn't as obvious as it + * may seem, there are various conflicting requirements. + */ +int +sysctlnametomib(const char *name, int *mibp, size_t *sizep) +{ + int oid[2]; + int error; + + oid[0] = 0; + oid[1] = 3; + + *sizep *= sizeof(int); + error = sysctl(oid, 2, mibp, sizep, name, strlen(name)); + *sizep /= sizeof(int); + return (error); +} diff --git a/rtemsbsd/rtems/rtems-kernel-thread.c b/rtemsbsd/rtems/rtems-kernel-thread.c new file mode 100644 index 00000000..fe213201 --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-thread.c @@ -0,0 +1,370 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2009-2015 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#undef ticks + +#include +#include +#include +#include +#include +#include + +static size_t rtems_bsd_extension_index; + +static CHAIN_DEFINE_EMPTY(rtems_bsd_thread_delay_start_chain); + +static bool rtems_bsd_thread_ready_to_start; + +struct thread * +rtems_bsd_get_thread(const Thread_Control *thread) +{ + return thread->extensions[rtems_bsd_extension_index]; +} + +static Thread_Control * +rtems_bsd_get_thread_by_id(rtems_id task_id) +{ + Thread_Control *thread; + Objects_Locations location; + + thread = _Thread_Get(task_id, &location); + switch (location) { + case OBJECTS_LOCAL: + _Objects_Put(&thread->Object); + break; +#if defined(RTEMS_MULTIPROCESSING) + case OBJECTS_REMOTE: + _Thread_Dispatch(); + thread = NULL; + break; +#endif + default: + thread = NULL; + break; + } + + return thread; +} + +struct thread * +rtems_bsd_thread_create(Thread_Control *thread, int wait) +{ + struct thread *td = malloc(sizeof(*td), M_TEMP, M_ZERO | wait); + struct sleepqueue *sq = sleepq_alloc(); + + if (td != NULL && sq != NULL) { + td->td_thread = thread; + td->td_sleepqueue = sq; + } else { + free(td, M_TEMP); + sleepq_free(sq); + td = NULL; + } + + thread->extensions[rtems_bsd_extension_index] = td; + + return td; +} + +static struct thread * +rtems_bsd_get_curthread(int wait) +{ + Thread_Control *executing = _Thread_Get_executing(); + struct thread *td = rtems_bsd_get_thread(executing); + + if (td == NULL) { + td = rtems_bsd_thread_create(executing, wait); + } + + return td; +} + +struct thread * +rtems_bsd_get_curthread_or_wait_forever(void) +{ + return rtems_bsd_get_curthread(M_WAITOK); +} + +struct thread * +rtems_bsd_get_curthread_or_null(void) +{ + return rtems_bsd_get_curthread(0); +} + +static bool +rtems_bsd_is_bsd_thread(Thread_Control *thread) +{ + return thread->Object.name.name_u32 == BSD_TASK_NAME; +} + +static bool +rtems_bsd_extension_thread_create( + Thread_Control *executing, + Thread_Control *created +) +{ + bool ok; + + if (rtems_bsd_is_bsd_thread(created)) { + struct thread *td = rtems_bsd_thread_create(created, 0); + + ok = td != NULL; + } else { + ok = true; + } + + return ok; +} + +static void +rtems_bsd_extension_thread_delete( + Thread_Control *executing, + Thread_Control *deleted +) +{ + struct thread *td = rtems_bsd_get_thread(deleted); + + if (td != NULL) { + seltdfini(td); + sleepq_free(td->td_sleepqueue); + free(td, M_TEMP); + } +} + +static const rtems_extensions_table rtems_bsd_extensions = { + .thread_create = rtems_bsd_extension_thread_create, + .thread_delete = rtems_bsd_extension_thread_delete +}; + +static void +rtems_bsd_threads_init_early(void *arg) +{ + rtems_id ext_id; + rtems_status_code sc; + + (void) arg; + + sc = rtems_extension_create( + BSD_TASK_NAME, + &rtems_bsd_extensions, + &ext_id + ); + if (sc != RTEMS_SUCCESSFUL) { + BSD_PANIC("cannot create extension"); + } + + rtems_bsd_extension_index = rtems_object_id_get_index(ext_id); +} + +static void +rtems_bsd_threads_init_late(void *arg) +{ + Chain_Control *chain = &rtems_bsd_thread_delay_start_chain; + Chain_Node *node; + + (void) arg; + + while ((node = _Chain_Get_unprotected(chain)) != NULL) { + Thread_Control *thread = (Thread_Control *) node; + rtems_status_code sc; + + sc = rtems_task_start(thread->Object.id, + thread->Start.Entry.Kinds.Numeric.entry, + thread->Start.Entry.Kinds.Numeric.argument); + BSD_ASSERT(sc == RTEMS_SUCCESSFUL); + } + + rtems_bsd_thread_ready_to_start = true; +} + +SYSINIT(rtems_bsd_threads_early, SI_SUB_INTRINSIC, SI_ORDER_ANY, + rtems_bsd_threads_init_early, NULL); + +SYSINIT(rtems_bsd_threads_late, SI_SUB_LAST, SI_ORDER_ANY, + rtems_bsd_threads_init_late, NULL); + +static int +rtems_bsd_thread_start(struct thread **td_ptr, void (*func)(void *), void *arg, + int flags, int pages, const char *fmt, va_list ap) +{ + int eno = 0; + rtems_status_code sc; + rtems_id task_id; + struct thread *td; + char name[sizeof(td->td_name)]; + + BSD_ASSERT(pages >= 0); + + vsnprintf(name, sizeof(name), fmt, ap); + + sc = rtems_task_create( + BSD_TASK_NAME, + rtems_bsd_get_task_priority(name), + rtems_bsd_get_task_stack_size(name) + + (size_t) pages * PAGE_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &task_id + ); + if (sc == RTEMS_SUCCESSFUL) { + Thread_Control *thread = rtems_bsd_get_thread_by_id(task_id); + + BSD_ASSERT(thread != NULL); + + td = rtems_bsd_get_thread(thread); + BSD_ASSERT(td != NULL); + + memcpy(td->td_name, name, sizeof(name)); + + if (rtems_bsd_thread_ready_to_start) { + sc = rtems_task_start(task_id, (rtems_task_entry) func, + (rtems_task_argument) arg); + BSD_ASSERT(sc == RTEMS_SUCCESSFUL); + } else { + thread->Start.Entry.Kinds.Numeric.entry = + (void (*)(Thread_Entry_numeric_type))func; + thread->Start.Entry.Kinds.Numeric.argument = + (Thread_Entry_numeric_type)arg; + _Chain_Append_unprotected( + &rtems_bsd_thread_delay_start_chain, + &thread->Object.Node); + } + + if (td_ptr != NULL) { + *td_ptr = td; + } + } else { + eno = ENOMEM; + } + + return eno; +} + +static __dead2 void +rtems_bsd_thread_delete(void) +{ + rtems_task_delete(RTEMS_SELF); + BSD_PANIC("delete self failed"); +} + +void +kproc_start(const void *udata) +{ + const struct kproc_desc *pd = udata; + int eno = kproc_create((void (*)(void *))pd->func, NULL, pd->global_procpp, 0, 0, "%s", pd->arg0); + + BSD_ASSERT(eno == 0); +} + +int +kproc_create(void (*func)(void *), void *arg, struct proc **newpp, int flags, int pages, const char *fmt, ...) +{ + int eno = 0; + va_list ap; + + va_start(ap, fmt); + eno = rtems_bsd_thread_start(newpp, func, arg, flags, pages, fmt, ap); + va_end(ap); + + return eno; +} + +void +kproc_exit(int ecode) +{ + rtems_bsd_thread_delete(); +} + +void +kthread_start(const void *udata) +{ + const struct kthread_desc *td = udata; + int eno = kthread_add((void (*)(void *)) td->func, NULL, NULL, td->global_threadpp, 0, 0, "%s", td->arg0); + + BSD_ASSERT(eno == 0); +} + +int +kthread_add(void (*func)(void *), void *arg, struct proc *p, struct thread **newtdp, int flags, int pages, const char *fmt, ...) +{ + int eno = 0; + va_list ap; + + va_start(ap, fmt); + eno = rtems_bsd_thread_start(newtdp, func, arg, flags, pages, fmt, ap); + va_end(ap); + + return eno; +} + +void +kthread_exit(void) +{ + rtems_bsd_thread_delete(); +} + +int +kproc_kthread_add(void (*func)(void *), void *arg, struct proc **procptr, struct thread **tdptr, int flags, int pages, const char * procname, const char *fmt, ...) +{ + int eno = 0; + va_list ap; + + va_start(ap, fmt); + eno = rtems_bsd_thread_start(tdptr, func, arg, flags, pages, fmt, ap); + va_end(ap); + + return eno; +} diff --git a/rtemsbsd/rtems/rtems-kernel-timesupport.c b/rtemsbsd/rtems/rtems-kernel-timesupport.c new file mode 100644 index 00000000..ef14d1fa --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-timesupport.c @@ -0,0 +1,54 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * COPYRIGHT (c) 2012. + * On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include + +#include + +/* + * Compute number of ticks in the specified amount of time. + */ +int +tvtohz(struct timeval *tv) +{ + struct timespec ts; + + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + + return (int) _Timespec_To_ticks( &ts ); +} diff --git a/rtemsbsd/rtems/rtems-kernel-vprintf.c b/rtemsbsd/rtems/rtems-kernel-vprintf.c new file mode 100644 index 00000000..36f0c59c --- /dev/null +++ b/rtemsbsd/rtems/rtems-kernel-vprintf.c @@ -0,0 +1,119 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * Copyright (c) 2014, 2016 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include + +#include + +#include + +#undef printf + +#define VPRINTF_LOCK() _Mutex_Acquire(&vprintf_mtx) +#define VPRINTF_UNLOCK() _Mutex_Release(&vprintf_mtx) + +static const char * const log_priorities[] = { + [LOG_EMERG] = "emerg", + [LOG_ALERT] = "alert", + [LOG_CRIT] = "crit", + [LOG_ERR] = "err", + [LOG_WARNING] = "warning", + [LOG_NOTICE] = "notice", + [LOG_INFO] = "info", + [LOG_DEBUG] = "debug" +}; + +/* Use a mutex due to the static initialization capability */ +static struct _Mutex_Control vprintf_mtx = _MUTEX_INITIALIZER; + +static void +vprintf_putchar(int c, void *arg) +{ + int *last; + + last = arg; + *last = c; + putchar(c); +} + +static int +default_vprintf_handler(int level, const char *fmt, va_list ap) +{ + int n; + int last; + + VPRINTF_LOCK(); + + if (level != LOG_PRINTF) { + printf("%s: ", log_priorities[LOG_PRI(level)]); + } + + last = -1; + n = kvprintf(fmt, vprintf_putchar, &last, 10, ap); + + if (level != LOG_PRINTF && last != '\n') { + putchar('\n'); + } + + VPRINTF_UNLOCK(); + return (n); +} + +static int (*vprintf_handler)(int, const char *, va_list) = + default_vprintf_handler; + +void +rtems_bsd_set_vprintf_handler(int (*new_vprintf_handler) + (int, const char *, va_list)) +{ + + vprintf_handler = new_vprintf_handler; +} + +int +rtems_bsd_vprintf(int level, const char *fmt, va_list ap) +{ + + return ((*vprintf_handler)(level, fmt, ap)); +} diff --git a/rtemsbsd/rtems/rtems-legacy-mii.c b/rtemsbsd/rtems/rtems-legacy-mii.c new file mode 100644 index 00000000..f36f2ca5 --- /dev/null +++ b/rtemsbsd/rtems/rtems-legacy-mii.c @@ -0,0 +1,254 @@ +/* Simple (default) implementation for SIOCGIFMEDIA/SIOCSIFMEDIA + * to be used by ethernet drivers [from their ioctl]. + * + * KERNEL PART (support for drivers) + * + * NOTE: This much simpler than the BSD ifmedia API + */ + +/* + * Authorship + * ---------- + * This software was created by + * Till Straumann , 2005, + * Stanford Linear Accelerator Center, Stanford University. + * + * Acknowledgement of sponsorship + * ------------------------------ + * This software was produced by + * the Stanford Linear Accelerator Center, Stanford University, + * under Contract DE-AC03-76SFO0515 with the Department of Energy. + * + * Government disclaimer of liability + * ---------------------------------- + * Neither the United States nor the United States Department of Energy, + * nor any of their employees, makes any warranty, express or implied, or + * assumes any legal liability or responsibility for the accuracy, + * completeness, or usefulness of any data, apparatus, product, or process + * disclosed, or represents that its use would not infringe privately owned + * rights. + * + * Stanford disclaimer of liability + * -------------------------------- + * Stanford University makes no representations or warranties, express or + * implied, nor assumes any liability for the use of this software. + * + * Stanford disclaimer of copyright + * -------------------------------- + * Stanford University, owner of the copyright, hereby disclaims its + * copyright and all other rights in this software. Hence, anyone may + * freely use it for any purpose without restriction. + * + * Maintenance of notices + * ---------------------- + * In the interest of clarity regarding the origin and status of this + * SLAC software, this and all the preceding Stanford University notices + * are to remain affixed to any copy or derivative of this software made + * or distributed by the recipient and are to be affixed to any copy of + * software made or distributed by the recipient that contains a copy or + * derivative of this software. + * + * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 + */ + +/* include first to avoid 'malloc' clash with rtems_bsdnet_malloc() hack */ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + + +#define DEBUG + + +#ifndef MII_1000TCR +#define MII_1000TCR MII_100T2CR +#endif + +#ifndef MII_1000TSR +#define MII_1000TSR MII_100T2SR +#endif + +int +rtems_mii_ioctl (struct rtems_mdio_info *info, void *uarg, uint32_t cmd, + int *media) +{ + uint32_t bmcr, bmsr, aner, bmcr2 = 0, bmsr2 = 0, anar, lpar; + int phy = IFM_INST (*media); + uint32_t tmp; + int subtype = 0, options = 0; + + switch (cmd) { + default: + return EINVAL; + +#ifdef DEBUG + case 0: +#endif + case SIOCGIFMEDIA: + if (info->mdio_r (phy, uarg, MII_BMCR, &bmcr)) + return EINVAL; + /* read BMSR twice to clear latched link status low */ + if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr)) + return EINVAL; + if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr)) + return EINVAL; + if (info->mdio_r (phy, uarg, MII_ANER, &aner)) + return EINVAL; + if (info->has_gmii) { + if (info->mdio_r (phy, uarg, MII_1000TCR, &bmcr2)) + return EINVAL; + if (info->mdio_r (phy, uarg, MII_1000TSR, &bmsr2)) + return EINVAL; + } + + /* link status */ + if (BMSR_LINK & bmsr) + options |= IFM_LINK_OK; + + /* do we have autonegotiation disabled ? */ + if (!(BMCR_AUTOEN & bmcr)) { + options |= IFM_ANEG_DIS; + + /* duplex is enforced */ + options |= BMCR_FDX & bmcr ? IFM_FDX : IFM_HDX; + + /* determine speed */ + switch (BMCR_SPEED (bmcr)) { + case BMCR_S10: + subtype = IFM_10_T; + break; + case BMCR_S100: + subtype = IFM_100_TX; + break; + case BMCR_S1000: + subtype = IFM_1000_T; + break; + default: + return ENOTSUP; /* ?? */ + } + } else if (!(BMSR_LINK & bmsr) || !(BMSR_ACOMP & bmsr)) { + subtype = IFM_NONE; + } else { + /* everything ok on our side */ + + if ( ! (ANER_LPAN & aner) ) { + /* Link partner doesn't autonegotiate --> our settings are the + * result of 'parallel detect' (in particular: duplex status is HALF + * according to the standard!). + * Let them know that something's fishy... + */ + options |= IFM_ANEG_DIS; + } + + tmp = ((bmcr2 << 2) & bmsr2) & (GTSR_LP_1000THDX | GTSR_LP_1000TFDX); + if (tmp) { + if (GTSR_LP_1000TFDX & tmp) + options |= IFM_FDX; + subtype = IFM_1000_T; + } else { + if (info->mdio_r (phy, uarg, MII_ANAR, &anar)) + return EINVAL; + if (info->mdio_r (phy, uarg, MII_ANLPAR, &lpar)) + return EINVAL; + if (ANLPAR_ACK & lpar) { + /* this is a negotiated link; otherwise we merely detect the partner's ability */ + } + tmp = anar & lpar; + if (ANLPAR_TX_FD & tmp) { + options |= IFM_FDX; + subtype = IFM_100_TX; + } else if (ANLPAR_T4 & tmp) { + subtype = IFM_100_T4; + } else if (ANLPAR_TX & tmp) { + subtype = IFM_100_TX; + } else if (ANLPAR_10_FD & tmp) { + options |= IFM_FDX; + subtype = IFM_10_T; + } else { + subtype = IFM_10_T; + } + } + } + + *media = IFM_MAKEWORD (IFM_ETHER, subtype, options, phy); + + break; + +#ifdef DEBUG + case 1: +#endif + case SIOCSIFMEDIA: + if (IFM_ETHER != IFM_TYPE (*media)) + return EINVAL; + + if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr)) + return EINVAL; + + tmp = (IFM_FDX & *media); + + switch (IFM_SUBTYPE (*media)) { + default: + return ENOTSUP; + + case IFM_AUTO: + bmcr = BMCR_AUTOEN | BMCR_STARTNEG; + tmp = 0; + break; + + case IFM_1000_T: + if (!info->has_gmii) + return ENOTSUP; + + if (info->mdio_r (phy, uarg, MII_EXTSR, &bmsr2)) + return EINVAL; + + if (!(bmsr2 & (tmp ? EXTSR_1000TFDX : EXTSR_1000THDX))) + return EOPNOTSUPP; + + /* NOTE: gige standard demands auto-negotiation for gige links. + * Disabling autoneg did NOT work on the PHYs I tried + * (BCM5421S, intel 82540). + * I've seen drivers that simply change what they advertise + * to the desired gig mode and re-negotiate. + * We could do that here, too, but we don't see the point - + * If autoneg works fine then we can as well use it. + */ + bmcr = BMCR_S1000; + break; + + case IFM_100_TX: + if (!(bmsr & (tmp ? BMSR_100TXFDX : BMSR_100TXHDX))) + return EOPNOTSUPP; + bmcr = BMCR_S100; + break; + + case IFM_10_T: + if (!(bmsr & (tmp ? BMSR_10TFDX : BMSR_10THDX))) + return EOPNOTSUPP; + bmcr = BMCR_S10; + break; + } + + if (tmp) + bmcr |= BMCR_FDX; + + if (info->mdio_w (phy, uarg, MII_BMCR, bmcr)) + return EINVAL; + + /* TODO: should we adapt advertised capabilites ? */ + + break; + } + + return 0; +} diff --git a/rtemsbsd/rtems/rtems-legacy-newproc.c b/rtemsbsd/rtems/rtems-legacy-newproc.c new file mode 100644 index 00000000..c01b41d2 --- /dev/null +++ b/rtemsbsd/rtems/rtems-legacy-newproc.c @@ -0,0 +1,116 @@ +/** + * @file + * + * @ingroup rtems_bsd_rtems + * + * @brief TODO. + */ + +/* + * COPYRIGHT (c) 2012. + * On-Line Applications Research Corporation (OAR). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include + +/* + * Structure passed to task-start stub + */ +struct newtask { + void (*entry)(void *); + void *arg; +}; + +/* + * Task-start stub + */ +static void +taskEntry (rtems_task_argument arg) +{ + struct newtask t; + + /* + * Pick up task information and free + * the memory allocated to pass the + * information to this task. + */ + t = *(struct newtask *)arg; + free ((struct newtask *)arg); + + /* + * XXX If we need a semaphore it should be added here + */ + + /* + * Enter the task + */ + (*t.entry)(t.arg); + rtems_panic ("Network task returned!\n"); +} + +/* + * Start a network task + */ +rtems_id +rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg) +{ + struct newtask *t; + char nm[4]; + rtems_id tid; + rtems_status_code sc; + + strncpy (nm, name, 4); + sc = rtems_task_create (rtems_build_name(nm[0], nm[1], nm[2], nm[3]), + rtems_bsd_get_task_priority(name), + stacksize, + RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), + RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, + &tid + ); + if (sc != RTEMS_SUCCESSFUL) + rtems_panic ("Can't create network daemon `%s': `%s'\n", name, rtems_status_text (sc)); + + /* + * Set up task arguments + */ + t = malloc (sizeof *t); + t->entry = entry; + t->arg = arg; + + /* + * Start the task + */ + sc = rtems_task_start (tid, taskEntry, (rtems_task_argument)t); + if (sc != RTEMS_SUCCESSFUL) + rtems_panic ("Can't start network daemon `%s': `%s'\n", name, rtems_status_text (sc)); + + /* + * Let our caller know the i.d. of the new task + */ + return tid; +} diff --git a/rtemsbsd/rtems/rtems-legacy-rtrequest.c b/rtemsbsd/rtems/rtems-legacy-rtrequest.c new file mode 100644 index 00000000..e1269be9 --- /dev/null +++ b/rtemsbsd/rtems/rtems-legacy-rtrequest.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include + +#include + +#include + +#include + +int +rtems_bsdnet_rtrequest(int req, struct sockaddr *dst, struct sockaddr *gateway, + struct sockaddr *netmask, int flags, struct rtentry **net_nrt) +{ + int error; + + error = rtrequest(req, dst, gateway, netmask, flags, net_nrt); + if (error != 0) { + errno = error; + + return (-1); + } else { + return (0); + } +} diff --git a/rtemsbsd/rtems/rtems_mii_ioctl_kern.c b/rtemsbsd/rtems/rtems_mii_ioctl_kern.c deleted file mode 100644 index f36f2ca5..00000000 --- a/rtemsbsd/rtems/rtems_mii_ioctl_kern.c +++ /dev/null @@ -1,254 +0,0 @@ -/* Simple (default) implementation for SIOCGIFMEDIA/SIOCSIFMEDIA - * to be used by ethernet drivers [from their ioctl]. - * - * KERNEL PART (support for drivers) - * - * NOTE: This much simpler than the BSD ifmedia API - */ - -/* - * Authorship - * ---------- - * This software was created by - * Till Straumann , 2005, - * Stanford Linear Accelerator Center, Stanford University. - * - * Acknowledgement of sponsorship - * ------------------------------ - * This software was produced by - * the Stanford Linear Accelerator Center, Stanford University, - * under Contract DE-AC03-76SFO0515 with the Department of Energy. - * - * Government disclaimer of liability - * ---------------------------------- - * Neither the United States nor the United States Department of Energy, - * nor any of their employees, makes any warranty, express or implied, or - * assumes any legal liability or responsibility for the accuracy, - * completeness, or usefulness of any data, apparatus, product, or process - * disclosed, or represents that its use would not infringe privately owned - * rights. - * - * Stanford disclaimer of liability - * -------------------------------- - * Stanford University makes no representations or warranties, express or - * implied, nor assumes any liability for the use of this software. - * - * Stanford disclaimer of copyright - * -------------------------------- - * Stanford University, owner of the copyright, hereby disclaims its - * copyright and all other rights in this software. Hence, anyone may - * freely use it for any purpose without restriction. - * - * Maintenance of notices - * ---------------------- - * In the interest of clarity regarding the origin and status of this - * SLAC software, this and all the preceding Stanford University notices - * are to remain affixed to any copy or derivative of this software made - * or distributed by the recipient and are to be affixed to any copy of - * software made or distributed by the recipient that contains a copy or - * derivative of this software. - * - * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 - */ - -/* include first to avoid 'malloc' clash with rtems_bsdnet_malloc() hack */ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - - -#define DEBUG - - -#ifndef MII_1000TCR -#define MII_1000TCR MII_100T2CR -#endif - -#ifndef MII_1000TSR -#define MII_1000TSR MII_100T2SR -#endif - -int -rtems_mii_ioctl (struct rtems_mdio_info *info, void *uarg, uint32_t cmd, - int *media) -{ - uint32_t bmcr, bmsr, aner, bmcr2 = 0, bmsr2 = 0, anar, lpar; - int phy = IFM_INST (*media); - uint32_t tmp; - int subtype = 0, options = 0; - - switch (cmd) { - default: - return EINVAL; - -#ifdef DEBUG - case 0: -#endif - case SIOCGIFMEDIA: - if (info->mdio_r (phy, uarg, MII_BMCR, &bmcr)) - return EINVAL; - /* read BMSR twice to clear latched link status low */ - if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr)) - return EINVAL; - if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr)) - return EINVAL; - if (info->mdio_r (phy, uarg, MII_ANER, &aner)) - return EINVAL; - if (info->has_gmii) { - if (info->mdio_r (phy, uarg, MII_1000TCR, &bmcr2)) - return EINVAL; - if (info->mdio_r (phy, uarg, MII_1000TSR, &bmsr2)) - return EINVAL; - } - - /* link status */ - if (BMSR_LINK & bmsr) - options |= IFM_LINK_OK; - - /* do we have autonegotiation disabled ? */ - if (!(BMCR_AUTOEN & bmcr)) { - options |= IFM_ANEG_DIS; - - /* duplex is enforced */ - options |= BMCR_FDX & bmcr ? IFM_FDX : IFM_HDX; - - /* determine speed */ - switch (BMCR_SPEED (bmcr)) { - case BMCR_S10: - subtype = IFM_10_T; - break; - case BMCR_S100: - subtype = IFM_100_TX; - break; - case BMCR_S1000: - subtype = IFM_1000_T; - break; - default: - return ENOTSUP; /* ?? */ - } - } else if (!(BMSR_LINK & bmsr) || !(BMSR_ACOMP & bmsr)) { - subtype = IFM_NONE; - } else { - /* everything ok on our side */ - - if ( ! (ANER_LPAN & aner) ) { - /* Link partner doesn't autonegotiate --> our settings are the - * result of 'parallel detect' (in particular: duplex status is HALF - * according to the standard!). - * Let them know that something's fishy... - */ - options |= IFM_ANEG_DIS; - } - - tmp = ((bmcr2 << 2) & bmsr2) & (GTSR_LP_1000THDX | GTSR_LP_1000TFDX); - if (tmp) { - if (GTSR_LP_1000TFDX & tmp) - options |= IFM_FDX; - subtype = IFM_1000_T; - } else { - if (info->mdio_r (phy, uarg, MII_ANAR, &anar)) - return EINVAL; - if (info->mdio_r (phy, uarg, MII_ANLPAR, &lpar)) - return EINVAL; - if (ANLPAR_ACK & lpar) { - /* this is a negotiated link; otherwise we merely detect the partner's ability */ - } - tmp = anar & lpar; - if (ANLPAR_TX_FD & tmp) { - options |= IFM_FDX; - subtype = IFM_100_TX; - } else if (ANLPAR_T4 & tmp) { - subtype = IFM_100_T4; - } else if (ANLPAR_TX & tmp) { - subtype = IFM_100_TX; - } else if (ANLPAR_10_FD & tmp) { - options |= IFM_FDX; - subtype = IFM_10_T; - } else { - subtype = IFM_10_T; - } - } - } - - *media = IFM_MAKEWORD (IFM_ETHER, subtype, options, phy); - - break; - -#ifdef DEBUG - case 1: -#endif - case SIOCSIFMEDIA: - if (IFM_ETHER != IFM_TYPE (*media)) - return EINVAL; - - if (info->mdio_r (phy, uarg, MII_BMSR, &bmsr)) - return EINVAL; - - tmp = (IFM_FDX & *media); - - switch (IFM_SUBTYPE (*media)) { - default: - return ENOTSUP; - - case IFM_AUTO: - bmcr = BMCR_AUTOEN | BMCR_STARTNEG; - tmp = 0; - break; - - case IFM_1000_T: - if (!info->has_gmii) - return ENOTSUP; - - if (info->mdio_r (phy, uarg, MII_EXTSR, &bmsr2)) - return EINVAL; - - if (!(bmsr2 & (tmp ? EXTSR_1000TFDX : EXTSR_1000THDX))) - return EOPNOTSUPP; - - /* NOTE: gige standard demands auto-negotiation for gige links. - * Disabling autoneg did NOT work on the PHYs I tried - * (BCM5421S, intel 82540). - * I've seen drivers that simply change what they advertise - * to the desired gig mode and re-negotiate. - * We could do that here, too, but we don't see the point - - * If autoneg works fine then we can as well use it. - */ - bmcr = BMCR_S1000; - break; - - case IFM_100_TX: - if (!(bmsr & (tmp ? BMSR_100TXFDX : BMSR_100TXHDX))) - return EOPNOTSUPP; - bmcr = BMCR_S100; - break; - - case IFM_10_T: - if (!(bmsr & (tmp ? BMSR_10TFDX : BMSR_10THDX))) - return EOPNOTSUPP; - bmcr = BMCR_S10; - break; - } - - if (tmp) - bmcr |= BMCR_FDX; - - if (info->mdio_w (phy, uarg, MII_BMCR, bmcr)) - return EINVAL; - - /* TODO: should we adapt advertised capabilites ? */ - - break; - } - - return 0; -} -- cgit v1.2.3