Re: [PATCH] Proposal for new GPIO API and example implementation for STM32F4 BSP

2022-06-24 Thread oss

Hello Duc,

Am 24.06.22 um 16:28 schrieb Duc Doan:

Hello Christian,

On Thu, 2022-06-23 at 18:30 +0200, o...@c-mauderer.de wrote:

Another tricky part can be how to handle pins or pin groups. At the
moment I just used an "unsigned" for a single pin. That wouldn't be
able
to handle a pin group. Maybe a pin group needs it's own type or some
kind of extensible type. For the usual controller with <= 32 bit a
mask
in a uint32_t would be great. For other controllers maybe a longer
mask
is necessary. That's a bit tricky.


Thank you for the pseudocode, I think your method is better than mine.
I am currently rewriting the code. However, I am not clear about pin
groups: Is a "pin group" same as a "port"? Or does a group mean pins
from that group can come from different ports/GPIO controllers?


It's not unlikely that you want to change multiple pins on one 
controller at the same time. That's what I meant with "pin groups". On a 
controller level it would be (for most controllers):


- Read current value from output register into a temporary variable.
- Change the pins in the group to the new value in that temporary variable.
- Write back the new value to the output register.



Also, I am thinking that maybe I can create an opaque type for pin mask
that BSPs will implement, instead of a specific type like
uint32_t. That type could be used as a long mask or just a pin number,
depending on the BSP.


Be careful with everything that depends on the BSP. Again: Please think 
about an i2c GPIO expander. That chip can be used on different BSPs. It 
can be even an independent driver that can be used by a user on demand 
on any BSP that supports i2c.


Best regards

Christian



Best,

Duc Doan


___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] Proposal for new GPIO API and example implementation for STM32F4 BSP

2022-06-24 Thread Duc Doan
Hello Christian,

On Thu, 2022-06-23 at 18:30 +0200, o...@c-mauderer.de wrote:
> Another tricky part can be how to handle pins or pin groups. At the 
> moment I just used an "unsigned" for a single pin. That wouldn't be
> able 
> to handle a pin group. Maybe a pin group needs it's own type or some 
> kind of extensible type. For the usual controller with <= 32 bit a
> mask 
> in a uint32_t would be great. For other controllers maybe a longer
> mask 
> is necessary. That's a bit tricky.

Thank you for the pseudocode, I think your method is better than mine.
I am currently rewriting the code. However, I am not clear about pin
groups: Is a "pin group" same as a "port"? Or does a group mean pins
from that group can come from different ports/GPIO controllers?

Also, I am thinking that maybe I can create an opaque type for pin mask
that BSPs will implement, instead of a specific type like
uint32_t. That type could be used as a long mask or just a pin number,
depending on the BSP.

Best,

Duc Doan
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] libstdc++: testsuite: work around bitset namespace pollution

2022-06-24 Thread Sebastian Huber

On 21.06.22 07:31, Alexandre Oliva via Gcc-patches wrote:

rtems6 declares a global struct bitset in a header file included
indirectly by sys/types.h, that ambiguates the unqualified references
to bitset after "using namespace std" in the testsuite.

Work around the namespace pollution with using declarations of
std::bitset.


I fixed the problem in Newlib. This patch should be no longer necessary.

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] arm/gicv3: Fix building arm/r52

2022-06-24 Thread Sebastian Huber

On 20.06.22 04:03, chr...@rtems.org wrote:

From: Chris Johns 

---
  bsps/include/dev/irq/arm-gicv3.h | 5 +
  1 file changed, 5 insertions(+)

diff --git a/bsps/include/dev/irq/arm-gicv3.h b/bsps/include/dev/irq/arm-gicv3.h
index a79368ebdf..aac02fa191 100644
--- a/bsps/include/dev/irq/arm-gicv3.h
+++ b/bsps/include/dev/irq/arm-gicv3.h
@@ -335,7 +335,12 @@ static void gicv3_init_cpu_interface(uint32_t cpu_index)
}
  
/* Enable interrupt groups 0 and 1 */

+#ifdef ARM_MULTILIB_ARCH_V4
+  WRITE_SR(ICC_IGRPEN0, 0x1);
+  WRITE_SR(ICC_IGRPEN1, 0x1);
+#else
gic_icc_write(IGRPEN1, 1);
+#endif
WRITE_SR(ICC_CTLR, 0x0);
  }


I have a different patch to fix this:

https://lists.rtems.org/pipermail/devel/2022-June/072056.html

Why was the isb added? Why was the IGRPEN0 write removed in 
e70384d3f406251422bac64d11ff44570a678434?


I have to check if the removed ICC_BPR0 is an issue for AArch32.

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH] irq/arm-gicv3.h: Enable interrupt groups 0 and 1

2022-06-24 Thread Sebastian Huber
The GICv3 support is used by AArch32 (indicated by the ARM_MULTILIB_ARCH_V4
define) and AArch64 targets.  Use the existing WRITE_SR() abstraction to access
the interrupt group 0 and 1 enable registers.  This fixes the build for the
AArch32 target.
---
 bsps/include/dev/irq/arm-gicv3.h | 23 ++-
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/bsps/include/dev/irq/arm-gicv3.h b/bsps/include/dev/irq/arm-gicv3.h
index a79368ebdf..7db7bad034 100644
--- a/bsps/include/dev/irq/arm-gicv3.h
+++ b/bsps/include/dev/irq/arm-gicv3.h
@@ -116,9 +116,11 @@ extern "C" {
 #else /* ARM_MULTILIB_ARCH_V4 */
 
 /* AArch64 GICv3 registers are not named in GCC */
-#define ICC_IGRPEN0 "S3_0_C12_C12_6, %0"
-#define ICC_IGRPEN1 "S3_0_C12_C12_7, %0"
+#define ICC_IGRPEN0_EL1 "S3_0_C12_C12_6, %0"
+#define ICC_IGRPEN1_EL1 "S3_0_C12_C12_7, %0"
 #define ICC_IGRPEN1_EL3 "S3_6_C12_C12_7, %0"
+#define ICC_IGRPEN0 ICC_IGRPEN0_EL1
+#define ICC_IGRPEN1 ICC_IGRPEN1_EL1
 #define ICC_PMR "S3_0_C4_C6_0, %0"
 #define ICC_EOIR1   "S3_0_C12_C12_1, %0"
 #define ICC_SRE "S3_0_C12_C12_5, %0"
@@ -300,20 +302,6 @@ static void gicv3_init_dist(volatile gic_dist *dist)
   }
 }
 
-/*
- * A better way to access these registers than special opcodes
- */
-#define isb() __asm __volatile("isb" : : : "memory")
-
-#define  WRITE_SPECIALREG(reg, _val)\
-  __asm __volatile("msr  " __STRING(reg) ", %0" : : "r"((uint64_t)_val))
-
-#define  gic_icc_write(reg, val)\
-do {\
-  WRITE_SPECIALREG(icc_ ##reg ##_el1, val); \
-  isb();\
-} while (0)
-
 static void gicv3_init_cpu_interface(uint32_t cpu_index)
 {
   uint32_t sre_value = 0x7;
@@ -335,7 +323,8 @@ static void gicv3_init_cpu_interface(uint32_t cpu_index)
   }
 
   /* Enable interrupt groups 0 and 1 */
-  gic_icc_write(IGRPEN1, 1);
+  WRITE_SR(ICC_IGRPEN0, 0x1);
+  WRITE_SR(ICC_IGRPEN1, 0x1);
   WRITE_SR(ICC_CTLR, 0x0);
 }
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] sys/event.h: Use rtems_libio_t

2022-06-24 Thread Sebastian Huber
Make it explicit that kqueue uses rtems_libio_t.

Update #4475.
---
 cpukit/include/sys/event.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/cpukit/include/sys/event.h b/cpukit/include/sys/event.h
index c64db98b95..6c5666030e 100644
--- a/cpukit/include/sys/event.h
+++ b/cpukit/include/sys/event.h
@@ -33,6 +33,9 @@
 
 #include 
 #include 
+#ifdef __rtems__
+struct rtems_libio_tt;
+#endif /* __rtems__ */
 
 #define EVFILT_READ(-1)
 #define EVFILT_WRITE   (-2)
@@ -300,7 +303,11 @@ struct knote {
int kn_sfflags; /* saved filter flags */
int64_t kn_sdata;   /* saved data field */
union {
+#ifndef __rtems__
struct  file *p_fp; /* file data pointer */
+#else /* __rtems__ */
+   struct  rtems_libio_tt *p_fp;
+#endif /* __rtems__ */
struct  proc *p_proc;   /* proc pointer */
struct  kaiocb *p_aio;  /* AIO job pointer */
struct  aioliojob *p_lio;   /* LIO job pointer */
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 14/22] Move select(), pselect(), and poll(), avoid VFS

2022-06-24 Thread Sebastian Huber
Collecting all system calls in a single translation unit is not good due to the
library initialization through linker sets.

Partly revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in
"freebsd/sys/kern/sys_generic.c".  The goal is to use USB, network, PCI, and
NVMe support without the VFS to reduce the memory and runtime overhead
introduced by VFS.

Avoid the VFS by providing a weak bwillwrite() implementation.

Update #4475.
---
 freebsd/sys/kern/sys_generic.c| 111 +-
 freebsd/sys/sys/sysproto.h|   4 +-
 .../machine/rtems-bsd-kernel-namespace.h  |   3 -
 rtemsbsd/rtems/rtems-bsd-syscall-api.c|  86 --
 4 files changed, 108 insertions(+), 96 deletions(-)

diff --git a/freebsd/sys/kern/sys_generic.c b/freebsd/sys/kern/sys_generic.c
index 1e5351a7..1c3bb714 100644
--- a/freebsd/sys/kern/sys_generic.c
+++ b/freebsd/sys/kern/sys_generic.c
@@ -77,6 +77,19 @@ __FBSDID("$FreeBSD$");
 #endif
 
 #include 
+#ifdef __rtems__
+#include 
+
+static int kern_select(struct thread *, int, fd_set *, fd_set *,
+fd_set *, struct timeval *, int);
+
+__weak_symbol void
+bwillwrite(void)
+{
+
+   /* Do not pull in the VFS support only through this translation unit */
+}
+#endif /* __rtems__ */
 
 /*
  * The following macro defines how many bytes will be allocated from
@@ -259,7 +272,6 @@ freebsd6_pread(struct thread *td, struct 
freebsd6_pread_args *uap)
return (kern_pread(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 #endif
-#endif /* __rtems__ */
 
 /*
  * Scatter read system call.
@@ -284,6 +296,7 @@ sys_readv(struct thread *td, struct readv_args *uap)
free(auio, M_IOV);
return (error);
 }
+#endif /* __rtems__ */
 
 int
 kern_readv(struct thread *td, int fd, struct uio *auio)
@@ -465,7 +478,6 @@ freebsd6_pwrite(struct thread *td, struct 
freebsd6_pwrite_args *uap)
return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte, uap->offset));
 }
 #endif
-#endif /* __rtems__ */
 
 /*
  * Gather write system call.
@@ -490,6 +502,7 @@ sys_writev(struct thread *td, struct writev_args *uap)
free(auio, M_IOV);
return (error);
 }
+#endif /* __rtems__ */
 
 int
 kern_writev(struct thread *td, int fd, struct uio *auio)
@@ -865,6 +878,7 @@ poll_no_poll(int events)
return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
 }
 
+#ifndef __rtems__
 int
 sys_pselect(struct thread *td, struct pselect_args *uap)
 {
@@ -898,7 +912,6 @@ kern_pselect(struct thread *td, int nd, fd_set *in, fd_set 
*ou, fd_set *ex,
 {
int error;
 
-#ifndef __rtems__
if (uset != NULL) {
error = kern_sigprocmask(td, SIG_SETMASK, uset,
>td_oldsigmask, 0);
@@ -914,7 +927,6 @@ kern_pselect(struct thread *td, int nd, fd_set *in, fd_set 
*ou, fd_set *ex,
td->td_flags |= TDF_ASTPENDING;
thread_unlock(td);
}
-#endif /* __rtems__ */
error = kern_select(td, nd, in, ou, ex, tvp, abi_nfdbits);
return (error);
 }
@@ -943,6 +955,7 @@ sys_select(struct thread *td, struct select_args *uap)
return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
NFDBITS));
 }
