Go to the documentation of this file.00001 #include <stdlib.h>
00002 #include <string.h>
00003 #include "types.h"
00004 #include "debug.h"
00005 #include "nand.h"
00006 #include "vmbitmap.h"
00007
00008
00009
00010
00011
00012
00013 struct bitmap_t {
00014 int size;
00015 unsigned int *map;
00016 } bitmap;
00017
00018
00019 #define BITS_PER_RECORD 32
00020 #define NUMSUB ((config_nand.page_per_blk + BITS_PER_RECORD - 1) / BITS_PER_RECORD)
00021 #define CREATE_BITMAP_KEY(blkno, i) ((MUFTL_BITMAP_H) | (((blkno)*(NUMSUB)) + (i)))
00022
00023
00024
00025
00026
00027
00028
00029 void bitmap_s_invalidate_page(_t_blk pbn, _t_page ppn, _t_size length) {
00030 unsigned int i, start;
00031 int idx, offset;
00032
00033 assert(length==1);
00034
00035 start = (pbn*config_nand.page_per_blk + ppn);
00036
00037 for(i=start; i< start+length; i++) {
00038 idx = i / BITS_PER_RECORD;
00039 offset = i % BITS_PER_RECORD;
00040
00041 assert((bitmap.map[idx] & (1<<offset)) == 0);
00042 bitmap.map[idx] |= (1<<offset);
00043 }
00044
00045 }
00046
00047
00048
00049
00050 void bitmap_s_invalidate(_t_blk pbn, _t_page ppn, _t_size length) {
00051
00052 bitmap_s_invalidate_page(pbn, ppn, length);
00053 }
00054
00055
00056 void bitmap_s_end() {
00057 free(bitmap.map);
00058 }
00059
00060
00061 void bitmap_s_init() {
00062
00063 bitmap.size = (config_nand.numblks * config_nand.page_per_blk + BITS_PER_RECORD -1) / BITS_PER_RECORD;
00064 bitmap.map = malloc(sizeof(int) * bitmap.size);
00065
00066 memset(bitmap.map, 0, sizeof(int) * bitmap.size);
00067
00068 printf("Simple bitmap(using memory table) initialized\n");
00069 }
00070
00071
00072
00073
00074
00075
00076 void bitmap_s_get_block(int pbn, _u8 *block_bitmap) {
00077 int i, bit;
00078 int start, idx, offset;
00079
00080 start = (pbn*config_nand.page_per_blk);
00081
00082 for(i=start; i<start+config_nand.page_per_blk;i++) {
00083 idx = i / BITS_PER_RECORD;
00084 offset = i % BITS_PER_RECORD;
00085 bit = (bitmap.map[idx] & (1<<offset)) >> offset;
00086 block_bitmap[i-start] = bit;
00087 }
00088 }
00089
00090
00091
00092
00093
00094 void bitmap_s_clear_block(_t_blk pbn) {
00095 int i;
00096 int start, idx, offset;
00097
00098 start = (pbn * config_nand.page_per_blk);
00099
00100 for(i=start; i<start+config_nand.page_per_blk;i++) {
00101 idx = i / BITS_PER_RECORD;
00102 offset = i % BITS_PER_RECORD;
00103
00104 bitmap.map[idx] &= (0<<offset);
00105 }
00106
00107 }