Распечатка 4.1 Имитация функции probe |
Предыдущая Содержание Следующая |
Распечатка 4.1
static struct mtd_info *dummy_probe(struct map_info *map) { struct mtd_info * mtd = kmalloc(sizeof(*mtd), GFP_KERNEL); unsigned int i; unsigned long size; struct dummy_private_info_struct * dummy_private_info = kmalloc(sizeof(struct dummy_private_info_struct), GFP_KERNEL);
if(!dummy_private_info) { return NULL; } memset(dummy_private_info, 0, sizeof(*dummy_private_info));
/* Функция probe возвращает число опознанных микросхем */ dummy_private_info->number_of_chips = PROBE_FLASH(map); if(!dummy_private_info->number_of_chips) { kfree(mtd); return NULL; }
/* Инициализация структуры mtd */ memset(mtd, 0, sizeof(*mtd)); mtd->erasesize = DUMMY_FLASH_ERASE_SIZE; mtd->size = dummy_private_info->number_of_chips * DUMMY_FLASH_SIZE; for(size = mtd->size; size > 1; size >>= 1) dummy_private_info->chipshift++; mtd->priv = map; mtd->type = MTD_NORFLASH; mtd->flags = MTD_CAP_NORFLASH; mtd->name = "DUMMY"; mtd->erase = dummy_flash_erase; mtd->read = dummy_flash_read; mtd->write = dummy_flash_write; mtd->sync = dummy_flash_sync;
dummy_private_info->chips = kmalloc(sizeof(struct flchip) * dummy_private_info->number_of_chips, GFP_KERNEL); memset(dummy_private_info->chips, 0, sizeof(*(dummy_private_info->chips))); for(i=0; i < dummy_private_info->number_of_chips; i++) { dummy_private_info->chips[i].start = (DUMMY_FLASH_SIZE * i); dummy_private_info->chips[i].state = FL_READY; dummy_private_info->chips[i].mutex = &dummy_private_info->chips[i]._spinlock; init_waitqueue_head(&dummy_private_info->chips[i].wq); spin_lock_init(&dummy_private_info->chips[i]._spinlock); dummy_private_info->chips[i].erase_time = DUMMY_FLASH_ERASE_TIME; }
map->fldrv = &dummy_chipdrv; map->fldrv_priv = dummy_private_info;
printk("Probed and found the dummy flash chip\n"); return mtd; }
|
Предыдущая Содержание Следующая |