+#endif /* __rtems__ */
 
 /*
  * In the unlikely case when user specified n greater then the last
@@ -1171,6 +1184,65 @@ done:
 
return (error);
 }
+#ifdef __rtems__
+int
+select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
+struct timeval *timeout)
+{
+   struct thread *td = rtems_bsd_get_curthread_or_null();
+   int error;
+
+   if (td != NULL) {
+   error = kern_select(td, nfds, readfds, writefds, errorfds,
+   timeout, NFDBITS);
+   } else {
+   error = ENOMEM;
+   }
+
+   if (error == 0) {
+   return td->td_retval[0];
+   } else {
+   rtems_set_errno_and_return_minus_one(error);
+   }
+}
+
+int
+pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds,
+const struct timespec *timeout, const sigset_t *set)
+{
+   struct thread *td;
+   int error;
+
+   if (set != NULL) {
+   rtems_set_errno_and_return_minus_one(ENOSYS);
+   }
+
+   td = rtems_bsd_get_curthread_or_null();
+
+   if (td != NULL) {
+   struct timeval tv;
+   struct timeval *tvp;
+
+   if (timeout != NULL) {
+   TIMESPEC_TO_TIMEVAL(, timeout);
+   tvp = 
+   } else {
+   tvp = NULL;
+   }
+
+   error = kern_select(td, nfds, readfds, writefds, errorfds,
+   tvp, NFDBITS);
+   } else {
+   error = ENOMEM;
+   }
+
+   if (error == 0) {
+   return td->td_retval[0];
+   } else {
+   rtems_set_errno_and_return_minus_one(error);
+   }
+}
+#endif /* __rtems__ */
 
 /* 
  * Convert a select bit set to poll 

[libbsd 20/22] Remove unused rtems_bsd_sysgen_imfsnodeops

2022-06-24 Thread Sebastian Huber
Update #4475.
---
 rtemsbsd/include/machine/rtems-bsd-libio.h | 11 
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 64 --
 2 files changed, 75 deletions(-)

diff --git a/rtemsbsd/include/machine/rtems-bsd-libio.h 
b/rtemsbsd/include/machine/rtems-bsd-libio.h
index 3c3a8bbb..6dd75394 100644
--- a/rtemsbsd/include/machine/rtems-bsd-libio.h
+++ b/rtemsbsd/include/machine/rtems-bsd-libio.h
@@ -50,7 +50,6 @@
 struct rtems_bsd_vfs_loc;
 
 extern const rtems_filesystem_file_handlers_r rtems_bsd_sysgen_nodeops;
-extern const rtems_filesystem_file_handlers_r rtems_bsd_sysgen_imfsnodeops;
 extern const rtems_filesystem_file_handlers_r rtems_bsd_sysgen_dirops;
 extern const rtems_filesystem_file_handlers_r rtems_bsd_sysgen_fileops;
 
@@ -93,16 +92,6 @@ rtems_bsd_libio_loc_to_iop(const 
rtems_filesystem_location_info_t *loc)
->node_access;
 }
 
-struct socket;
-
-static inline struct socket *
-rtems_bsd_libio_imfs_loc_to_so(const rtems_filesystem_location_info_t *loc)
-{
-   return (struct socket *)RTEMS_DECONST(
-   rtems_filesystem_location_info_t *, loc)
-   ->node_access_2;
-}
-
 static struct vnode *
 rtems_bsd_libio_loc_to_vnode(const rtems_filesystem_location_info_t *loc)
 {
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 7caeecf8..fc554fad 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -146,25 +146,6 @@ const rtems_filesystem_file_handlers_r 
rtems_bsd_sysgen_nodeops = {
.mmap_h = rtems_filesystem_default_mmap
 };
 
-const rtems_filesystem_file_handlers_r rtems_bsd_sysgen_imfsnodeops = {
-   .open_h = rtems_bsd_sysgen_open_error,
-   .close_h = rtems_bsd_sysgen_close,
-   .read_h = rtems_bsd_sysgen_read,
-   .write_h = rtems_bsd_sysgen_write,
-   .ioctl_h = rtems_bsd_sysgen_ioctl,
-   .lseek_h = rtems_filesystem_default_lseek,
-   .fstat_h = rtems_bsd_sysgen_imfsfstat,
-   .ftruncate_h = rtems_filesystem_default_ftruncate,
-   .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
-   .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
-   .fcntl_h = rtems_bsd_sysgen_fcntl,
-   .poll_h = rtems_bsd_sysgen_poll,
-   .kqfilter_h = rtems_bsd_sysgen_kqfilter,
-   .readv_h = rtems_bsd_sysgen_readv,
-   .writev_h = rtems_bsd_sysgen_writev,
-   .mmap_h = rtems_filesystem_default_mmap
-};
-
 struct file *
 rtems_bsd_iop_to_file(const rtems_libio_t *iop)
 {
@@ -712,51 +693,6 @@ rtems_bsd_sysgen_fstat(
return rtems_bsd_error_to_status_and_errno(error);
 }
 
-int
-rtems_bsd_sysgen_imfsfstat(
-const rtems_filesystem_location_info_t *loc, struct stat *buf)
-{
-   struct thread *td = curthread;
-   struct socket *so = rtems_bsd_libio_imfs_loc_to_so(loc);
-   struct file *fp = NULL;
-   int error;
-   int fd;
-   if (RTEMS_BSD_SYSCALL_TRACE) {
-   printf("bsd: sys: imfsfstat: socket=%p\n", so);
-   }
-   if (td == NULL) {
-   if (RTEMS_BSD_SYSCALL_TRACE) {
-   printf("bsd: sys: fstat: no curthread\n");
-   }
-   return rtems_bsd_error_to_status_and_errno(ENOMEM);
-   }
-   rtems_libio_lock();
-   for (fd = 0; fd < (int)rtems_libio_number_iops; ++fd) {
-   rtems_libio_t *iop;
-
-   iop = rtems_libio_iop(fd);
-   if (iop->pathinfo.handlers == NULL) {
-   continue;
-   }
-   fp = rtems_bsd_iop_to_file(iop);
-   if (fp != NULL && fp->f_data == so) {
-   break;
-   }
-
-   fp = NULL;
-   }
-   rtems_libio_unlock();
-   if (fp != NULL) {
-   if (RTEMS_BSD_SYSCALL_TRACE) {
-   printf("bsd: sys: imfsfstat: %d\n", fd);
-   }
-   error = fo_stat(fp, buf, NULL, td);
-   } else {
-   error = EBADF;
-   }
-   return rtems_bsd_error_to_status_and_errno(error);
-}
-
 int
 rtems_bsd_sysgen_ftruncate(rtems_libio_t *iop, off_t length)
 {
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 16/22] Move socket system calls, avoid VFS

2022-06-24 Thread Sebastian Huber
Collecting all system calls in a single translation unit is not good due to the
library initialization through linker sets.

Revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in the socket API
implementation files.  The goal is to use USB, network, PCI, and NVMe support
without the VFS to reduce the memory and runtime overhead introduced by VFS.

Update #4475.
---
 freebsd/sys/kern/sys_socket.c  | 271 -
 freebsd/sys/kern/uipc_socket.c |  27 +-
 freebsd/sys/kern/uipc_syscalls.c   | 516 +++--
 freebsd/sys/kern/uipc_usrreq.c |  16 +-
 freebsd/sys/sys/socketvar.h|  14 +-
 freebsd/sys/sys/sysproto.h |  10 +-
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 366 --
 testsuite/syscalls01/test_main.c   |   6 +-
 8 files changed, 774 insertions(+), 452 deletions(-)

diff --git a/freebsd/sys/kern/sys_socket.c b/freebsd/sys/kern/sys_socket.c
index 2fde0dd1..587a9806 100644
--- a/freebsd/sys/kern/sys_socket.c
+++ b/freebsd/sys/kern/sys_socket.c
@@ -33,6 +33,9 @@
  * @(#)sys_socket.c8.1 (Berkeley) 6/10/93
  */
 
+#ifdef __rtems__
+#include 
+#endif /* __rtems__ */
 #include 
 __FBSDID("$FreeBSD$");
 
@@ -79,7 +82,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#endif /* __rtems__ */
 
 static SYSCTL_NODE(_kern_ipc, OID_AUTO, aio, CTLFLAG_RD, NULL,
 "socket AIO stats");
@@ -96,7 +98,9 @@ static fo_rdwr_t soo_read;
 static fo_rdwr_t soo_write;
 static fo_ioctl_t soo_ioctl;
 static fo_poll_t soo_poll;
+#endif /* __rtems__ */
 extern fo_kqfilter_t soo_kqfilter;
+#ifndef __rtems__
 static fo_stat_t soo_stat;
 static fo_close_t soo_close;
 static fo_fill_kinfo_t soo_fill_kinfo;
@@ -120,8 +124,13 @@ struct fileops socketops = {
.fo_aio_queue = soo_aio_queue,
.fo_flags = DFLAG_PASSABLE
 };
