From owner-svn-src-stable-11@freebsd.org Wed May 10 21:42:14 2017 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 921D0D67918; Wed, 10 May 2017 21:42:14 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5FA1B8FE; Wed, 10 May 2017 21:42:14 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4ALgDiq060805; Wed, 10 May 2017 21:42:13 GMT (envelope-from marius@FreeBSD.org) Received: (from marius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4ALgCs7060797; Wed, 10 May 2017 21:42:12 GMT (envelope-from marius@FreeBSD.org) Message-Id: <201705102142.v4ALgCs7060797@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: marius set sender to marius@FreeBSD.org using -f From: Marius Strobl Date: Wed, 10 May 2017 21:42:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r318158 - in stable/11/sys: dev/bhnd/cores/chipc dev/fdt dev/nand geom modules/geom modules/geom/geom_flashmap powerpc/mikrotik sys X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 May 2017 21:42:14 -0000 Author: marius Date: Wed May 10 21:42:12 2017 New Revision: 318158 URL: https://svnweb.freebsd.org/changeset/base/318158 Log: MFC: r314097 - 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/11/sys/modules/geom/geom_flashmap/ - copied from r314097, head/sys/modules/geom/geom_flashmap/ Modified: stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.c stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.h stable/11/sys/dev/fdt/fdt_slicer.c stable/11/sys/dev/nand/nfc_rb.c stable/11/sys/geom/geom_flashmap.c stable/11/sys/modules/geom/Makefile stable/11/sys/powerpc/mikrotik/platform_rb.c stable/11/sys/sys/slicer.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.c ============================================================================== --- stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.c Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.c Wed May 10 21:42:12 2017 (r318158) @@ -63,10 +63,12 @@ chipc_register_slicer(chipc_flash flash_ switch (flash_type) { case CHIPC_SFLASH_AT: case CHIPC_SFLASH_ST: - flash_register_slicer(chipc_slicer_spi); + flash_register_slicer(chipc_slicer_spi, FLASH_SLICES_TYPE_SPI, + TRUE); break; case CHIPC_PFLASH_CFI: - flash_register_slicer(chipc_slicer_cfi); + flash_register_slicer(chipc_slicer_cfi, FLASH_SLICES_TYPE_CFI, + TRUE); break; default: /* Unsupported */ @@ -75,7 +77,8 @@ chipc_register_slicer(chipc_flash flash_ } int -chipc_slicer_cfi(device_t dev, struct flash_slice *slices, int *nslices) +chipc_slicer_cfi(device_t dev, const char *provider __unused, + struct flash_slice *slices, int *nslices) { struct cfi_softc *sc; device_t parent; @@ -100,7 +103,8 @@ chipc_slicer_cfi(device_t dev, struct fl } int -chipc_slicer_spi(device_t dev, struct flash_slice *slices, int *nslices) +chipc_slicer_spi(device_t dev, const char *provider __unused, + struct flash_slice *slices, int *nslices) { struct chipc_spi_softc *sc; device_t chipc, spi, spibus; Modified: stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.h ============================================================================== --- stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.h Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/dev/bhnd/cores/chipc/chipc_slicer.h Wed May 10 21:42:12 2017 (r318158) @@ -41,9 +41,9 @@ #define NVRAM_MAGIC 0x48534C46 void chipc_register_slicer(chipc_flash flash_type); -int chipc_slicer_spi(device_t dev, struct flash_slice *slices, - int *nslices); -int chipc_slicer_cfi(device_t dev, struct flash_slice *slices, - int *nslices); +int chipc_slicer_spi(device_t dev, const char *provider, + struct flash_slice *slices, int *nslices); +int chipc_slicer_cfi(device_t dev, const char *provider, + struct flash_slice *slices, int *nslices); #endif /* _BHND_CORES_CHIPC_CHIPC_SLICER_H_ */ Modified: stable/11/sys/dev/fdt/fdt_slicer.c ============================================================================== --- stable/11/sys/dev/fdt/fdt_slicer.c Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/dev/fdt/fdt_slicer.c Wed May 10 21:42:12 2017 (r318158) @@ -30,10 +30,11 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include +#include +#include #ifdef DEBUG #define debugf(fmt, args...) do { printf("%s(): ", __func__); \ @@ -42,8 +43,13 @@ __FBSDID("$FreeBSD$"); #define debugf(fmt, args...) #endif -int -fdt_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 @@ fdt_flash_fill_slices(device_t dev, stru (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 @@ fdt_flash_fill_slices(device_t dev, stru *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/11/sys/dev/nand/nfc_rb.c ============================================================================== --- stable/11/sys/dev/nand/nfc_rb.c Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/dev/nand/nfc_rb.c Wed May 10 21:42:12 2017 (r318158) @@ -36,6 +36,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + +#include #include @@ -106,6 +109,40 @@ static const struct nand_ecc_data rb_ecc }; #endif +/* Slicer operates on the NAND controller, so we have to find the chip. */ +static int +rb_nand_slicer(device_t dev, const char *provider __unused, + struct flash_slice *slices, int *nslices) +{ + struct nand_chip *chip; + device_t *children; + int n; + + if (device_get_children(dev, &children, &n) != 0) { + panic("Slicer called on controller with no child!"); + } + dev = children[0]; + free(children, M_TEMP); + + if (device_get_children(dev, &children, &n) != 0) { + panic("Slicer called on controller with nandbus but no child!"); + } + dev = children[0]; + free(children, M_TEMP); + + chip = device_get_softc(dev); + *nslices = 2; + slices[0].base = 0; + slices[0].size = 4 * 1024 * 1024; + slices[0].label = "boot"; + + slices[1].base = 4 * 1024 * 1024; + slices[1].size = chip->ndisk->d_mediasize - slices[0].size; + slices[1].label = "rootfs"; + + return (0); +} + static int rb_nand_probe(device_t dev) { @@ -175,6 +212,8 @@ rb_nand_attach(device_t dev) return (ENXIO); } + flash_register_slicer(rb_nand_slicer, FLASH_SLICES_TYPE_NAND, TRUE); + nand_init(&sc->nand_dev, dev, NAND_ECC_SOFT, 0, 0, NULL, NULL); err = nandbus_create(dev); Modified: stable/11/sys/geom/geom_flashmap.c ============================================================================== --- stable/11/sys/geom/geom_flashmap.c Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/geom/geom_flashmap.c Wed May 10 21:42:12 2017 (r318158) @@ -29,13 +29,9 @@ __FBSDID("$FreeBSD$"); #include -#include #include #include -#include #include -#include -#include #include #include #include @@ -43,9 +39,10 @@ __FBSDID("$FreeBSD$"); #include #include #include + #include -#define FLASHMAP_CLASS_NAME "Flashmap" +#define FLASHMAP_CLASS_NAME "Flashmap" struct g_flashmap_slice { off_t sl_start; @@ -57,21 +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 int (*flash_fill_slices)(device_t, struct flash_slice *, int *) = - fdt_flash_fill_slices; +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"); @@ -104,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); @@ -125,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) { @@ -161,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(); @@ -179,27 +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)) { - size = sizeof(device_t); - if (g_io_getattr("SPI::device", cp, &size, - &dev)) - break; + 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, @@ -208,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); @@ -219,25 +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 && - 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); @@ -254,19 +227,21 @@ g_flashmap_load(device_t dev, struct g_f return (nslices); } -void flash_register_slicer(int (*slicer)(device_t, struct flash_slice *, int *)) +void flash_register_slicer(flash_slicer_t slicer, u_int type, bool force) { - flash_fill_slices = slicer; + 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/11/sys/modules/geom/Makefile ============================================================================== --- stable/11/sys/modules/geom/Makefile Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/modules/geom/Makefile Wed May 10 21:42:12 2017 (r318158) @@ -7,6 +7,7 @@ SUBDIR= geom_bde \ geom_cache \ geom_concat \ geom_eli \ + geom_flashmap \ geom_gate \ geom_journal \ geom_label \ Modified: stable/11/sys/powerpc/mikrotik/platform_rb.c ============================================================================== --- stable/11/sys/powerpc/mikrotik/platform_rb.c Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/powerpc/mikrotik/platform_rb.c Wed May 10 21:42:12 2017 (r318158) @@ -32,15 +32,12 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include -#include #include -#include #include @@ -59,39 +56,6 @@ DEFINE_CLASS_1(rb, rb_platform, rb_metho PLATFORM_DEF(rb_platform); -/* Slicer operates on the NAND controller, so we have to find the chip. */ -static int -rb_nand_slicer(device_t dev, struct flash_slice *slices, int *nslices) -{ - struct nand_chip *chip; - device_t *children; - int n; - - if (device_get_children(dev, &children, &n) != 0) { - panic("Slicer called on controller with no child!"); - } - dev = children[0]; - free(children, M_TEMP); - - if (device_get_children(dev, &children, &n) != 0) { - panic("Slicer called on controller with nandbus but no child!"); - } - dev = children[0]; - free(children, M_TEMP); - - chip = device_get_softc(dev); - *nslices = 2; - slices[0].base = 0; - slices[0].size = 4 * 1024 * 1024; - slices[0].label = "boot"; - - slices[1].base = 4 * 1024 * 1024; - slices[1].size = chip->ndisk->d_mediasize - slices[0].size; - slices[1].label = "rootfs"; - - return (0); -} - static int rb_probe(platform_t plat) { @@ -117,7 +81,5 @@ rb_attach(platform_t plat) if (error) return (error); - flash_register_slicer(rb_nand_slicer); - return (0); } Modified: stable/11/sys/sys/slicer.h ============================================================================== --- stable/11/sys/sys/slicer.h Wed May 10 21:11:15 2017 (r318157) +++ stable/11/sys/sys/slicer.h Wed May 10 21:42:12 2017 (r318158) @@ -27,26 +27,38 @@ */ #ifndef _FLASH_SLICER_H_ -#define _FLASH_SLICER_H_ +#define _FLASH_SLICER_H_ #include -#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 fdt_flash_fill_slices(device_t, struct flash_slice *, int *) __weak_symbol; -void flash_register_slicer(int (*)(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_ */