Seperate drivers and tags handlers into their own interface structures
authorCharles Manning <cdhmanning@gmail.com>
Thu, 21 Jun 2012 04:33:35 +0000 (16:33 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Thu, 21 Jun 2012 04:33:35 +0000 (16:33 +1200)
These were in yaffs_params, but that was getting a bit cluttered.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/yaffs_fileem2k.c
direct/basic-test/yaffs_norif1.c
yaffs_checkptrw.c
yaffs_guts.c
yaffs_guts.h
yaffs_mtdif_multi.c
yaffs_nand.c
yaffs_tagscompat.c
yaffs_tagsmarshall.c

index 6604f04..53970cf 100644 (file)
@@ -322,13 +322,14 @@ static int yflash2_Initialise(struct yaffs_dev *dev)
 void yflash2_install_drv(struct yaffs_dev *dev)
 {
        struct yaffs_param *param = &dev->param;
-
-       param->drv_write_chunk_fn = yflash2_WriteChunk;
-       param->drv_read_chunk_fn = yflash2_ReadChunk;
-       param->drv_erase_fn = yflash2_EraseBlock;
-       param->drv_mark_bad_fn = yflash2_MarkBad;
-       param->drv_check_bad_fn = yflash2_CheckBad;
-       param->drv_initialise_fn = yflash2_Initialise;
+       struct yaffs_driver *drv = &dev->drv;
+
+       drv->drv_write_chunk_fn = yflash2_WriteChunk;
+       drv->drv_read_chunk_fn = yflash2_ReadChunk;
+       drv->drv_erase_fn = yflash2_EraseBlock;
+       drv->drv_mark_bad_fn = yflash2_MarkBad;
+       drv->drv_check_bad_fn = yflash2_CheckBad;
+       drv->drv_initialise_fn = yflash2_Initialise;
 
 
        param->total_bytes_per_chunk = 2048;
index 25bf1a9..d358a43 100644 (file)
@@ -322,6 +322,7 @@ static int ynorif1_Deinitialise_flash_fn(struct yaffs_dev *dev)
 void ynorif1_install_drv(struct yaffs_dev *dev)
 {
        struct yaffs_param *param = &dev->param;
+       struct yaffs_driver *drv = &dev->drv;
 
        param->total_bytes_per_chunk = 1024;
        param->chunks_per_block =248;
@@ -329,10 +330,10 @@ void ynorif1_install_drv(struct yaffs_dev *dev)
        param->start_block = 0; // Can use block 0
        param->end_block = 31; // Last block
        param->use_nand_ecc = 0; // use YAFFS's ECC
-       param->drv_write_chunk_fn = ynorif1_WriteChunkToNAND;
-       param->drv_read_chunk_fn = ynorif1_ReadChunkFromNAND;
-       param->drv_erase_fn = ynorif1_EraseBlockInNAND;
-       param->drv_initialise_fn = ynorif1_InitialiseNAND;
-       param->drv_deinitialise_fn = ynorif1_Deinitialise_flash_fn;
+       drv->drv_write_chunk_fn = ynorif1_WriteChunkToNAND;
+       drv->drv_read_chunk_fn = ynorif1_ReadChunkFromNAND;
+       drv->drv_erase_fn = ynorif1_EraseBlockInNAND;
+       drv->drv_initialise_fn = ynorif1_InitialiseNAND;
+       drv->drv_deinitialise_fn = ynorif1_Deinitialise_flash_fn;
 }
 
index d64c436..4229196 100644 (file)
@@ -74,7 +74,7 @@ static int yaffs_checkpt_erase(struct yaffs_dev *dev)
 {
        int i;
 
-       if (!dev->param.drv_erase_fn)
+       if (!dev->drv.drv_erase_fn)
                return 0;
        yaffs_trace(YAFFS_TRACE_CHECKPOINT,
                "checking blocks %d to %d",
@@ -91,14 +91,14 @@ static int yaffs_checkpt_erase(struct yaffs_dev *dev)
 
                        dev->n_erasures++;
 
-                       result = dev->param.drv_erase_fn(dev, offset_i);
+                       result = dev->drv.drv_erase_fn(dev, offset_i);
                        if(result) {
                                bi->block_state = YAFFS_BLOCK_STATE_EMPTY;
                                dev->n_erased_blocks++;
                                dev->n_free_chunks +=
                                    dev->param.chunks_per_block;
                        } else {
-                               dev->param.drv_mark_bad_fn(dev, offset_i);
+                               dev->drv.drv_mark_bad_fn(dev, offset_i);
                                bi->block_state = YAFFS_BLOCK_STATE_DEAD;
                        }
                }
@@ -159,7 +159,7 @@ static void yaffs2_checkpt_find_block(struct yaffs_dev *dev)
                        enum yaffs_block_state state;
                        u32 seq;
 
-                       dev->param.read_chunk_tags_fn(dev,
+                       dev->th.read_chunk_tags_fn(dev,
                                        apply_chunk_offset(dev, chunk),
                                        NULL, &tags);
                        yaffs_trace(YAFFS_TRACE_CHECKPOINT,
@@ -171,7 +171,7 @@ static void yaffs2_checkpt_find_block(struct yaffs_dev *dev)
                        if (tags.seq_number != YAFFS_SEQUENCE_CHECKPOINT_DATA)
                                continue;
 
-                       dev->param.query_block_fn(dev,
+                       dev->th.query_block_fn(dev,
                                                apply_block_offset(dev, i),
                                                &state, &seq);
                        if (state == YAFFS_BLOCK_STATE_DEAD)
@@ -200,10 +200,10 @@ int yaffs2_checkpt_open(struct yaffs_dev *dev, int writing)
        dev->checkpt_open_write = writing;
 
        /* Got the functions we need? */
-       if (!dev->param.write_chunk_tags_fn ||
-           !dev->param.read_chunk_tags_fn ||
-           !dev->param.drv_erase_fn ||
-           !dev->param.drv_mark_bad_fn)
+       if (!dev->th.write_chunk_tags_fn ||
+           !dev->th.read_chunk_tags_fn ||
+           !dev->drv.drv_erase_fn ||
+           !dev->drv.drv_mark_bad_fn)
                return 0;
 
        if (writing && !yaffs2_checkpt_space_ok(dev))
@@ -299,7 +299,7 @@ static int yaffs2_checkpt_flush_buffer(struct yaffs_dev *dev)
 
        dev->n_page_writes++;
 
-       dev->param.write_chunk_tags_fn(dev, offset_chunk,
+       dev->th.write_chunk_tags_fn(dev, offset_chunk,
                                       dev->checkpt_buffer, &tags);
        dev->checkpt_page_seq++;
        dev->checkpt_cur_chunk++;
@@ -383,7 +383,7 @@ int yaffs2_checkpt_rd(struct yaffs_dev *dev, void *data, int n_bytes)
                        dev->n_page_reads++;
 
                        /* read in the next chunk */
-                       dev->param.read_chunk_tags_fn(dev,
+                       dev->th.read_chunk_tags_fn(dev,
                                                offset_chunk,
                                                dev->checkpt_buffer,
                                                &tags);
index 14ab472..ce5f238 100644 (file)
@@ -609,10 +609,10 @@ static void yaffs_retire_block(struct yaffs_dev *dev, int flash_block)
                        memset(buffer, 0xff, dev->data_bytes_per_chunk);
                        memset(&tags, 0, sizeof(tags));
                        tags.seq_number = YAFFS_SEQUENCE_BAD_BLOCK;
-                       if (dev->param.write_chunk_tags_fn(dev, chunk_id -
-                                                          dev->chunk_offset,
-                                                          buffer,
-                                                          &tags) != YAFFS_OK)
+                       if (dev->th.write_chunk_tags_fn(dev, chunk_id -
+                                                       dev->chunk_offset,
+                                                       buffer,
+                                                       &tags) != YAFFS_OK)
                                yaffs_trace(YAFFS_TRACE_ALWAYS,
                                        "yaffs: Failed to write bad block marker to block %d",
                                        flash_block);
@@ -4535,16 +4535,17 @@ YCHAR *yaffs_get_symlink_alias(struct yaffs_obj *obj)
 
 static int yaffs_check_dev_fns(struct yaffs_dev *dev)
 {
-       struct yaffs_param *param = &dev->param;
+       struct yaffs_driver *drv = &dev->drv;
+       struct yaffs_tags_handler *th = &dev->th;
 
        /* Common functions, gotta have */
-       if (!param->drv_read_chunk_fn ||
-           !param->drv_write_chunk_fn ||
-           !param->drv_erase_fn)
+       if (!drv->drv_read_chunk_fn ||
+           !drv->drv_write_chunk_fn ||
+           !drv->drv_erase_fn)
                return 0;
 
-       if (param->is_yaffs2 &&
-            (!param->drv_mark_bad_fn  || !param->drv_check_bad_fn))
+       if (dev->param.is_yaffs2 &&
+            (!drv->drv_mark_bad_fn  || !drv->drv_check_bad_fn))
                return 0;
 
        /* Install the default tags marshalling functions if needed. */
@@ -4552,10 +4553,10 @@ static int yaffs_check_dev_fns(struct yaffs_dev *dev)
        yaffs_tags_marshall_install(dev);
 
        /* Check we now have the marshalling functions required. */
-       if (!param->write_chunk_tags_fn ||
-           !param->read_chunk_tags_fn ||
-           !param->query_block_fn ||
-           !param->mark_bad_fn)
+       if (!th->write_chunk_tags_fn ||
+           !th->read_chunk_tags_fn ||
+           !th->query_block_fn ||
+           !th->mark_bad_fn)
                return 0;
 
        return 1;
index eab3e08..f108f21 100644 (file)
@@ -558,39 +558,6 @@ struct yaffs_param {
 
        int enable_xattr;       /* Enable xattribs */
 
-       /* Tags marshalling functions.
-        * If these are not set then defaults will be assigned.
-        */
-       int (*write_chunk_tags_fn) (struct yaffs_dev *dev,
-                                   int nand_chunk, const u8 *data,
-                                   const struct yaffs_ext_tags *tags);
-       int (*read_chunk_tags_fn) (struct yaffs_dev *dev,
-                                  int nand_chunk, u8 *data,
-                                  struct yaffs_ext_tags *tags);
-
-       int (*query_block_fn) (struct yaffs_dev *dev, int block_no,
-                              enum yaffs_block_state *state,
-                              u32 *seq_number);
-       int (*mark_bad_fn) (struct yaffs_dev *dev, int block_no);
-
-       /* NAND driver access functions All required except
-        * the deinitialise function which is optional.
-        */
-
-       int (*drv_write_chunk_fn) (struct yaffs_dev *dev, int nand_chunk,
-                                  const u8 *data, int data_len,
-                                  const u8 *oob, int oob_len);
-       int (*drv_read_chunk_fn) (struct yaffs_dev *dev, int nand_chunk,
-                                  u8 *data, int data_len,
-                                  u8 *oob, int oob_len,
-                                  enum yaffs_ecc_result *ecc_result);
-       int (*drv_erase_fn) (struct yaffs_dev *dev, int block_no);
-       int (*drv_mark_bad_fn) (struct yaffs_dev *dev, int block_no);
-       int (*drv_check_bad_fn) (struct yaffs_dev *dev, int block_no);
-       int (*drv_initialise_fn) (struct yaffs_dev *dev);
-       int (*drv_deinitialise_fn) (struct yaffs_dev *dev);
-
-
        int max_objects;        /*
                                 * Set to limit the number of objects created.
                                 * 0 = no limit.
@@ -628,8 +595,39 @@ struct yaffs_param {
 
 };
 
+struct yaffs_driver {
+       int (*drv_write_chunk_fn) (struct yaffs_dev *dev, int nand_chunk,
+                                  const u8 *data, int data_len,
+                                  const u8 *oob, int oob_len);
+       int (*drv_read_chunk_fn) (struct yaffs_dev *dev, int nand_chunk,
+                                  u8 *data, int data_len,
+                                  u8 *oob, int oob_len,
+                                  enum yaffs_ecc_result *ecc_result);
+       int (*drv_erase_fn) (struct yaffs_dev *dev, int block_no);
+       int (*drv_mark_bad_fn) (struct yaffs_dev *dev, int block_no);
+       int (*drv_check_bad_fn) (struct yaffs_dev *dev, int block_no);
+       int (*drv_initialise_fn) (struct yaffs_dev *dev);
+       int (*drv_deinitialise_fn) (struct yaffs_dev *dev);
+};
+
+struct yaffs_tags_handler {
+       int (*write_chunk_tags_fn) (struct yaffs_dev *dev,
+                                   int nand_chunk, const u8 *data,
+                                   const struct yaffs_ext_tags *tags);
+       int (*read_chunk_tags_fn) (struct yaffs_dev *dev,
+                                  int nand_chunk, u8 *data,
+                                  struct yaffs_ext_tags *tags);
+
+       int (*query_block_fn) (struct yaffs_dev *dev, int block_no,
+                              enum yaffs_block_state *state,
+                              u32 *seq_number);
+       int (*mark_bad_fn) (struct yaffs_dev *dev, int block_no);
+};
+
 struct yaffs_dev {
        struct yaffs_param param;
+       struct yaffs_driver drv;
+       struct yaffs_tags_handler th;
 
        /* Context storage. Holds extra OS specific data for this device */
 
index 6280d2e..e61699d 100644 (file)
@@ -211,13 +211,13 @@ static int yaffs_mtd_deinitialise(struct yaffs_dev *dev)
 
 void yaffs_mtd_drv_install(struct yaffs_dev *dev)
 {
-       struct yaffs_param *param = &dev->param;
-
-       param->drv_write_chunk_fn = yaffs_mtd_write;
-       param->drv_read_chunk_fn = yaffs_mtd_read;
-       param->drv_erase_fn = yaffs_mtd_erase;
-       param->drv_mark_bad_fn = yaffs_mtd_mark_bad;
-       param->drv_check_bad_fn = yaffs_mtd_check_bad;
-       param->drv_initialise_fn = yaffs_mtd_initialise;
-       param->drv_deinitialise_fn = yaffs_mtd_deinitialise;
+       struct yaffs_driver *drv = &dev->drv;
+
+       drv->drv_write_chunk_fn = yaffs_mtd_write;
+       drv->drv_read_chunk_fn = yaffs_mtd_read;
+       drv->drv_erase_fn = yaffs_mtd_erase;
+       drv->drv_mark_bad_fn = yaffs_mtd_mark_bad;
+       drv->drv_check_bad_fn = yaffs_mtd_check_bad;
+       drv->drv_initialise_fn = yaffs_mtd_initialise;
+       drv->drv_deinitialise_fn = yaffs_mtd_deinitialise;
 }
index 240abc4..d322e35 100644 (file)
@@ -35,7 +35,7 @@ int yaffs_rd_chunk_tags_nand(struct yaffs_dev *dev, int nand_chunk,
        if (!tags)
                tags = &local_tags;
 
-       result = dev->param.read_chunk_tags_fn(dev, flash_chunk, buffer, tags);
+       result = dev->th.read_chunk_tags_fn(dev, flash_chunk, buffer, tags);
        if (tags && tags->ecc_result > YAFFS_ECC_RESULT_NO_ERROR) {
 
                struct yaffs_block_info *bi;
@@ -68,7 +68,7 @@ int yaffs_wr_chunk_tags_nand(struct yaffs_dev *dev,
                "Writing chunk %d tags %d %d",
                nand_chunk, tags->obj_id, tags->chunk_id);
 
-       result = dev->param.write_chunk_tags_fn(dev, flash_chunk,
+       result = dev->th.write_chunk_tags_fn(dev, flash_chunk,
                                                        buffer, tags);
 
        yaffs_summary_add(dev, tags, nand_chunk);
@@ -80,7 +80,7 @@ int yaffs_mark_bad(struct yaffs_dev *dev, int block_no)
 {
        block_no -= dev->block_offset;
        dev->n_bad_markings++;
-       return dev->param.mark_bad_fn(dev, block_no);
+       return dev->th.mark_bad_fn(dev, block_no);
 }
 
 
@@ -90,7 +90,7 @@ int yaffs_query_init_block_state(struct yaffs_dev *dev,
                                 u32 *seq_number)
 {
        block_no -= dev->block_offset;
-       return dev->param.query_block_fn(dev, block_no, state, seq_number);
+       return dev->th.query_block_fn(dev, block_no, state, seq_number);
 }
 
 int yaffs_erase_block(struct yaffs_dev *dev, int block_no)
@@ -99,20 +99,20 @@ int yaffs_erase_block(struct yaffs_dev *dev, int block_no)
 
        block_no -= dev->block_offset;
        dev->n_erasures++;
-       result = dev->param.drv_erase_fn(dev, block_no);
+       result = dev->drv.drv_erase_fn(dev, block_no);
        return result;
 }
 
 int yaffs_init_nand(struct yaffs_dev *dev)
 {
-       if (dev->param.drv_initialise_fn)
-               return dev->param.drv_initialise_fn(dev);
+       if (dev->drv.drv_initialise_fn)
+               return dev->drv.drv_initialise_fn(dev);
        return YAFFS_OK;
 }
 
 int yaffs_deinit_nand(struct yaffs_dev *dev)
 {
-       if (dev->param.drv_deinitialise_fn)
-               return dev->param.drv_deinitialise_fn(dev);
+       if (dev->drv.drv_deinitialise_fn)
+               return dev->drv.drv_deinitialise_fn(dev);
        return YAFFS_OK;
 }
index 23e6947..e213a31 100644 (file)
@@ -124,7 +124,7 @@ static int yaffs_wr_nand(struct yaffs_dev *dev,
 {
        int data_size = dev->data_bytes_per_chunk;
 
-       return dev->param.drv_write_chunk_fn(dev, nand_chunk,
+       return dev->drv.drv_write_chunk_fn(dev, nand_chunk,
                                data, data_size,
                                (u8 *) spare, sizeof(*spare));
 }
@@ -152,7 +152,7 @@ static int yaffs_rd_chunk_nand(struct yaffs_dev *dev,
        spare_size = sizeof(struct yaffs_spare);
 
        if (dev->param.use_nand_ecc)
-               return dev->param.drv_read_chunk_fn(dev, nand_chunk,
+               return dev->drv.drv_read_chunk_fn(dev, nand_chunk,
                                                data, data_size,
                                                (u8 *) spare, spare_size,
                                                ecc_result);
@@ -160,7 +160,7 @@ static int yaffs_rd_chunk_nand(struct yaffs_dev *dev,
 
        /* Handle the ECC at this level. */
 
-       ret_val = dev->param.drv_read_chunk_fn(dev, nand_chunk,
+       ret_val = dev->drv.drv_read_chunk_fn(dev, nand_chunk,
                                                 data, data_size,
                                                 (u8 *)spare, spare_size,
                                                NULL);
@@ -369,12 +369,12 @@ void yaffs_tags_compat_install(struct yaffs_dev *dev)
 {
        if(dev->param.is_yaffs2)
                return;
-       if(!dev->param.write_chunk_tags_fn)
-               dev->param.write_chunk_tags_fn = yaffs_tags_compat_wr;
-       if(!dev->param.read_chunk_tags_fn)
-               dev->param.read_chunk_tags_fn = yaffs_tags_compat_rd;
-       if(!dev->param.query_block_fn)
-               dev->param.query_block_fn = yaffs_tags_compat_query_block;
-       if(!dev->param.mark_bad_fn)
-               dev->param.mark_bad_fn = yaffs_tags_compat_mark_bad;
+       if(!dev->th.write_chunk_tags_fn)
+               dev->th.write_chunk_tags_fn = yaffs_tags_compat_wr;
+       if(!dev->th.read_chunk_tags_fn)
+               dev->th.read_chunk_tags_fn = yaffs_tags_compat_rd;
+       if(!dev->th.query_block_fn)
+               dev->th.query_block_fn = yaffs_tags_compat_query_block;
+       if(!dev->th.mark_bad_fn)
+               dev->th.mark_bad_fn = yaffs_tags_compat_mark_bad;
 }
index bbc228b..401a756 100644 (file)
@@ -48,7 +48,7 @@ static int yaffs_tags_marshall_write(struct yaffs_dev *dev,
                yaffs_pack_tags2(&pt, tags, !dev->param.no_tags_ecc);
        }
 
-       retval = dev->param.drv_write_chunk_fn(dev, nand_chunk,
+       retval = dev->drv.drv_write_chunk_fn(dev, nand_chunk,
                        data, dev->param.total_bytes_per_chunk,
                        (dev->param.inband_tags) ? NULL : packed_tags_ptr,
                        (dev->param.inband_tags) ? 0 : packed_tags_size);
@@ -84,12 +84,12 @@ static int yaffs_tags_marshall_read(struct yaffs_dev *dev,
        }
 
        if (dev->param.inband_tags || (data && !tags))
-               retval = dev->param.drv_read_chunk_fn(dev, nand_chunk,
+               retval = dev->drv.drv_read_chunk_fn(dev, nand_chunk,
                                        data, dev->param.total_bytes_per_chunk,
                                        NULL, 0,
                                        &ecc_result);
        else if (tags)
-               retval = dev->param.drv_read_chunk_fn(dev, nand_chunk,
+               retval = dev->drv.drv_read_chunk_fn(dev, nand_chunk,
                                        data, dev->param.total_bytes_per_chunk,
                                        spare_buffer, packed_tags_size,
                                        &ecc_result);
@@ -139,7 +139,7 @@ static int yaffs_tags_marshall_query_block(struct yaffs_dev *dev, int block_no,
        yaffs_trace(YAFFS_TRACE_MTD, "yaffs_tags_marshall_query_block %d",
                        block_no);
 
-       retval = dev->param.drv_check_bad_fn(dev, block_no);
+       retval = dev->drv.drv_check_bad_fn(dev, block_no);
 
        if (retval== YAFFS_FAIL) {
                yaffs_trace(YAFFS_TRACE_MTD, "block is bad");
@@ -174,7 +174,7 @@ static int yaffs_tags_marshall_query_block(struct yaffs_dev *dev, int block_no,
 
 static int yaffs_tags_marshall_mark_bad(struct yaffs_dev *dev, int block_no)
 {
-       return dev->param.drv_mark_bad_fn(dev, block_no);
+       return dev->drv.drv_mark_bad_fn(dev, block_no);
 
 }
 
@@ -184,16 +184,16 @@ void yaffs_tags_marshall_install(struct yaffs_dev *dev)
        if (!dev->param.is_yaffs2)
                return;
 
-       if (!dev->param.write_chunk_tags_fn)
-               dev->param.write_chunk_tags_fn = yaffs_tags_marshall_write;
+       if (!dev->th.write_chunk_tags_fn)
+               dev->th.write_chunk_tags_fn = yaffs_tags_marshall_write;
 
-       if (!dev->param.read_chunk_tags_fn)
-               dev->param.read_chunk_tags_fn = yaffs_tags_marshall_read;
+       if (!dev->th.read_chunk_tags_fn)
+               dev->th.read_chunk_tags_fn = yaffs_tags_marshall_read;
 
-       if (!dev->param.query_block_fn)
-               dev->param.query_block_fn = yaffs_tags_marshall_query_block;
+       if (!dev->th.query_block_fn)
+               dev->th.query_block_fn = yaffs_tags_marshall_query_block;
 
-       if (!dev->param.mark_bad_fn)
-               dev->param.mark_bad_fn = yaffs_tags_marshall_mark_bad;
+       if (!dev->th.mark_bad_fn)
+               dev->th.mark_bad_fn = yaffs_tags_marshall_mark_bad;
 
 }