Пример #1
0
static void gta02_init(void)
{
	s3c24xx_irqc_regs_t *irqc_regs;

	gta02_timer = (void *) km_map(S3C24XX_TIMER_ADDRESS, PAGE_SIZE,
	    PAGE_NOT_CACHEABLE);
	irqc_regs = (void *) km_map(S3C24XX_IRQC_ADDRESS, PAGE_SIZE,
	    PAGE_NOT_CACHEABLE);

	/* Initialize interrupt controller. */
	s3c24xx_irqc_init(&gta02_irqc, irqc_regs);
}
Пример #2
0
static void raspberrypi_init(void)
{
	/* Initialize interrupt controller */
	raspi.irc = (void *) km_map(BCM2835_IRC_ADDR, sizeof(bcm2835_irc_t),
				    PAGE_NOT_CACHEABLE);
	ASSERT(raspi.irc);
	bcm2835_irc_init(raspi.irc);

	/* Initialize system timer */
	raspi.timer = (void *) km_map(BCM2835_TIMER_ADDR,
				      sizeof(bcm2835_timer_t),
				      PAGE_NOT_CACHEABLE);
}
Пример #3
0
/** Create a temporary page.
 *
 * The page is mapped read/write to a newly allocated frame of physical memory.
 * The page must be returned back to the system by a call to
 * km_temporary_page_put().
 *
 * @param[inout] framep	Pointer to a variable which will receive the physical
 *			address of the allocated frame.
 * @param[in] flags	Frame allocation flags. FRAME_NONE, FRAME_NO_RESERVE
 *			and FRAME_ATOMIC bits are allowed.
 * @return		Virtual address of the allocated frame.
 */
