svn commit: r318159 - in stable/10/sys: dev/fdt geom modules/geom modules/geom/geom_flashmap sys
Marius Strobl
marius at FreeBSD.org
Wed May 10 21:42:18 UTC 2017
Author: marius
Date: Wed May 10 21:42:16 2017
New Revision: 318159
URL: https://svnweb.freebsd.org/changeset/base/318159
Log:
MFC: r287013 (partial), r294616, r314097 (partial)
- Allow overriding the FDT slicer with a custom slicer.
- Teach the flashmap code about SPI flash.
- Allow different slicers for different flash types to be registered
with geom_flashmap(4) and teach it about MMC for slicing enhanced
user data area partitions. The FDT slicer still is the default for
CFI, NAND and SPI flash on FDT-enabled platforms.
- In addition to a device_t, also pass the name of the GEOM provider
in question to the slicers as a single device may provide more than
one provider.
- Build a geom_flashmap.ko.
- Use MODULE_VERSION() so other modules can depend on geom_flashmap(4).
- Remove redundant/superfluous GEOM routines that either do nothing
or provide/just call default GEOM (slice) functionality.
- Trim/adjust includes
Added:
stable/10/sys/modules/geom/geom_flashmap/
- copied from r314097, head/sys/modules/geom/geom_flashmap/
Modified:
stable/10/sys/dev/fdt/fdt_slicer.c
stable/10/sys/geom/geom_flashmap.c
stable/10/sys/modules/geom/Makefile
stable/10/sys/sys/slicer.h
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sys/dev/fdt/fdt_slicer.c
==============================================================================
--- stable/10/sys/dev/fdt/fdt_slicer.c Wed May 10 21:42:12 2017 (r318158)
+++ stable/10/sys/dev/fdt/fdt_slicer.c Wed May 10 21:42:16 2017 (r318159)
@@ -30,10 +30,11 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/module.h>
#include <sys/slicer.h>
#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/openfirm.h>
#ifdef DEBUG
#define debugf(fmt, args...) do { printf("%s(): ", __func__); \
@@ -42,8 +43,13 @@ __FBSDID("$FreeBSD$");
#define debugf(fmt, args...)
#endif
-int
-flash_fill_slices(device_t dev, struct flash_slice *slices, int *slices_num)
+static int fdt_flash_fill_slices(device_t dev, const char *provider,
+ struct flash_slice *slices, int *slices_num);
+static void fdt_slicer_init(void);
+
+static int
+fdt_flash_fill_slices(device_t dev, const char *provider __unused,
+ struct flash_slice *slices, int *slices_num)
{
char *slice_name;
phandle_t dt_node, dt_child;
@@ -90,8 +96,8 @@ flash_fill_slices(device_t dev, struct f
(void **)&slice_name);
if (name_len <= 0) {
/* Use node name if no label defined */
- name_len = OF_getprop_alloc(dt_child, "name", sizeof(char),
- (void **)&slice_name);
+ name_len = OF_getprop_alloc(dt_child, "name",
+ sizeof(char), (void **)&slice_name);
if (name_len <= 0) {
debugf("slice i=%d with no name\n", i);
slice_name = NULL;
@@ -110,3 +116,23 @@ flash_fill_slices(device_t dev, struct f
*slices_num = i;
return (0);
}
+
+static void
+fdt_slicer_init(void)
+{
+
+ flash_register_slicer(fdt_flash_fill_slices, FLASH_SLICES_TYPE_NAND,
+ FALSE);
+ flash_register_slicer(fdt_flash_fill_slices, FLASH_SLICES_TYPE_CFI,
+ FALSE);
+ flash_register_slicer(fdt_flash_fill_slices, FLASH_SLICES_TYPE_SPI,
+ FALSE);
+}
+
+/*
+ * Must be initialized after GEOM classes (SI_SUB_DRIVERS/SI_ORDER_FIRST),
+ * i. e. after g_init() is called, due to the use of the GEOM topology_lock
+ * in flash_register_slicer(). However, must be before SI_SUB_CONFIGURE.
+ */
+SYSINIT(fdt_slicer_rootconf, SI_SUB_DRIVERS, SI_ORDER_SECOND, fdt_slicer_init,
+ NULL);
Modified: stable/10/sys/geom/geom_flashmap.c
==============================================================================
--- stable/10/sys/geom/geom_flashmap.c Wed May 10 21:42:12 2017 (r318158)
+++ stable/10/sys/geom/geom_flashmap.c Wed May 10 21:42:16 2017 (r318159)
@@ -29,13 +29,9 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
-#include <sys/endian.h>
#include <sys/systm.h>
#include <sys/kernel.h>
-#include <sys/fcntl.h>
#include <sys/malloc.h>
-#include <sys/bio.h>
-#include <sys/bus.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/slicer.h>
@@ -43,9 +39,10 @@ __FBSDID("$FreeBSD$");
#include <geom/geom.h>
#include <geom/geom_slice.h>
#include <geom/geom_disk.h>
+
#include <dev/nand/nand_dev.h>
-#define FLASHMAP_CLASS_NAME "Flashmap"
+#define FLASHMAP_CLASS_NAME "Flashmap"
struct g_flashmap_slice {
off_t sl_start;
@@ -57,19 +54,24 @@ struct g_flashmap_slice {
STAILQ_HEAD(g_flashmap_head, g_flashmap_slice);
-static void g_flashmap_print(struct g_flashmap_slice *);
-static int g_flashmap_modify(struct g_geom *, const char *,
- int, struct g_flashmap_head *);
-static int g_flashmap_start(struct bio *);
-static int g_flashmap_ioctl(struct g_provider *, u_long, void *,
- int, struct thread *);
-static void g_flashmap_dumpconf(struct sbuf *, const char *,
- struct g_geom *, struct g_consumer *, struct g_provider *);
-static struct g_geom *g_flashmap_taste(struct g_class *,
- struct g_provider *, int);
-static void g_flashmap_config(struct gctl_req *, struct g_class *,
- const char *);
-static int g_flashmap_load(device_t, struct g_flashmap_head *);
+static struct {
+ const char *type;
+ flash_slicer_t slicer;
+} g_flashmap_slicers[] = {
+ { "NAND::device", NULL },
+ { "CFI::device", NULL },
+ { "SPI::device", NULL },
+ { "MMC::device", NULL }
+};
+
+static g_ioctl_t g_flashmap_ioctl;
+static g_taste_t g_flashmap_taste;
+
+static int g_flashmap_load(device_t dev, struct g_provider *pp,
+ flash_slicer_t slicer, struct g_flashmap_head *head);
+static int g_flashmap_modify(struct g_geom *gp, const char *devname,
+ int secsize, struct g_flashmap_head *slices);
+static void g_flashmap_print(struct g_flashmap_slice *slice);
MALLOC_DECLARE(M_FLASHMAP);
MALLOC_DEFINE(M_FLASHMAP, "geom_flashmap", "GEOM flash memory slicer class");
@@ -102,7 +104,7 @@ g_flashmap_modify(struct g_geom *gp, con
error = g_slice_config(gp, i++, G_SLICE_CONFIG_CHECK,
slice->sl_start,
slice->sl_end - slice->sl_start + 1,
- secsize, "%ss.%s", gp->name, slice->sl_name);
+ secsize, FLASH_SLICES_FMT, gp->name, slice->sl_name);
if (error)
return (error);
@@ -123,23 +125,6 @@ g_flashmap_modify(struct g_geom *gp, con
}
static int
-g_flashmap_start(struct bio *bp)
-{
-
- return (0);
-}
-
-static void
-g_flashmap_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
- struct g_consumer *cp __unused, struct g_provider *pp)
-{
- struct g_slicer *gsp;
-
- gsp = gp->softc;
- g_slice_dumpconf(sb, indent, gp, cp, pp);
-}
-
-static int
g_flashmap_ioctl(struct g_provider *pp, u_long cmd, void *data, int fflag,
struct thread *td)
{
@@ -159,16 +144,16 @@ g_flashmap_ioctl(struct g_provider *pp,
return (gp->ioctl(cp->provider, cmd, data, fflag, td));
}
-
static struct g_geom *
g_flashmap_taste(struct g_class *mp, struct g_provider *pp, int flags)
{
- struct g_geom *gp = NULL;
+ struct g_geom *gp;
struct g_consumer *cp;
struct g_flashmap_head head;
struct g_flashmap_slice *slice, *slice_temp;
+ flash_slicer_t slicer;
device_t dev;
- int nslices, size;
+ int i, size;
g_trace(G_T_TOPOLOGY, "flashmap_taste(%s,%s)", mp->name, pp->name);
g_topology_assert();
@@ -177,23 +162,26 @@ g_flashmap_taste(struct g_class *mp, str
strcmp(pp->geom->class->name, G_DISK_CLASS_NAME) != 0)
return (NULL);
- gp = g_slice_new(mp, FLASH_SLICES_MAX_NUM, pp, &cp, NULL, 0,
- g_flashmap_start);
+ gp = g_slice_new(mp, FLASH_SLICES_MAX_NUM, pp, &cp, NULL, 0, NULL);
if (gp == NULL)
return (NULL);
STAILQ_INIT(&head);
do {
- size = sizeof(device_t);
- if (g_io_getattr("NAND::device", cp, &size, &dev)) {
+ slicer = NULL;
+ for (i = 0; i < nitems(g_flashmap_slicers); i++) {
size = sizeof(device_t);
- if (g_io_getattr("CFI::device", cp, &size, &dev))
+ if (g_io_getattr(g_flashmap_slicers[i].type, cp,
+ &size, &dev) == 0) {
+ slicer = g_flashmap_slicers[i].slicer;
break;
+ }
}
+ if (slicer == NULL)
+ break;
- nslices = g_flashmap_load(dev, &head);
- if (nslices == 0)
+ if (g_flashmap_load(dev, pp, slicer, &head) == 0)
break;
g_flashmap_modify(gp, cp->provider->name,
@@ -202,9 +190,8 @@ g_flashmap_taste(struct g_class *mp, str
g_access(cp, -1, 0, 0);
- STAILQ_FOREACH_SAFE(slice, &head, sl_link, slice_temp) {
+ STAILQ_FOREACH_SAFE(slice, &head, sl_link, slice_temp)
free(slice, M_FLASHMAP);
- }
if (LIST_EMPTY(&gp->provider)) {
g_slice_spoiled(cp);
@@ -213,24 +200,17 @@ g_flashmap_taste(struct g_class *mp, str
return (gp);
}
-static void
-g_flashmap_config(struct gctl_req *req, struct g_class *mp, const char *verb)
-{
-
- gctl_error(req, "unknown config verb");
-}
-
static int
-g_flashmap_load(device_t dev, struct g_flashmap_head *head)
+g_flashmap_load(device_t dev, struct g_provider *pp, flash_slicer_t slicer,
+ struct g_flashmap_head *head)
{
struct flash_slice *slices;
struct g_flashmap_slice *slice;
- uint32_t i, buf_size;
- int nslices = 0;
+ int i, nslices = 0;
- buf_size = sizeof(struct flash_slice) * FLASH_SLICES_MAX_NUM;
- slices = malloc(buf_size, M_FLASHMAP, M_WAITOK | M_ZERO);
- if (flash_fill_slices(dev, slices, &nslices) == 0) {
+ slices = malloc(sizeof(struct flash_slice) * FLASH_SLICES_MAX_NUM,
+ M_FLASHMAP, M_WAITOK | M_ZERO);
+ if (slicer(dev, pp->name, slices, &nslices) == 0) {
for (i = 0; i < nslices; i++) {
slice = malloc(sizeof(struct g_flashmap_slice),
M_FLASHMAP, M_WAITOK);
@@ -247,13 +227,21 @@ g_flashmap_load(device_t dev, struct g_f
return (nslices);
}
+void flash_register_slicer(flash_slicer_t slicer, u_int type, bool force)
+{
+
+ g_topology_lock();
+ if (g_flashmap_slicers[type].slicer == NULL || force == TRUE)
+ g_flashmap_slicers[type].slicer = slicer;
+ g_topology_unlock();
+}
+
static struct g_class g_flashmap_class = {
.name = FLASHMAP_CLASS_NAME,
.version = G_VERSION,
.taste = g_flashmap_taste,
- .dumpconf = g_flashmap_dumpconf,
.ioctl = g_flashmap_ioctl,
- .ctlreq = g_flashmap_config,
};
DECLARE_GEOM_CLASS(g_flashmap_class, g_flashmap);
+MODULE_VERSION(g_flashmap, 0);
Modified: stable/10/sys/modules/geom/Makefile
==============================================================================
--- stable/10/sys/modules/geom/Makefile Wed May 10 21:42:12 2017 (r318158)
+++ stable/10/sys/modules/geom/Makefile Wed May 10 21:42:16 2017 (r318159)
@@ -7,6 +7,7 @@ SUBDIR= geom_bde \
geom_cache \
geom_concat \
geom_eli \
+ geom_flashmap \
geom_fox \
geom_gate \
geom_journal \
Modified: stable/10/sys/sys/slicer.h
==============================================================================
--- stable/10/sys/sys/slicer.h Wed May 10 21:42:12 2017 (r318158)
+++ stable/10/sys/sys/slicer.h Wed May 10 21:42:16 2017 (r318159)
@@ -27,25 +27,38 @@
*/
#ifndef _FLASH_SLICER_H_
-#define _FLASH_SLICER_H_
+#define _FLASH_SLICER_H_
#include <sys/types.h>
-#define FLASH_SLICES_MAX_NUM 8
-#define FLASH_SLICES_MAX_NAME_LEN (32 + 1)
+#define FLASH_SLICES_MAX_NUM 8
+#define FLASH_SLICES_MAX_NAME_LEN (32 + 1)
#define FLASH_SLICES_FLAG_NONE 0
#define FLASH_SLICES_FLAG_RO 1 /* Read only */
+#define FLASH_SLICES_FMT "%ss.%s"
+
struct flash_slice {
off_t base;
off_t size;
- char *label;
+ const char *label;
unsigned int flags;
};
#ifdef _KERNEL
-int flash_fill_slices(device_t, struct flash_slice *, int *);
+
+typedef int (*flash_slicer_t)(device_t dev, const char *provider,
+ struct flash_slice *slices, int *slices_num);
+
+#define FLASH_SLICES_TYPE_NAND 0
+#define FLASH_SLICES_TYPE_CFI 1
+#define FLASH_SLICES_TYPE_SPI 2
+#define FLASH_SLICES_TYPE_MMC 3
+
+/* Use NULL for deregistering a slicer */
+void flash_register_slicer(flash_slicer_t slicer, u_int type, bool force);
+
#endif /* _KERNEL */
#endif /* _FLASH_SLICER_H_ */
More information about the svn-src-all
mailing list