BOOLEAN gpci_initialize(void)
{
    GUEST_HANDLE   guest;
    GUEST_ECONTEXT guest_ctx;

    vmm_zeromem(guest_pci_devices, sizeof(guest_pci_devices));
    list_init(guest_pci_devices);
    device_to_guest = hash64_create_default_hash(256);
    for( guest = guest_first( &guest_ctx ); guest; guest = guest_next( &guest_ctx )) {
        gpci_guest_initialize(guest_get_id(guest));
    }
    return TRUE;
}
Beispiel #2
0
/*
 * Init guest except of guest memory
 * Return NULL on error
 */
static guest_handle_t init_single_guest(uint32_t number_of_host_processors,
					const mon_guest_startup_t *gstartup,
					const mon_policy_t *guest_policy)
{
	guest_handle_t guest;
	uint32_t cpu_affinity = 0;
	uint32_t bit_number;
	boolean_t ready_to_run = FALSE;

	if ((gstartup->size_of_this_struct != sizeof(mon_guest_startup_t)) ||
	    (gstartup->version_of_this_struct != MON_GUEST_STARTUP_VERSION)) {
		MON_LOG(mask_anonymous, level_trace,
			"ASSERT: unknown guest struct: size: %#x version %d\n",
			gstartup->size_of_this_struct,
			gstartup->version_of_this_struct);

		return NULL;
	}

	/* create guest */
	guest = guest_register(gstartup->guest_magic_number,
		gstartup->physical_memory_size,
		gstartup->cpu_affinity, guest_policy);

	if (!guest) {
		MON_LOG(mask_anonymous,
			level_trace,
			"Cannot create guest with the following params: \n"
			"\t\tguest_magic_number    = %#x\n"
			"\t\tphysical_memory_size  = %#x\n"
			"\t\tcpu_affinity          = %#x\n",
			gstartup->guest_magic_number,
			gstartup->physical_memory_size,
			gstartup->cpu_affinity);

		return NULL;
	}

	fvs_initialize(guest, number_of_host_processors);

	vmexit_guest_initialize(guest_get_id(guest));

	if (gstartup->devices_count != 0) {
		MON_LOG(mask_anonymous, level_trace,
			"ASSERT: devices virtualization is not supported yet\n"
			"\t\tguest_magic_number    = %#x\n"
			"\t\tdevices_count         = %d\n",
			gstartup->guest_magic_number, gstartup->devices_count);

		MON_DEADLOOP();
		return NULL;
	}

	if (gstartup->image_size) {
		guest_set_executable_image(guest,
			(const uint8_t *)gstartup->image_address,
			gstartup->image_size,
			gstartup->image_offset_in_guest_physical_memory,
			BITMAP_GET(gstartup->flags,
				MON_GUEST_FLAG_IMAGE_COMPRESSED) != 0);
	}

	if (BITMAP_GET(gstartup->flags,
		    MON_GUEST_FLAG_REAL_BIOS_ACCESS_ENABLE) !=
	    0) {
		guest_set_real_BIOS_access_enabled(guest);
	}

	msr_vmexit_guest_setup(guest); /* setup MSR-related control structure */

	/* init cpus. */
	/* first init CPUs that has initial state */
	cpu_affinity = gstartup->cpu_affinity;
	if (cpu_affinity == 0) {
		MON_LOG(mask_anonymous,
			level_trace,
			"ASSERT: guest without CPUs:\n"
			"\t\tguest_magic_number    = %#x\n"
			"\t\tcpu_affinity          = %#x\n",
			gstartup->guest_magic_number,
			gstartup->cpu_affinity);

		MON_DEADLOOP();
		return NULL;
	}

	ready_to_run =
		(BITMAP_GET(gstartup->flags,
			 MON_GUEST_FLAG_LAUNCH_IMMEDIATELY) != 0);

	if (cpu_affinity == (uint32_t)-1) {
		/* special case - run on all existing CPUs */
		for (bit_number = 0; bit_number < number_of_host_processors;
		     bit_number++) {
			add_cpu_to_guest(gstartup, guest, (cpu_id_t)bit_number,
				ready_to_run);
			MON_LOG(mask_anonymous,
				level_trace,
				"CPU #%d added successfully to the current guest\n",
				bit_number);
		}
	}
#ifdef DEBUG
	guest_register_vmcall_services(guest);
#endif

	return guest;
}