Re: [PATCH] libstdc++: 60241.cc: tolerate slightly shorter aggregate sleep

2022-06-23 Thread Sebastian Huber

On 23/06/2022 08:44, Sebastian Huber wrote:

On 23/06/2022 02:19, Alexandre Oliva wrote:
On Jun 22, 2022, Sebastian Huber  
wrote:



The clock_nanosleep() uses the coarse resolution which may give a time
before now().

Uhh, sorry, hit send too early.

I also meant to ask whether you'd like me to file an RTEMS ticket about
this issue.


I already created a ticket for this and work on it:

http://devel.rtems.org/ticket/4669


This problem should be fixed now in the RTEMS master branch. I had to 
adjust the test case so that it works in a system with only one processor:


  while (!sleeping)
  {
// Wait for the thread to start sleeping.
std::this_thread::yield();
  }

--
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] score: Make SMP only code explicit

2022-06-23 Thread Sebastian Huber
Conditional expressions with inline functions are not optimized away if
optimization is disabled.  Avoid such expressions to prevent dead
branches.  It helps also during code review to immediately see if a loop
is used or not.
---
 cpukit/include/rtems/score/priorityimpl.h | 33 ---
 cpukit/score/src/kern_tc.c|  4 +++
 cpukit/score/src/threadchangepriority.c   | 10 ++-
 cpukit/score/src/threadqops.c | 16 +--
 cpukit/score/src/watchdogtick.c   |  4 +++
 5 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/cpukit/include/rtems/score/priorityimpl.h 
b/cpukit/include/rtems/score/priorityimpl.h
index 1463bf6c2a..55cddf53be 100644
--- a/cpukit/include/rtems/score/priorityimpl.h
+++ b/cpukit/include/rtems/score/priorityimpl.h
@@ -124,26 +124,6 @@ RTEMS_INLINE_ROUTINE bool _Priority_Actions_is_empty(
   return actions->actions == NULL;
 }
 
-/**
- * @brief Checks if the priority actions is valid.
- *
- * @param aggregation The aggregation of the priority action.
- *
- * @retval true The @a aggregation is valid.
- * @retval false The @a aggregation is not valid.
- */
-RTEMS_INLINE_ROUTINE bool _Priority_Actions_is_valid(
-  const Priority_Aggregation *aggregation
-)
-{
-#if defined(RTEMS_SMP)
-  return aggregation != NULL;
-#else
-  (void) aggregation;
-  return false;
-#endif
-}
-
 /**
  * @brief Moves the priority actions' actions.
  *
@@ -389,25 +369,22 @@ RTEMS_INLINE_ROUTINE void _Priority_Set_action(
   aggregation->Action.type = type;
 }
 
+#if defined(RTEMS_SMP)
 /**
  * @brief Gets the next action of the priority aggregation.
  *
- * @param aggregation The priority aggregation to get the next action of.
+ * @param aggregation is the priority aggregation to get the next action of.
  *
- * @retval next_action The next action of @a aggregation if RTEMS_SMP is 
defined.
- * @retval NULL RTEMS_SMP is not defined.
+ * @return Returns the next action of the priority aggregation or NULL if there
+ *   is no next action.
  */
 RTEMS_INLINE_ROUTINE Priority_Aggregation *_Priority_Get_next_action(
   const Priority_Aggregation *aggregation
 )
 {
-#if defined(RTEMS_SMP)
   return aggregation->Action.next;
-#else
-  (void) aggregation;
-  return NULL;
-#endif
 }
+#endif
 
 /**
  * @brief Compares two priorities.
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index 2b7aeaad31..643026a1c8 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -2329,9 +2329,13 @@ _Timecounter_Tick(void)
 {
Per_CPU_Control *cpu_self = _Per_CPU_Get();
 
+#if defined(RTEMS_SMP)
if (_Per_CPU_Is_boot_processor(cpu_self)) {
+#endif
 tc_windup(NULL);
+#if defined(RTEMS_SMP)
}
+#endif
 
_Watchdog_Tick(cpu_self);
 }
diff --git a/cpukit/score/src/threadchangepriority.c 
b/cpukit/score/src/threadchangepriority.c
index 321bb15cab..80f030fdc6 100644
--- a/cpukit/score/src/threadchangepriority.c
+++ b/cpukit/score/src/threadchangepriority.c
@@ -135,11 +135,15 @@ static void _Thread_Priority_do_perform_actions(
   priority_aggregation = _Priority_Actions_move( 
&queue_context->Priority.Actions );
 
   do {
+#if defined(RTEMS_SMP)
 Priority_Aggregation *next_aggregation;
+#endif
 Priority_Node*priority_action_node;
 Priority_Action_type  priority_action_type;
 
+#if defined(RTEMS_SMP)
 next_aggregation = _Priority_Get_next_action( priority_aggregation );
+#endif
 
 priority_action_node = priority_aggregation->Action.node;
 priority_action_type = priority_aggregation->Action.type;
@@ -198,8 +202,12 @@ static void _Thread_Priority_do_perform_actions(
 break;
 }
 
+#if defined(RTEMS_SMP)
 priority_aggregation = next_aggregation;
-  } while ( _Priority_Actions_is_valid( priority_aggregation ) );
+  } while ( priority_aggregation != NULL );
+#else
+  } while ( false );
+#endif
 
   if ( !_Priority_Actions_is_empty( &queue_context->Priority.Actions ) ) {
 _Thread_queue_Context_add_priority_update( queue_context, the_thread );
diff --git a/cpukit/score/src/threadqops.c b/cpukit/score/src/threadqops.c
index 33fc5a44cb..fbea9f6de6 100644
--- a/cpukit/score/src/threadqops.c
+++ b/cpukit/score/src/threadqops.c
@@ -404,8 +404,12 @@ static void _Thread_queue_Priority_priority_actions(
 break;
 }
 
+#if defined(RTEMS_SMP)
 priority_aggregation = _Priority_Get_next_action( priority_aggregation );
-  } while ( _Priority_Actions_is_valid( priority_aggregation ) );
+  } while ( priority_aggregation != NULL );
+#else
+  } while ( false );
+#endif
 }
 
 static void _Thread_queue_Priority_do_initialize(
@@ -734,14 +738,18 @@ static void 
_Thread_queue_Priority_inherit_priority_actions(
   priority_aggregation = _Priority_Actions_move( priority_actions );
 
   do {
+#if defined(RTEMS_SMP)
 Priority_Aggregation*next_aggregation;
+#endif
 Scheduler_Node  *scheduler_node;
 size_t   scheduler_in

[libbsd 3/4] if_lpe.c: Move transmit initialization

2022-06-23 Thread Sebastian Huber
Move the transmit initialization out of the transmit task to be able to
remove the transmit task in the next patch.
---
 rtemsbsd/sys/arm/lpc/if_lpe.c | 269 +++---
 1 file changed, 152 insertions(+), 117 deletions(-)

diff --git a/rtemsbsd/sys/arm/lpc/if_lpe.c b/rtemsbsd/sys/arm/lpc/if_lpe.c
index 247bd486..0ae60884 100755
--- a/rtemsbsd/sys/arm/lpc/if_lpe.c
+++ b/rtemsbsd/sys/arm/lpc/if_lpe.c
@@ -260,7 +260,9 @@ static volatile lpc_eth_controller *const lpc_eth =
 
 /* Events */
 