+#endif /* __rtems__ */
 
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
 int flags, struct thread *td)
 {
@@ -136,8 +145,74 @@ soo_read(struct file *fp, struct uio *uio, struct ucred 
*active_cred,
error = soreceive(so, 0, uio, 0, 0, 0);
return (error);
 }
+#ifdef __rtems__
+static ssize_t
+rtems_bsd_soo_read(rtems_libio_t *iop, void *buffer, size_t count)
+{
+   struct thread *td = rtems_bsd_get_curthread_or_null();
+   struct iovec iov = {
+   .iov_base = buffer,
+   .iov_len = count
+   };
+   struct uio auio = {
+   .uio_iov = ,
+   .uio_iovcnt = 1,
+   .uio_offset = 0,
+   .uio_resid = count,
+   .uio_segflg = UIO_USERSPACE,
+   .uio_rw = UIO_READ,
+   .uio_td = td
+   };
+   int error;
+
+   if (td != NULL) {
+   error = soo_read(iop, , NULL, 0, NULL);
+   } else {
+   error = ENOMEM;
+   }
 
+   if (error == 0) {
+   return (count - auio.uio_resid);
+   } else {
+   rtems_set_errno_and_return_minus_one(error);
+   }
+}
+
+static ssize_t
+rtems_bsd_soo_readv(rtems_libio_t *iop, const struct iovec *iov,
+int iovcnt, ssize_t total)
+{
+   struct thread *td = rtems_bsd_get_curthread_or_null();
+   struct uio auio = {
+   .uio_iov = __DECONST(struct iovec *, iov),
+   .uio_iovcnt = iovcnt,
+   .uio_offset = 0,
+   .uio_resid = total,
+   .uio_segflg = UIO_USERSPACE,
+   .uio_rw = UIO_READ,
+   .uio_td = td
+   };
+   int error;
+
+   if (td != NULL) {
+   error = soo_read(iop, , NULL, 0, NULL);
+   } else {
+   error = ENOMEM;
+   }
+
+   if (error == 0) {
+   return (total - auio.uio_resid);
+   } else {
+   rtems_set_errno_and_return_minus_one(error);
+   }
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int
+#else /* __rtems__ */
 static int
+#endif /* __rtems__ */
 soo_write(struct file *fp, struct uio *uio, struct ucred *active_cred,
 int flags, struct thread *td)
 {
@@ -161,8 +236,74 @@ soo_write(struct file *fp, struct uio *uio, struct ucred 
*active_cred,
}
return (error);
 }
+#ifdef __rtems__
+static ssize_t
+rtems_bsd_soo_write(rtems_libio_t *iop, const void *buffer, size_t count)
+{
+   struct thread *td = rtems_bsd_get_curthread_or_null();
+   struct iovec iov = {
+   .iov_base = __DECONST(void *, buffer),
+   .iov_len = count
+   };
+   struct uio auio = {
+   .uio_iov = ,
+   .uio_iovcnt = 1,
+   .uio_offset = 0,
+   .uio_resid = count,
+   .uio_segflg = UIO_USERSPACE,
+   .uio_rw = UIO_WRITE,
+   .uio_td = td
+   };
+   int error;
+
+   if (td != NULL) {
+   error = soo_write(iop, , NULL, 0, NULL);
+   } else 

[libbsd 12/22] Move kqueue() and kevent(), avoid VFS

2022-06-24 Thread Sebastian Huber
Collecting all system calls in a single translation unit is not good due to the
library initialization through linker sets.

Revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in
"freebsd/sys/kern/kern_event.c".  The goal is to use USB, network, PCI, and
NVMe support without the VFS to reduce the memory and runtime overhead
introduced by VFS.

Update #4475.
---
 freebsd/sys/kern/kern_event.c  | 187 ++---
 freebsd/sys/sys/eventvar.h |   2 +
 freebsd/sys/sys/sysproto.h |   4 -
 rtemsbsd/rtems/rtems-bsd-syscall-api.c |  48 ---
 testsuite/syscalls01/test_main.c   |   7 +-
 5 files changed, 173 insertions(+), 75 deletions(-)

diff --git a/freebsd/sys/kern/kern_event.c b/freebsd/sys/kern/kern_event.c
index f5682b03..0d8332da 100644
--- a/freebsd/sys/kern/kern_event.c
+++ b/freebsd/sys/kern/kern_event.c
@@ -40,6 +40,9 @@ __FBSDID("$FreeBSD$");
 #define_WANT_FREEBSD11_KEVENT
 #endif
 
+#ifdef __rtems__
+#include 
+#endif /* __rtems__ */
 #include 
 #include 
 #include 
@@ -81,6 +84,8 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #ifdef __rtems__
+#include 
+
 /* Maintain a global kqueue list on RTEMS */
 static struct kqlist fd_kqlist;
 #endif /* __rtems__ */
@@ -129,6 +134,7 @@ static int  kern_kevent_generic(struct thread *td,
struct g_kevent_args *uap,
struct kevent_copyops *k_ops, const char *struct_name);
 
+#ifndef __rtems__
 static fo_rdwr_t   kqueue_read;
 static fo_rdwr_t   kqueue_write;
 static fo_truncate_t   kqueue_truncate;
@@ -153,6 +159,9 @@ static struct fileops kqueueops = {
.fo_sendfile = invfo_sendfile,
.fo_fill_kinfo = kqueue_fill_kinfo,
 };
+#else /* __rtems__ */
+static const rtems_filesystem_file_handlers_r kqueueops;
+#endif /* __rtems__ */
 
 static int knote_attach(struct knote *kn, struct kqueue *kq);
 static voidknote_drop(struct knote *kn, struct thread *td);
@@ -404,11 +413,7 @@ filt_fileattach(struct knote *kn)
 static int
 kqueue_kqfilter(struct file *fp, struct knote *kn)
 {
-#ifndef __rtems__
struct kqueue *kq = kn->kn_fp->f_data;
-#else /* __rtems__ */
-   struct kqueue *kq = rtems_bsd_knote_to_file(kn);
-#endif /* __rtems__ */
 
if (kn->kn_filter != EVFILT_READ)
return (EINVAL);
@@ -419,15 +424,20 @@ kqueue_kqfilter(struct file *fp, struct knote *kn)
 
return (0);
 }
+#ifdef __rtems__
+static int
+rtems_bsd_kqueue_kqfilter(rtems_libio_t *iop, struct knote *kn)
+{
+
+   (void)iop;
+   return kqueue_kqfilter(NULL, kn);
+}
+#endif /* __rtems__ */
 
 static void
 filt_kqdetach(struct knote *kn)
 {
-#ifndef __rtems__
struct kqueue *kq = kn->kn_fp->f_data;
-#else /* __rtems__ */
-   struct kqueue *kq = rtems_bsd_knote_to_file(kn);
-#endif /* __rtems__ */
 
knlist_remove(>kq_sel.si_note, kn, 0);
 }
@@ -436,11 +446,7 @@ filt_kqdetach(struct knote *kn)
 static int
 filt_kqueue(struct knote *kn, long hint)
 {
-#ifndef __rtems__
struct kqueue *kq = kn->kn_fp->f_data;
-#else /* __rtems__ */
-   struct kqueue *kq = rtems_bsd_knote_to_file(kn);
-#endif /* __rtems__ */
 
kn->kn_data = kq->kq_count;
return (kn->kn_data > 0);
@@ -992,6 +998,12 @@ filt_usertouch(struct knote *kn, struct kevent *kev, 
u_long type)
}
 }
 
+#ifdef __rtems__
+static int
+kern_kqueue(struct thread *td, int flags, struct filecaps *fcaps);
+
+static
+#endif /* __rtems__ */
 int
 sys_kqueue(struct thread *td, struct kqueue_args *uap)
 {
@@ -1018,10 +1030,15 @@ kern_kqueue(struct thread *td, int flags, struct 
filecaps *fcaps)
struct ucred *cred;
int fd, error;
 
+#ifndef __rtems__
fdp = td->td_proc->p_fd;
cred = td->td_ucred;
if (!chgkqcnt(cred->cr_ruidinfo, 1, lim_cur(td, RLIMIT_KQUEUES)))
return (ENOMEM);
+#else /* __rtems__ */
+   (void)fdp;
+   (void)cred;
+#endif /* __rtems__ */
 
error = falloc_caps(td, , , flags, fcaps);
if (error != 0) {
@@ -1032,8 +1049,10 @@ kern_kqueue(struct thread *td, int flags, struct 
filecaps *fcaps)
/* An extra reference on `fp' has been held for us by falloc(). */
kq = malloc(sizeof *kq, M_KQUEUE, M_WAITOK | M_ZERO);
kqueue_init(kq);
+#ifndef __rtems__
kq->kq_fdp = fdp;
kq->kq_cred = crhold(cred);
+#endif /* __rtems__ */
 
FILEDESC_XLOCK(fdp);
 #ifndef __rtems__
@@ -1051,16 +1070,50 @@ kern_kqueue(struct thread *td, int flags, struct 
filecaps *fcaps)
td->td_retval[0] = fd;
return (0);
 }
+#ifdef __rtems__
+int
+kqueue(void)
+{
+   struct thread *td = rtems_bsd_get_curthread_or_null();
+   struct kqueue_args ua;
+   int error;
+
+   if (td != NULL) {
+   error = sys_kqueue(td, );
+   } else {
+   error = ENOMEM;
+   }
+
+   if (error == 0) {
+   return td->td_retval[0];
+   } else {
+   

[libbsd 11/22] Add struct file wrapper

2022-06-24 Thread Sebastian Huber
Add a struct file wrapper in  as an alternative to the
full FreeBSD struct file in .  This allows using  for
FreeBSD file systems (VFS) and the wrapper for other areas such as devfs,
cryptodev, sockets, kqueue, poll, and select which do not need the VFS support.

Update #4475.
---
 rtemsbsd/include/rtems/bsd/sys/file.h  | 248 +
 rtemsbsd/rtems/rtems-kernel-get-file.c |   9 +-
 2 files changed, 252 insertions(+), 5 deletions(-)
 create mode 100644 rtemsbsd/include/rtems/bsd/sys/file.h

diff --git a/rtemsbsd/include/rtems/bsd/sys/file.h 
b/rtemsbsd/include/rtems/bsd/sys/file.h
new file mode 100644
index ..04898677
--- /dev/null
+++ b/rtemsbsd/include/rtems/bsd/sys/file.h
@@ -0,0 +1,248 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup rtems_bsd_rtems
+ *
+ * @brief This header file provides a alternative implementation for interfaces
+ *   normally provided via .
+ */
+
+/*
+ * Copyright (C) 2013, 2022 embedded brains GmbH
+ *
+ * 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.
+ */
+
+#ifndef _SYS_FILE_H_
+#define_SYS_FILE_H_
+#define_SYS_FILEDESC_H_
+
+#include 
+#include 
+#include 
+#include 
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+struct filecaps;
+struct filedesc;
+struct ucred;
+
+extern const rtems_filesystem_file_handlers_r socketops;
+
+#definefile rtems_libio_tt
+#definef_data pathinfo.node_access_2
+
+#definemaxfiles rtems_libio_number_iops
+
+typedef int fo_kqfilter_t(struct file *, struct knote *);
+
+static inline void *
+rtems_bsd_loc_to_f_data(const rtems_filesystem_location_info_t *loc)
+{
+   return loc->node_access_2;
+}
+
+static inline uint32_t
+rtems_bsd_fflag_to_libio_flags(u_int fflag)
+{
+   uint32_t libio_flags = 0;
+
+   if ((fflag & FREAD) == FREAD) {
+   libio_flags |= LIBIO_FLAGS_READ;
+   }
+
+   if ((fflag & FWRITE) == FWRITE) {
+   libio_flags |= LIBIO_FLAGS_WRITE;
+   }
+
+   if ((fflag & FNONBLOCK) == FNONBLOCK) {
+   libio_flags |= LIBIO_FLAGS_NO_DELAY;
+   }
+
+   return (libio_flags);
+}
+
+static inline u_int
+rtems_bsd_libio_flags_to_fflag(uint32_t libio_flags)
+{
+   u_int fflag = 0;
+
+   if ((libio_flags & LIBIO_FLAGS_READ) == LIBIO_FLAGS_READ) {
+   fflag |= FREAD;
+   }
+
+   if ((libio_flags & LIBIO_FLAGS_WRITE) == LIBIO_FLAGS_WRITE) {
+   fflag |= FWRITE;
+   }
+
+   if ((libio_flags & LIBIO_FLAGS_NO_DELAY) == LIBIO_FLAGS_NO_DELAY) {
+   fflag |= FNONBLOCK;
+   }
+
+   return (fflag);
+}
+
+static int inline
+rtems_bsd_error_to_status_and_errno(int error)
+{
+   if (error == 0) {
+   return 0;
+   } else {
+   rtems_set_errno_and_return_minus_one(error);
+   }
+}
+
+struct file *rtems_bsd_get_file(int fd);
+
+static inline int
+rtems_bsd_do_fget(int fd, struct file **fpp)
+{
+   struct file *fp;
+
+   fp = rtems_bsd_get_file(fd);
+   *fpp = fp;
+   return (fp != NULL ? 0 : EBADF);
+}
+
+#undef fget
+#definefget(td, fd, rights, fpp) rtems_bsd_do_fget(fd, fpp)
+
+static inline void
+rtems_bsd_finit(struct file *fp, u_int fflag, void *data,
+const rtems_filesystem_file_handlers_r *ops)
+{
+
+   fp->f_data = data;
+   fp->pathinfo.handlers = ops;
+   rtems_libio_iop_flags_set(fp, LIBIO_FLAGS_OPEN |
+   rtems_bsd_fflag_to_libio_flags(fflag));
+}
+
+#undef finit
+#definefinit(fp, fflag, type, data, ops) rtems_bsd_finit(fp, fflag, 
data, ops)
+
+/*
+ * WARNING: fdalloc() and falloc_caps() do not increment the reference count of
+ * the file descriptor in contrast to 

[libbsd 21/22] Make rtems_bsd_iop_to_file() static

2022-06-24 Thread Sebastian Huber
Update #4475.
---
 rtemsbsd/include/machine/rtems-bsd-libio.h | 2 --
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/rtemsbsd/include/machine/rtems-bsd-libio.h 
b/rtemsbsd/include/machine/rtems-bsd-libio.h
index 6dd75394..1d2cd0d2 100644
--- a/rtemsbsd/include/machine/rtems-bsd-libio.h
+++ b/rtemsbsd/include/machine/rtems-bsd-libio.h
@@ -120,8 +120,6 @@ rtems_bsd_knote_to_file(const struct knote *kn)
return (kn->kn_fp->data1);
 }
 
-struct file *rtems_bsd_iop_to_file(const rtems_libio_t *iop);
-
 /*
  * Set the vnode in the libio location.
  */
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index fc554fad..be5c615f 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -146,7 +146,7 @@ const rtems_filesystem_file_handlers_r 
rtems_bsd_sysgen_nodeops = {
.mmap_h = rtems_filesystem_default_mmap
 };
 
-struct file *
+static struct file *
 rtems_bsd_iop_to_file(const rtems_libio_t *iop)
 {
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 19/22] Move VFS BIO initialization

2022-06-24 Thread Sebastian Huber
rtems_bsd_initialize() should initialize the bare minimum.

Update #4475.
---
 freebsd/sys/kern/vfs_bio.c| 24 ++-
 .../machine/rtems-bsd-kernel-namespace.h  |  1 -
 rtemsbsd/rtems/rtems-kernel-init.c| 20 
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/freebsd/sys/kern/vfs_bio.c b/freebsd/sys/kern/vfs_bio.c
index 7be96690..594f878c 100644
--- a/freebsd/sys/kern/vfs_bio.c
+++ b/freebsd/sys/kern/vfs_bio.c
@@ -95,7 +95,14 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #ifdef __rtems__
+#include 
+#include 
+
+#include 
+
 int bio_transient_maxcnt = 1024;
+long maxbcache;
+static caddr_t unmapped_base;
 #endif /* __rtems__ */
 static MALLOC_DEFINE(M_BIOBUF, "biobuf", "BIO buffer");
 
@@ -1201,7 +1208,6 @@ bufinit(void)
 #ifndef __rtems__
unmapped_buf = (caddr_t)kva_alloc(MAXPHYS);
 #else /* __rtems__ */
-   extern caddr_t unmapped_base;
unmapped_buf = (caddr_t)unmapped_base;
 #endif /* __rtems__ */
 
@@ -1332,6 +1338,22 @@ bufinit(void)
bufdefragcnt = counter_u64_alloc(M_WAITOK);
bufkvaspace = counter_u64_alloc(M_WAITOK);
 }
+#ifdef __rtems__
+static void
+vfs_bio_init(void *dummy)
+{
+
+   maxbcache = rtems_bsd_get_allocator_domain_size(
+   RTEMS_BSD_ALLOCATOR_DOMAIN_BIO);
+   unmapped_base = (caddr_t)rtems_heap_allocate_aligned_with_boundary(
+   maxbcache, CACHE_LINE_SIZE, 0);
+   BSD_ASSERT(unmapped_base != NULL);
+   kern_vfs_bio_buffer_alloc(unmapped_base, maxbcache);
+   bufinit();
+   vm_pager_bufferinit();
+}
+SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, vfs_bio_init, NULL);
+#endif /* __rtems__ */
 
 #ifdef INVARIANTS
 static inline void
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 9a7b0c09..0b5fa321 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -6381,7 +6381,6 @@
 #defineuma_zone_set_zinit _bsd_uma_zone_set_zinit
 #defineuma_zsecond_create _bsd_uma_zsecond_create
 #defineuma_zwait _bsd_uma_zwait
-#defineunmapped_base _bsd_unmapped_base
 #defineunmapped_buf _bsd_unmapped_buf
 #defineunmapped_buf_allowed _bsd_unmapped_buf_allowed
 #defineunp_copy_peercred _bsd_unp_copy_peercred
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c 
b/rtemsbsd/rtems/rtems-kernel-init.c
index 9b24ba6d..af563c81 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -67,7 +67,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 SYSINIT_REFERENCE(configure1);
@@ -108,8 +107,6 @@ sbintime_t tc_tick_sbt;
 int tc_precexp;
 int maxproc;
 int ngroups_max;
-caddr_t unmapped_base;
-long maxbcache;
 struct sx allproc_lock;
 struct vmem *rtems_bsd_transient_arena;
 int nbuf;   /* The number of buffer headers */
@@ -128,15 +125,6 @@ SYSCTL_INT(_kern_smp, OID_AUTO, maxid, CTLFLAG_RD | 
CTLFLAG_CAPRD,
 SYSCTL_INT(_kern_smp, OID_AUTO, maxcpus, CTLFLAG_RD | CTLFLAG_CAPRD,
 _maxcpus, 0, "Max number of CPUs that the system was compiled for.");
 
-static void
-cpu_startup(void *dummy)
-{
-   kern_vfs_bio_buffer_alloc(unmapped_base, maxbcache);
-   bufinit();
-   vm_pager_bufferinit();
-}
-SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
-
 static struct filedesc p_fd = {
 .fd_cmask = CMASK
 };
@@ -211,14 +199,6 @@ rtems_bsd_initialize(void)
maxproc = 16;
ngroups_max = 4;
 
-   maxbcache = rtems_bsd_get_allocator_domain_size(
-   RTEMS_BSD_ALLOCATOR_DOMAIN_BIO);
-   unmapped_base = (caddr_t)rtems_heap_allocate_aligned_with_boundary(
-   maxbcache, CACHE_LINE_SIZE, 0);
-   if (unmapped_base == NULL) {
-   return RTEMS_UNSATISFIED;
-   }
-
mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
 
sc = rtems_timer_initiate_server(rtems_bsd_get_task_priority(name),
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 17/22] Move bio_transient_maxcnt

2022-06-24 Thread Sebastian Huber
rtems_bsd_initialize() should initialize the bare minimum.

Update #4475.
---
 freebsd/sys/kern/vfs_bio.c | 3 +++
 rtemsbsd/rtems/rtems-kernel-init.c | 2 --
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/freebsd/sys/kern/vfs_bio.c b/freebsd/sys/kern/vfs_bio.c
index 50e87ff8..1177b907 100644
--- a/freebsd/sys/kern/vfs_bio.c
+++ b/freebsd/sys/kern/vfs_bio.c
@@ -94,6 +94,9 @@ __FBSDID("$FreeBSD$");
 #endif /* __rtems__ */
 #include 
 
+#ifdef __rtems__
+int bio_transient_maxcnt = 1024;
+#endif /* __rtems__ */
 static MALLOC_DEFINE(M_BIOBUF, "biobuf", "BIO buffer");
 
 struct bio_ops bioops; /* I/O operation notification */
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c 
b/rtemsbsd/rtems/rtems-kernel-init.c
index 305010b1..11c1861b 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -111,7 +111,6 @@ int ngroups_max;
 int unmapped_buf_allowed;
 caddr_t unmapped_base;
 long maxbcache;
-int bio_transient_maxcnt;
 struct sx allproc_lock;
 struct vmem *rtems_bsd_transient_arena;
 int nbuf;   /* The number of buffer headers */
@@ -208,7 +207,6 @@ rtems_bsd_initialize(void)
sbt_timethreshold = bttosbt(bt_timethreshold);
sbt_tickthreshold = bttosbt(bt_tickthreshold);
maxid_maxcpus = (int)rtems_scheduler_get_processor_maximum();
-   bio_transient_maxcnt = 1024;
sx_init(_lock, "allproc");
 
maxproc = 16;
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 03/22] Update kernel namespace

2022-06-24 Thread Sebastian Huber
Update #4475.
---
 .../machine/rtems-bsd-kernel-namespace.h  | 391 ++
 1 file changed, 391 insertions(+)

diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 599c7d82..85f66912 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -134,6 +134,34 @@
 #defineM_IPSEC_SR _bsd_M_IPSEC_SR
 #defineM_LLTABLE _bsd_M_LLTABLE
 #defineM_MOUNT _bsd_M_MOUNT
+#defineM_NEWNFSCLCLIENT _bsd_M_NEWNFSCLCLIENT
+#defineM_NEWNFSCLDELEG _bsd_M_NEWNFSCLDELEG
+#defineM_NEWNFSCLDS _bsd_M_NEWNFSCLDS
+#defineM_NEWNFSCLLOCK _bsd_M_NEWNFSCLLOCK
+#defineM_NEWNFSCLLOCKOWNER _bsd_M_NEWNFSCLLOCKOWNER
+#defineM_NEWNFSCLOPEN _bsd_M_NEWNFSCLOPEN
+#defineM_NEWNFSCLOWNER _bsd_M_NEWNFSCLOWNER
+#defineM_NEWNFSDCLIENT _bsd_M_NEWNFSDCLIENT
+#defineM_NEWNFSDEVINFO _bsd_M_NEWNFSDEVINFO
+#defineM_NEWNFSDIRECTIO _bsd_M_NEWNFSDIRECTIO
+#defineM_NEWNFSDIROFF _bsd_M_NEWNFSDIROFF
+#defineM_NEWNFSDLOCK _bsd_M_NEWNFSDLOCK
+#defineM_NEWNFSDLOCKFILE _bsd_M_NEWNFSDLOCKFILE
+#defineM_NEWNFSDREQ _bsd_M_NEWNFSDREQ
+#defineM_NEWNFSDROLLBACK _bsd_M_NEWNFSDROLLBACK
+#defineM_NEWNFSDSESSION _bsd_M_NEWNFSDSESSION
+#defineM_NEWNFSDSTATE _bsd_M_NEWNFSDSTATE
+#defineM_NEWNFSFH _bsd_M_NEWNFSFH
+#defineM_NEWNFSFLAYOUT _bsd_M_NEWNFSFLAYOUT
+#defineM_NEWNFSLAYOUT _bsd_M_NEWNFSLAYOUT
+#defineM_NEWNFSLAYRECALL _bsd_M_NEWNFSLAYRECALL
+#defineM_NEWNFSMNT _bsd_M_NEWNFSMNT
+#defineM_NEWNFSREQ _bsd_M_NEWNFSREQ
+#defineM_NEWNFSRVCACHE _bsd_M_NEWNFSRVCACHE
+#defineM_NEWNFSSOCKREQ _bsd_M_NEWNFSSOCKREQ
+#defineM_NEWNFSSTRING _bsd_M_NEWNFSSTRING
+#defineM_NEWNFSUSERGROUP _bsd_M_NEWNFSUSERGROUP
+#defineM_NEWNFSV4NODE _bsd_M_NEWNFSV4NODE
 #defineM_NVME _bsd_M_NVME
 #defineM_OFWPROP _bsd_M_OFWPROP
 #defineM_PCB _bsd_M_PCB
@@ -153,6 +181,7 @@
 #defineM_VNODE _bsd_M_VNODE
 #defineM_VNODE_MARKER _bsd_M_VNODE_MARKER
 #defineM_XDATA _bsd_M_XDATA
+#defineM_XDMA _bsd_M_XDMA
 #defineNDFREE _bsd_NDFREE
 #defineNDINIT_ALL _bsd_NDINIT_ALL
 #defineOF_call_method _bsd_OF_call_method
@@ -757,6 +786,7 @@
 #defineblist_resize _bsd_blist_resize
 #defineblist_stats _bsd_blist_stats
 #definebnoreuselist _bsd_bnoreuselist
+#definebootpc_init _bsd_bootpc_init
 #definebpf_buffer_append_bytes _bsd_bpf_buffer_append_bytes
 #definebpf_buffer_append_mbuf _bsd_bpf_buffer_append_mbuf
 #definebpf_buffer_free _bsd_bpf_buffer_free
@@ -813,6 +843,7 @@
 #definebucket_zones _bsd_bucket_zones
 #definebuf_dirty_count_severe _bsd_buf_dirty_count_severe
 #definebuf_ops_bio _bsd_buf_ops_bio
+#definebuf_ops_newnfs _bsd_buf_ops_newnfs
 #definebuf_ring_alloc _bsd_buf_ring_alloc
 #definebuf_ring_free _bsd_buf_ring_free
 #definebuf_wmesg _bsd_buf_wmesg
@@ -1785,6 +1816,11 @@
 #definefgetvp _bsd_fgetvp
 #definefgetvp_read _bsd_fgetvp_read
 #definefgetvp_rights _bsd_fgetvp_rights
+#definefha_assign _bsd_fha_assign
+#definefha_init _bsd_fha_init
+#definefha_nd_complete _bsd_fha_nd_complete
+#definefha_uninit _bsd_fha_uninit
+#definefhe_stats_sysctl _bsd_fhe_stats_sysctl
 #definefib4_free_nh_ext _bsd_fib4_free_nh_ext
 #definefib4_lookup_nh_basic _bsd_fib4_lookup_nh_basic
 #definefib4_lookup_nh_ext _bsd_fib4_lookup_nh_ext
@@ -3285,6 +3321,8 @@
 #definekqfd_register _bsd_kqfd_register
 #definekqueue_add_filteropts _bsd_kqueue_add_filteropts
 #definekqueue_del_filteropts _bsd_kqueue_del_filteropts
+#definekrpc_call _bsd_krpc_call
+#definekrpc_portmap _bsd_krpc_portmap
 #definekthread_add _bsd_kthread_add
 #definekthread_exit _bsd_kthread_exit
 #definekthread_start _bsd_kthread_start
@@ -3559,7 +3597,54 @@
 #definenatt_cksum_policy _bsd_natt_cksum_policy
 #definenbuf _bsd_nbuf
 #definenchstats _bsd_nchstats
+#definencl_asyncio _bsd_ncl_asyncio
+#definencl_bioread _bsd_ncl_bioread
+#definencl_call_invalcaches _bsd_ncl_call_invalcaches
+#definencl_clearcommit _bsd_ncl_clearcommit
+#definencl_commit _bsd_ncl_commit
+#definencl_dircookie_lock _bsd_ncl_dircookie_lock
+#definencl_dircookie_unlock _bsd_ncl_dircookie_unlock
+#definencl_doio _bsd_ncl_doio
+#definencl_doio_directwrite _bsd_ncl_doio_directwrite
+#definencl_excl_finish _bsd_ncl_excl_finish
+#definencl_excl_start _bsd_ncl_excl_start
+#definencl_flush _bsd_ncl_flush
+#definencl_fsinfo _bsd_ncl_fsinfo
+#define

[libbsd 13/22] cryptodev: Do not use VFS

2022-06-24 Thread Sebastian Huber
Revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in
"freebsd/sys/opencrypto/cryptodev.c".  The goal is to use USB, network, PCI,
and NVMe support without the VFS to reduce the memory and runtime overhead
introduced by VFS.

Update #4475.
---
 freebsd/sys/opencrypto/cryptodev.c | 70 ++
 1 file changed, 70 insertions(+)

diff --git a/freebsd/sys/opencrypto/cryptodev.c 
b/freebsd/sys/opencrypto/cryptodev.c
index 97459559..babff6b3 100644
--- a/freebsd/sys/opencrypto/cryptodev.c
+++ b/freebsd/sys/opencrypto/cryptodev.c
@@ -40,6 +40,9 @@
  * Materiel Command, USAF, under agreement number F30602-01-2-0537.
  */
 
+#ifdef __rtems__
+#include 
+#endif /* __rtems__ */
 #include 
 __FBSDID("$FreeBSD$");
 
@@ -303,6 +306,7 @@ SYSCTL_TIMEVAL_SEC(_kern, OID_AUTO, 
cryptodev_warn_interval, CTLFLAG_RW,
 ,
 "Delay in seconds between warnings of deprecated /dev/crypto algorithms");
 
+#ifndef __rtems__
 static int cryptof_ioctl(struct file *, u_long, void *,
struct ucred *, struct thread *);
 static int cryptof_stat(struct file *, struct stat *,
@@ -325,6 +329,9 @@ static struct fileops cryptofops = {
 .fo_sendfile = invfo_sendfile,
 .fo_fill_kinfo = cryptof_fill_kinfo,
 };
+#else /* __rtems__ */
+static const rtems_filesystem_file_handlers_r cryptofops;
+#endif /* __rtems__ */
 
 static struct csession *csefind(struct fcrypt *, u_int);
 static bool csedelete(struct fcrypt *, u_int);
@@ -768,6 +775,24 @@ bail:
return (error);
 #undef SES2
 }
+#ifdef __rtems__
+static int
+rtems_bsd_cryptof_ioctl(rtems_libio_t *iop, ioctl_command_t request,
+void *buffer)
+{
+   struct thread *td;
+   int error;
+
+   td = rtems_bsd_get_curthread_or_null();
+   if (td != NULL) {
+   error = cryptof_ioctl(iop, request, buffer, NULL, td);
+   } else {
+   error = ENOMEM;
+   }
+
+   return (rtems_bsd_error_to_status_and_errno(error));
+}
+#endif /* __rtems__ */
 
 static int cryptodev_cb(struct cryptop *);
 
@@ -1358,11 +1383,17 @@ cryptodev_find(struct crypt_find_op *find)
 
 /* ARGSUSED */
 static int
+#ifndef __rtems__
 cryptof_stat(
struct file *fp,
struct stat *sb,
struct ucred *active_cred,
struct thread *td)
+#else /* __rtems__ */
+rtems_bsd_cryptof_stat(const rtems_filesystem_location_info_t *loc,
+struct stat *buf
+#endif /* __rtems__ */
+)
 {
 
return (EOPNOTSUPP);
@@ -1386,7 +1417,25 @@ cryptof_close(struct file *fp, struct thread *td)
fp->f_data = NULL;
return 0;
 }
+#ifdef __rtems__
+static int
+rtems_bsd_cryptof_close(rtems_libio_t *iop)
+{
+   struct thread *td;
+   int error;
+
+   td = rtems_bsd_get_curthread_or_null();
+   if (td != NULL) {
+   error = cryptof_close(iop, td);
+   } else {
+   error = ENOMEM;
+   }
 
+   return (rtems_bsd_error_to_status_and_errno(error));
+}
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 static int
 cryptof_fill_kinfo(struct file *fp, struct kinfo_file *kif, struct filedesc 
*fdp)
 {
@@ -1394,6 +1443,7 @@ cryptof_fill_kinfo(struct file *fp, struct kinfo_file 
*kif, struct filedesc *fdp
kif->kf_type = KF_TYPE_CRYPTO;
return (0);
 }
+#endif /* __rtems__ */
 
 static struct csession *
 csefind(struct fcrypt *fcr, u_int ses)
@@ -1573,3 +1623,23 @@ MODULE_VERSION(cryptodev, 1);
 DECLARE_MODULE(cryptodev, cryptodev_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
 MODULE_DEPEND(cryptodev, crypto, 1, 1, 1);
 MODULE_DEPEND(cryptodev, zlib, 1, 1, 1);
+#ifdef __rtems__
+static const rtems_filesystem_file_handlers_r cryptofops = {
+   .open_h = rtems_filesystem_default_open,
+   .close_h = rtems_bsd_cryptof_close,
+   .read_h = rtems_filesystem_default_read,
+   .write_h = rtems_filesystem_default_write,
+   .ioctl_h = rtems_bsd_cryptof_ioctl,
+   .lseek_h = rtems_filesystem_default_lseek,
+   .fstat_h = rtems_bsd_cryptof_stat,
+   .ftruncate_h = rtems_filesystem_default_ftruncate,
+   .fsync_h = rtems_filesystem_default_fsync_or_fdatasync,
+   .fdatasync_h = rtems_filesystem_default_fsync_or_fdatasync,
+   .fcntl_h = rtems_filesystem_default_fcntl,
+   .poll_h = rtems_filesystem_default_poll,
+   .kqfilter_h = rtems_filesystem_default_kqfilter,
+   .readv_h = rtems_filesystem_default_readv,
+   .writev_h = rtems_filesystem_default_writev,
+   .mmap_h = rtems_filesystem_default_mmap
+};
+#endif /* __rtems__ */
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 08/22] devfs: Do not use FreeBSD file descriptors

2022-06-24 Thread Sebastian Huber
Revert commit 6514d561587fd1527fe6a26cb43e6b5742c8c779 in
"rtemsbsd/sys/fs/devfs/devfs_devs.c".  Using the FreeBSD file descriptors for
the device file system is unnecessary.

Update #4475.
---
 freebsd/sys/fs/devfs/devfs_int.h   |   3 +-
 freebsd/sys/fs/devfs/devfs_vnops.c |   4 +-
 rtemsbsd/sys/fs/devfs/devfs_devs.c | 181 -
 3 files changed, 53 insertions(+), 135 deletions(-)

diff --git a/freebsd/sys/fs/devfs/devfs_int.h b/freebsd/sys/fs/devfs/devfs_int.h
index e3991cbd..51064ed1 100644
--- a/freebsd/sys/fs/devfs/devfs_int.h
+++ b/freebsd/sys/fs/devfs/devfs_int.h
@@ -95,7 +95,8 @@ extern struct sx clone_drain_lock;
 extern struct mtx cdevpriv_mtx;
 extern TAILQ_HEAD(cdev_priv_list, cdev_priv) cdevp_list;
 #ifdef __rtems__
-void devfs_fpdrop(struct file *);
+struct rtems_libio_tt;
+void devfs_fpdrop(struct rtems_libio_tt *);
 #endif /* __rtems__ */
 
 #endif /* _KERNEL */
diff --git a/freebsd/sys/fs/devfs/devfs_vnops.c 
b/freebsd/sys/fs/devfs/devfs_vnops.c
index f1027e6f..9ca39259 100644
--- a/freebsd/sys/fs/devfs/devfs_vnops.c
+++ b/freebsd/sys/fs/devfs/devfs_vnops.c
@@ -209,10 +209,12 @@ devfs_destroy_cdevpriv(struct cdev_privdata *p)
 
 #ifndef __rtems__
 static void
+devfs_fpdrop(struct file *fp)
 #else /* __rtems__ */
+#definef_cdevpriv data1
 void
+devfs_fpdrop(rtems_libio_t *fp)
 #endif /* __rtems__ */
-devfs_fpdrop(struct file *fp)
 {
struct cdev_privdata *p;
 
diff --git a/rtemsbsd/sys/fs/devfs/devfs_devs.c 
b/rtemsbsd/sys/fs/devfs/devfs_devs.c
index 39a38d62..c105661b 100644
--- a/rtemsbsd/sys/fs/devfs/devfs_devs.c
+++ b/rtemsbsd/sys/fs/devfs/devfs_devs.c
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -43,8 +42,6 @@
 #include 
 #include 
 
-#include 
-
 #include 
 
 #include 
@@ -76,24 +73,15 @@ devfs_imfs_open(rtems_libio_t *iop, const char *path, int 
oflag, mode_t mode)
 {
struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
struct thread *td = rtems_bsd_get_curthread_or_null();
-   struct file *fp = NULL;
-   struct cdevsw *dsw = NULL;
struct file *fpop;
+   struct cdevsw *dsw;
int error, ref;
-   int fd = -1;
 
if (td != NULL) {
if (cdev == NULL) {
error = ENXIO;
goto err;
}
-   error = falloc(td, , , oflag);
-   if (error != 0)
-   goto err;
-   finit(fp, FREAD | FWRITE, DTYPE_DEV, NULL, NULL);
-   rtems_libio_iop_hold(iop);
-   rtems_bsd_libio_iop_set_bsd_descriptor(iop, fd);
-   rtems_bsd_libio_iop_set_bsd_file(iop, fp);
if (cdev->si_flags & SI_ALIAS) {
cdev = cdev->si_parent;
}
@@ -103,26 +91,19 @@ devfs_imfs_open(rtems_libio_t *iop, const char *path, int 
oflag, mode_t mode)
goto err;
}
fpop = td->td_fpop;
-   curthread->td_fpop = fp;
-   fp->f_cdevpriv = NULL;
+   curthread->td_fpop = (struct file *)iop;
+   iop->data1 = NULL;
error = dsw->d_open(cdev, oflag + 1, 0, td);
/* Clean up any cdevpriv upon error. */
if (error != 0)
devfs_clear_cdevpriv();
curthread->td_fpop = fpop;
+   dev_relthread(cdev, ref);
} else {
error = ENOMEM;
}
 
 err:
-   if (dsw != NULL)
-   dev_relthread(cdev, ref);
-   if (td != NULL && fp != NULL) {
-   if (error != 0)
-   fdclose(td, fp, fd);
-   else
-   fdrop(fp, td);
-   }
return rtems_bsd_error_to_status_and_errno(error);
 }
 
@@ -132,9 +113,8 @@ devfs_imfs_close(rtems_libio_t *iop)
struct cdev *cdev = devfs_imfs_get_context_by_iop(iop);
struct thread *td = rtems_bsd_get_curthread_or_null();
int flags = rtems_libio_to_fcntl_flags(iop->flags);
-   struct file *fp = NULL;
-   struct cdevsw *dsw = NULL;
struct file *fpop;
+   struct cdevsw *dsw;
int error, ref;
 
if (td != NULL) {
@@ -145,31 +125,23 @@ devfs_imfs_close(rtems_libio_t *iop)
if (cdev->si_flags & SI_ALIAS) {
cdev = cdev->si_parent;
}
-   fp = rtems_bsd_libio_iop_to_file_hold(iop, td);
-   if (fp == NULL) {
-   error = EBADF;
-   goto err;
-   }
dsw = dev_refthread(cdev, );
if (dsw == NULL) {
error = ENXIO;
goto err;
}
fpop = td->td_fpop;
-   curthread->td_fpop = fp;
+   curthread->td_fpop = (struct file *)iop;
error = dsw->d_close(cdev, flags, 0, td);

[libbsd 04/22] Move setfib() back to route.c

2022-06-24 Thread Sebastian Huber
Collecting all system calls in a single translation unit is not good due to the
library initialization through linker sets.

Update #4475.
---
 freebsd/sys/net/route.c| 18 ++
 freebsd/sys/sys/sysproto.h |  2 --
 .../machine/rtems-bsd-kernel-namespace.h   |  1 -
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 14 --
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/freebsd/sys/net/route.c b/freebsd/sys/net/route.c
index 2e9883a1..adbf91bd 100644
--- a/freebsd/sys/net/route.c
+++ b/freebsd/sys/net/route.c
@@ -407,6 +407,9 @@ struct setfib_args {
int fibnum;
 };
 #endif
+#ifdef __rtems__
+static
+#endif /* __rtems__ */
 int
 sys_setfib(struct thread *td, struct setfib_args *uap)
 {
@@ -420,6 +423,20 @@ sys_setfib(struct thread *td, struct setfib_args *uap)
 #endif /* __rtems__ */
return (0);
 }
+#ifdef __rtems__
+int
+setfib(int fibnum)
+{
+   struct setfib_args ua = {
+   .fibnum = fibnum
+   };
+   int error;
+
+   error = sys_setfib(NULL, );
+
+   return rtems_bsd_error_to_status_and_errno(error);
+}
+#endif /* __rtems__ */
 
 /*
  * Packet routing routines.
@@ -2285,3 +2302,4 @@ rt_newaddrmsg_fib(int cmd, struct ifaddr *ifa, int error, 
struct rtentry *rt,
rt_addrmsg(cmd, ifa, fibnum);
}
 }
+
diff --git a/freebsd/sys/sys/sysproto.h b/freebsd/sys/sys/sysproto.h
index a1ab7e44..1c1891de 100644
--- a/freebsd/sys/sys/sysproto.h
+++ b/freebsd/sys/sys/sysproto.h
@@ -2027,9 +2027,7 @@ int   sys_rtprio(struct thread *, struct rtprio_args 
*);
 intsys_semsys(struct thread *, struct semsys_args *);
 intsys_msgsys(struct thread *, struct msgsys_args *);
 intsys_shmsys(struct thread *, struct shmsys_args *);
-#endif /* __rtems__ */
 intsys_setfib(struct thread *, struct setfib_args *);
-#ifndef __rtems__
 intsys_ntp_adjtime(struct thread *, struct ntp_adjtime_args *);
 intsys_setgid(struct thread *, struct setgid_args *);
 intsys_setegid(struct thread *, struct setegid_args *);
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 85f66912..a83334b5 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -5872,7 +5872,6 @@
 #definesys_select _bsd_sys_select
 #definesys_sendmsg _bsd_sys_sendmsg
 #definesys_sendto _bsd_sys_sendto
-#definesys_setfib _bsd_sys_setfib
 #definesys_setsockopt _bsd_sys_setsockopt
 #definesys_shutdown _bsd_sys_shutdown
 #definesys_socket _bsd_sys_socket
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 76fc8ad7..1f659112 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -644,20 +644,6 @@ sendmsg(int socket, const struct msghdr *message, int 
flags)
return rtems_bsd_error_to_status_and_errno(error);
 }
 
-int
-setfib(int fibnum)
-{
-   struct thread *td = rtems_bsd_get_curthread_or_null();
-   int error;
-   if (td != NULL) {
-   struct setfib_args ua = { .fibnum = fibnum };
-   error = sys_setfib(td, );
-   } else {
-   error = ENOMEM;
-   }
-   return rtems_bsd_error_to_status_and_errno(error);
-}
-
 int
 setsockopt(int socket, int level, int option_name, const void *option_value,
 socklen_t option_len)
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 05/22] Remove duplicate sysctl(), etc. definitions

2022-06-24 Thread Sebastian Huber
Collecting all system calls in a single translation unit is not good due to the
library initialization through linker sets.

Update #4475.
---
 freebsd/sys/kern/kern_sysctl.c |  4 ++
 freebsd/sys/sys/sysctl.h   |  8 
 rtemsbsd/rtems/rtems-bsd-syscall-api.c | 64 --
 3 files changed, 12 insertions(+), 64 deletions(-)

diff --git a/freebsd/sys/kern/kern_sysctl.c b/freebsd/sys/kern/kern_sysctl.c
index 71cbd2d8..f529704a 100644
--- a/freebsd/sys/kern/kern_sysctl.c
+++ b/freebsd/sys/kern/kern_sysctl.c
@@ -1773,7 +1773,11 @@ sysctl_new_kernel(struct sysctl_req *req, void *p, 
size_t l)
 
 int
 kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
+#ifndef __rtems__
 size_t *oldlenp, void *new, size_t newlen, size_t *retval, int flags)
+#else /* __rtems__ */
+size_t *oldlenp, const void *new, size_t newlen, size_t *retval, int flags)
+#endif /* __rtems__ */
 {
int error = 0;
struct sysctl_req req;
diff --git a/freebsd/sys/sys/sysctl.h b/freebsd/sys/sys/sysctl.h
index fa9779f3..c21f19d3 100644
--- a/freebsd/sys/sys/sysctl.h
+++ b/freebsd/sys/sys/sysctl.h
@@ -1129,10 +1129,18 @@ int sysctl_ctx_entry_del(struct sysctl_ctx_list 
*clist,
struct sysctl_oid *oidp);
 
 intkernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
+#ifndef __rtems__
size_t *oldlenp, void *new, size_t newlen, size_t *retval,
+#else /* __rtems__ */
+   size_t *oldlenp, const void *newp, size_t newlen, size_t *retval,
+#endif /* __rtems__ */
int flags);
 intkernel_sysctlbyname(struct thread *td, char *name, void *old,
+#ifndef __rtems__
size_t *oldlenp, void *new, size_t newlen, size_t *retval,
+#else /* __rtems__ */
+   size_t *oldlenp, const void *newp, size_t newlen, size_t *retval,
+#endif /* __rtems__ */
int flags);
 #ifndef __rtems__
 intuserland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 1f659112..5c45d88a 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -4,8 +4,6 @@
  * @ingroup rtems_bsd_rtems
  *
  * @brief TODO.
