cp: split the guest init from shell init
[hvf.git] / cp / guest / init.c
blob614f90b44f0e83776ed841939ae055a513cd66b8
1 /*
2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #include <directory.h>
9 #include <sched.h>
10 #include <errno.h>
11 #include <page.h>
12 #include <buddy.h>
13 #include <slab.h>
14 #include <dat.h>
15 #include <clock.h>
16 #include <ebcdic.h>
17 #include <vdevice.h>
18 #include <cpu.h>
19 #include <mutex.h>
20 #include <vsprintf.h>
22 void alloc_guest_devices(struct virt_sys *sys)
24 int ret;
25 int i;
27 INIT_LIST_HEAD(&sys->virt_devs);
29 for(i=0; sys->directory->devices[i].type != VDEV_INVAL; i++) {
30 ret = alloc_virt_dev(sys, &sys->directory->devices[i],
31 0x10000 + i);
32 if (ret)
33 con_printf(sys->con, "Failed to allocate vdev %04X, SCH = %05X (%s)\n",
34 sys->directory->devices[i].vdev,
35 0x10000 + i, errstrings[-ret]);
39 int alloc_guest_storage(struct virt_sys *sys)
41 u64 pages = sys->directory->storage_size >> PAGE_SHIFT;
42 struct page *p;
44 INIT_LIST_HEAD(&sys->guest_pages);
46 while (pages) {
47 p = alloc_pages(0, ZONE_NORMAL);
48 if (!p)
49 return -ENOMEM;
51 list_add(&p->guest, &sys->guest_pages);
53 pages--;
55 dat_insert_page(&sys->as, (u64) page_to_addr(p),
56 pages << PAGE_SHIFT);
59 return 0;
62 int alloc_vcpu(struct virt_sys *sys)
64 struct virt_cpu *cpu;
65 struct page *page;
67 page = alloc_pages(0, ZONE_NORMAL);
68 if (!page)
69 return -ENOMEM;
71 cpu = page_to_addr(page);
73 memset(cpu, 0, PAGE_SIZE);
74 INIT_LIST_HEAD(&cpu->int_io[0]);
75 INIT_LIST_HEAD(&cpu->int_io[1]);
76 INIT_LIST_HEAD(&cpu->int_io[2]);
77 INIT_LIST_HEAD(&cpu->int_io[3]);
78 INIT_LIST_HEAD(&cpu->int_io[4]);
79 INIT_LIST_HEAD(&cpu->int_io[5]);
80 INIT_LIST_HEAD(&cpu->int_io[6]);
81 INIT_LIST_HEAD(&cpu->int_io[7]);
83 cpu->cpuid = getcpuid() | 0xFF00000000000000ULL;
85 cpu->sie_cb.gmsor = 0;
86 cpu->sie_cb.gmslm = sys->directory->storage_size;
87 cpu->sie_cb.gbea = 1;
88 cpu->sie_cb.ecb = 2;
89 cpu->sie_cb.eca = 0xC1002001U;
91 * TODO: What about ->scaoh and ->scaol?
94 sys->task->cpu = cpu;
95 return 0;
98 void free_vcpu(struct virt_sys *sys)
100 struct virt_cpu *cpu = sys->task->cpu;
102 BUG_ON(!list_empty(&cpu->int_io[0]));
103 BUG_ON(!list_empty(&cpu->int_io[1]));
104 BUG_ON(!list_empty(&cpu->int_io[2]));
105 BUG_ON(!list_empty(&cpu->int_io[3]));
106 BUG_ON(!list_empty(&cpu->int_io[4]));
107 BUG_ON(!list_empty(&cpu->int_io[5]));
108 BUG_ON(!list_empty(&cpu->int_io[6]));
109 BUG_ON(!list_empty(&cpu->int_io[7]));
111 free_pages(cpu, 0);
113 sys->task->cpu = NULL;