예제 #1
0
파일: ktimer.c 프로젝트: KunYi/f9-kernel
ktimer_event_t *ktimer_event_create(uint32_t ticks,
	                                ktimer_event_handler_t handler,
	                                void *data)
{
	ktimer_event_t *kte = NULL;

	if (!handler)
		goto ret;

	kte = (ktimer_event_t *) ktable_alloc(&ktimer_event_table);

	/* No available slots */
	if (kte == NULL)
		goto ret;

	kte->next = NULL;
	kte->handler = handler;
	kte->data = data;

	if (ktimer_event_schedule(ticks, kte) == -1) {
		ktable_free(&ktimer_event_table, kte);
		kte = NULL;
	}

ret:
	return kte;
}
예제 #2
0
fpage_t* split_fpage(as_t* as, fpage_t* fpage, memptr_t split, int rl) {
	memptr_t base = fpage->fpage.base,
			 end = fpage->fpage.base + (1 << fpage->fpage.shift);
	fpage_t *lfirst, *llast, *rfirst, *rlast;
	split = mempool_align(fpage->fpage.mpid, split);

	if(!as)
		return NULL;

	/*Check if we can split something*/
	if(split == base || split == end) {
		return fpage;
	}

	if(fpage->map_next != fpage) {
		/*Splitting not supported for mapped pages*/
		/*UNIMPLIMENTED*/
		return NULL;
	}

	/*Split fpage into two chains of fpages*/
	create_fpage_chain(base, (split - base), fpage->fpage.mpid, &lfirst, &llast);
	create_fpage_chain(split,(end - split),  fpage->fpage.mpid, &rfirst, &rlast);

	remove_fpage_from_as(as, fpage);
	ktable_free(&fpage_table, fpage);

	insert_fpage_chain_to_as(as, lfirst, llast);
	insert_fpage_chain_to_as(as, rfirst, rlast);

	if(rl == 0) return lfirst;
	else return llast;
}
예제 #3
0
파일: ktimer.c 프로젝트: KunYi/f9-kernel
void ktimer_event_handler()
{
	ktimer_event_t *event = event_queue;
	ktimer_event_t *last_event = NULL;
	ktimer_event_t *next_event = NULL;
	uint32_t h_retvalue  = 0;

	if (!event_queue) {
		/* That is bug if we are here */
		dbg_printf(DL_KTIMER, "KTE: OOPS! handler found no events\n");

		ktimer_disable();
		return;
	}

	/* Search last event in event chain */
	do {
		event = event->next;
	} while (event && event->delta == 0);

	last_event = event;

	/* All rescheduled events will be scheduled after last event */
	event = event_queue;
	event_queue = last_event;

	/* walk chain */
	do {
		h_retvalue = event->handler(event);
		next_event = event->next;

		if (h_retvalue != 0x0) {
			dbg_printf(DL_KTIMER,
			           "KTE: Handled and rescheduled event %p @%ld\n",
			           event, ktimer_now);
			ktimer_event_schedule(h_retvalue, event);
		} else {
			dbg_printf(DL_KTIMER,
			           "KTE: Handled event %p @%ld\n",
			           event, ktimer_now);
			ktable_free(&ktimer_event_table, event);
		}

		event = next_event;	/* Guaranteed to be next
					   regardless of re-scheduling */
	} while (next_event && next_event != last_event);

	if (event_queue) {
		/* Reset ktimer */
		ktimer_enable(event_queue->delta);
	}
}
예제 #4
0
int unmap_fpage(as_t* as, fpage_t* fpage) {
	fpage_t* fpprev = fpage;

	dbg_printf(DL_MEMORY, "MEM: unmapped fpage %p from %p\n", fpage, as);

	/* Fpages that are not mapped or granted
	 * are destroyed with it's AS */
	if(!(fpage->fpage.flags & FPAGE_CLONE))
		return -1;

	while(fpprev->map_next != fpage) fpprev = fpprev->map_next;
	/*Clear flags*/
	fpprev->fpage.flags &= ~FPAGE_MAPPED;

	fpprev->map_next = fpage->map_next;
	remove_fpage_from_as(as, fpage);

	if(as->lru == fpage)
		as->lru = NULL;

	ktable_free(&fpage_table, fpage);

	return 0;
}