-#define LPC_ETH_EVENT_INITIALIZE RTEMS_EVENT_1
+#define LPC_ETH_EVENT_INIT_RX RTEMS_EVENT_0
+
+#define LPC_ETH_EVENT_INIT_TX RTEMS_EVENT_1
 
 #define LPC_ETH_EVENT_TXSTART RTEMS_EVENT_2
 
@@ -324,6 +326,8 @@ typedef struct {
   volatile lpc_eth_transfer_descriptor *tx_desc_table;
   volatile uint32_t *tx_status_table;
   void *tx_buf_table;
+  uint32_t tx_produce_index;
+  uint32_t tx_consume_index;
   unsigned received_frames;
   unsigned receive_interrupts;
   unsigned transmitted_frames;
@@ -418,9 +422,16 @@ static void lpc_eth_interrupt_handler(void *arg)
   uint32_t is = lpc_eth->intstatus & im;
 
   /* Check receive interrupts */
-  if ((is & ETH_INT_RX_OVERRUN) != 0) {
-re = LPC_ETH_EVENT_INITIALIZE;
-++e->receive_fatal_errors;
+  if ((is & (ETH_INT_RX_OVERRUN | ETH_INT_TX_UNDERRUN)) != 0) {
+if ((is & ETH_INT_RX_OVERRUN) != 0) {
+  re = LPC_ETH_EVENT_INIT_RX;
+  ++e->receive_fatal_errors;
+}
+
+if ((is & ETH_INT_TX_UNDERRUN) != 0) {
+  re = LPC_ETH_EVENT_INIT_TX;
+  ++e->transmit_fatal_errors;
+}
   } else if ((is & LPC_ETH_INTERRUPT_RECEIVE) != 0) {
 re = LPC_ETH_EVENT_INTERRUPT;
 ie |= LPC_ETH_INTERRUPT_RECEIVE;
@@ -433,10 +444,7 @@ static void lpc_eth_interrupt_handler(void *arg)
   }
 
   /* Check transmit interrupts */
-  if ((is & ETH_INT_TX_UNDERRUN) != 0) {
-te = LPC_ETH_EVENT_INITIALIZE;
-++e->transmit_fatal_errors;
-  } else if ((is & LPC_ETH_INTERRUPT_TRANSMIT) != 0) {
+  if ((is & LPC_ETH_INTERRUPT_TRANSMIT) != 0) {
 te = LPC_ETH_EVENT_INTERRUPT;
 ie |= LPC_ETH_INTERRUPT_TRANSMIT;
   }
@@ -492,6 +500,66 @@ static void lpc_eth_disable_transmit_interrupts(void)
   rtems_interrupt_enable(level);
 }
 
+static void lpc_eth_initialize_transmit(lpc_eth_driver_entry *e)
+{
+  volatile uint32_t *const status = e->tx_status_table;
+  uint32_t const index_max = e->tx_unit_count - 1;
+  volatile lpc_eth_transfer_descriptor *const desc = e->tx_desc_table;
+  #ifdef LPC_ETH_CONFIG_USE_TRANSMIT_DMA
+struct mbuf **const mbufs = e->tx_buf_table;
+  #else
+char *const buf = e->tx_buf_table;
+  #endif
+  uint32_t produce_index;
+
+  /* Disable transmit interrupts */
+  lpc_eth_disable_transmit_interrupts();
+
+  /* Disable transmitter */
+  lpc_eth->command &= ~ETH_CMD_TX_ENABLE;
+
+  /* Wait for inactive status */
+  while ((lpc_eth->status & ETH_STAT_TX_ACTIVE) != 0) {
+/* Wait */
+  }
+
+  /* Reset */
+  lpc_eth->command |= ETH_CMD_TX_RESET;
+
+  /* Clear transmit interrupts */
+  lpc_eth->intclear = LPC_ETH_INTERRUPT_TRANSMIT;
+
+  /* Transmit descriptors */
+  lpc_eth->txdescriptornum = index_max;
+  lpc_eth->txdescriptor = (uint32_t) desc;
+  lpc_eth->txstatus = (uint32_t) status;
+
+  #ifdef LPC_ETH_CONFIG_USE_TRANSMIT_DMA
+/* Discard outstanding fragments (= data loss) */
+for (produce_index = 0; produce_index <= index_max; ++produce_index) {
+  struct mbuf *victim = mbufs [produce_index];
+
+  if (victim != NULL) {
+m_free(victim);
+mbufs [produce_index] = NULL;
+  }
+}
+  #else
+/* Initialize descriptor table */
+for (produce_index = 0; produce_index <= index_max; ++produce_index) {
+  desc [produce_index].start =
+(uint32_t) (buf + produce_index * LPC_ETH_CONFIG_TX_BUF_SIZE);
+}
+  #endif
+
+  /* Initialize indices */
+  e->tx_produce_index = lpc_eth->txproduceindex;
+  e->tx_consume_index = lpc_eth->txconsumeindex;
+
+  /* Enable transmitter */
+  lpc_eth->command |= ETH_CMD_TX_ENABLE;
+}
+
 #define LPC_ETH_RX_DATA_OFFSET 2
 
 static struct mbuf *lpc_eth_new_mbuf(struct ifnet *ifp, bool wait)
@@ -576,7 +644,8 @@ static void lpc_eth_receive_task(rtems_task_argument arg)
   while (true) {
 /* Wait for events */
 sc = rtems_event_receive(
-  LPC_ETH_EVENT_INITIALIZE
+  LPC_ETH_EVENT_INIT_RX
+| LPC_ETH_EVENT_INIT_TX
 | LPC_ETH_EVENT_STOP
 | LPC_ETH_EVENT_INTERRUPT,
   RTEMS_EVENT_ANY | RTEMS_WAIT,
@@ -595,59 +664,67 @@ static void lpc_eth_receive_task(rtems_task_argument arg)
   continue;
 }
 
-/* Initialize receiver? */
-if ((events & LPC_ETH_EVENT_INITIALIZE) != 0) {
-  /* Disable receive interrupts */
-  lpc_eth_disable_receive_interrupts();
+/* Initialize receiver or transmitter? */
+if ((events & (LPC_ETH_EVENT_INIT_RX | LPC_ETH_EVENT_INIT_TX)) != 0) {
+  if ((events & LPC_ETH_EVENT_INIT_RX) != 0) {
+/* Disable receive interrupts */
+lpc_eth_disable_recei

[libbsd 0/4] Replace LPC Ethernet interface driver

2022-06-23 Thread Sebastian Huber
The standard FreeBSD MII support causes severe problems on the LPC3200
chip family.  If an Ethernet module register is accessed while there is
no clock from the PHY, the chip completely locks up and only an external
watchdog can recover from this state.  The legacy driver had a custom
PHY management code which helped to avoid such issues.  The if_lpe.c
driver is no longer maintained by FreeBSD.

Sebastian Huber (4):
  if_lpe.c: Import legacy LPC Ethernet driver
  if_lpe.c: Port to LibBSD
  if_lpe.c: Move transmit initialization
  if_lpe.c: Use interface transmit

 rtemsbsd/sys/arm/lpc/if_lpe.c| 2860 +-
 rtemsbsd/sys/arm/lpc/if_lpereg.h |  210 ---
 2 files changed, 1602 insertions(+), 1468 deletions(-)
 delete mode 100644 rtemsbsd/sys/arm/lpc/if_lpereg.h

-- 
2.35.3

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


[libbsd 2/4] if_lpe.c: Port to LibBSD

2022-06-23 Thread Sebastian Huber
---
 libbsd.py |   1 +
 rtemsbsd/sys/arm/lpc/if_lpe.c | 466 +-
 2 files changed, 228 insertions(+), 239 deletions(-)

diff --git a/libbsd.py b/libbsd.py
index de22eaa9..983f41a1 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -235,6 +235,7 @@ class rtems(builder.Module):
 'rtems/rtems-legacy-rtrequest.c',
 'rtems/rtems-legacy-newproc.c',
 'rtems/rtems-legacy-mii.c',
+'sys/arm/lpc/if_lpe.c',
 'sys/arm/lpc/lpc_pwr.c',
 'sys/dev/atsam/if_atsam.c',
 'sys/dev/atsam/if_atsam_media.c',
diff --git a/rtemsbsd/sys/arm/lpc/if_lpe.c b/rtemsbsd/sys/arm/lpc/if_lpe.c
index ccfe1696..247bd486 100755
--- a/rtemsbsd/sys/arm/lpc/if_lpe.c
+++ b/rtemsbsd/sys/arm/lpc/if_lpe.c
@@ -22,28 +22,32 @@
 
 #include 
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+#include 
 
-#include 
-#include 
-#include 
+#if defined(LIBBSP_ARM_LPC24XX_BSP_H) || defined(LIBBSP_ARM_LPC32XX_BSP_H)
 
 #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 
@@ -128,6 +132,10 @@ typedef struct {
   uint32_t powerdown;
 } lpc_eth_controller;
 
+#define LPE_LOCK(e) mtx_lock(&(e)->mtx)
+
+#define LPE_UNLOCK(e) mtx_unlock(&(e)->mtx)
+
 static volatile lpc_eth_controller *const lpc_eth = 
   (volatile lpc_eth_controller *) LPC_ETH_CONFIG_REG_BASE;
 
@@ -300,10 +308,12 @@ typedef enum {
 } lpc_eth_state;
 
 typedef struct {
-  struct arpcom arpcom;
+  device_t dev;
+  struct ifnet *ifp;
+  struct mtx mtx;
   lpc_eth_state state;
-  struct rtems_mdio_info mdio;
   uint32_t anlpar;
+  struct callout watchdog_callout;
   rtems_id receive_task;
   rtems_id transmit_task;
   unsigned rx_unit_count;
@@ -338,14 +348,18 @@ typedef struct {
   int phy;
   rtems_vector_number interrupt_number;
   rtems_id control_task;
+  int if_flags;
+  struct ifmedia ifmedia;
 } lpc_eth_driver_entry;
 
-static lpc_eth_driver_entry lpc_eth_driver_data;
+static void lpc_eth_interface_watchdog(void *arg);
+
+static void lpc_eth_setup_rxfilter(lpc_eth_driver_entry *e);
 
 static void lpc_eth_control_request_complete(const lpc_eth_driver_entry *e)
 {
   rtems_status_code sc = rtems_event_transient_send(e->control_task);
-  assert(sc == RTEMS_SUCCESSFUL);
+  BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 }
 
 static void lpc_eth_control_request(
@@ -355,17 +369,14 @@ static void lpc_eth_control_request(
 )
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
-  uint32_t nest_count = 0;
 
   e->control_task = rtems_task_self();
 
-  sc = rtems_bsdnet_event_send(task, event);
-  assert(sc == RTEMS_SUCCESSFUL);
+  sc = rtems_event_send(task, event);
+  BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 
-  nest_count = rtems_bsdnet_semaphore_release_recursive();
   sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
-  assert(sc == RTEMS_SUCCESSFUL);
-  rtems_bsdnet_semaphore_obtain_recursive(nest_count);
+  BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 
   e->control_task = 0;
 }
@@ -418,7 +429,7 @@ static void lpc_eth_interrupt_handler(void *arg)
   /* Send events to receive task */
   if (re != 0) {
 ++e->receive_interrupts;
-(void) rtems_bsdnet_event_send(e->receive_task, re);
+(void) rtems_event_send(e->receive_task, re);
   }
 
   /* Check transmit interrupts */
@@ -433,7 +444,7 @@ static void lpc_eth_interrupt_handler(void *arg)
   /* Send events to transmit task */
   if (te != 0) {
 ++e->transmit_interrupts;
-(void) rtems_bsdnet_event_send(e->transmit_task, te);
+(void) rtems_event_send(e->transmit_task, te);
   }
 
   LPC_ETH_PRINTK("interrupt: rx = 0x%08x, tx = 0x%08x\n", re, te);
@@ -486,7 +497,7 @@ static void lpc_eth_disable_transmit_interrupts(void)
 static struct mbuf *lpc_eth_new_mbuf(struct ifnet *ifp, bool wait)
 {
   struct mbuf *m = NULL;
-  int mw = wait ? M_WAIT : M_DONTWAIT;
+  int mw = wait ? M_WAITOK : M_NOWAIT;
 
   MGETHDR(m, mw, MT_DATA);
   if (m != NULL) {
@@ -546,12 +557,12 @@ static bool lpc_eth_add_new_mbuf(
   }
 }
 
-static void lpc_eth_receive_task(void *arg)
+static void lpc_eth_receive_task(rtems_task_argument arg)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
   rtems_event_set events = 0;
   lpc_eth_driver_entry *const e = (lpc_eth_driver_entry *) arg;
-  struct ifnet *const ifp = &e->arpcom.ac_if;
+  struct ifnet *const ifp = e->ifp;
   volatile lpc_eth_transfer_descriptor *const desc = e->rx_desc_table;
   volatile lpc_eth_receive_status *const status = e->rx_status_table;
   struct mbuf **const mbufs = e->rx_mbuf_table;
@@ -564,7 +575,7 @@ static void lpc_eth_receive_task(void *arg)
   /* Main event loop */
   while (true) {
 /* Wait for events */
-sc = rtems_bsdnet_event_receive(
+sc = rtems_event_receive(
   LPC_ETH_EVENT_INITIALIZE

[libbsd 4/4] if_lpe.c: Use interface transmit

2022-06-23 Thread Sebastian Huber
This avoids the need for a transmit task and transmit interrupts.
---
 rtemsbsd/sys/arm/lpc/if_lpe.c | 502 ++
 1 file changed, 206 insertions(+), 296 deletions(-)

diff --git a/rtemsbsd/sys/arm/lpc/if_lpe.c b/rtemsbsd/sys/arm/lpc/if_lpe.c
index 0ae60884..8c58a58d 100755
--- a/rtemsbsd/sys/arm/lpc/if_lpe.c
+++ b/rtemsbsd/sys/arm/lpc/if_lpe.c
@@ -264,8 +264,6 @@ static volatile lpc_eth_controller *const lpc_eth =
 
 #define LPC_ETH_EVENT_INIT_TX RTEMS_EVENT_1
 
-#define LPC_ETH_EVENT_TXSTART RTEMS_EVENT_2
-
 #define LPC_ETH_EVENT_INTERRUPT RTEMS_EVENT_3
 
 #define LPC_ETH_EVENT_STOP RTEMS_EVENT_4
@@ -275,9 +273,6 @@ static volatile lpc_eth_controller *const lpc_eth =
 #define LPC_ETH_INTERRUPT_RECEIVE \
   (ETH_INT_RX_ERROR | ETH_INT_RX_FINISHED | ETH_INT_RX_DONE)
 
-#define LPC_ETH_INTERRUPT_TRANSMIT \
-  (ETH_INT_TX_DONE | ETH_INT_TX_FINISHED | ETH_INT_TX_ERROR)
-
 #define LPC_ETH_RX_STAT_ERRORS \
   (ETH_RX_STAT_CRC_ERROR \
 | ETH_RX_STAT_SYMBOL_ERROR \
@@ -317,7 +312,6 @@ typedef struct {
   uint32_t anlpar;
   struct callout watchdog_callout;
   rtems_id receive_task;
-  rtems_id transmit_task;
   unsigned rx_unit_count;
   unsigned tx_unit_count;
   volatile lpc_eth_transfer_descriptor *rx_desc_table;
@@ -331,7 +325,6 @@ typedef struct {
   unsigned received_frames;
   unsigned receive_interrupts;
   unsigned transmitted_frames;
-  unsigned transmit_interrupts;
   unsigned receive_drop_errors;
   unsigned receive_overrun_errors;
   unsigned receive_fragment_errors;
@@ -435,26 +428,14 @@ static void lpc_eth_interrupt_handler(void *arg)
   } else if ((is & LPC_ETH_INTERRUPT_RECEIVE) != 0) {
 re = LPC_ETH_EVENT_INTERRUPT;
 ie |= LPC_ETH_INTERRUPT_RECEIVE;
+++e->receive_interrupts;
   }
 
   /* Send events to receive task */
   if (re != 0) {
-++e->receive_interrupts;
 (void) rtems_event_send(e->receive_task, re);
   }
 
-  /* Check transmit interrupts */
-  if ((is & LPC_ETH_INTERRUPT_TRANSMIT) != 0) {
-te = LPC_ETH_EVENT_INTERRUPT;
-ie |= LPC_ETH_INTERRUPT_TRANSMIT;
-  }
-
-  /* Send events to transmit task */
-  if (te != 0) {
-++e->transmit_interrupts;
-(void) rtems_event_send(e->transmit_task, te);
-  }
-
   LPC_ETH_PRINTK("interrupt: rx = 0x%08x, tx = 0x%08x\n", re, te);
 
   /* Update interrupt mask */
@@ -482,24 +463,6 @@ static void lpc_eth_disable_receive_interrupts(void)
   rtems_interrupt_enable(level);
 }
 
-static void lpc_eth_enable_transmit_interrupts(void)
-{
-  rtems_interrupt_level level;
-
-  rtems_interrupt_disable(level);
-  lpc_eth->intenable |= LPC_ETH_INTERRUPT_TRANSMIT;
-  rtems_interrupt_enable(level);
-}
-
-static void lpc_eth_disable_transmit_interrupts(void)
-{
-  rtems_interrupt_level level;
-
-  rtems_interrupt_disable(level);
-  lpc_eth->intenable &= ~LPC_ETH_INTERRUPT_TRANSMIT;
-  rtems_interrupt_enable(level);
-}
-
 static void lpc_eth_initialize_transmit(lpc_eth_driver_entry *e)
 {
   volatile uint32_t *const status = e->tx_status_table;
@@ -512,9 +475,6 @@ static void 
lpc_eth_initialize_transmit(lpc_eth_driver_entry *e)
   #endif
   uint32_t produce_index;
 
-  /* Disable transmit interrupts */
-  lpc_eth_disable_transmit_interrupts();
-
   /* Disable transmitter */
   lpc_eth->command &= ~ETH_CMD_TX_ENABLE;
 
@@ -526,9 +486,6 @@ static void 
lpc_eth_initialize_transmit(lpc_eth_driver_entry *e)
   /* Reset */
   lpc_eth->command |= ETH_CMD_TX_RESET;
 
-  /* Clear transmit interrupts */
-  lpc_eth->intclear = LPC_ETH_INTERRUPT_TRANSMIT;
-
   /* Transmit descriptors */
   lpc_eth->txdescriptornum = index_max;
   lpc_eth->txdescriptor = (uint32_t) desc;
@@ -537,12 +494,8 @@ static void 
lpc_eth_initialize_transmit(lpc_eth_driver_entry *e)
   #ifdef LPC_ETH_CONFIG_USE_TRANSMIT_DMA
 /* Discard outstanding fragments (= data loss) */
 for (produce_index = 0; produce_index <= index_max; ++produce_index) {
-  struct mbuf *victim = mbufs [produce_index];
-
-  if (victim != NULL) {
-m_free(victim);
-mbufs [produce_index] = NULL;
-  }
+  m_freem(mbufs [produce_index]);
+  mbufs [produce_index] = NULL;
 }
   #else
 /* Initialize descriptor table */
@@ -815,20 +768,10 @@ static struct mbuf *lpc_eth_next_fragment(
   uint32_t *ctrl
 )
 {
-  struct mbuf *n = NULL;
-  int size = 0;
+  struct mbuf *n;
+  int size;
 
   while (true) {
-if (m == NULL) {
-  /* Dequeue first fragment of the next frame */
-  IF_DEQUEUE(&ifp->if_snd, m);
-
-  /* Empty queue? */
-  if (m == NULL) {
-return m;
-  }
-}
-
 /* Get fragment size */
 size = m->m_len;
 
@@ -836,8 +779,12 @@ static struct mbuf *lpc_eth_next_fragment(
   /* Now we have a not empty fragment */
   break;
 } else {
-  /* Discard empty fragments */
-  m = m_free(m);
+  /* Skip empty fragments */
+  m = m->m_next;
+
+  if (m == NULL) {
+return NULL;
+  }
 }
   }
 
@@ -859,266 +806,224 @@ static struct mbuf *lpc_eth_next_fragment

[libbsd 1/4] if_lpe.c: Import legacy LPC Ethernet driver

2022-06-23 Thread Sebastian Huber
The standard FreeBSD MII support causes severe problems on the LPC3200
chip family.  If an Ethernet module register is accessed while there is
no clock from the PHY, the chip completely locks up and only an external
watchdog can recover from this state.  The legacy driver had a custom
PHY management code which helped to avoid such issues.  The if_lpe.c
driver is no longer maintained by FreeBSD.
---
 libbsd.py|1 -
 rtemsbsd/sys/arm/lpc/if_lpe.c| 2953 +-
 rtemsbsd/sys/arm/lpc/if_lpereg.h |  210 ---
 3 files changed, 1682 insertions(+), 1482 deletions(-)
 delete mode 100644 rtemsbsd/sys/arm/lpc/if_lpereg.h

diff --git a/libbsd.py b/libbsd.py
index 983f41a1..de22eaa9 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -235,7 +235,6 @@ class rtems(builder.Module):
 'rtems/rtems-legacy-rtrequest.c',
 'rtems/rtems-legacy-newproc.c',
 'rtems/rtems-legacy-mii.c',
-'sys/arm/lpc/if_lpe.c',
 'sys/arm/lpc/lpc_pwr.c',
 'sys/dev/atsam/if_atsam.c',
 'sys/dev/atsam/if_atsam_media.c',
diff --git a/rtemsbsd/sys/arm/lpc/if_lpe.c b/rtemsbsd/sys/arm/lpc/if_lpe.c
index 40ac162e..ccfe1696 100755
--- a/rtemsbsd/sys/arm/lpc/if_lpe.c
+++ b/rtemsbsd/sys/arm/lpc/if_lpe.c
@@ -1,1428 +1,1839 @@
-#include 
-
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+/**
+ * @file
  *
- * Copyright (c) 2011 Jakub Wojciech Klama 
- * All rights reserved.
+ * @ingroup lpc_eth
  *
- * 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.
+ * @brief Ethernet driver.
+ */
+
+/*
+ * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
  *
- * 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.
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  
  *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
  */
-#include 
-__FBSDID("$FreeBSD$");
+
+#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 
-#ifndef __rtems__
-#include 
-#endif /* __rtems__ */
 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#if MCLBYTES > (2 * 1024)
+  #error "MCLBYTES to large"
+#endif
 
-#include 
+#ifdef LPC_ETH_CONFIG_USE_TRANSMIT_DMA
+  #define LPC_ETH_CONFIG_TX_BUF_SIZE sizeof(struct mbuf *)
+#else
+  #define LPC_ETH_CONFIG_TX_BUF_SIZE 1518U
+#endif
 
-#ifndef __rtems__
-#include 
-#include 
-#endif /* __rtems__ */
+#define DEFAULT_PHY 0
+#define WATCHDOG_TIMEOUT 5
+
+typedef struct {
+  uint32_t start;
+  uint32_t control;
+} lpc_eth_transfer_descriptor;
+
+typedef struct {
+  uint32_t info;
+  uint32_t hash_crc;
+} lpc_eth_receive_status;
+
+typedef struct {
+  uint32_t mac1;
+  uint32_t mac2;
+  uint32_t ipgt;
+  uint32_t ipgr;
+  uint32_t clrt;
+  uint32_t maxf;
+  uint32_t supp;
+  uint32_t test;
+  uint32_t mcfg;
+  uint32_t mcmd;
+  uint32_t madr;
+  uint32_t mwtd;
+  uint32_t mrdd;
+  uint32_t mind;
+  uint32_t reserved_0 [2];
+  uint32_t sa0;
+  uint32_t sa1;
+  uint32_t sa2;
+  uint32_t reserved_1 [45];
+  uint32_t command;
+  uint32_t status;
+  uint32_t rxdescriptor;
+  uint32_t rxstatus;
+  uint32_t rxdescriptornum;
+  uint32_t rxproduceindex;
+  uint32_t rxconsumeindex;
+  uint32_t txdescriptor;
+  uint32_t txstatus;
+  uint32_t txdescriptornum;
+  uint32_t txproduceindex;
+  uint32_t txconsumeindex;
+  uint32_t reserved_2 [10];
+  uint

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

2022-06-23 Thread Duc Doan
On Tue, 2022-06-21 at 17:23 +0200, o...@c-mauderer.de wrote:
> OK. So every BSP that want's to use that API will have a different 
> rtems_gpio_config_t (or every other structure) that is defined in
> (for 
> example) bsp.h? The application has to know the details of the
> current 
> BSP and initialize the structure accordingly.
> 
> That means that if I write an application that can run on an STM32 or
> alternatively on some RISC-V based CPU the API will be different. Not
> really portable.
> 

Yes, you are right: rtems_gpio_config_t was defined by each BSP. I have
fixed by making rtems_gpio_t and rtems_gpio_config_t concrete structs
that hold common information among architectures. They also have a
pointer to a bsp-specific structure if required, like in the current
API.
   /**
  * @brief Structure for a GPIO object. It holds information
  *like port number and pin number/pin mask.
  * 
  */
typedef struct {
void *port; /* Pointer to the GPIO port */
uint32_t pin_mask;  /* The pin number or pin mask */
bool is_expander;   /* If the GPIO is an expander, set to
   true.
   Else false. */
uint32_t expander_id;   /* This field specifies which GPIO
   expander is
   in use. In case of using multiple
   expanders,
   this field is necessary to handle
   each. */
void *bsp;  /* Pointer to BSP-specific data */
} rtems_gpio_t;
   
   /**
  * @brief Structure for configuration of a GPIO object.
  */
typedef struct {
rtems_gpio_pin_mode mode;   /* Pin mode */
rtems_gpio_pull pull;   /* Pull resistor configuration */
void *bsp;  /* Pointer to BSP-specific config */
} rtems_gpio_config_t;

Hopefully this makes the application code more portable. I have also
updated the blink code:
https://github.com/dtbpkmte/GSoC-2022-RTEMS-Sample-Apps/blob/main/RTEMS_Blink_API/src/init.c
This time, for simple tasks like basic I/O, users won't need to care
about the details of a BSP.

One thing I am not sure about is that do all architectures have ports
and pins for GPIO? I am worried that my structure is still skewed
towards STM32 because I don't have much knowledge about different types
of microcontrollers.

> If you ask me: We have SYSINIT functions for this kind of 
> initializations. If something should be done at about bsp_start, the 
> user can register a function at RTEMS_SYSINIT_BSP_START.

Thank you for the suggestion. This is what I have and it seems to be
working:

   RTEMS_SYSINIT_ITEM(
   rtems_gpio_initialize,
   RTEMS_SYSINIT_BSP_START,
   RTEMS_SYSINIT_ORDER_LAST
   );

> 
> 
> I think I haven't written clearly what I meant: Let's assume a I2C
> chip 
> like the TCA9537 from TI (can be any other GPIO expander from any
> other 
> vendor): You connect it to a I2C bus and control 4 GPIOs with it.
> It's a 
> GPIO so a good GPIO API should be able to handle it.
> 
> In that case the GPIO API would do some I2C transfers under the hood
> if 
> you switch or read a GPIO. So what happens if some error happens
> during 
> one of these transfers. If the only error option is UNSATISFIED, the 
> application can't distinguish the errors. It only knows something
> didn't 
> work. It can't (for example) retry only on certain error cases like
> if 
> the bus is busy.
> 
> Please also note that the I2C GPIO expander is one example where a
> BSP 
> would have two completely different GPIO controllers: A number of 
> integrated ones and a number of I2C ones. A generic API should be
> able 
> to handle that case too.

I understand what you mean now. I have added that capability to by
creating the field is_expander to select between integrated GPIO and
expander. I also have a field called expander_id to select among
multiple expanders. You can see those in the rtems_gpio_t struct above.
The API function prototypes stay the same, but the BSP now need to
implement 2 functions in private: one is the "*_default" function which
controls the built-in GPIO and the other is the "*_ex" function which
controls the expander. Here are the example read and write functions,
which are in bsps/shared/dev/gpio/gpio.c:

   rtems_status_code rtems_gpio_write_pin(rtems_gpio_t *gpiox,
   rtems_gpio_pin_state value) {
   if (gpiox->is_expander) {
   return rtems_gpio_write_pin_ex(gpiox, value);
   } else {
   return rtems_gpio_write_pin_default(gpiox, value);
   }
   }
   
   rtems_status_code rtems_gpio_read_pin(rtems_gpio_t *gpiox,
   rtems_gpio_pin_state *value) {
   if (gpiox->is_expander) {
   return rtems_gpio_read_pin_ex(gpiox, value);
   } else {
   return rtems_gpio_read_pin_default(gpiox, value);
   }
   }
> > 
Please give me more feedback. Thank you very much.

Best,

Duc Doan

> 

_

Re: [PATCH] libstdc++: 60241.cc: tolerate slightly shorter aggregate sleep

2022-06-23 Thread Sebastian Huber

On 23/06/2022 13:33, Alexandre Oliva wrote:

Anyway...  I was considering this xfail patch before, and I wonder if it
would still be appropriate to install something like it, narrowed down
to rtems < 6.1, or if it would be better to let it fail noisily so that
people look it up, find the fix proper and merge it.


I would not make it an xfail. It is now likely fixed and if someone uses 
a broken RTEMS version getting an error message would be nice.


--
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] Proposal for new GPIO API and example implementation for STM32F4 BSP

2022-06-23 Thread oss

Hello Duc,

Am 23.06.22 um 13:36 schrieb Duc Doan:

On Tue, 2022-06-21 at 17:23 +0200, o...@c-mauderer.de wrote:

OK. So every BSP that want's to use that API will have a different
rtems_gpio_config_t (or every other structure) that is defined in
(for
example) bsp.h? The application has to know the details of the
current
BSP and initialize the structure accordingly.

That means that if I write an application that can run on an STM32 or
alternatively on some RISC-V based CPU the API will be different. Not
really portable.



Yes, you are right: rtems_gpio_config_t was defined by each BSP. I have
fixed by making rtems_gpio_t and rtems_gpio_config_t concrete structs
that hold common information among architectures. They also have a
pointer to a bsp-specific structure if required, like in the current
API.
/**
   * @brief Structure for a GPIO object. It holds information
   *like port number and pin number/pin mask.
   *
   */
 typedef struct {
 void *port; /* Pointer to the GPIO port */
 uint32_t pin_mask;  /* The pin number or pin mask */
 bool is_expander;   /* If the GPIO is an expander, set to
true.
Else false. */
 uint32_t expander_id;   /* This field specifies which GPIO
expander is
in use. In case of using multiple
expanders,
this field is necessary to handle
each. */
 void *bsp;  /* Pointer to BSP-specific data */
 } rtems_gpio_t;

/**

   * @brief Structure for configuration of a GPIO object.
   */
 typedef struct {
 rtems_gpio_pin_mode mode;   /* Pin mode */
 rtems_gpio_pull pull;   /* Pull resistor configuration */
 void *bsp;  /* Pointer to BSP-specific config */
 } rtems_gpio_config_t;

Hopefully this makes the application code more portable. I have also
updated the blink code:
https://github.com/dtbpkmte/GSoC-2022-RTEMS-Sample-Apps/blob/main/RTEMS_Blink_API/src/init.c
This time, for simple tasks like basic I/O, users won't need to care
about the details of a BSP.

One thing I am not sure about is that do all architectures have ports
and pins for GPIO? I am worried that my structure is still skewed
towards STM32 because I don't have much knowledge about different types
of microcontrollers.


Most controllers I've worked with use that organization but I'm not sure 
whether it's true for all controllers. Isn't the controller on the 
raspberry an example where there is only one big group of GPIO0 to 
GPIO<$BigNumber>?


But I think you can always organize pins in that way. Only make sure 
that you don't assume that every controller has a maximum of 32 pins. If 
there is only one GPIO controller on a system that has 400 pins, that 
shouldn't be a problem. The same is true if you have 400 controllers 
with one pin each. The logical structure works in both cases.


Note that not all controllers have to be the same type. See my notes 
below regarding the I2C GPIO chip.





If you ask me: We have SYSINIT functions for this kind of
initializations. If something should be done at about bsp_start, the
user can register a function at RTEMS_SYSINIT_BSP_START.


Thank you for the suggestion. This is what I have and it seems to be
working:

RTEMS_SYSINIT_ITEM(
rtems_gpio_initialize,
RTEMS_SYSINIT_BSP_START,
RTEMS_SYSINIT_ORDER_LAST
);




I think I haven't written clearly what I meant: Let's assume a I2C
chip
like the TCA9537 from TI (can be any other GPIO expander from any
other
vendor): You connect it to a I2C bus and control 4 GPIOs with it.
It's a
GPIO so a good GPIO API should be able to handle it.

In that case the GPIO API would do some I2C transfers under the hood
if
you switch or read a GPIO. So what happens if some error happens
during
one of these transfers. If the only error option is UNSATISFIED, the
application can't distinguish the errors. It only knows something
didn't
work. It can't (for example) retry only on certain error cases like
if
the bus is busy.

Please also note that the I2C GPIO expander is one example where a
BSP
would have two completely different GPIO controllers: A number of
integrated ones and a number of I2C ones. A generic API should be
able
to handle that case too.


I understand what you mean now. I have added that capability to by
creating the field is_expander to select between integrated GPIO and
expander. I also have a field called expander_id to select among
multiple expanders. You can see those in the rtems_gpio_t struct above.
The API function prototypes stay the same, but the BSP now need to
implement 2 functions in private: one is the "*_default" function which
controls the built-in GPIO and the other is the "*_ex" function which
controls the expander. Here are the example read and write functions,
which are

Re: [PATCH] score: Make SMP only code explicit

2022-06-23 Thread Joel Sherrill
Does this have a gcc issue?

On Thu, Jun 23, 2022, 3:28 AM Sebastian Huber <
sebastian.hu...@embedded-brains.de> wrote:

> Conditional expressions with inline functions are not optimized away if
> optimization is disabled.  Avoid such expressions to prevent dead
> branches.  It helps also during code review to immediately see if a loop
> is used or not.
> ---
>  cpukit/include/rtems/score/priorityimpl.h | 33 ---
>  cpukit/score/src/kern_tc.c|  4 +++
>  cpukit/score/src/threadchangepriority.c   | 10 ++-
>  cpukit/score/src/threadqops.c | 16 +--
>  cpukit/score/src/watchdogtick.c   |  4 +++
>  5 files changed, 36 insertions(+), 31 deletions(-)
>
> diff --git a/cpukit/include/rtems/score/priorityimpl.h
> b/cpukit/include/rtems/score/priorityimpl.h
> index 1463bf6c2a..55cddf53be 100644
> --- a/cpukit/include/rtems/score/priorityimpl.h
> +++ b/cpukit/include/rtems/score/priorityimpl.h
> @@ -124,26 +124,6 @@ RTEMS_INLINE_ROUTINE bool _Priority_Actions_is_empty(
>return actions->actions == NULL;
>  }
>
> -/**
> - * @brief Checks if the priority actions is valid.
> - *
> - * @param aggregation The aggregation of the priority action.
> - *
> - * @retval true The @a aggregation is valid.
> - * @retval false The @a aggregation is not valid.
> - */
> -RTEMS_INLINE_ROUTINE bool _Priority_Actions_is_valid(
> -  const Priority_Aggregation *aggregation
> -)
> -{
> -#if defined(RTEMS_SMP)
> -  return aggregation != NULL;
> -#else
> -  (void) aggregation;
> -  return false;
> -#endif
> -}
> -
>  /**
>   * @brief Moves the priority actions' actions.
>   *
> @@ -389,25 +369,22 @@ RTEMS_INLINE_ROUTINE void _Priority_Set_action(
>aggregation->Action.type = type;
>  }
>
> +#if defined(RTEMS_SMP)
>  /**
>   * @brief Gets the next action of the priority aggregation.
>   *
> - * @param aggregation The priority aggregation to get the next action of.
> + * @param aggregation is the priority aggregation to get the next action
> of.
>   *
> - * @retval next_action The next action of @a aggregation if RTEMS_SMP is
> defined.
> - * @retval NULL RTEMS_SMP is not defined.
> + * @return Returns the next action of the priority aggregation or NULL if
> there
> + *   is no next action.
>   */
>  RTEMS_INLINE_ROUTINE Priority_Aggregation *_Priority_Get_next_action(
>const Priority_Aggregation *aggregation
>  )
>  {
> -#if defined(RTEMS_SMP)
>return aggregation->Action.next;
> -#else
> -  (void) aggregation;
> -  return NULL;
> -#endif
>  }
> +#endif
>
>  /**
>   * @brief Compares two priorities.
> diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
> index 2b7aeaad31..643026a1c8 100644
> --- a/cpukit/score/src/kern_tc.c
> +++ b/cpukit/score/src/kern_tc.c
> @@ -2329,9 +2329,13 @@ _Timecounter_Tick(void)
>  {
> Per_CPU_Control *cpu_self = _Per_CPU_Get();
>
> +#if defined(RTEMS_SMP)
> if (_Per_CPU_Is_boot_processor(cpu_self)) {
> +#endif
>  tc_windup(NULL);
> +#if defined(RTEMS_SMP)
> }
> +#endif
>
> _Watchdog_Tick(cpu_self);
>  }
> diff --git a/cpukit/score/src/threadchangepriority.c
> b/cpukit/score/src/threadchangepriority.c
> index 321bb15cab..80f030fdc6 100644
> --- a/cpukit/score/src/threadchangepriority.c
> +++ b/cpukit/score/src/threadchangepriority.c
> @@ -135,11 +135,15 @@ static void _Thread_Priority_do_perform_actions(
>priority_aggregation = _Priority_Actions_move(
> &queue_context->Priority.Actions );
>
>do {
> +#if defined(RTEMS_SMP)
>  Priority_Aggregation *next_aggregation;
> +#endif
>  Priority_Node*priority_action_node;
>  Priority_Action_type  priority_action_type;
>
> +#if defined(RTEMS_SMP)
>  next_aggregation = _Priority_Get_next_action( priority_aggregation );
> +#endif
>
>  priority_action_node = priority_aggregation->Action.node;
>  priority_action_type = priority_aggregation->Action.type;
> @@ -198,8 +202,12 @@ static void _Thread_Priority_do_perform_actions(
>  break;
>  }
>
> +#if defined(RTEMS_SMP)
>  priority_aggregation = next_aggregation;
> -  } while ( _Priority_Actions_is_valid( priority_aggregation ) );
> +  } while ( priority_aggregation != NULL );
> +#else
> +  } while ( false );
> +#endif
>
>if ( !_Priority_Actions_is_empty( &queue_context->Priority.Actions ) ) {
>  _Thread_queue_Context_add_priority_update( queue_context, the_thread
> );
> diff --git a/cpukit/score/src/threadqops.c b/cpukit/score/src/threadqops.c
> index 33fc5a44cb..fbea9f6de6 100644
> --- a/cpukit/score/src/threadqops.c
> +++ b/cpukit/score/src/threadqops.c
> @@ -404,8 +404,12 @@ static void _Thread_queue_Priority_priority_actions(
>  break;
>  }
>
> +#if defined(RTEMS_SMP)
>  priority_aggregation = _Priority_Get_next_action(
> priority_aggregation );
> -  } while ( _Priority_Actions_is_valid( priority_aggregation ) );
> +  } while ( priority_aggregation != NULL );
> +#else
> +  } while ( false );
> +#endif
>  }
>
>

Re: [libbsd 0/4] Replace LPC Ethernet interface driver

2022-06-23 Thread Chris Johns
OK

Chris

On 23/6/2022 7:20 pm, Sebastian Huber wrote:
> The standard FreeBSD MII support causes severe problems on the LPC3200
> chip family.  If an Ethernet module register is accessed while there is
> no clock from the PHY, the chip completely locks up and only an external
> watchdog can recover from this state.  The legacy driver had a custom
> PHY management code which helped to avoid such issues.  The if_lpe.c
> driver is no longer maintained by FreeBSD.
> 
> Sebastian Huber (4):
>   if_lpe.c: Import legacy LPC Ethernet driver
>   if_lpe.c: Port to LibBSD
>   if_lpe.c: Move transmit initialization
>   if_lpe.c: Use interface transmit
> 
>  rtemsbsd/sys/arm/lpc/if_lpe.c| 2860 +-
>  rtemsbsd/sys/arm/lpc/if_lpereg.h |  210 ---
>  2 files changed, 1602 insertions(+), 1468 deletions(-)
>  delete mode 100644 rtemsbsd/sys/arm/lpc/if_lpereg.h
> 
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] score: Make SMP only code explicit

2022-06-23 Thread Sebastian Huber

On 24.06.22 00:33, Joel Sherrill wrote:

Does this have a gcc issue?


I don't think this is a GCC issue. Calling an inline function if 
optimization is disabled seems to be all right for me.


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

[libbsd 02/22] Fix redefinition warnings

2022-06-23 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-23 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


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

2022-06-23 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 07/22] nfsclient: Fix extra token after #else warning

2022-06-23 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 00/22] Remove FreeBSD file descriptors and avoid VFS

2022-06-23 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 15/22] Use define for maxfiles and maxfilesperproc

2022-06-23 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(&allproc_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 18/22] Move unmapped_buf_allowed

2022-06-23 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, ¬bufdflushes,
 static long barrierwrites;
 SYSCTL_LONG(_vfs, OID_AUTO, barrierwrites, CTLFLAG_RW, &barrierwrites, 0,
 "Number of barrier writes");
+#ifdef __rtems__
+int unmapped_buf_allowed;
+#endif /* __rtems__ */
 SYSCTL_INT(_vfs, OID_AUTO, unmapped_buf_allowed, CTLFLAG_RD,
 &unmapped_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 09/22] Remove FreeBSD file descriptors

2022-06-23 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, &cap_fcntl_rights, F_GETFL, &fp);
@@ -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(&fcaps->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(&fcaps->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) ||
op

[libbsd 22/22] Disable UNIX Domain Sockets credentials

2022-06-23 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->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, &xu, 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, &client_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 10/22] Update CONTRIBUTING.rst

2022-06-23 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 clos

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

2022-06-23 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, &oidlen);
-   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 04/22] Move setfib() back to route.c

2022-06-23 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, &ua);
+
+   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, &ua);
-   } 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 08/22] devfs: Do not use FreeBSD file descriptors

2022-06-23 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, &fp, &fd, 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, &ref);
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,

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

2022-06-23 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,
 &warninterval,
 "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 03/22] Update kernel namespace

2022-06-23 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 17/22] Move bio_transient_maxcnt

2022-06-23 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(&allproc_lock, "allproc");
 
maxproc = 16;
-- 
2.35.3

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


[libbsd 21/22] Make rtems_bsd_iop_to_file() static

2022-06-23 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-23 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,
 &maxid_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 11/22] Add struct file wrapper

2022-06-23 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 Fre

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

2022-06-23 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->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, &fp, &fd, 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, &ua);
+   } else {
+   error = ENOMEM;
+   }
+
+   if (error == 0) {
+   return td->td_retval[0];
+   } else {
+   rtems_set_errno_and_retur

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

2022-06-23 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 = &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, &auio, 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, &auio, 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 = &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, &auio, NULL, 0, 

[libbsd 20/22] Remove unused rtems_bsd_sysgen_imfsnodeops

2022-06-23 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 14/22] Move select(), pselect(), and poll(), avoid VFS

2022-06-23 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->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(&tv, timeout);
+   tvp = &tv;
+   } 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

[PATCH] sys/event.h: Use rtems_libio_t

2022-06-23 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