Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/uebayasi-xip]: src/sys/dev Implement XIP in md(4).
details: https://anonhg.NetBSD.org/src/rev/6be3c3458857
branches: uebayasi-xip
changeset: 751863:6be3c3458857
user: uebayasi <uebayasi%NetBSD.org@localhost>
date: Thu Nov 18 16:09:46 2010 +0000
description:
Implement XIP in md(4).
diffstat:
sys/dev/md.c | 32 +++++++++++++++++++++--
sys/dev/md.h | 6 +++-
sys/dev/md_root.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 106 insertions(+), 7 deletions(-)
diffs (218 lines):
diff -r 405ad0669ebd -r 6be3c3458857 sys/dev/md.c
--- a/sys/dev/md.c Thu Nov 18 16:07:52 2010 +0000
+++ b/sys/dev/md.c Thu Nov 18 16:09:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: md.c,v 1.62.2.1 2010/11/18 16:07:52 uebayasi Exp $ */
+/* $NetBSD: md.c,v 1.62.2.2 2010/11/18 16:09:46 uebayasi Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
@@ -40,9 +40,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.62.2.1 2010/11/18 16:07:52 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.62.2.2 2010/11/18 16:09:46 uebayasi Exp $");
#include "opt_md.h"
+#include "opt_xip.h"
#include <sys/param.h>
#include <sys/kernel.h>
@@ -99,6 +100,7 @@
static dev_type_ioctl(mdioctl);
static dev_type_strategy(mdstrategy);
static dev_type_size(mdsize);
+static dev_type_mmap(mdmmap);
const struct bdevsw md_bdevsw = {
mdopen, mdclose, mdstrategy, mdioctl, nodump, mdsize, D_DISK
@@ -106,7 +108,7 @@
const struct cdevsw md_cdevsw = {
mdopen, mdclose, mdread, mdwrite, mdioctl,
- nostop, notty, nopoll, nommap, nokqfilter, D_DISK
+ nostop, notty, nopoll, mdmmap, nokqfilter, D_DISK
};
static struct dkdriver mddkdriver = { mdstrategy, NULL };
@@ -443,6 +445,19 @@
pp->part =
&sc->sc_dkdev.dk_label->d_partitions[DISKPART(dev)];
return 0;
+
+#if defined(XIP) && !defined(XIP_CDEV_MMAP)
+ case DIOCGPHYSSEG:
+ {
+ int error = 0;
+
+ if (sc->sc_md.md_phys == NULL)
+ error = EINVAL;
+ else
+ *(void **)data = sc->sc_md.md_phys;
+ return error;
+ }
+#endif
}
}
@@ -475,6 +490,17 @@
return EINVAL;
}
+paddr_t
+mdmmap(dev_t dev, off_t off, int flags)
+{
+
+#if defined(MEMORY_DISK_HOOKS) && defined(XIP)
+ return md_mmap_hook(dev, off, flags);
+#else
+ return -1;
+#endif
+}
+
static void
md_set_disklabel(struct md_softc *sc)
{
diff -r 405ad0669ebd -r 6be3c3458857 sys/dev/md.h
--- a/sys/dev/md.h Thu Nov 18 16:07:52 2010 +0000
+++ b/sys/dev/md.h Thu Nov 18 16:09:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: md.h,v 1.11 2009/12/14 03:11:22 uebayasi Exp $ */
+/* $NetBSD: md.h,v 1.11.2.1 2010/11/18 16:09:46 uebayasi Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
@@ -38,6 +38,9 @@
void *md_addr;
size_t md_size;
int md_type;
+#ifndef XIP_CDEV_MMAP
+ void *md_phys; /* XIP */
+#endif
};
#define MD_GETCONF _IOR('r', 0, struct md_conf) /* get unit config */
@@ -86,6 +89,7 @@
extern void md_attach_hook(int, struct md_conf *);
extern void md_open_hook(int, struct md_conf *);
extern void md_root_setconf(char *, size_t);
+extern paddr_t md_mmap_hook(dev_t, off_t, int);
extern int md_is_root;
#endif /* _KERNEL */
diff -r 405ad0669ebd -r 6be3c3458857 sys/dev/md_root.c
--- a/sys/dev/md_root.c Thu Nov 18 16:07:52 2010 +0000
+++ b/sys/dev/md_root.c Thu Nov 18 16:09:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: md_root.c,v 1.17 2009/04/16 14:46:33 tsutsui Exp $ */
+/* $NetBSD: md_root.c,v 1.17.2.1 2010/11/18 16:09:46 uebayasi Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -30,14 +30,17 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: md_root.c,v 1.17 2009/04/16 14:46:33 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: md_root.c,v 1.17.2.1 2010/11/18 16:09:46 uebayasi Exp $");
#include "opt_md.h"
+#include "opt_xip.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/reboot.h>
+#include <uvm/uvm_extern.h>
+
#include <dev/md.h>
#ifdef MEMORY_DISK_DYNAMIC
@@ -68,8 +71,16 @@
* This array will be patched to contain a file-system image.
* See the program mdsetimage(8) for details.
*/
+
+#ifdef XIP
+#define ROOTALIGN __aligned(PAGE_SIZE)
+CTASSERT(ROOTBYTES % PAGE_SIZE == 0);
+#else
+#define ROOTALIGN
+#endif
+
uint32_t md_root_size = ROOTBYTES;
-char md_root_image[ROOTBYTES] = "|This is the root ramdisk!\n";
+char md_root_image[ROOTBYTES] ROOTALIGN = "|This is the root ramdisk!\n";
#endif /* MEMORY_DISK_IMAGE */
#endif /* MEMORY_DISK_DYNAMIC */
@@ -103,6 +114,25 @@
md->md_addr = (void *)md_root_image;
md->md_size = (size_t)md_root_size;
md->md_type = MD_KMEM_FIXED;
+#ifdef XIP
+ paddr_t start, end;
+
+ pmap_extract(pmap_kernel(),
+ (vaddr_t)md_root_image, &start);
+ pmap_extract(pmap_kernel(),
+ (vaddr_t)md_root_image + (size_t)md_root_size, &end);
+ if (end - start == md_root_size) {
+ aprint_verbose("md%d: allocating physseg\n", unit);
+#ifndef XIP_CDEV_MMAP
+ md->md_phys =
+#endif
+ uvm_page_physload_device(atop(start), atop(end),
+ UVM_PROT_READ, 0);
+ } else {
+ aprint_error("md%d: can't alloc non-contig physseg\n",
+ unit);
+ }
+#endif
format_bytes(pbuf, sizeof(pbuf), md->md_size);
aprint_verbose("md%d: internal %s image area\n", unit, pbuf);
}
@@ -119,3 +149,42 @@
boothowto |= MEMORY_DISK_RBFLAGS;
}
}
+
+paddr_t
+md_mmap_hook(dev_t dev, off_t off, int flags)
+{
+ int success;
+ paddr_t pa;
+
+ success = pmap_extract(pmap_kernel(),
+ (vaddr_t)(md_root_image + off), &pa);
+ KASSERT(success);
+
+ /* XXXUEBS copied from sys/dev/usb/udl.c */
+ /* XXX we need MI paddr_t -> mmap cookie API */
+#if defined(__alpha__)
+#define PTOMMAP(paddr) alpha_btop((char *)paddr)
+#elif defined(__arm__)
+#define PTOMMAP(paddr) arm_btop((u_long)paddr)
+#elif defined(__hppa__)
+#define PTOMMAP(paddr) btop((u_long)paddr)
+#elif defined(__i386__) || defined(__x86_64__)
+#define PTOMMAP(paddr) x86_btop(paddr)
+#elif defined(__m68k__)
+#define PTOMMAP(paddr) m68k_btop((char *)paddr)
+#elif defined(__mips__)
+#define PTOMMAP(paddr) mips_btop(paddr)
+#elif defined(__powerpc__)
+#define PTOMMAP(paddr) (paddr)
+#elif defined(__sh__)
+#define PTOMMAP(paddr) sh3_btop(paddr)
+#elif defined(__sparc__)
+#define PTOMMAP(paddr) (paddr)
+#elif defined(__sparc64__)
+#define PTOMMAP(paddr) atop(paddr)
+#elif defined(__vax__)
+#define PTOMMAP(paddr) btop((u_int)paddr)
+#endif
+
+ return PTOMMAP(pa);
+}
Home |
Main Index |
Thread Index |
Old Index