- *
- * File origin from FreeBSD 'lib/libc/gen/sysctlnametomib.c'.
  */
 
 /*
@@ -794,68 +792,6 @@ out:
return rtems_bsd_error_to_status_and_errno(error);
 }
 
-int
-sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp,
-const void *newp, size_t newlen)
-{
-   int error = EINVAL;
-   if (namelen <= CTL_MAXNAME) {
-   int namedup[CTL_MAXNAME];
-   memcpy(namedup, name, namelen * sizeof(*name));
-   error = kernel_sysctl(NULL, namedup, namelen, oldp, oldlenp,
-   RTEMS_DECONST(void *, newp), newlen, oldlenp, 0);
-   }
-   return rtems_bsd_error_to_status_and_errno(error);
-}
-
-/*
- * 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
- * 
- *
- */
-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, );
-   if (error < 0)
-   return (error);
-   error = sysctl(real_oid, oidlen, oldp, oldlenp, newp, newlen);
-   return rtems_bsd_error_to_status_and_errno(error);
-}
-
-/*
- * File origin from FreeBSD 'lib/libc/gen/sysctlnametomib.c'.
- *
- * 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);
-}
 
 static int
 rtems_bsd_sysgen_open_error(
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 10/22] Update CONTRIBUTING.rst

2022-06-24 Thread Sebastian Huber
Add porting advice.  Explain file descriptor tradeoffs in CONTRIBUTING.rst.

Update #4475.
---
 CONTRIBUTING.rst | 79 
 1 file changed, 79 insertions(+)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 04593cf6..19abb766 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -463,6 +463,24 @@ In general, provide empty header files and do not guard 
includes.
 For new code use
 `STYLE(9) 
`_.
 
+Porting Advice
+==
+
+In FreeBSD there is a kernel and user space separation.  The kernel is invoked
+by applications through system calls.  These system calls are usually
+implemented by associated ``kern_*()`` functions.  For example, the
+``select()`` system call is implemented by ``kern_select()``.  In RTEMS, there
+is no kernel and user space separation.  The system call functions should be
+added directly after the associated ``kern_*()`` function.  The associated
+``kern_*()`` function should be made static.  This allows the compiler to
+remove the function call.  It may also reduce the need for stack variables in
+favour of registers for parameters.  Placing the system calls directly to the
+kernel implementation helps the linker to only include code needed by the
+application and works well with the linker set based LibBSD initialization.  It
+also helps during FreeBSD baseline updates since changes in the kernel
+implementation may be indicated through merge conflicts and this may highlight
+fixes in the porting code.
+
 Automatically Generated FreeBSD Files
 =
 
@@ -677,6 +695,67 @@ If you get undefined references to ``_bsd_sysctl_*`` 
symbols, then you have to
 locate and add the associated system control node, see
 `SYSCTL(9) `_.
 
+File Descriptor Tradeoffs
+=
+
+In POSIX systems, individual objects (for example files, sockets, kqueues) are
+usually referenced by file descriptors at API level.  A file descriptor is an
+integer.  One of the jobs of an API level function is checking that a file
+descriptor is valid, mapping it to internal data structures and operations, and
+checking that the operation is allowed.  This procedure is done for every call
+of an API level function, so it should be done quickly.  File descriptors are a
+process-specific resource.
+
+In RTEMS, there is only one process (with multiple threads), so the file
+descriptor is simply used as an index into a global array
+(``rtems_libio_iops``) of file control blocks (``rtems_libio_t``).  Firstly, a
+file descriptor is checked that it is in the range of the array.  The size of
+the array is defined by the application configuration
+(``CONFIGURE_MAXIMUM_FILE_DESCRIPTORS``, ``rtems_libio_number_iops``).
+Secondly, it is checked that the referenced file control block is open.  If one
+of the two checks fails, then an ``EBADF`` error is indicated.  Closed file
+control blocks are queued in a FIFO.  If a new file control block is needed it
+is dequeued from the FIFO.  Since files can be opened and closed, file
+descriptors are recycled after a while.  Using a file descriptor after it was
+closed is a software error.  This error may be indicated by an ``EBADF`` error
+status.  However, if the file descriptor is already reused, then a different
+file object is wrongly used.  To increase the time until a file descriptor is
+recycled, the list of closed file descriptors is organized as a FIFO.  File
+descriptors may be closed while an operation with the file object is in
+progress on another thread.  To avoid destroying the file object while it is
+still in use, the file close operation is performed only if the file object is
+no longer used by a thread.  If it is still in use, then the ``EBUSY`` error is
+indicated by the ``close()`` call.  This is accomplished by a reference count
+located in the file control block.  Since the file control blocks are
+statically allocated we do not need to consider a garbage collection of file
+control blocks.  The reference count is incremented by the
+``rtems_libio_iop_hold()`` function and decremented by the
+``rtems_libio_iop_drop()`` function.
+
+In FreeBSD, the situation is a bit more complicated, since it supports
+processes and dynamic file descriptor limits.  The file descriptor to file
+control block mapping starts with the thread pointer (``curthread``), which is
+used to get the process structure, which is used to get the file descriptor
+table (``struct filedesc``):
+
+.. code-block:: c
+
+struct thread *td = curthread;
+struct filedesc *fdp = td->td_proc->p_fd;
+
+Then ``fget_unlocked()`` is used to map the file descriptor to a
+``struct file`` pointer using ``fdp``.  This function takes into account that
+the file table is dynamically allocated and may be reallocated.  It also deals
+with the file reference count.  A file is closed when the reference 

[libbsd 22/22] Disable UNIX Domain Sockets credentials

2022-06-24 Thread Sebastian Huber
---
 freebsd/sys/kern/uipc_usrreq.c | 8 
 freebsd/sys/sys/unpcb.h| 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/freebsd/sys/kern/uipc_usrreq.c b/freebsd/sys/kern/uipc_usrreq.c
index 47cdcfbd..164f9ee3 100644
--- a/freebsd/sys/kern/uipc_usrreq.c
+++ b/freebsd/sys/kern/uipc_usrreq.c
@@ -1038,7 +1038,9 @@ uipc_listen(struct socket *so, int backlog, struct thread 
*td)
SOCK_LOCK(so);
error = solisten_proto_check(so);
if (error == 0) {
+#ifndef __rtems__
cru2x(td->td_ucred, >unp_peercred);
+#endif /* __rtems__ */
solisten_proto(so, backlog);
}
SOCK_UNLOCK(so);
@@ -1566,14 +1568,18 @@ uipc_ctloutput(struct socket *so, struct sockopt *sopt)
switch (sopt->sopt_name) {
case LOCAL_PEERCRED:
UNP_PCB_LOCK(unp);
+#ifndef __rtems__
if (unp->unp_flags & UNP_HAVEPC)
xu = unp->unp_peercred;
else {
+#endif /* __rtems__ */
if (so->so_type == SOCK_STREAM)
error = ENOTCONN;
else
error = EINVAL;
+#ifndef __rtems__
}
+#endif /* __rtems__ */
UNP_PCB_UNLOCK(unp);
if (error == 0)
error = sooptcopyout(sopt, , sizeof(xu));
@@ -1843,6 +1849,7 @@ void
 unp_copy_peercred(struct thread *td, struct unpcb *client_unp,
 struct unpcb *server_unp, struct unpcb *listen_unp)
 {
+#ifndef __rtems__
cru2x(td->td_ucred, _unp->unp_peercred);
client_unp->unp_flags |= UNP_HAVEPC;
 
@@ -1851,6 +1858,7 @@ unp_copy_peercred(struct thread *td, struct unpcb 
*client_unp,
server_unp->unp_flags |= UNP_HAVEPC;
if (listen_unp->unp_flags & UNP_WANTCRED)
client_unp->unp_flags |= UNP_WANTCRED;
+#endif /* __rtems__ */
 }
 
 static int
diff --git a/freebsd/sys/sys/unpcb.h b/freebsd/sys/sys/unpcb.h
index 3ea20b1d..43320481 100644
--- a/freebsd/sys/sys/unpcb.h
+++ b/freebsd/sys/sys/unpcb.h
@@ -80,10 +80,10 @@ struct unpcb {
/* Cache line 2 */
 #ifndef __rtems__
struct  vnode *unp_vnode;   /* if associated with file */
+   struct  xucred unp_peercred;/* peer credentials, if applicable */
 #else /* __rtems__ */
void *unp_vnode;/* if associated with file */
 #endif /* __rtems__ */
-   struct  xucred unp_peercred;/* peer credentials, if applicable */
LIST_ENTRY(unpcb) unp_reflink;  /* link in unp_refs list */
LIST_ENTRY(unpcb) unp_link; /* glue on list of all PCBs */
struct  unp_head unp_refs;  /* referencing socket linked list */
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 09/22] Remove FreeBSD file descriptors

2022-06-24 Thread Sebastian Huber
Remove FreeBSD file descriptors due to performance and code complexity reasons.

Update #4475.
---
 freebsd/sys/kern/kern_descrip.c   |  58 +--
 freebsd/sys/kern/kern_event.c | 121 ++---
 freebsd/sys/kern/sys_generic.c| 136 --
 freebsd/sys/kern/uipc_socket.c|  24 +
 freebsd/sys/kern/uipc_syscalls.c  |  16 +
 freebsd/sys/kern/vfs_cache.c  |   2 +
 freebsd/sys/kern/vfs_lookup.c |   4 +
 freebsd/sys/kern/vfs_mount.c  |   2 +
 freebsd/sys/kern/vfs_subr.c   |   4 +
 freebsd/sys/kern/vfs_syscalls.c   |  18 +
 freebsd/sys/opencrypto/cryptodev.c|  11 +-
 freebsd/sys/sys/file.h|  98 +++-
 freebsd/sys/sys/filedesc.h|  89 +++-
 freebsd/sys/sys/namei.h   |   2 +
 freebsd/sys/sys/proc.h|   2 +-
 freebsd/sys/sys/socketvar.h   |  15 +-
 freebsd/sys/sys/syscallsubr.h |   5 +
 libbsd.py |   1 +
 .../machine/rtems-bsd-kernel-namespace.h  |  18 -
 .../include/machine/rtems-bsd-kernel-space.h  |   5 -
 rtemsbsd/include/machine/rtems-bsd-libio.h| 196 +---
 rtemsbsd/rtems/rtems-bsd-libio.c  |  61 ---
 rtemsbsd/rtems/rtems-bsd-syscall-api.c| 462 --
 rtemsbsd/rtems/rtems-kernel-fget.c|  79 +++
 rtemsbsd/rtems/rtems-kernel-init.c|   7 +-
 25 files changed, 713 insertions(+), 723 deletions(-)
 create mode 100644 rtemsbsd/rtems/rtems-kernel-fget.c

diff --git a/freebsd/sys/kern/kern_descrip.c b/freebsd/sys/kern/kern_descrip.c
index ddc50633..e32201c9 100644
--- a/freebsd/sys/kern/kern_descrip.c
+++ b/freebsd/sys/kern/kern_descrip.c
@@ -76,7 +76,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #ifdef KTRACE
@@ -92,6 +92,7 @@ __FBSDID("$FreeBSD$");
 
 #include 
 
+#ifndef __rtems__
 static MALLOC_DEFINE(M_FILEDESC, "filedesc", "Open file descriptor table");
 static MALLOC_DEFINE(M_FILEDESC_TO_LEADER, "filedesc_to_leader",
 "file desc to leader structures");
@@ -362,7 +363,6 @@ sys_getdtablesize(struct thread *td, struct 
getdtablesize_args *uap)
return (0);
 }
 
-#ifndef __rtems__
 /*
  * Duplicate a file descriptor to a particular value.
  *
@@ -526,7 +526,6 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
tmp = arg;
error = kern_dup(td, FDDUP_FIXED, FDDUP_FLAG_CLOEXEC, fd, tmp);
break;
-#endif /* __rtems__ */
 
case F_GETFD:
error = EBADF;
@@ -551,6 +550,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
}
FILEDESC_XUNLOCK(fdp);
break;
+#endif /* __rtems__ */
 
