Lines Matching +full:erase +full:- +full:size
1 /*-
54 * boundaries, but ERASE is only at flash-block-size block alignments and sizes.
57 * - Reads are on a 512-byte block boundary and size
58 * - Writes and Erases are aligned and sized on flash-block-size bytes.
70 bool sc_erase; /* Erase is needed before write. */
73 #define OPALFLASH_LOCK(sc) mtx_lock(&(sc)->sc_mtx)
74 #define OPALFLASH_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx)
76 mtx_init(&(sc)->sc_mtx, device_get_nameunit((sc)->sc_dev), \
130 if (bp->bio_disk == NULL || bp->bio_disk->d_drv1 == NULL) in opalflash_getattr()
133 sc = bp->bio_disk->d_drv1; in opalflash_getattr()
134 dev = sc->sc_dev; in opalflash_getattr()
136 if (strcmp(bp->bio_attribute, "NAND::device") == 0) { in opalflash_getattr()
137 if (bp->bio_length != sizeof(dev)) in opalflash_getattr()
139 bcopy(&dev, bp->bio_data, sizeof(dev)); in opalflash_getattr()
141 return (-1); in opalflash_getattr()
150 sc = (struct opalflash_softc *)bp->bio_disk->d_drv1; in opalflash_strategy()
152 bioq_disksort(&sc->sc_bio_queue, bp); in opalflash_strategy()
162 int rv, size, token; in opalflash_read() local
164 /* Ensure we write aligned to a full block size. */ in opalflash_read()
165 if (off % sc->sc_disk->d_sectorsize != 0 || in opalflash_read()
166 count % sc->sc_disk->d_sectorsize != 0) in opalflash_read()
177 size = MIN(count, PAGE_SIZE); in opalflash_read()
178 size = MIN(size, PAGE_SIZE - ((u_long)data & PAGE_MASK)); in opalflash_read()
179 rv = opal_call(OPAL_FLASH_READ, sc->sc_opal_id, off, in opalflash_read()
180 vtophys(data), size, token); in opalflash_read()
188 count -= size; in opalflash_read()
189 off += size; in opalflash_read()
190 data += size; in opalflash_read()
207 /* Ensure we write aligned to a full block size. */ in opalflash_erase()
208 if (off % sc->sc_disk->d_stripesize != 0 || in opalflash_erase()
209 count % sc->sc_disk->d_stripesize != 0) in opalflash_erase()
214 rv = opal_call(OPAL_FLASH_ERASE, sc->sc_opal_id, off, count, token); in opalflash_erase()
235 int rv, size, token; in opalflash_write() local
237 /* Ensure we write aligned to a full block size. */ in opalflash_write()
238 if (off % sc->sc_disk->d_sectorsize != 0 || in opalflash_write()
239 count % sc->sc_disk->d_sectorsize != 0) in opalflash_write()
242 if (sc->sc_erase) { in opalflash_write()
243 /* Erase the full block first, then write in page chunks. */ in opalflash_write()
256 size = MIN(count, PAGE_SIZE); in opalflash_write()
257 size = MIN(size, PAGE_SIZE - ((u_long)data & PAGE_MASK)); in opalflash_write()
258 rv = opal_call(OPAL_FLASH_WRITE, sc->sc_opal_id, off, in opalflash_write()
259 vtophys(data), size, token); in opalflash_write()
267 count -= size; in opalflash_write()
268 off += size; in opalflash_write()
269 data += size; in opalflash_write()
293 bp = bioq_first(&sc->sc_bio_queue); in opalflash_task()
295 msleep(sc, &sc->sc_mtx, PRIBIO, "opalflash", 0); in opalflash_task()
297 bioq_remove(&sc->sc_bio_queue, bp); in opalflash_task()
300 switch (bp->bio_cmd) { in opalflash_task()
302 bp->bio_error = opalflash_erase(sc, bp->bio_offset, in opalflash_task()
303 bp->bio_bcount); in opalflash_task()
306 bp->bio_error = opalflash_read(sc, bp->bio_offset, in opalflash_task()
307 bp->bio_data, bp->bio_bcount); in opalflash_task()
310 bp->bio_error = opalflash_write(sc, bp->bio_offset, in opalflash_task()
311 bp->bio_data, bp->bio_bcount); in opalflash_task()
314 bp->bio_error = EINVAL; in opalflash_task()
325 if (!ofw_bus_is_compatible(dev, "ibm,opal-flash")) in opalflash_probe()
342 sc->sc_dev = dev; in opalflash_attach()
345 OF_getencprop(node, "ibm,opal-id", &opal_id, sizeof(opal_id)); in opalflash_attach()
346 sc->sc_opal_id = opal_id; in opalflash_attach()
348 if (OF_getencprop(node, "ibm,flash-block-size", in opalflash_attach()
350 device_printf(dev, "Cannot determine flash block size.\n"); in opalflash_attach()
354 if (!OF_hasprop(node, "no-erase")) in opalflash_attach()
355 sc->sc_erase = true; in opalflash_attach()
360 device_printf(dev, "Unable to get flash size.\n"); in opalflash_attach()
364 sc->sc_disk = disk_alloc(); in opalflash_attach()
365 sc->sc_disk->d_name = "opalflash"; in opalflash_attach()
366 sc->sc_disk->d_open = opalflash_open; in opalflash_attach()
367 sc->sc_disk->d_close = opalflash_close; in opalflash_attach()
368 sc->sc_disk->d_strategy = opalflash_strategy; in opalflash_attach()
369 sc->sc_disk->d_ioctl = opalflash_ioctl; in opalflash_attach()
370 sc->sc_disk->d_getattr = opalflash_getattr; in opalflash_attach()
371 sc->sc_disk->d_drv1 = sc; in opalflash_attach()
372 sc->sc_disk->d_maxsize = DFLTPHYS; in opalflash_attach()
373 sc->sc_disk->d_mediasize = regs[1]; in opalflash_attach()
374 sc->sc_disk->d_unit = device_get_unit(sc->sc_dev); in opalflash_attach()
375 sc->sc_disk->d_sectorsize = FLASH_BLOCKSIZE; in opalflash_attach()
376 sc->sc_disk->d_stripesize = flash_blocksize; in opalflash_attach()
377 sc->sc_disk->d_dump = NULL; in opalflash_attach()
379 disk_create(sc->sc_disk, DISK_VERSION); in opalflash_attach()
380 bioq_init(&sc->sc_bio_queue); in opalflash_attach()
382 kproc_create(&opalflash_task, sc, &sc->sc_p, 0, 0, "task: OPAL Flash"); in opalflash_attach()