summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2023-07-19 10:42:13 +1000
committerDamien Zammit <damien@zamaudio.com>2023-07-20 14:17:01 +1000
commit5cc4528bce7e364ffe5cc423db2f2377d00befd5 (patch)
tree90e12ce5659747c59c802f42f9389576e1d4caab
parente22f3a3170e5c3028dc83fbdfb0d8705fd00df75 (diff)
pci-arbiter: Remove machdev dependency
-rw-r--r--pci-arbiter/Makefile2
-rw-r--r--pci-arbiter/main.c175
2 files changed, 74 insertions, 103 deletions
diff --git a/pci-arbiter/Makefile b/pci-arbiter/Makefile
index 821c3ca9..b61365d8 100644
--- a/pci-arbiter/Makefile
+++ b/pci-arbiter/Makefile
@@ -25,7 +25,7 @@ SRCS = main.c pci-ops.c netfs_impl.c \
device_map.c pciServer.c startup_notifyServer.c
OBJS = $(SRCS:.c=.o) $(MIGSTUBS)
-HURDLIBS= fshelp ports shouldbeinlibc netfs iohelp ihash trivfs machdev
+HURDLIBS= fshelp ports shouldbeinlibc netfs iohelp ihash
LDLIBS = -lpthread $(libpciaccess_LIBS)
target = pci-arbiter
diff --git a/pci-arbiter/main.c b/pci-arbiter/main.c
index 5e54b2f2..e83c369c 100644
--- a/pci-arbiter/main.c
+++ b/pci-arbiter/main.c
@@ -29,6 +29,7 @@
#include <hurd/ports.h>
#include <hurd/fsys.h>
#include <hurd/paths.h>
+#include <hurd/startup.h>
#include <device/device.h>
#include <sys/mman.h>
@@ -40,7 +41,6 @@
#include "libnetfs/fsys_S.h"
#include "libports/interrupt_S.h"
#include "libnetfs/ifsock_S.h"
-#include "libmachdev/machdev.h"
#include "libshouldbeinlibc/wire.h"
#include <pciaccess.h>
#include <pthread.h>
@@ -56,67 +56,70 @@ char *netfs_server_version = HURD_VERSION;
static mach_port_t pci_control_port;
+struct port_class *pci_shutdown_notify_class;
-static io_return_t
-pci_device_open (mach_port_t reply_port, mach_msg_type_name_t reply_port_type,
- dev_mode_t mode, const char *name, device_t * devp,
- mach_msg_type_name_t * devicePoly)
+error_t
+S_startup_dosync (mach_port_t notify_port)
{
- io_return_t err = D_SUCCESS;
- mach_port_t dev_master, root;
- string_t retry_name;
- retry_type retry;
- uid_t idlist[] = {0, 0, 0};
+ /* Nothing to sync */
+ return 0;
+}
- if (strncmp(name, "pci", 3))
- err = D_NO_SUCH_DEVICE;
+static void
+essential_task (void)
+{
+ mach_port_t host, startup;
+ error_t err;
- /* Fall back to opening kernel device master */
+ err = get_privileged_ports (&host, 0);
if (err)
{
- err = get_privileged_ports(NULL, &dev_master);
- if (err)
- return err;
- if (dev_master == MACH_PORT_NULL)
- return D_NO_SUCH_DEVICE;
- err = device_open (dev_master, mode, name, devp);
- if (err)
- return err;
- *devicePoly = MACH_MSG_TYPE_MOVE_SEND;
- return D_SUCCESS;
+ mach_print ("WARNING: pci cannot register as essential task\n");
+ return;
}
+ startup = file_name_lookup (_SERVERS_STARTUP, 0, 0);
+ if (startup == MACH_PORT_NULL)
+ {
+ mach_print ("WARNING: pci cannot register as essential task\n");
+ mach_port_deallocate (mach_task_self (), host);
+ return;
+ }
+ startup_essential_task (startup, mach_task_self (), MACH_PORT_NULL,
+ program_invocation_short_name, host);
+ mach_port_deallocate (mach_task_self (), startup);
+ mach_port_deallocate (mach_task_self (), host);
+}
+
+static void
+arrange_shutdown_notification (void)
+{
+ error_t err;
+ mach_port_t initport, notify;
+ struct port_info *pi;
- err = fsys_getroot(pci_control_port, MACH_PORT_NULL, MACH_MSG_TYPE_COPY_SEND,
- idlist, 3, idlist, 3, 0,
- &retry, retry_name, &root);
+ pci_shutdown_notify_class = ports_create_class (0, 0);
+
+ /* Arrange to get notified when the system goes down */
+ err = ports_create_port (pci_shutdown_notify_class, netfs_port_bucket,
+ sizeof (struct port_info), &pi);
if (err)
- return err;
+ return;
- *devp = root;
- *devicePoly = MACH_MSG_TYPE_COPY_SEND;
- return D_SUCCESS;
-}
+ initport = file_name_lookup (_SERVERS_STARTUP, 0, 0);
+ if (initport == MACH_PORT_NULL)
+ {
+ mach_print ("WARNING: pci not registered for shutdown\n");
+ return;
+ }
-static struct machdev_device_emulation_ops pci_arbiter_emulation_ops = {
- NULL,
- NULL,
- NULL,
- NULL,
- pci_device_open,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
+ notify = ports_get_send_right (pi);
+ ports_port_deref (pi);
+ startup_request_notification (initport, notify,
+ MACH_MSG_TYPE_MAKE_SEND,
+ program_invocation_short_name);
+ mach_port_deallocate (mach_task_self (), notify);
+ mach_port_deallocate (mach_task_self (), initport);
+}
int
netfs_demuxer (mach_msg_header_t * inp, mach_msg_header_t * outp)
@@ -172,12 +175,13 @@ pcifs_startup(mach_port_t bootstrap, int flags)
pci_control_port = ports_get_send_right (newpi);
- if (bootstrap != MACH_PORT_NULL)
- {
- err = fsys_startup (bootstrap, flags, pci_control_port, MACH_MSG_TYPE_COPY_SEND,
- &realnode);
- assert_perror_backtrace (err);
- }
+ err = fsys_startup (bootstrap, flags, pci_control_port, MACH_MSG_TYPE_COPY_SEND,
+ &realnode);
+ assert_perror_backtrace (err);
+
+ essential_task();
+
+ arrange_shutdown_notification();
return realnode;
}
@@ -187,42 +191,22 @@ main (int argc, char **argv)
{
error_t err;
mach_port_t bootstrap;
- mach_port_t next_task;
- pthread_t t, mt;
file_t underlying_node = MACH_PORT_NULL;
/* Parse options */
alloc_file_system (&fs);
argp_parse (netfs_runtime_argp, argc, argv, 0, 0, 0);
- next_task = fs->params.next_task;
- if (next_task != MACH_PORT_NULL)
- {
- /* We are a bootstrap process */
-
- machdev_register (&pci_arbiter_emulation_ops);
- /* TODO: make libmachdev allow us to also run netfs on the translated path,
- * so that we don't need a second pci-arbiter to serve /servers/bus/pci. */
- machdev_trivfs_init (argc, argv, next_task, "pci", NULL /* _SERVERS_BUS "/pci" */, &bootstrap);
-
- /* Make sure we will not swap out, in case we are needed for swapping
- back in. */
- err = wire_task_self ();
- if (err)
- error (1, errno, "cannot lock all memory");
-
- machdev_device_init ();
- err = pthread_create (&t, NULL, machdev_server, NULL);
- if (err)
- error (1, err, "Creating machdev_server thread");
- pthread_detach (t);
- }
- else
- {
- task_get_bootstrap_port (mach_task_self (), &bootstrap);
- if (bootstrap == MACH_PORT_NULL)
- error (1, 0, "must be started as a translator");
- }
+ task_get_bootstrap_port (mach_task_self (), &bootstrap);
+ if (bootstrap == MACH_PORT_NULL)
+ error (1, 0, "must be started as a translator");
+
+ /* Make sure we will not swap out, in case we are needed for swapping
+ back in. */
+ err = wire_task_self ();
+ if (err)
+ error (1, errno, "cannot lock all memory");
+
/* Initialize netfs and start the translator. */
netfs_init ();
@@ -237,20 +221,13 @@ main (int argc, char **argv)
if (err)
error (1, err, "Starting the PCI system");
- if (next_task != MACH_PORT_NULL)
- machdev_trivfs_server_startup (bootstrap);
-
- if (next_task == MACH_PORT_NULL)
- underlying_node = netfs_startup (bootstrap, O_READ);
+ underlying_node = netfs_startup (bootstrap, O_READ);
/* Create the root node first */
err = init_root_node (underlying_node);
if (err)
error (1, err, "Creating the root node");
- if (next_task != MACH_PORT_NULL)
- pcifs_startup (bootstrap, O_READ);
-
err = init_file_system (fs);
if (err)
error (1, err, "Creating the PCI filesystem");
@@ -265,13 +242,7 @@ main (int argc, char **argv)
if (err)
error (1, err, "Setting permissions");
- if (next_task != MACH_PORT_NULL)
- {
- err = pthread_create(&mt, NULL, machdev_trivfs_server_loop, NULL);
- if (err)
- error(1, err, "Creating machdev_trivfs_server_loop thread");
- pthread_detach(mt);
- }
+ pcifs_startup (bootstrap, O_READ);
netfs_server_func (NULL);