case F_GETFL:
error = fget_fcntl(td, fd, _fcntl_rights, F_GETFL, );
@@ -813,6 +813,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
return (error);
 }
 
+#ifndef __rtems__
 static int
 getmaxfd(struct thread *td)
 {
@@ -820,7 +821,6 @@ getmaxfd(struct thread *td)
return (min((int)lim_cur(td, RLIMIT_NOFILE), maxfilesperproc));
 }
 
-#ifndef __rtems__
 /*
  * Common code for dup, dup2, fcntl(F_DUPFD) and fcntl(F_DUP2FD).
  */
@@ -1182,7 +1182,6 @@ fgetown(struct sigio **sigiop)
SIGIO_UNLOCK();
return (pgid);
 }
-#endif /* __rtems__ */
 
 /*
  * Function drops the filedesc lock on return.
@@ -1273,7 +1272,6 @@ kern_close(struct thread *td, int fd)
return (closefp(fdp, fd, fp, td, 1));
 }
 
-#ifndef __rtems__
 /*
  * Close open file descriptors.
  */
@@ -1309,7 +1307,6 @@ sys_closefrom(struct thread *td, struct closefrom_args 
*uap)
FILEDESC_SUNLOCK(fdp);
return (0);
 }
-#endif /* __rtems__ */
 
 #if defined(COMPAT_43)
 /*
@@ -1436,7 +1433,6 @@ freebsd11_nfstat(struct thread *td, struct 
freebsd11_nfstat_args *uap)
 }
 #endif /* COMPAT_FREEBSD11 */
 
