Endiannes fixes from Brett Slager in ONFI Param page parsing. Similar changes in nandemulator by me. Remove panic about more than one LUNs.diff -r1.21 -r1.22 src/sys/dev/nand/nand.c
(ahoka)
--- src/sys/dev/nand/nand.c 2012/11/03 12:12:48 1.21
+++ src/sys/dev/nand/nand.c 2012/11/03 12:45:28 1.22
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nand.c,v 1.21 2012/11/03 12:12:48 ahoka Exp $ */ | 1 | /* $NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2010 Department of Software Engineering, | 4 | * Copyright (c) 2010 Department of Software Engineering, | |
5 | * University of Szeged, Hungary | 5 | * University of Szeged, Hungary | |
6 | * Copyright (c) 2010 Adam Hoka <ahoka@NetBSD.org> | 6 | * Copyright (c) 2010 Adam Hoka <ahoka@NetBSD.org> | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * This code is derived from software contributed to The NetBSD Foundation | 9 | * This code is derived from software contributed to The NetBSD Foundation | |
10 | * by the Department of Software Engineering, University of Szeged, Hungary | 10 | * by the Department of Software Engineering, University of Szeged, Hungary | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -24,27 +24,27 @@ | @@ -24,27 +24,27 @@ | |||
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | /* Common driver for NAND chips implementing the ONFI 2.2 specification */ | 34 | /* Common driver for NAND chips implementing the ONFI 2.2 specification */ | |
35 | 35 | |||
36 | #include <sys/cdefs.h> | 36 | #include <sys/cdefs.h> | |
37 | __KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.21 2012/11/03 12:12:48 ahoka Exp $"); | 37 | __KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $"); | |
38 | 38 | |||
39 | #include "locators.h" | 39 | #include "locators.h" | |
40 | 40 | |||
41 | #include <sys/param.h> | 41 | #include <sys/param.h> | |
42 | #include <sys/types.h> | 42 | #include <sys/types.h> | |
43 | #include <sys/device.h> | 43 | #include <sys/device.h> | |
44 | #include <sys/kmem.h> | 44 | #include <sys/kmem.h> | |
45 | #include <sys/atomic.h> | 45 | #include <sys/atomic.h> | |
46 | 46 | |||
47 | #include <dev/flash/flash.h> | 47 | #include <dev/flash/flash.h> | |
48 | #include <dev/flash/flash_io.h> | 48 | #include <dev/flash/flash_io.h> | |
49 | #include <dev/nand/nand.h> | 49 | #include <dev/nand/nand.h> | |
50 | #include <dev/nand/onfi.h> | 50 | #include <dev/nand/onfi.h> | |
@@ -540,53 +540,49 @@ nand_fill_chip_structure(device_t self, | @@ -540,53 +540,49 @@ nand_fill_chip_structure(device_t self, | |||
540 | return 1; | 540 | return 1; | |
541 | } | 541 | } | |
542 | 542 | |||
543 | /* strip manufacturer and model string */ | 543 | /* strip manufacturer and model string */ | |
544 | strlcpy(vendor, params.param_manufacturer, sizeof(vendor)); | 544 | strlcpy(vendor, params.param_manufacturer, sizeof(vendor)); | |
545 | for (i = 11; i > 0 && vendor[i] == ' '; i--) | 545 | for (i = 11; i > 0 && vendor[i] == ' '; i--) | |
546 | vendor[i] = 0; | 546 | vendor[i] = 0; | |
547 | strlcpy(model, params.param_model, sizeof(model)); | 547 | strlcpy(model, params.param_model, sizeof(model)); | |
548 | for (i = 19; i > 0 && model[i] == ' '; i--) | 548 | for (i = 19; i > 0 && model[i] == ' '; i--) | |
549 | model[i] = 0; | 549 | model[i] = 0; | |
550 | 550 | |||
551 | aprint_normal_dev(self, "vendor: %s, model: %s\n", vendor, model); | 551 | aprint_normal_dev(self, "vendor: %s, model: %s\n", vendor, model); | |
552 | 552 | |||
553 | /* XXX TODO multiple LUNs */ | 553 | chip->nc_page_size = le32toh(params.param_pagesize); | |
554 | if (params.param_numluns != 1) { | 554 | chip->nc_block_size = | |
555 | aprint_error_dev(self, | 555 | le32toh(params.param_blocksize) * chip->nc_page_size; | |
556 | "more than one LUNs are not supported yet!\n"); | 556 | chip->nc_spare_size = le16toh(params.param_sparesize); | |
557 | 557 | chip->nc_lun_blocks = le32toh(params.param_lunsize); | ||
558 | return 1; | |||
559 | } | |||
560 | ||||
561 | chip->nc_size = params.param_pagesize * params.param_blocksize * | |||
562 | params.param_lunsize * params.param_numluns; | |||
563 | ||||
564 | chip->nc_page_size = params.param_pagesize; | |||
565 | chip->nc_block_size = params.param_blocksize * params.param_pagesize; | |||
566 | chip->nc_spare_size = params.param_sparesize; | |||
567 | chip->nc_lun_blocks = params.param_lunsize; | |||
568 | chip->nc_num_luns = params.param_numluns; | 558 | chip->nc_num_luns = params.param_numluns; | |
569 | 559 | |||
560 | chip->nc_size = | |||
561 | chip->nc_block_size * chip->nc_lun_blocks * chip->nc_num_luns; | |||
562 | ||||
570 | /* the lower 4 bits contain the row address cycles */ | 563 | /* the lower 4 bits contain the row address cycles */ | |
571 | chip->nc_addr_cycles_row = params.param_addr_cycles & 0x07; | 564 | chip->nc_addr_cycles_row = params.param_addr_cycles & 0x07; | |
572 | /* the upper 4 bits contain the column address cycles */ | 565 | /* the upper 4 bits contain the column address cycles */ | |
573 | chip->nc_addr_cycles_column = (params.param_addr_cycles & ~0x07) >> 4; | 566 | chip->nc_addr_cycles_column = (params.param_addr_cycles & ~0x07) >> 4; | |
574 | 567 | |||
575 | if (params.param_features & ONFI_FEATURE_16BIT) | 568 | uint16_t features = le16toh(params.param_features); | |
569 | if (features & ONFI_FEATURE_16BIT) { | |||
576 | chip->nc_flags |= NC_BUSWIDTH_16; | 570 | chip->nc_flags |= NC_BUSWIDTH_16; | |
571 | } | |||
577 | 572 | |||
578 | if (params.param_features & ONFI_FEATURE_EXTENDED_PARAM) | 573 | if (features & ONFI_FEATURE_EXTENDED_PARAM) { | |
579 | chip->nc_flags |= NC_EXTENDED_PARAM; | 574 | chip->nc_flags |= NC_EXTENDED_PARAM; | |
575 | } | |||
580 | 576 | |||
581 | return 0; | 577 | return 0; | |
582 | } | 578 | } | |
583 | 579 | |||
584 | /* ARGSUSED */ | 580 | /* ARGSUSED */ | |
585 | bool | 581 | bool | |
586 | nand_shutdown(device_t self, int howto) | 582 | nand_shutdown(device_t self, int howto) | |
587 | { | 583 | { | |
588 | return true; | 584 | return true; | |
589 | } | 585 | } | |
590 | 586 | |||
591 | static void | 587 | static void | |
592 | nand_address_column(device_t self, size_t row, size_t column) | 588 | nand_address_column(device_t self, size_t row, size_t column) |
--- src/sys/dev/nand/nandemulator.c 2011/06/28 10:32:45 1.5
+++ src/sys/dev/nand/nandemulator.c 2012/11/03 12:45:28 1.6
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: nandemulator.c,v 1.5 2011/06/28 10:32:45 ahoka Exp $ */ | 1 | /* $NetBSD: nandemulator.c,v 1.6 2012/11/03 12:45:28 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 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * This code is derived from software contributed to The NetBSD Foundation | 9 | * This code is derived from software contributed to The NetBSD Foundation | |
10 | * by the Department of Software Engineering, University of Szeged, Hungary | 10 | * by the Department of Software Engineering, University of Szeged, Hungary | |
11 | * | 11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | 12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | 13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | 14 | * are met: | |
@@ -22,27 +22,27 @@ | @@ -22,27 +22,27 @@ | |||
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <sys/cdefs.h> | 34 | #include <sys/cdefs.h> | |
35 | __KERNEL_RCSID(0, "$NetBSD: nandemulator.c,v 1.5 2011/06/28 10:32:45 ahoka Exp $"); | 35 | __KERNEL_RCSID(0, "$NetBSD: nandemulator.c,v 1.6 2012/11/03 12:45:28 ahoka Exp $"); | |
36 | 36 | |||
37 | #include <sys/param.h> | 37 | #include <sys/param.h> | |
38 | #include <sys/device.h> | 38 | #include <sys/device.h> | |
39 | #include <sys/conf.h> | 39 | #include <sys/conf.h> | |
40 | #include <sys/kmem.h> | 40 | #include <sys/kmem.h> | |
41 | #include <sys/kernel.h> | 41 | #include <sys/kernel.h> | |
42 | 42 | |||
43 | #include "nandemulator.h" | 43 | #include "nandemulator.h" | |
44 | 44 | |||
45 | #include <dev/nand/nand.h> | 45 | #include <dev/nand/nand.h> | |
46 | #include <dev/nand/onfi.h> | 46 | #include <dev/nand/onfi.h> | |
47 | #include <dev/nand/nand_crc.h> | 47 | #include <dev/nand/nand_crc.h> | |
48 | 48 | |||
@@ -225,40 +225,41 @@ nandemulator_attach(device_t parent, dev | @@ -225,40 +225,41 @@ nandemulator_attach(device_t parent, dev | |||
225 | 225 | |||
226 | sc->sc_backend = kmem_alloc(sc->sc_backend_size, KM_SLEEP); | 226 | sc->sc_backend = kmem_alloc(sc->sc_backend_size, KM_SLEEP); | |
227 | memset(sc->sc_backend, 0xff, sc->sc_backend_size); | 227 | memset(sc->sc_backend, 0xff, sc->sc_backend_size); | |
228 | 228 | |||
229 | sc->sc_parameter_page = | 229 | sc->sc_parameter_page = | |
230 | kmem_zalloc(sizeof(struct onfi_parameter_page) * 4, KM_SLEEP); | 230 | kmem_zalloc(sizeof(struct onfi_parameter_page) * 4, KM_SLEEP); | |
231 | 231 | |||
232 | struct onfi_parameter_page *opp; | 232 | struct onfi_parameter_page *opp; | |
233 | uint8_t sig[4] = { 'O', 'N', 'F', 'I' }; | 233 | uint8_t sig[4] = { 'O', 'N', 'F', 'I' }; | |
234 | 234 | |||
235 | for (i = 0; i < 4; i++) { | 235 | for (i = 0; i < 4; i++) { | |
236 | opp = &sc->sc_parameter_page[i]; | 236 | opp = &sc->sc_parameter_page[i]; | |
237 | 237 | |||
238 | opp->param_signature = *(uint32_t *)sig; | 238 | opp->param_signature = htole32(*(uint32_t *)sig); | |
239 | opp->param_pagesize = sc->sc_page_size; | 239 | opp->param_pagesize = htole32(sc->sc_page_size); | |
240 | opp->param_blocksize = sc->sc_block_size; | 240 | opp->param_blocksize = htole32(sc->sc_block_size); | |
241 | opp->param_sparesize = sc->sc_spare_size; | 241 | opp->param_sparesize = htole16(sc->sc_spare_size); | |
242 | opp->param_lunsize = sc->sc_lun_size; | 242 | opp->param_lunsize = htole32(sc->sc_lun_size); | |
243 | opp->param_numluns = 1; | 243 | opp->param_numluns = 1; | |
244 | 244 | |||
245 | opp->param_manufacturer_id = 0x00; | 245 | opp->param_manufacturer_id = 0x00; | |
246 | memcpy(opp->param_manufacturer, | 246 | memcpy(opp->param_manufacturer, | |
247 | "NETBSD", strlen("NETBSD")); | 247 | "NETBSD", strlen("NETBSD")); | |
248 | memcpy(opp->param_model, | 248 | memcpy(opp->param_model, | |
249 | "NANDEMULATOR", strlen("NANDEMULATOR")); | 249 | "NANDEMULATOR", strlen("NANDEMULATOR")); | |
250 | 250 | |||
251 | opp->param_features = ONFI_FEATURE_16BIT; | 251 | uint16_t features = ONFI_FEATURE_16BIT; | |
252 | opp->param_features = htole16(features); | |||
252 | 253 | |||
253 | /* the lower 4 bits contain the row address cycles | 254 | /* the lower 4 bits contain the row address cycles | |
254 | * the upper 4 bits contain the column address cycles | 255 | * the upper 4 bits contain the column address cycles | |
255 | */ | 256 | */ | |
256 | opp->param_addr_cycles = sc->sc_row_cycles; | 257 | opp->param_addr_cycles = sc->sc_row_cycles; | |
257 | opp->param_addr_cycles |= (sc->sc_column_cycles << 4); | 258 | opp->param_addr_cycles |= (sc->sc_column_cycles << 4); | |
258 | 259 | |||
259 | opp->param_integrity_crc = nand_crc16((uint8_t *)opp, 254); | 260 | opp->param_integrity_crc = nand_crc16((uint8_t *)opp, 254); | |
260 | } | 261 | } | |
261 | 262 | |||
262 | sc->sc_ids[0] = 0x00; | 263 | sc->sc_ids[0] = 0x00; | |
263 | sc->sc_ids[1] = 0x00; | 264 | sc->sc_ids[1] = 0x00; | |
264 | 265 |