bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] Expose device(mbinfo) with read access to multiboot info


From: Damien Zammit
Subject: [PATCH 3/3] Expose device(mbinfo) with read access to multiboot info
Date: Thu, 24 Oct 2024 00:11:11 +0000

This adds a new mach device called mbinfo that exposes the multiboot
information to userspace.

---
 i386/Makefrag.am        |  2 ++
 i386/i386at/conf.c      |  8 +++++++
 i386/i386at/mbinfo.c    | 53 +++++++++++++++++++++++++++++++++++++++++
 i386/i386at/mbinfo.h    | 35 +++++++++++++++++++++++++++
 i386/i386at/model_dep.c |  3 +++
 5 files changed, 101 insertions(+)
 create mode 100644 i386/i386at/mbinfo.c
 create mode 100644 i386/i386at/mbinfo.h

diff --git a/i386/Makefrag.am b/i386/Makefrag.am
index 7a339417..906ccc2d 100644
--- a/i386/Makefrag.am
+++ b/i386/Makefrag.am
@@ -69,6 +69,8 @@ libkernel_a_SOURCES += \
        i386/i386at/kd_mouse.h \
        i386/i386at/kdasm.S \
        i386/i386at/kdsoft.h \
+       i386/i386at/mbinfo.c \
+       i386/i386at/mbinfo.h \
        i386/i386at/mem.c \
        i386/i386at/mem.h \
        i386/i386at/rtc.c \
diff --git a/i386/i386at/conf.c b/i386/i386at/conf.c
index ecbf1e45..ba056ea1 100644
--- a/i386/i386at/conf.c
+++ b/i386/i386at/conf.c
@@ -71,6 +71,9 @@
 #include <device/intr.h>
 #define irqname                        "irq"
 
+#include <i386at/mbinfo.h>
+#define mbinfoname             "mbinfo"
+
 /*
  * List of devices - console must be at slot 0
  */
@@ -157,6 +160,11 @@ struct dev_ops     dev_name_list[] =
           nodev_async_in,        nulldev_reset,        nulldev_portdeath,0,
           nodev_info },
 
+        { mbinfoname,  nulldev_open,   nulldev_close,  mbinforead,
+          nulldev_write,nulldev_getstat,nulldev_setstat,nomap,
+          nodev_async_in,      nulldev_reset,  nulldev_portdeath,0,
+          nodev_info },
+
 };
 int    dev_name_count = sizeof(dev_name_list)/sizeof(dev_name_list[0]);
 
diff --git a/i386/i386at/mbinfo.c b/i386/i386at/mbinfo.c
new file mode 100644
index 00000000..521119b8
--- /dev/null
+++ b/i386/i386at/mbinfo.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2024 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <i386at/mbinfo.h>
+#include <mach/vm_param.h>
+#include <vm/pmap.h>
+#include <device/ds_routines.h>
+
+struct multiboot_raw_info mb_info;
+
+void
+mbinfo_register_boot_data(const struct multiboot_raw_info *mbi)
+{
+       mb_info = *mbi;
+}
+
+io_return_t
+mbinforead(dev_t dev, io_req_t ior)
+{
+       int err, count;
+
+       /* Check if IO_COUNT is valid */
+       if (ior->io_count != sizeof(struct multiboot_raw_info))
+           return D_INVALID_SIZE;
+
+       err = device_read_alloc(ior, (vm_size_t)ior->io_count);
+       if (err != KERN_SUCCESS)
+           return (err);
+
+       count = 0;
+       uint8_t *byte = (uint8_t *)&mb_info;
+       while (count < ior->io_count) {
+           *(uint8_t *)(&ior->io_data[count]) = *byte;
+           count++;
+           byte++;
+       }
+       ior->io_residual = ior->io_count - count;
+       return (D_SUCCESS);
+}
diff --git a/i386/i386at/mbinfo.h b/i386/i386at/mbinfo.h
new file mode 100644
index 00000000..0e623250
--- /dev/null
+++ b/i386/i386at/mbinfo.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2024 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _I386AT_MBINFO_H_
+#define _I386AT_MBINFO_H_      1
+
+#include <sys/types.h>
+
+#include <vm/vm_types.h>
+#include <mach/vm_prot.h>
+#include <device/device_types.h>
+#include <device/io_req.h>
+#include <mach/machine/multiboot.h>
+
+extern struct multiboot_raw_info mb_info;
+
+void mbinfo_register_boot_data(const struct multiboot_raw_info *mbi);
+
+io_return_t mbinforead(dev_t dev, io_req_t ior);
+
+#endif /* !_I386AT_MBINFO_H_ */
diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
index a3e9b630..01489353 100644
--- a/i386/i386at/model_dep.c
+++ b/i386/i386at/model_dep.c
@@ -75,6 +75,7 @@
 #include <i386at/int_init.h>
 #include <i386at/kd.h>
 #include <i386at/rtc.h>
+#include <i386at/mbinfo.h>
 #include <i386at/model_dep.h>
 #include <machine/irq.h>
 
@@ -354,6 +355,8 @@ register_boot_data(const struct multiboot_raw_info *mbi)
                                biosmem_register_boot_data(shdr->addr, 
shdr->addr + shdr->size, FALSE);
                }
        }
+
+       mbinfo_register_boot_data(mbi);
 }
 
 #endif /* MACH_HYP */
-- 
2.45.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]