-#ifndef __rtems__
 /*
  * Return pathconf information about a file descriptor.
  */
@@ -1493,7 +1489,6 @@ out:
fdrop(fp, td);
return (error);
 }
-#endif /* __rtems__ */
 
 /*
  * Initialize filecaps structure.
@@ -1628,7 +1623,6 @@ static void
 filecaps_validate(const struct filecaps *fcaps, const char *func)
 {
 
-#ifndef __rtems__
KASSERT(cap_rights_is_valid(>fc_rights),
("%s: invalid rights", func));
KASSERT((fcaps->fc_fcntls & ~CAP_FCNTL_ALL) == 0,
@@ -1642,7 +1636,6 @@ filecaps_validate(const struct filecaps *fcaps, const 
char *func)
KASSERT(fcaps->fc_nioctls == 0 ||
cap_rights_is_set(>fc_rights, CAP_IOCTL),
("%s: ioctls without CAP_IOCTL", func));
-#endif /* __rtems__ */
 }
 
 static void
@@ -1891,12 +1884,10 @@ falloc_noinstall(struct thread *td, struct file 
**resultfp)
priv_check(td, PRIV_MAXFILES) != 0) ||
openfiles_new >= 

[libbsd 18/22] Move unmapped_buf_allowed

2022-06-24 Thread Sebastian Huber
rtems_bsd_initialize() should initialize the bare minimum.

