• Home
  • Raw
  • Download

Lines Matching refs:part

158 static int scan_header(partition_t *part)  in scan_header()  argument
164 part->header.FormattedSize = 0; in scan_header()
165 max_offset = (0x100000<part->mbd.mtd->size)?0x100000:part->mbd.mtd->size; in scan_header()
169 offset += part->mbd.mtd->erasesize ? : 0x2000) { in scan_header()
171 err = mtd_read(part->mbd.mtd, offset, sizeof(header), &ret, in scan_header()
190 if ((1 << header.EraseUnitSize) != part->mbd.mtd->erasesize) { in scan_header()
192 1 << header.EraseUnitSize,part->mbd.mtd->erasesize); in scan_header()
195 part->header = header; in scan_header()
199 static int build_maps(partition_t *part) in build_maps() argument
209 part->DataUnits = le16_to_cpu(part->header.NumEraseUnits) - in build_maps()
210 part->header.NumTransferUnits; in build_maps()
211 part->EUNInfo = kmalloc(part->DataUnits * sizeof(struct eun_info_t), in build_maps()
213 if (!part->EUNInfo) in build_maps()
215 for (i = 0; i < part->DataUnits; i++) in build_maps()
216 part->EUNInfo[i].Offset = 0xffffffff; in build_maps()
217 part->XferInfo = in build_maps()
218 kmalloc(part->header.NumTransferUnits * sizeof(struct xfer_info_t), in build_maps()
220 if (!part->XferInfo) in build_maps()
224 for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) { in build_maps()
225 offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN)) in build_maps()
226 << part->header.EraseUnitSize); in build_maps()
227 ret = mtd_read(part->mbd.mtd, offset, sizeof(header), &retval, in build_maps()
236 if (hdr_ok && (le16_to_cpu(header.LogicalEUN) < part->DataUnits) && in build_maps()
237 (part->EUNInfo[le16_to_cpu(header.LogicalEUN)].Offset == 0xffffffff)) { in build_maps()
238 part->EUNInfo[le16_to_cpu(header.LogicalEUN)].Offset = offset; in build_maps()
239 part->EUNInfo[le16_to_cpu(header.LogicalEUN)].EraseCount = in build_maps()
243 if (xtrans == part->header.NumTransferUnits) { in build_maps()
249 part->XferInfo[xtrans].state = XFER_PREPARED; in build_maps()
250 part->XferInfo[xtrans].EraseCount = le32_to_cpu(header.EraseCount); in build_maps()
252 part->XferInfo[xtrans].state = XFER_UNKNOWN; in build_maps()
254 part->XferInfo[xtrans].EraseCount = in build_maps()
255 le32_to_cpu(part->header.EraseCount); in build_maps()
257 part->XferInfo[xtrans].Offset = offset; in build_maps()
262 header = part->header; in build_maps()
272 part->VirtualBlockMap = vmalloc(blocks * sizeof(uint32_t)); in build_maps()
273 if (!part->VirtualBlockMap) in build_maps()
276 memset(part->VirtualBlockMap, 0xff, blocks * sizeof(uint32_t)); in build_maps()
277 part->BlocksPerUnit = (1 << header.EraseUnitSize) >> header.BlockSize; in build_maps()
279 part->bam_cache = kmalloc(part->BlocksPerUnit * sizeof(uint32_t), in build_maps()
281 if (!part->bam_cache) in build_maps()
284 part->bam_index = 0xffff; in build_maps()
285 part->FreeTotal = 0; in build_maps()
287 for (i = 0; i < part->DataUnits; i++) { in build_maps()
288 part->EUNInfo[i].Free = 0; in build_maps()
289 part->EUNInfo[i].Deleted = 0; in build_maps()
290 offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset); in build_maps()
292 ret = mtd_read(part->mbd.mtd, offset, in build_maps()
293 part->BlocksPerUnit * sizeof(uint32_t), &retval, in build_maps()
294 (unsigned char *)part->bam_cache); in build_maps()
299 for (j = 0; j < part->BlocksPerUnit; j++) { in build_maps()
300 if (BLOCK_FREE(le32_to_cpu(part->bam_cache[j]))) { in build_maps()
301 part->EUNInfo[i].Free++; in build_maps()
302 part->FreeTotal++; in build_maps()
303 } else if ((BLOCK_TYPE(le32_to_cpu(part->bam_cache[j])) == BLOCK_DATA) && in build_maps()
304 (BLOCK_NUMBER(le32_to_cpu(part->bam_cache[j])) < blocks)) in build_maps()
305 part->VirtualBlockMap[BLOCK_NUMBER(le32_to_cpu(part->bam_cache[j]))] = in build_maps()
307 else if (BLOCK_DELETED(le32_to_cpu(part->bam_cache[j]))) in build_maps()
308 part->EUNInfo[i].Deleted++; in build_maps()
316 kfree(part->bam_cache); in build_maps()
318 vfree(part->VirtualBlockMap); in build_maps()
320 kfree(part->XferInfo); in build_maps()
322 kfree(part->EUNInfo); in build_maps()
334 static int erase_xfer(partition_t *part, in erase_xfer() argument
341 xfer = &part->XferInfo[xfernum]; in erase_xfer()
352 erase->mtd = part->mbd.mtd; in erase_xfer()
355 erase->len = 1 << part->header.EraseUnitSize; in erase_xfer()
356 erase->priv = (u_long)part; in erase_xfer()
358 ret = mtd_erase(part->mbd.mtd, erase); in erase_xfer()
377 partition_t *part; in ftl_erase_callback() local
382 part = (partition_t *)(erase->priv); in ftl_erase_callback()
384 for (i = 0; i < part->header.NumTransferUnits; i++) in ftl_erase_callback()
385 if (part->XferInfo[i].Offset == erase->addr) break; in ftl_erase_callback()
387 if (i == part->header.NumTransferUnits) { in ftl_erase_callback()
393 xfer = &part->XferInfo[i]; in ftl_erase_callback()
406 static int prepare_xfer(partition_t *part, int i) in prepare_xfer() argument
415 xfer = &part->XferInfo[i]; in prepare_xfer()
421 header = part->header; in prepare_xfer()
425 ret = mtd_write(part->mbd.mtd, xfer->Offset, sizeof(header), &retlen, in prepare_xfer()
433 nbam = (part->BlocksPerUnit * sizeof(uint32_t) + in prepare_xfer()
434 le32_to_cpu(part->header.BAMOffset) + SECTOR_SIZE - 1) / SECTOR_SIZE; in prepare_xfer()
436 offset = xfer->Offset + le32_to_cpu(part->header.BAMOffset); in prepare_xfer()
441 ret = mtd_write(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, in prepare_xfer()
464 static int copy_erase_unit(partition_t *part, uint16_t srcunit, in copy_erase_unit() argument
477 eun = &part->EUNInfo[srcunit]; in copy_erase_unit()
478 xfer = &part->XferInfo[xferunit]; in copy_erase_unit()
484 if (part->bam_index != srcunit) { in copy_erase_unit()
486 offset = eun->Offset + le32_to_cpu(part->header.BAMOffset); in copy_erase_unit()
488 ret = mtd_read(part->mbd.mtd, offset, in copy_erase_unit()
489 part->BlocksPerUnit * sizeof(uint32_t), &retlen, in copy_erase_unit()
490 (u_char *)(part->bam_cache)); in copy_erase_unit()
493 part->bam_index = 0xffff; in copy_erase_unit()
506 ret = mtd_write(part->mbd.mtd, offset, sizeof(uint16_t), &retlen, in copy_erase_unit()
519 for (i = 0; i < part->BlocksPerUnit; i++) { in copy_erase_unit()
520 switch (BLOCK_TYPE(le32_to_cpu(part->bam_cache[i]))) { in copy_erase_unit()
526 ret = mtd_read(part->mbd.mtd, src, SECTOR_SIZE, &retlen, in copy_erase_unit()
534 ret = mtd_write(part->mbd.mtd, dest, SECTOR_SIZE, &retlen, in copy_erase_unit()
544 part->bam_cache[i] = cpu_to_le32(0xffffffff); in copy_erase_unit()
553 ret = mtd_write(part->mbd.mtd, in copy_erase_unit()
554 xfer->Offset + le32_to_cpu(part->header.BAMOffset), in copy_erase_unit()
555 part->BlocksPerUnit * sizeof(int32_t), in copy_erase_unit()
557 (u_char *)part->bam_cache); in copy_erase_unit()
565 ret = mtd_write(part->mbd.mtd, xfer->Offset + 20, sizeof(uint16_t), in copy_erase_unit()
581 part->FreeTotal -= eun->Free; in copy_erase_unit()
582 part->FreeTotal += free; in copy_erase_unit()
587 part->bam_index = srcunit; in copy_erase_unit()
608 static int reclaim_block(partition_t *part) in reclaim_block() argument
615 pr_debug("NumTransferUnits == %x\n", part->header.NumTransferUnits); in reclaim_block()
620 for (i = 0; i < part->header.NumTransferUnits; i++) { in reclaim_block()
622 if (part->XferInfo[i].state == XFER_UNKNOWN) { in reclaim_block()
625 erase_xfer(part, i); in reclaim_block()
627 if (part->XferInfo[i].state == XFER_ERASING) { in reclaim_block()
632 else if (part->XferInfo[i].state == XFER_ERASED) { in reclaim_block()
635 prepare_xfer(part, i); in reclaim_block()
637 if (part->XferInfo[i].state == XFER_PREPARED) { in reclaim_block()
640 if (part->XferInfo[i].EraseCount <= best) { in reclaim_block()
641 best = part->XferInfo[i].EraseCount; in reclaim_block()
646 pr_debug("XferInfo[%d].state == %x\n",i, part->XferInfo[i].state); in reclaim_block()
653 mtd_sync(part->mbd.mtd); in reclaim_block()
672 for (i = 0; i < part->DataUnits; i++) in reclaim_block()
673 if (part->EUNInfo[i].EraseCount <= best) { in reclaim_block()
674 best = part->EUNInfo[i].EraseCount; in reclaim_block()
679 for (i = 0; i < part->DataUnits; i++) in reclaim_block()
680 if (part->EUNInfo[i].Deleted >= best) { in reclaim_block()
681 best = part->EUNInfo[i].Deleted; in reclaim_block()
696 ret = copy_erase_unit(part, eun, xfer); in reclaim_block()
698 erase_xfer(part, xfer); in reclaim_block()
715 static void dump_lists(partition_t *part) in dump_lists() argument
718 printk(KERN_DEBUG "ftl_cs: Free total = %d\n", part->FreeTotal); in dump_lists()
719 for (i = 0; i < part->DataUnits; i++) in dump_lists()
722 part->EUNInfo[i].Offset >> part->header.EraseUnitSize, in dump_lists()
723 part->EUNInfo[i].Free, part->EUNInfo[i].Deleted); in dump_lists()
727 static uint32_t find_free(partition_t *part) in find_free() argument
735 stop = (part->bam_index == 0xffff) ? 0 : part->bam_index; in find_free()
738 if (part->EUNInfo[eun].Free != 0) break; in find_free()
740 if (++eun == part->DataUnits) eun = 0; in find_free()
743 if (part->EUNInfo[eun].Free == 0) in find_free()
747 if (eun != part->bam_index) { in find_free()
749 part->bam_index = 0xffff; in find_free()
751 ret = mtd_read(part->mbd.mtd, in find_free()
752 part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset), in find_free()
753 part->BlocksPerUnit * sizeof(uint32_t), in find_free()
755 (u_char *)(part->bam_cache)); in find_free()
761 part->bam_index = eun; in find_free()
765 for (blk = 0; blk < part->BlocksPerUnit; blk++) in find_free()
766 if (BLOCK_FREE(le32_to_cpu(part->bam_cache[blk]))) break; in find_free()
767 if (blk == part->BlocksPerUnit) { in find_free()
771 dump_lists(part); in find_free()
788 static int ftl_read(partition_t *part, caddr_t buffer, in ftl_read() argument
797 part, sector, nblocks); in ftl_read()
798 if (!(part->state & FTL_FORMATTED)) { in ftl_read()
802 bsize = 1 << part->header.EraseUnitSize; in ftl_read()
805 if (((sector+i) * SECTOR_SIZE) >= le32_to_cpu(part->header.FormattedSize)) { in ftl_read()
809 log_addr = part->VirtualBlockMap[sector+i]; in ftl_read()
813 offset = (part->EUNInfo[log_addr / bsize].Offset in ftl_read()
815 ret = mtd_read(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, in ftl_read()
834 static int set_bam_entry(partition_t *part, uint32_t log_addr, in set_bam_entry() argument
846 part, log_addr, virt_addr); in set_bam_entry()
847 bsize = 1 << part->header.EraseUnitSize; in set_bam_entry()
850 offset = (part->EUNInfo[eun].Offset + blk * sizeof(uint32_t) + in set_bam_entry()
851 le32_to_cpu(part->header.BAMOffset)); in set_bam_entry()
854 ret = mtd_read(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, in set_bam_entry()
875 if (part->bam_index == eun) { in set_bam_entry()
877 if (le32_to_cpu(part->bam_cache[blk]) != old_addr) { in set_bam_entry()
884 le32_to_cpu(part->bam_cache[blk]), old_addr); in set_bam_entry()
889 part->bam_cache[blk] = le_virt_addr; in set_bam_entry()
891 ret = mtd_write(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, in set_bam_entry()
902 static int ftl_write(partition_t *part, caddr_t buffer, in ftl_write() argument
911 part, sector, nblocks); in ftl_write()
912 if (!(part->state & FTL_FORMATTED)) { in ftl_write()
917 while (part->FreeTotal < nblocks) { in ftl_write()
918 ret = reclaim_block(part); in ftl_write()
923 bsize = 1 << part->header.EraseUnitSize; in ftl_write()
927 if (virt_addr >= le32_to_cpu(part->header.FormattedSize)) { in ftl_write()
933 blk = find_free(part); in ftl_write()
943 log_addr = part->bam_index * bsize + blk * SECTOR_SIZE; in ftl_write()
944 part->EUNInfo[part->bam_index].Free--; in ftl_write()
945 part->FreeTotal--; in ftl_write()
946 if (set_bam_entry(part, log_addr, 0xfffffffe)) in ftl_write()
948 part->EUNInfo[part->bam_index].Deleted++; in ftl_write()
949 offset = (part->EUNInfo[part->bam_index].Offset + in ftl_write()
951 ret = mtd_write(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, buffer); in ftl_write()
962 old_addr = part->VirtualBlockMap[sector+i]; in ftl_write()
964 part->VirtualBlockMap[sector+i] = 0xffffffff; in ftl_write()
965 part->EUNInfo[old_addr/bsize].Deleted++; in ftl_write()
966 if (set_bam_entry(part, old_addr, 0)) in ftl_write()
971 if (set_bam_entry(part, log_addr, virt_addr)) in ftl_write()
973 part->VirtualBlockMap[sector+i] = log_addr; in ftl_write()
974 part->EUNInfo[part->bam_index].Deleted--; in ftl_write()
984 partition_t *part = (void *)dev; in ftl_getgeo() local
988 sect = le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE; in ftl_getgeo()
1012 partition_t *part = (void *)dev; in ftl_discardsect() local
1013 uint32_t bsize = 1 << part->header.EraseUnitSize; in ftl_discardsect()
1019 uint32_t old_addr = part->VirtualBlockMap[sector]; in ftl_discardsect()
1021 part->VirtualBlockMap[sector] = 0xffffffff; in ftl_discardsect()
1022 part->EUNInfo[old_addr/bsize].Deleted++; in ftl_discardsect()
1023 if (set_bam_entry(part, old_addr, 0)) in ftl_discardsect()
1034 static void ftl_freepart(partition_t *part) in ftl_freepart() argument
1036 vfree(part->VirtualBlockMap); in ftl_freepart()
1037 part->VirtualBlockMap = NULL; in ftl_freepart()
1038 kfree(part->VirtualPageMap); in ftl_freepart()
1039 part->VirtualPageMap = NULL; in ftl_freepart()
1040 kfree(part->EUNInfo); in ftl_freepart()
1041 part->EUNInfo = NULL; in ftl_freepart()
1042 kfree(part->XferInfo); in ftl_freepart()
1043 part->XferInfo = NULL; in ftl_freepart()
1044 kfree(part->bam_cache); in ftl_freepart()
1045 part->bam_cache = NULL; in ftl_freepart()