Ejemplo n.º 1
0
static void
nandsim_loop(void *arg)
{
	struct nandsim_chip *chip = (struct nandsim_chip *)arg;
	struct nandsim_ev *ev;

	nand_debug(NDBG_SIM,"Start main loop for chip%d [%8p]", chip->chip_num,
	    chip);
	for(;;) {
		NANDSIM_CHIP_LOCK(chip);
		if (!(chip->flags & NANDSIM_CHIP_ACTIVE)) {
			chip->flags |= NANDSIM_CHIP_ACTIVE;
			wakeup(chip->nandsim_td);
		}

		if (STAILQ_EMPTY(&chip->nandsim_events)) {
			nand_debug(NDBG_SIM,"Chip%d [%8p] going sleep",
			    chip->chip_num, chip);
			msleep(chip, &chip->ns_lock, PRIBIO, "nandev", 0);
		}

		ev = STAILQ_FIRST(&chip->nandsim_events);
		STAILQ_REMOVE_HEAD(&chip->nandsim_events, links);
		NANDSIM_CHIP_UNLOCK(chip);
		if (ev->type == NANDSIM_EV_EXIT) {
			NANDSIM_CHIP_LOCK(chip);
			destroy_event(ev);
			wakeup(ev);
			while (!STAILQ_EMPTY(&chip->nandsim_events)) {
				ev = STAILQ_FIRST(&chip->nandsim_events);
				STAILQ_REMOVE_HEAD(&chip->nandsim_events,
				    links);
				destroy_event(ev);
				wakeup(ev);
			}
			NANDSIM_CHIP_UNLOCK(chip);
			nandsim_log(chip, NANDSIM_LOG_SM, "destroyed\n");
			mtx_destroy(&chip->ns_lock);
			nandsim_blk_state_destroy(chip);
			nandsim_swap_destroy(chip->swap);
			free(chip, M_NANDSIM);
			nandsim_proc = NULL;

			kthread_exit();
		}

		if (!(chip->flags & NANDSIM_CHIP_FROZEN)) {
			nand_debug(NDBG_SIM,"Chip [%x] get event [%x]",
			    chip->chip_num, ev->type);
			chip->ev_handler(chip, ev->type, ev->data);
		}

		wakeup(ev);
		destroy_event(ev);
	}

}
Ejemplo n.º 2
0
struct chip_swap *
nandsim_swap_init(const char *swap_file, uint32_t nof_blks, uint32_t blk_size)
{
	struct chip_swap *swap;
	int err = 0;

	if ((swap_file == NULL) || (nof_blks == 0) || (blk_size == 0))
		return (NULL);

	swap = malloc(sizeof(*swap), M_NANDSIM, M_WAITOK | M_ZERO);

	SLIST_INIT(&swap->free_bs);
	STAILQ_INIT(&swap->used_bs);
	swap->blk_size = blk_size;
	swap->nof_blks = nof_blks;

	err = init_block_state(swap);
	if (err) {
		nandsim_swap_destroy(swap);
		return (NULL);
	}

	err = create_buffers(swap);
	if (err) {
		nandsim_swap_destroy(swap);
		return (NULL);
	}

	err = swap_file_open(swap, swap_file);
	if (err) {
		nandsim_swap_destroy(swap);
		return (NULL);
	}

	return (swap);
}