Lines Matching refs:cxt

27 static int mtdpstore_block_isbad(struct mtdpstore_context *cxt, loff_t off)
30 struct mtd_info *mtd = cxt->mtd;
36 if (test_bit(blknum, cxt->badmap))
43 set_bit(blknum, cxt->badmap);
49 static inline int mtdpstore_panic_block_isbad(struct mtdpstore_context *cxt,
52 struct mtd_info *mtd = cxt->mtd;
57 return test_bit(blknum, cxt->badmap);
60 static inline void mtdpstore_mark_used(struct mtdpstore_context *cxt,
63 struct mtd_info *mtd = cxt->mtd;
64 u64 zonenum = div_u64(off, cxt->info.kmsg_size);
67 set_bit(zonenum, cxt->usedmap);
70 static inline void mtdpstore_mark_unused(struct mtdpstore_context *cxt,
73 struct mtd_info *mtd = cxt->mtd;
74 u64 zonenum = div_u64(off, cxt->info.kmsg_size);
77 clear_bit(zonenum, cxt->usedmap);
80 static inline void mtdpstore_block_mark_unused(struct mtdpstore_context *cxt,
83 struct mtd_info *mtd = cxt->mtd;
84 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
88 zonenum = div_u64(off, cxt->info.kmsg_size);
91 clear_bit(zonenum, cxt->usedmap);
97 static inline int mtdpstore_is_used(struct mtdpstore_context *cxt, loff_t off)
99 u64 zonenum = div_u64(off, cxt->info.kmsg_size);
100 u64 blknum = div_u64(off, cxt->mtd->erasesize);
102 if (test_bit(blknum, cxt->badmap))
104 return test_bit(zonenum, cxt->usedmap);
107 static int mtdpstore_block_is_used(struct mtdpstore_context *cxt,
110 struct mtd_info *mtd = cxt->mtd;
111 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
115 zonenum = div_u64(off, cxt->info.kmsg_size);
117 if (test_bit(zonenum, cxt->usedmap))
125 static int mtdpstore_is_empty(struct mtdpstore_context *cxt, char *buf,
128 struct mtd_info *mtd = cxt->mtd;
140 static void mtdpstore_mark_removed(struct mtdpstore_context *cxt, loff_t off)
142 struct mtd_info *mtd = cxt->mtd;
143 u64 zonenum = div_u64(off, cxt->info.kmsg_size);
146 set_bit(zonenum, cxt->rmmap);
149 static void mtdpstore_block_clear_removed(struct mtdpstore_context *cxt,
152 struct mtd_info *mtd = cxt->mtd;
153 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
157 zonenum = div_u64(off, cxt->info.kmsg_size);
159 clear_bit(zonenum, cxt->rmmap);
165 static int mtdpstore_block_is_removed(struct mtdpstore_context *cxt,
168 struct mtd_info *mtd = cxt->mtd;
169 u32 zonecnt = mtd->erasesize / cxt->info.kmsg_size;
173 zonenum = div_u64(off, cxt->info.kmsg_size);
175 if (test_bit(zonenum, cxt->rmmap))
183 static int mtdpstore_erase_do(struct mtdpstore_context *cxt, loff_t off)
185 struct mtd_info *mtd = cxt->mtd;
189 off = ALIGN_DOWN(off, cxt->mtd->erasesize);
191 erase.len = cxt->mtd->erasesize;
193 ret = mtd_erase(cxt->mtd, &erase);
195 mtdpstore_block_clear_removed(cxt, off);
199 (unsigned long long)erase.len, cxt->info.device);
212 struct mtdpstore_context *cxt = &oops_cxt;
214 if (mtdpstore_block_isbad(cxt, off))
217 mtdpstore_mark_unused(cxt, off);
220 if (likely(mtdpstore_block_is_used(cxt, off))) {
221 mtdpstore_mark_removed(cxt, off);
226 return mtdpstore_erase_do(cxt, off);
237 static int mtdpstore_security(struct mtdpstore_context *cxt, loff_t off)
240 struct mtd_info *mtd = cxt->mtd;
241 u32 zonenum = (u32)div_u64(off, cxt->info.kmsg_size);
242 u32 zonecnt = (u32)div_u64(cxt->mtd->size, cxt->info.kmsg_size);
243 u32 blkcnt = (u32)div_u64(cxt->mtd->size, cxt->mtd->erasesize);
244 u32 erasesize = cxt->mtd->erasesize;
250 if (!test_bit(num, cxt->usedmap))
256 div64_u64_rem(off + erasesize, cxt->mtd->size, (u64 *)&off);
258 if (mtdpstore_block_isbad(cxt, off))
261 ret = mtdpstore_erase_do(cxt, off);
263 mtdpstore_block_mark_unused(cxt, off);
276 struct mtdpstore_context *cxt = &oops_cxt;
277 struct mtd_info *mtd = cxt->mtd;
281 if (mtdpstore_block_isbad(cxt, off))
285 if (mtdpstore_is_used(cxt, off))
289 ret = mtd_write(cxt->mtd, off, size, &retlen, (u_char *)buf);
295 mtdpstore_mark_used(cxt, off);
297 mtdpstore_security(cxt, off);
312 struct mtdpstore_context *cxt = &oops_cxt;
313 struct mtd_info *mtd = cxt->mtd;
317 if (mtdpstore_block_isbad(cxt, off))
324 ret = mtd_read(cxt->mtd, off + done, size - done, &retlen,
347 if (mtdpstore_is_empty(cxt, buf, size))
348 mtdpstore_mark_unused(cxt, off);
350 mtdpstore_mark_used(cxt, off);
352 mtdpstore_security(cxt, off);
358 struct mtdpstore_context *cxt = &oops_cxt;
359 struct mtd_info *mtd = cxt->mtd;
363 if (mtdpstore_panic_block_isbad(cxt, off))
367 if (mtdpstore_is_used(cxt, off))
370 ret = mtd_panic_write(cxt->mtd, off, size, &retlen, (u_char *)buf);
376 mtdpstore_mark_used(cxt, off);
384 struct mtdpstore_context *cxt = &oops_cxt;
385 struct pstore_blk_config *info = &cxt->info;
389 cxt->index = mtd->index;
391 if (mtd->index != cxt->index || cxt->index < 0)
420 cxt->rmmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
421 cxt->usedmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
424 cxt->badmap = kcalloc(longcnt, sizeof(long), GFP_KERNEL);
426 cxt->dev.total_size = mtd->size;
428 cxt->dev.flags = PSTORE_FLAGS_DMESG;
429 cxt->dev.read = mtdpstore_read;
430 cxt->dev.write = mtdpstore_write;
431 cxt->dev.erase = mtdpstore_erase;
432 cxt->dev.panic_write = mtdpstore_panic_write;
434 ret = register_pstore_device(&cxt->dev);
440 cxt->mtd = mtd;
444 static int mtdpstore_flush_removed_do(struct mtdpstore_context *cxt,
447 struct mtd_info *mtd = cxt->mtd;
471 unsigned int zonesize = cxt->info.kmsg_size;
474 if (mtdpstore_is_used(cxt, off)) {
497 static int mtdpstore_flush_removed(struct mtdpstore_context *cxt)
499 struct mtd_info *mtd = cxt->mtd;
505 ret = mtdpstore_block_isbad(cxt, off);
509 ret = mtdpstore_block_is_removed(cxt, off);
513 ret = mtdpstore_flush_removed_do(cxt, off, mtd->erasesize);
522 struct mtdpstore_context *cxt = &oops_cxt;
524 if (mtd->index != cxt->index || cxt->index < 0)
527 mtdpstore_flush_removed(cxt);
529 unregister_pstore_device(&cxt->dev);
530 kfree(cxt->badmap);
531 kfree(cxt->usedmap);
532 kfree(cxt->rmmap);
533 cxt->mtd = NULL;
534 cxt->index = -1;
545 struct mtdpstore_context *cxt = &oops_cxt;
546 struct pstore_blk_config *info = &cxt->info;
562 ret = kstrtoint((char *)info->device, 0, &cxt->index);
564 cxt->index = -1;