uintptr_t km_temporary_page_get(uintptr_t *framep, frame_flags_t flags)
{
	uintptr_t frame;
	uintptr_t page;

	ASSERT(THREAD);
	ASSERT(framep);
	ASSERT(!(flags & ~(FRAME_NO_RESERVE | FRAME_ATOMIC)));

	/*
	 * Allocate a frame, preferably from high memory.
	 */
	frame = (uintptr_t) frame_alloc(ONE_FRAME,
	    FRAME_HIGHMEM | FRAME_ATOMIC | flags); 
	if (frame) {
		page = km_map(frame, PAGE_SIZE,
		    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
		ASSERT(page);	// FIXME
	} else {
		frame = (uintptr_t) frame_alloc(ONE_FRAME,
		    FRAME_LOWMEM | flags);
		if (!frame)
			return (uintptr_t) NULL;
		page = PA2KA(frame);
	}

	*framep = frame;
	return page;	
}
Пример #4
0
static struct acpi_sdt_header *map_sdt(struct acpi_sdt_header *psdt)
{
	struct acpi_sdt_header *vhdr;
	struct acpi_sdt_header *vsdt;

	/* Start with mapping the header only. */
	vhdr = (struct acpi_sdt_header *) km_map((uintptr_t) psdt,
	    sizeof(struct acpi_sdt_header), PAGE_READ | PAGE_NOT_CACHEABLE); 

	/* Now we can map the entire structure. */
	vsdt = (struct acpi_sdt_header *) km_map((uintptr_t) psdt,
	    vhdr->length, PAGE_WRITE | PAGE_NOT_CACHEABLE);
	
	// TODO: do not leak vtmp

	return vsdt; 
}
Пример #5
0
/** Initializes icp.hw_map. */
void icp_init(void)
{
	icp.hw_map.uart = km_map(ICP_UART, PAGE_SIZE,
	    PAGE_WRITE | PAGE_NOT_CACHEABLE);
	icp.hw_map.kbd_ctrl = km_map(ICP_KBD, PAGE_SIZE, PAGE_NOT_CACHEABLE);
	icp.hw_map.kbd_stat = icp.hw_map.kbd_ctrl + ICP_KBD_STAT;
	icp.hw_map.kbd_data = icp.hw_map.kbd_ctrl + ICP_KBD_DATA;
	icp.hw_map.kbd_intstat = icp.hw_map.kbd_ctrl + ICP_KBD_INTR_STAT;
	icp.hw_map.rtc = km_map(ICP_RTC, PAGE_SIZE,
	    PAGE_WRITE | PAGE_NOT_CACHEABLE);
	icp.hw_map.rtc1_load = icp.hw_map.rtc + ICP_RTC1_LOAD_OFFSET;
	icp.hw_map.rtc1_read = icp.hw_map.rtc + ICP_RTC1_READ_OFFSET;
	icp.hw_map.rtc1_ctl = icp.hw_map.rtc + ICP_RTC1_CTL_OFFSET;
	icp.hw_map.rtc1_intrclr = icp.hw_map.rtc + ICP_RTC1_INTRCLR_OFFSET;
	icp.hw_map.rtc1_bgload = icp.hw_map.rtc + ICP_RTC1_BGLOAD_OFFSET;
	icp.hw_map.rtc1_intrstat = icp.hw_map.rtc + ICP_RTC1_INTRSTAT_OFFSET;

	icp.hw_map.irqc = km_map(ICP_IRQC, PAGE_SIZE,
	    PAGE_WRITE | PAGE_NOT_CACHEABLE);
	icp.hw_map.irqc_mask = icp.hw_map.irqc + ICP_IRQC_MASK_OFFSET;
	icp.hw_map.irqc_unmask = icp.hw_map.irqc + ICP_IRQC_UNMASK_OFFSET;
	icp.hw_map.cmcr = km_map(ICP_CMCR, PAGE_SIZE,
	    PAGE_WRITE | PAGE_NOT_CACHEABLE);
	icp.hw_map.sdramcr = icp.hw_map.cmcr + ICP_SDRAMCR_OFFSET;
	icp.hw_map.vga = km_map(ICP_VGA, PAGE_SIZE,
	    PAGE_WRITE | PAGE_NOT_CACHEABLE);

	hw_map_init_called = true;
}
Пример #6
0
void ras_init(void)
{
	uintptr_t frame =
	    frame_alloc(1, FRAME_ATOMIC | FRAME_HIGHMEM, 0);
	if (!frame)
		frame = frame_alloc(1, FRAME_LOWMEM, 0);
	
	ras_page = (uintptr_t *) km_map(frame,
	    PAGE_SIZE, PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE);
	
	memsetb(ras_page, PAGE_SIZE, 0); 
	ras_page[RAS_START] = 0;
	ras_page[RAS_END] = 0xffffffff;
}
Пример #7
0
bool bcm2835_fb_init(fb_properties_t *prop)
{
	bcm2835_mbox_t *fb_mbox;
	bool ret = false;
        MBOX_BUFF_ALLOC(fb_desc, bcm2835_fb_desc_t);

	fb_mbox = (void *) km_map(BCM2835_MBOX0_ADDR, sizeof(bcm2835_mbox_t),
				  PAGE_NOT_CACHEABLE);

	fb_desc->width = 640;
	fb_desc->height = 480;
	fb_desc->virt_width = fb_desc->width;
	fb_desc->virt_height = fb_desc->height;
	fb_desc->pitch = 0;			/* Set by VC */
	fb_desc->bpp = 16;
	fb_desc->x_offset = 0;
	fb_desc->y_offset = 0;
	fb_desc->addr = 0;			/* Set by VC */
	fb_desc->size = 0;			/* Set by VC */

	mbox_write(fb_mbox, MBOX_CHAN_FB, KA2VCA(fb_desc));

	if (mbox_read(fb_mbox, MBOX_CHAN_FB)) {
		printf("BCM2835 framebuffer initialization failed\n");
		goto out;
	}

	prop->addr = fb_desc->addr;
	prop->offset = 0;
	prop->x = fb_desc->width;
	prop->y = fb_desc->height;
	prop->scan = fb_desc->pitch;
	prop->visual = VISUAL_RGB_5_6_5_LE;

	printf("BCM2835 framebuffer at 0x%08x (%dx%d)\n", prop->addr,
	       prop->x, prop->y);
	ret = true;
out:
	km_unmap((uintptr_t)fb_mbox, sizeof(bcm2835_mbox_t));
	return ret;
}
Пример #8
0
/** Kernel initialization thread.
 *
 * kinit takes care of higher level kernel
 * initialization (i.e. thread creation,
 * userspace initialization etc.).
 *
 * @param arg Not used.
 */
void kinit(void *arg)
{
	thread_t *thread;
	
	/*
	 * Detach kinit as nobody will call thread_join_timeout() on it.
	 */
	thread_detach(THREAD);
	
	interrupts_disable();
	
#ifdef CONFIG_SMP
	if (config.cpu_count > 1) {
		waitq_initialize(&ap_completion_wq);
		
		/*
		 * Create the kmp thread and wait for its completion.
		 * cpu1 through cpuN-1 will come up consecutively and
		 * not mess together with kcpulb threads.
		 * Just a beautification.
		 */
		thread = thread_create(kmp, NULL, TASK,
		    THREAD_FLAG_UNCOUNTED, "kmp");
		if (thread != NULL) {
			thread_wire(thread, &cpus[0]);
			thread_ready(thread);
		} else
			panic("Unable to create kmp thread.");
		
		thread_join(thread);
		thread_detach(thread);
		
		/*
		 * For each CPU, create its load balancing thread.
		 */
		unsigned int i;
		
		for (i = 0; i < config.cpu_count; i++) {
			thread = thread_create(kcpulb, NULL, TASK,
			    THREAD_FLAG_UNCOUNTED, "kcpulb");
			if (thread != NULL) {
				thread_wire(thread, &cpus[i]);
				thread_ready(thread);
			} else
				printf("Unable to create kcpulb thread for cpu%u\n", i);
		}
	}
#endif /* CONFIG_SMP */
	
	/*
	 * At this point SMP, if present, is configured.
	 */
	arch_post_smp_init();
	
	/* Start thread computing system load */
	thread = thread_create(kload, NULL, TASK, THREAD_FLAG_NONE,
	    "kload");
	if (thread != NULL)
		thread_ready(thread);
	else
		printf("Unable to create kload thread\n");
	
#ifdef CONFIG_KCONSOLE
	if (stdin) {
		/*
		 * Create kernel console.
		 */
		thread = thread_create(kconsole_thread, NULL, TASK,
		    THREAD_FLAG_NONE, "kconsole");
		if (thread != NULL)
			thread_ready(thread);
		else
			printf("Unable to create kconsole thread\n");
	}
#endif /* CONFIG_KCONSOLE */
	
	interrupts_enable();
	
	/*
	 * Create user tasks, load RAM disk images.
	 */
	size_t i;
	program_t programs[CONFIG_INIT_TASKS];
	
	for (i = 0; i < init.cnt; i++) {
		if (init.tasks[i].paddr % FRAME_SIZE) {
			printf("init[%zu]: Address is not frame aligned\n", i);
			programs[i].task = NULL;
			continue;
		}
		
		/*
		 * Construct task name from the 'init:' prefix and the
		 * name stored in the init structure (if any).
		 */
		
		char namebuf[TASK_NAME_BUFLEN];
		
		const char *name = init.tasks[i].name;
		if (name[0] == 0)
			name = "<unknown>";
		
		ASSERT(TASK_NAME_BUFLEN >= INIT_PREFIX_LEN);
		str_cpy(namebuf, TASK_NAME_BUFLEN, INIT_PREFIX);
		str_cpy(namebuf + INIT_PREFIX_LEN,
		    TASK_NAME_BUFLEN - INIT_PREFIX_LEN, name);
		
		/*
		 * Create virtual memory mappings for init task images.
		 */
		uintptr_t page = km_map(init.tasks[i].paddr,
		    init.tasks[i].size,
		    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
		ASSERT(page);
		
		int rc = program_create_from_image((void *) page, namebuf,
		    &programs[i]);
		
		if (rc == 0) {
			if (programs[i].task != NULL) {
				/*
				 * Set capabilities to init userspace tasks.
				 */
				cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER |
				    CAP_IO_MANAGER | CAP_IRQ_REG);
				
				if (!ipc_phone_0)
					ipc_phone_0 = &programs[i].task->answerbox;
			}
			
			/*
			 * If programs[i].task == NULL then it is
			 * the program loader and it was registered
			 * successfully.
			 */
		} else if (i == init.cnt - 1) {
			/*
			 * Assume the last task is the RAM disk.
			 */
			init_rd((void *) init.tasks[i].paddr, init.tasks[i].size);
		} else
			printf("init[%zu]: Init binary load failed "
			    "(error %d, loader status %u)\n", i, rc,
			    programs[i].loader_status);
	}
	
	/*
	 * Run user tasks.
	 */
	for (i = 0; i < init.cnt; i++) {
		if (programs[i].task != NULL)
			program_ready(&programs[i]);
	}
	
#ifdef CONFIG_KCONSOLE
	if (!stdin) {
		thread_sleep(10);
		printf("kinit: No stdin\nKernel alive: .");
		
		unsigned int i = 0;
		while (true) {
			printf("\b%c", alive[i % ALIVE_CHARS]);
			thread_sleep(1);
			i++;
		}
	}
#endif /* CONFIG_KCONSOLE */
}
Пример #9
0
/** Kernel initialization thread.
 *
 * kinit takes care of higher level kernel
 * initialization (i.e. thread creation,
 * userspace initialization etc.).
 *
 * @param arg Not used.
 */
void kinit(void *arg)
{
	thread_t *thread;
	
	/*
	 * Detach kinit as nobody will call thread_join_timeout() on it.
	 */
	thread_detach(THREAD);

	interrupts_disable();
	
	/* Start processing RCU callbacks. RCU is fully functional afterwards. */
	rcu_kinit_init();
	
	/*
	 * Start processing work queue items. Some may have been queued during boot.
	 */
	workq_global_worker_init();
	
#ifdef CONFIG_SMP
	if (config.cpu_count > 1) {
		waitq_initialize(&ap_completion_wq);
		
		/*
		 * Create the kmp thread and wait for its completion.
		 * cpu1 through cpuN-1 will come up consecutively and
		 * not mess together with kcpulb threads.
		 * Just a beautification.
		 */
		thread = thread_create(kmp, NULL, TASK,
		    THREAD_FLAG_UNCOUNTED, "kmp");
		if (thread != NULL) {
			thread_wire(thread, &cpus[0]);
			thread_ready(thread);
		} else
			panic("Unable to create kmp thread.");
		
		thread_join(thread);
		thread_detach(thread);
		
		/*
		 * For each CPU, create its load balancing thread.
		 */
		unsigned int i;
		
		for (i = 0; i < config.cpu_count; i++) {
			thread = thread_create(kcpulb, NULL, TASK,
			    THREAD_FLAG_UNCOUNTED, "kcpulb");
			if (thread != NULL) {
				thread_wire(thread, &cpus[i]);
				thread_ready(thread);
			} else
				log(LF_OTHER, LVL_ERROR,
				    "Unable to create kcpulb thread for cpu%u", i);
		}
	}
#endif /* CONFIG_SMP */
	
	/*
	 * At this point SMP, if present, is configured.
	 */
	ARCH_OP(post_smp_init);
	
	/* Start thread computing system load */
	thread = thread_create(kload, NULL, TASK, THREAD_FLAG_NONE,
	    "kload");
	if (thread != NULL)
		thread_ready(thread);
	else
		log(LF_OTHER, LVL_ERROR, "Unable to create kload thread");
	
#ifdef CONFIG_KCONSOLE
	if (stdin) {
		/*
		 * Create kernel console.
		 */
		thread = thread_create(kconsole_thread, NULL, TASK,
		    THREAD_FLAG_NONE, "kconsole");
		if (thread != NULL)
			thread_ready(thread);
		else
			log(LF_OTHER, LVL_ERROR,
			    "Unable to create kconsole thread");
	}
#endif /* CONFIG_KCONSOLE */
	
	/*
	 * Store the default stack size in sysinfo so that uspace can create
	 * stack with this default size.
	 */
	sysinfo_set_item_val("default.stack_size", NULL, STACK_SIZE_USER);
	
	interrupts_enable();
	
	/*
	 * Create user tasks, load RAM disk images.
	 */
	size_t i;
	program_t programs[CONFIG_INIT_TASKS];
	
	// FIXME: do not propagate arguments through sysinfo
	// but pass them directly to the tasks
	for (i = 0; i < init.cnt; i++) {
		const char *arguments = init.tasks[i].arguments;
		if (str_length(arguments) == 0)
			continue;
		if (str_length(init.tasks[i].name) == 0)
			continue;
		size_t arguments_size = str_size(arguments);

		void *arguments_copy = malloc(arguments_size, 0);
		if (arguments_copy == NULL)
			continue;
		memcpy(arguments_copy, arguments, arguments_size);

		char item_name[CONFIG_TASK_NAME_BUFLEN + 15];
		snprintf(item_name, CONFIG_TASK_NAME_BUFLEN + 15,
		    "init_args.%s", init.tasks[i].name);

		sysinfo_set_item_data(item_name, NULL, arguments_copy, arguments_size);
	}

	for (i = 0; i < init.cnt; i++) {
		if (init.tasks[i].paddr % FRAME_SIZE) {
			log(LF_OTHER, LVL_ERROR,
			    "init[%zu]: Address is not frame aligned", i);
			programs[i].task = NULL;
			continue;
		}
		
		/*
		 * Construct task name from the 'init:' prefix and the
		 * name stored in the init structure (if any).
		 */
		
		char namebuf[TASK_NAME_BUFLEN];
		
		const char *name = init.tasks[i].name;
		if (name[0] == 0)
			name = "<unknown>";
		
		STATIC_ASSERT(TASK_NAME_BUFLEN >= INIT_PREFIX_LEN);
		str_cpy(namebuf, TASK_NAME_BUFLEN, INIT_PREFIX);
		str_cpy(namebuf + INIT_PREFIX_LEN,
		    TASK_NAME_BUFLEN - INIT_PREFIX_LEN, name);
		
		/*
		 * Create virtual memory mappings for init task images.
		 */
		uintptr_t page = km_map(init.tasks[i].paddr,
		    init.tasks[i].size,
		    PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
		ASSERT(page);
		
		int rc = program_create_from_image((void *) page, namebuf,
		    &programs[i]);
		
		if (rc == 0) {
			if (programs[i].task != NULL) {
				/*
				 * Set capabilities to init userspace tasks.
				 */
				cap_set(programs[i].task, CAP_CAP | CAP_MEM_MANAGER |
				    CAP_IO_MANAGER | CAP_IRQ_REG);
				
				if (!ipc_phone_0) {
					ipc_phone_0 = &programs[i].task->answerbox;
					/*
					 * Hold the first task so that the
					 * ipc_phone_0 remains a valid pointer
					 * even if the first task exits for
					 * whatever reason.
					 */
					task_hold(programs[i].task);
				}
			}
			
			/*
			 * If programs[i].task == NULL then it is
			 * the program loader and it was registered
			 * successfully.
			 */
		} else if (i == init.cnt - 1) {
			/*
			 * Assume the last task is the RAM disk.
			 */
			init_rd((void *) init.tasks[i].paddr, init.tasks[i].size);
		} else
			log(LF_OTHER, LVL_ERROR,
			    "init[%zu]: Init binary load failed "
			    "(error %d, loader status %u)", i, rc,
			    programs[i].loader_status);
	}
	
	/*
	 * Run user tasks.
	 */
	for (i = 0; i < init.cnt; i++) {
		if (programs[i].task != NULL)
			program_ready(&programs[i]);
	}
	
#ifdef CONFIG_KCONSOLE
	if (!stdin) {
		thread_sleep(10);
		printf("kinit: No stdin\nKernel alive: .");
		
		unsigned int i = 0;
		while (true) {
			printf("\b%c", alive[i % ALIVE_CHARS]);
			thread_sleep(1);
			i++;
		}
	}
#endif /* CONFIG_KCONSOLE */
}