yaffs_nand.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  3. *
  4. * Copyright (C) 2002-2011 Aleph One Ltd.
  5. * for Toby Churchill Ltd and Brightstar Engineering
  6. *
  7. * Created by Charles Manning <charles@aleph1.co.uk>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include "yaffs_nand.h"
  14. #include "yaffs_tagscompat.h"
  15. #include "yaffs_getblockinfo.h"
  16. #include "yaffs_summary.h"
  17. static int apply_chunk_offset(struct yaffs_dev *dev, int chunk)
  18. {
  19. return chunk - dev->chunk_offset;
  20. }
  21. int yaffs_rd_chunk_tags_nand(struct yaffs_dev *dev, int nand_chunk,
  22. u8 *buffer, struct yaffs_ext_tags *tags)
  23. {
  24. int result;
  25. struct yaffs_ext_tags local_tags;
  26. int flash_chunk = apply_chunk_offset(dev, nand_chunk);
  27. dev->n_page_reads++;
  28. /* If there are no tags provided use local tags. */
  29. if (!tags)
  30. tags = &local_tags;
  31. result = dev->tagger.read_chunk_tags_fn(dev, flash_chunk, buffer, tags);
  32. if (tags && tags->ecc_result > YAFFS_ECC_RESULT_NO_ERROR) {
  33. struct yaffs_block_info *bi;
  34. bi = yaffs_get_block_info(dev,
  35. nand_chunk /
  36. dev->param.chunks_per_block);
  37. yaffs_handle_chunk_error(dev, bi);
  38. }
  39. return result;
  40. }
  41. int yaffs_wr_chunk_tags_nand(struct yaffs_dev *dev,
  42. int nand_chunk,
  43. const u8 *buffer, struct yaffs_ext_tags *tags)
  44. {
  45. int result;
  46. int flash_chunk = apply_chunk_offset(dev, nand_chunk);
  47. dev->n_page_writes++;
  48. if (!tags) {
  49. yaffs_trace(YAFFS_TRACE_ERROR, "Writing with no tags");
  50. BUG();
  51. return YAFFS_FAIL;
  52. }
  53. tags->seq_number = dev->seq_number;
  54. tags->chunk_used = 1;
  55. yaffs_trace(YAFFS_TRACE_WRITE,
  56. "Writing chunk %d tags %d %d",
  57. nand_chunk, tags->obj_id, tags->chunk_id);
  58. result = dev->tagger.write_chunk_tags_fn(dev, flash_chunk,
  59. buffer, tags);
  60. yaffs_summary_add(dev, tags, nand_chunk);
  61. return result;
  62. }
  63. int yaffs_mark_bad(struct yaffs_dev *dev, int block_no)
  64. {
  65. block_no -= dev->block_offset;
  66. dev->n_bad_markings++;
  67. if (dev->param.disable_bad_block_marking)
  68. return YAFFS_OK;
  69. return dev->tagger.mark_bad_fn(dev, block_no);
  70. }
  71. int yaffs_query_init_block_state(struct yaffs_dev *dev,
  72. int block_no,
  73. enum yaffs_block_state *state,
  74. u32 *seq_number)
  75. {
  76. block_no -= dev->block_offset;
  77. return dev->tagger.query_block_fn(dev, block_no, state, seq_number);
  78. }
  79. int yaffs_erase_block(struct yaffs_dev *dev, int block_no)
  80. {
  81. int result;
  82. block_no -= dev->block_offset;
  83. dev->n_erasures++;
  84. result = dev->drv.drv_erase_fn(dev, block_no);
  85. return result;
  86. }
  87. int yaffs_init_nand(struct yaffs_dev *dev)
  88. {
  89. if (dev->drv.drv_initialise_fn)
  90. return dev->drv.drv_initialise_fn(dev);
  91. return YAFFS_OK;
  92. }
  93. int yaffs_deinit_nand(struct yaffs_dev *dev)
  94. {
  95. if (dev->drv.drv_deinitialise_fn)
  96. return dev->drv.drv_deinitialise_fn(dev);
  97. return YAFFS_OK;
  98. }