Update #4475.
---
 freebsd/sys/kern/vfs_bio.c | 3 +++
 rtemsbsd/rtems/rtems-kernel-init.c | 1 -
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/freebsd/sys/kern/vfs_bio.c b/freebsd/sys/kern/vfs_bio.c
index 1177b907..7be96690 100644
--- a/freebsd/sys/kern/vfs_bio.c
+++ b/freebsd/sys/kern/vfs_bio.c
@@ -327,6 +327,9 @@ SYSCTL_COUNTER_U64(_vfs, OID_AUTO, notbufdflushes, 
CTLFLAG_RD, ,
 static long barrierwrites;
 SYSCTL_LONG(_vfs, OID_AUTO, barrierwrites, CTLFLAG_RW, , 0,
 "Number of barrier writes");
+#ifdef __rtems__
+int unmapped_buf_allowed;
+#endif /* __rtems__ */
 SYSCTL_INT(_vfs, OID_AUTO, unmapped_buf_allowed, CTLFLAG_RD,
 _buf_allowed, 0,
 "Permit the use of the unmapped i/o");
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c 
b/rtemsbsd/rtems/rtems-kernel-init.c
index 11c1861b..9b24ba6d 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -108,7 +108,6 @@ sbintime_t tc_tick_sbt;
 int tc_precexp;
 int maxproc;
 int ngroups_max;
-int unmapped_buf_allowed;
 caddr_t unmapped_base;
 long maxbcache;
 struct sx allproc_lock;
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 15/22] Use define for maxfiles and maxfilesperproc

