Add support for geom_flashmap by providing a getattr() for "SPI:device".

This commit is contained in:
Ian Lepore 2019-02-26 20:50:49 +00:00
parent e8643b01e6
commit fb01947189

View file

@ -119,6 +119,7 @@ static device_probe_t at45d_probe;
/* disk routines */
static int at45d_close(struct disk *dp);
static int at45d_open(struct disk *dp);
static int at45d_getattr(struct bio *bp);
static void at45d_strategy(struct bio *bp);
static void at45d_task(void *arg);
@ -338,6 +339,7 @@ at45d_delayed_attach(void *xsc)
sc->disk->d_open = at45d_open;
sc->disk->d_close = at45d_close;
sc->disk->d_strategy = at45d_strategy;
sc->disk->d_getattr = at45d_getattr;
sc->disk->d_name = "flash/at45d";
sc->disk->d_drv1 = sc;
sc->disk->d_maxsize = DFLTPHYS;
@ -368,6 +370,22 @@ at45d_close(struct disk *dp)
return (0);
}
static int
at45d_getattr(struct bio *bp)
{
struct at45d_softc *sc;
if (bp->bio_disk == NULL || bp->bio_disk->d_drv1 == NULL)
return (ENXIO);
if (strcmp(bp->bio_attribute, "SPI::device") != 0)
return (-1);
sc = bp->bio_disk->d_drv1;
if (bp->bio_length != sizeof(sc->dev))
return (EFAULT);
bcopy(&sc->dev, bp->bio_data, sizeof(sc->dev));
return (0);
}
static void
at45d_strategy(struct bio *bp)
{