Fri Jul 29 20:48:33 2011 UTC ()
add a function to get the size of the flash device


(ahoka)
diff -r1.8 -r1.9 src/sys/dev/flash/flash.c
diff -r1.6 -r1.7 src/sys/dev/flash/flash.h

cvs diff -r1.8 -r1.9 src/sys/dev/flash/flash.c (expand / switch to unified diff)

--- src/sys/dev/flash/flash.c 2011/07/15 19:19:57 1.8
+++ src/sys/dev/flash/flash.c 2011/07/29 20:48:33 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: flash.c,v 1.8 2011/07/15 19:19:57 cliff Exp $ */ 1/* $NetBSD: flash.c,v 1.9 2011/07/29 20:48:33 ahoka Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Department of Software Engineering, 4 * Copyright (c) 2011 Department of Software Engineering,
5 * University of Szeged, Hungary 5 * University of Szeged, Hungary
6 * Copyright (c) 2011 Adam Hoka <ahoka@NetBSD.org> 6 * Copyright (c) 2011 Adam Hoka <ahoka@NetBSD.org>
7 * Copyright (c) 2010 David Tengeri <dtengeri@inf.u-szeged.hu> 7 * Copyright (c) 2010 David Tengeri <dtengeri@inf.u-szeged.hu>
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by the Department of Software Engineering, University of Szeged, Hungary 11 * by the Department of Software Engineering, University of Szeged, Hungary
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35/*- 35/*-
36 * Framework for storage devices based on Flash technology 36 * Framework for storage devices based on Flash technology
37 */ 37 */
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.8 2011/07/15 19:19:57 cliff Exp $"); 40__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.9 2011/07/29 20:48:33 ahoka Exp $");
41 41
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
45#include <sys/errno.h> 45#include <sys/errno.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
47#include <sys/device.h> 47#include <sys/device.h>
48#include <sys/conf.h> 48#include <sys/conf.h>
49#include <sys/kmem.h> 49#include <sys/kmem.h>
50#include <sys/uio.h> 50#include <sys/uio.h>
51#include <sys/kernel.h> 51#include <sys/kernel.h>
52 52
53#include <sys/atomic.h> 53#include <sys/atomic.h>
@@ -515,26 +515,36 @@ flash_get_softc(dev_t dev) @@ -515,26 +515,36 @@ flash_get_softc(dev_t dev)
515 515
516device_t 516device_t
517flash_get_device(dev_t dev) 517flash_get_device(dev_t dev)
518{ 518{
519 struct flash_softc *sc; 519 struct flash_softc *sc;
520 int unit; 520 int unit;
521 521
522 unit = minor(dev); 522 unit = minor(dev);
523 sc = device_lookup_private(&flash_cd, unit); 523 sc = device_lookup_private(&flash_cd, unit);
524 524
525 return sc->sc_dev; 525 return sc->sc_dev;
526} 526}
527 527
 528flash_size_t
 529flash_get_size(dev_t dev)
 530{
 531 const struct flash_softc *sc;
 532
 533 sc = flash_get_softc(dev);
 534
 535 return sc->sc_partinfo.part_size;
 536}
 537
528static inline flash_off_t 538static inline flash_off_t
529flash_get_part_offset(struct flash_softc * const sc, size_t poffset) 539flash_get_part_offset(struct flash_softc * const sc, size_t poffset)
530{ 540{
531 return sc->sc_partinfo.part_offset + poffset; 541 return sc->sc_partinfo.part_offset + poffset;
532} 542}
533 543
534int 544int
535flash_erase(device_t self, struct flash_erase_instruction * const ei) 545flash_erase(device_t self, struct flash_erase_instruction * const ei)
536{ 546{
537 struct flash_softc * const sc = device_private(self); 547 struct flash_softc * const sc = device_private(self);
538 KASSERT(ei != NULL); 548 KASSERT(ei != NULL);
539 struct flash_erase_instruction e = *ei; 549 struct flash_erase_instruction e = *ei;
540 550

cvs diff -r1.6 -r1.7 src/sys/dev/flash/flash.h (expand / switch to unified diff)

--- src/sys/dev/flash/flash.h 2011/07/15 19:19:57 1.6
+++ src/sys/dev/flash/flash.h 2011/07/29 20:48:33 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: flash.h,v 1.6 2011/07/15 19:19:57 cliff Exp $ */ 1/* $NetBSD: flash.h,v 1.7 2011/07/29 20:48:33 ahoka Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 Department of Software Engineering, 4 * Copyright (c) 2011 Department of Software Engineering,
5 * University of Szeged, Hungary 5 * University of Szeged, Hungary
6 * Copyright (c) 2011 Adam Hoka <ahoka@NetBSD.org> 6 * Copyright (c) 2011 Adam Hoka <ahoka@NetBSD.org>
7 * Copyright (c) 2010 David Tengeri <dtengeri@inf.u-szeged.hu> 7 * Copyright (c) 2010 David Tengeri <dtengeri@inf.u-szeged.hu>
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by the Department of Software Engineering, University of Szeged, Hungary 11 * by the Department of Software Engineering, University of Szeged, Hungary
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -113,26 +113,27 @@ struct flash_interface { @@ -113,26 +113,27 @@ struct flash_interface {
113/** 113/**
114 * struct cache - for caching writes on block device 114 * struct cache - for caching writes on block device
115 */ 115 */
116struct flash_cache { 116struct flash_cache {
117 size_t fc_len; 117 size_t fc_len;
118 flash_off_t fc_block; 118 flash_off_t fc_block;
119 uint8_t *fc_data; 119 uint8_t *fc_data;
120}; 120};
121 121
122device_t flash_attach_mi(struct flash_interface *, device_t); 122device_t flash_attach_mi(struct flash_interface *, device_t);
123const struct flash_interface *flash_get_interface(dev_t); 123const struct flash_interface *flash_get_interface(dev_t);
124const struct flash_softc *flash_get_softc(dev_t); 124const struct flash_softc *flash_get_softc(dev_t);
125device_t flash_get_device(dev_t); 125device_t flash_get_device(dev_t);
 126flash_size_t flash_get_size(dev_t);
126 127
127/* flash operations should be used through these */ 128/* flash operations should be used through these */
128int flash_erase(device_t, struct flash_erase_instruction *); 129int flash_erase(device_t, struct flash_erase_instruction *);
129int flash_read(device_t, flash_off_t, size_t, size_t *, uint8_t *); 130int flash_read(device_t, flash_off_t, size_t, size_t *, uint8_t *);
130int flash_write(device_t, flash_off_t, size_t, size_t *, const uint8_t *); 131int flash_write(device_t, flash_off_t, size_t, size_t *, const uint8_t *);
131int flash_block_markbad(device_t, flash_off_t); 132int flash_block_markbad(device_t, flash_off_t);
132int flash_block_isbad(device_t, flash_off_t, bool *); 133int flash_block_isbad(device_t, flash_off_t, bool *);
133int flash_sync(device_t); 134int flash_sync(device_t);
134 135
135/* 136/*
136 * check_pattern - checks the buffer only contains the byte pattern 137 * check_pattern - checks the buffer only contains the byte pattern
137 * 138 *
138 * This functions checks if the buffer only contains a specified byte pattern. 139 * This functions checks if the buffer only contains a specified byte pattern.