2022-06-24 Thread Sebastian Huber
Update #4475.
---
 freebsd/sys/sys/file.h| 5 +
 rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h | 2 --
 rtemsbsd/rtems/rtems-kernel-init.c| 4 
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/freebsd/sys/sys/file.h b/freebsd/sys/sys/file.h
index 68c33299..14300cd8 100644
--- a/freebsd/sys/sys/file.h
+++ b/freebsd/sys/sys/file.h
@@ -243,8 +243,13 @@ struct xfile {
 extern struct fileops vnops;
 extern struct fileops badfileops;
 extern struct fileops socketops;
+#ifndef __rtems__
 extern int maxfiles;   /* kernel limit on number of open files */
 extern int maxfilesperproc;/* per process limit on number of open files */
+#else /* __rtems__ */
+#definemaxfiles rtems_libio_number_iops
+#definemaxfilesperproc rtems_libio_number_iops
+#endif /* __rtems__ */
 extern volatile int openfiles; /* actual number of open files */
 
 #ifndef __rtems__
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 6f28fea4..9a7b0c09 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -3476,8 +3476,6 @@
 #definemallocarray _bsd_mallocarray
 #definemaxbcache _bsd_maxbcache
 #definemaxbcachebuf _bsd_maxbcachebuf
-#definemaxfiles _bsd_maxfiles
-#definemaxfilesperproc _bsd_maxfilesperproc
 #definemaxpipekva _bsd_maxpipekva
 #definemaxproc _bsd_maxproc
 #definemaxvfsconf _bsd_maxvfsconf
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c 
b/rtemsbsd/rtems/rtems-kernel-init.c
index 454943b3..305010b1 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -107,8 +107,6 @@ struct bintime tc_tick_bt;
 sbintime_t tc_tick_sbt;
 int tc_precexp;
 int maxproc;
-int maxfiles;
-int maxfilesperproc;
 int ngroups_max;
 int unmapped_buf_allowed;
 caddr_t unmapped_base;
@@ -213,8 +211,6 @@ rtems_bsd_initialize(void)
bio_transient_maxcnt = 1024;
sx_init(_lock, "allproc");
 
-   maxfiles = rtems_libio_number_iops;
-   maxfilesperproc = maxfiles;
maxproc = 16;
ngroups_max = 4;
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 00/22] Remove FreeBSD file descriptors and avoid VFS

2022-06-24 Thread Sebastian Huber
This patch set removes the FreeBSD file descriptors.  The VFS is no longer used
if only the USB, SD/MMC, network, PCI, and NVMe support is used by the
application.  This change significantly reduce the memory usage of LibBSD for
these applications.  Using the media01 test case for the arm/lpc32xx BSP as a
benchmark, the heap usage dropped from 14.3MiB to 10.2MiB.  The "_BSD
bufdaemon", "_BSD vnlru", "_BSD syncer", and "_BSD bufspacedaemon-" tasks are
no longer present in media01.  The code size is reduced by about 8KiB.  The
data size is reduced by about 30KiB.  The throughput with a simple FTP test
increased by about 1%.

The "Remove FreeBSD file descriptors" change removes more lines than there are
added.

This change makes it easier to port the NFS support to the master branch since
now the changes are more localized.

Sebastian Huber (22):
  Fix default NET_CFG_NFS_MOUNT_PATH
  Fix redefinition warnings
  Update kernel namespace
  Move setfib() back to route.c
  Remove duplicate sysctl(), etc. definitions
  nfsclient: Include header for rtems_version()
  nfsclient: Fix extra token after #else warning
  devfs: Do not use FreeBSD file descriptors
  Remove FreeBSD file descriptors
  Update CONTRIBUTING.rst
  Add struct file wrapper
  Move kqueue() and kevent(), avoid VFS
  cryptodev: Do not use VFS
  Move select(), pselect(), and poll(), avoid VFS
  Use define for maxfiles and maxfilesperproc
  Move socket system calls, avoid VFS
  Move bio_transient_maxcnt
  Move unmapped_buf_allowed
  Move VFS BIO initialization
  Remove unused rtems_bsd_sysgen_imfsnodeops
  Make rtems_bsd_iop_to_file() static
  Disable UNIX Domain Sockets credentials

 CONTRIBUTING.rst  |  79 ++
 freebsd/sys/fs/devfs/devfs_int.h  |   3 +-
 freebsd/sys/fs/devfs/devfs_vnops.c|   4 +-
 freebsd/sys/fs/nfsclient/nfs_clrpcops.c   |   5 +-
 freebsd/sys/kern/kern_descrip.c   |  58 +-
 freebsd/sys/kern/kern_event.c | 288 --
 freebsd/sys/kern/kern_sysctl.c|   4 +
 freebsd/sys/kern/sys_generic.c| 247 -
 freebsd/sys/kern/sys_socket.c | 271 +-
 freebsd/sys/kern/uipc_socket.c|   3 +
 freebsd/sys/kern/uipc_syscalls.c  | 532 ++-
 freebsd/sys/kern/uipc_usrreq.c|  24 +-
 freebsd/sys/kern/vfs_bio.c|  30 +-
 freebsd/sys/kern/vfs_cache.c  |   2 +
 freebsd/sys/kern/vfs_lookup.c |   4 +
 freebsd/sys/kern/vfs_mount.c  |   2 +
 freebsd/sys/kern/vfs_subr.c   |   4 +
 freebsd/sys/kern/vfs_syscalls.c   |  18 +
 freebsd/sys/net/route.c   |  18 +
 freebsd/sys/netinet/in_pcb.h  |   4 +
 freebsd/sys/opencrypto/cryptodev.c|  81 +-
 freebsd/sys/sys/eventvar.h|   2 +
 freebsd/sys/sys/file.h| 103 +-
 freebsd/sys/sys/filedesc.h|  89 +-
 freebsd/sys/sys/namei.h   |   2 +
 freebsd/sys/sys/proc.h|   2 +-
 freebsd/sys/sys/socketvar.h   |   5 +-
 freebsd/sys/sys/syscallsubr.h |   5 +
 freebsd/sys/sys/sysctl.h  |   8 +
 freebsd/sys/sys/sysproto.h|  20 +-
 freebsd/sys/sys/unpcb.h   |   2 +-
 libbsd.py |   1 +
 .../machine/rtems-bsd-kernel-namespace.h  | 418 +++-
 .../include/machine/rtems-bsd-kernel-space.h  |   5 -
 rtemsbsd/include/machine/rtems-bsd-libio.h| 207 +---
 rtemsbsd/include/rtems/bsd/sys/file.h | 248 +
 rtemsbsd/rtems/rtems-bsd-libio.c  |  61 --
 rtemsbsd/rtems/rtems-bsd-syscall-api.c| 898 ++
 rtemsbsd/rtems/rtems-kernel-fget.c|  79 ++
 rtemsbsd/rtems/rtems-kernel-get-file.c|   9 +-
 rtemsbsd/rtems/rtems-kernel-init.c|  32 +-
 rtemsbsd/sys/fs/devfs/devfs_devs.c| 181 +---
 testsuite/syscalls01/test_main.c  |  13 +-
 waf_libbsd.py |   2 +-
 44 files changed, 2544 insertions(+), 1529 deletions(-)
 create mode 100644 rtemsbsd/include/rtems/bsd/sys/file.h
 create mode 100644 rtemsbsd/rtems/rtems-kernel-fget.c

-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 07/22] nfsclient: Fix extra token after #else warning

2022-06-24 Thread Sebastian Huber
Update #4475.
---
 freebsd/sys/fs/nfsclient/nfs_clrpcops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/freebsd/sys/fs/nfsclient/nfs_clrpcops.c 
b/freebsd/sys/fs/nfsclient/nfs_clrpcops.c
index 85238daa..8ae61446 100644
--- a/freebsd/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/freebsd/sys/fs/nfsclient/nfs_clrpcops.c
@@ -3001,7 +3001,7 @@ nfsrpc_readdir(vnode_t vp, struct uio *uiop, nfsuint64 
*cookiep,
dp->d_namlen = 2;
 #ifndef __rtems__
*((uint64_t *)dp->d_name) = 0;
-#else __rtems__
+#else /* __rtems__ */
dp->d_name[2] = '\0';
 #endif /* __rtems__ */
dp->d_name[0] = '.';
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 06/22] nfsclient: Include header for rtems_version()

2022-06-24 Thread Sebastian Huber
Update #4475.
---
 freebsd/sys/fs/nfsclient/nfs_clrpcops.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/freebsd/sys/fs/nfsclient/nfs_clrpcops.c 
b/freebsd/sys/fs/nfsclient/nfs_clrpcops.c
index 53e4a525..85238daa 100644
--- a/freebsd/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/freebsd/sys/fs/nfsclient/nfs_clrpcops.c
@@ -52,6 +52,9 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#ifdef __rtems__
+#include 
+#endif /* __rtems__ */
 
 SYSCTL_DECL(_vfs_nfs);
 
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 02/22] Fix redefinition warnings

2022-06-24 Thread Sebastian Huber
---
 freebsd/sys/netinet/in_pcb.h  | 4 
 rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h | 2 --
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/freebsd/sys/netinet/in_pcb.h b/freebsd/sys/netinet/in_pcb.h
index ecbd7a22..848a9af0 100644
--- a/freebsd/sys/netinet/in_pcb.h
+++ b/freebsd/sys/netinet/in_pcb.h
@@ -609,6 +609,10 @@ void inp_rlock(struct inpcb *);
 void inp_runlock(struct inpcb *);
 
 #ifdef INVARIANT_SUPPORT
+#ifdef __rtems__
+#defineinp_lock_assert _bsd_inp_lock_assert
+#defineinp_unlock_assert _bsd_inp_unlock_assert
+#endif /* __rtems__ */
 void inp_lock_assert(struct inpcb *);
 void inp_unlock_assert(struct inpcb *);
 #else
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 94e0d56f..599c7d82 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -2871,13 +2871,11 @@
 #defineinp_inpcbtotcpcb _bsd_inp_inpcbtotcpcb
 #defineinp_ip_tos_get _bsd_inp_ip_tos_get
 #defineinp_ip_tos_set _bsd_inp_ip_tos_set
-#defineinp_lock_assert _bsd_inp_lock_assert
 #defineinp_rlock _bsd_inp_rlock
 #defineinp_runlock _bsd_inp_runlock
 #defineinp_setmoptions _bsd_inp_setmoptions
 #defineinp_so_options _bsd_inp_so_options
 #defineinp_to_cpuid _bsd_inp_to_cpuid
-#defineinp_unlock_assert _bsd_inp_unlock_assert
 #defineinp_wlock _bsd_inp_wlock
 #defineinp_wunlock _bsd_inp_wunlock
 #defineinsmntque _bsd_insmntque
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[libbsd 01/22] Fix default NET_CFG_NFS_MOUNT_PATH

2022-06-24 Thread Sebastian Huber
The hostname and path must be separated by a ':'.
---
 waf_libbsd.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/waf_libbsd.py b/waf_libbsd.py
index acf93a2f..60ea7535 100644
--- a/waf_libbsd.py
+++ b/waf_libbsd.py
@@ -308,7 +308,7 @@ class Builder(builder.ModuleManager):
 'NET_CFG_PEER_IP': { 'mandatory': True },
 'NET_CFG_GATEWAY_IP': { 'manditory': True },
 'NET_CFG_NFS_MOUNT_PATH': { 'mandatory': False,
-'default': '@NET_CFG_PEER_IP@/rtems' },
+'default': '@NET_CFG_PEER_IP@:/rtems' 
},
 'NET_CFG_NFS_MOUNT_OPTIONS': { 'mandatory': False,
'default': 'nfsv4,minorversion=1' }
 }
-- 
2.35.3

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel