loader: remove shouting from ORB's variable name
[hvf.git] / cp / guest / attach.c
blob3ed2c48fff871c33eba70ecc1206a77511efc05b
1 /*
2 * (C) Copyright 2007-2012 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 <circbuf.h>
9 #include <vcpu.h>
10 #include <guest.h>
11 #include <sclp.h>
13 static void guest_append_crw(struct virt_sys *sys, struct crw *crw)
15 insert_circbuf(&sys->crws, crw);
18 int guest_attach(struct virt_sys *sys, u64 rdev, u64 vdev)
20 struct directory_vdev dv = {
21 .type = VDEV_DED,
22 .vdev = vdev,
23 .u.dedicate.rdev = rdev,
25 struct virt_device *cur;
26 struct crw crw;
27 int found;
28 int ret;
29 u64 sch;
31 mutex_lock(&sys->virt_devs_lock);
33 /* are we supposed to pick a vdev number? */
34 if (vdev == -1) {
35 /* TODO: this is a super-stupid algorithm - fix it */
36 for(vdev=0x0000; vdev<=0xffff; vdev++) {
37 found = 0;
38 list_for_each_entry(cur, &sys->virt_devs, devices) {
39 if (cur->pmcw.dev_num == vdev) {
40 found = 1;
41 break;
45 if (!found)
46 break;
49 if (found)
50 goto out_err;
52 dv.vdev = vdev;
55 /* pick a subchannel number
56 * TODO: this is a super-stupid algorithm - fix it
58 for(sch=0x10000; sch<=0x1ffff; sch++) {
59 found = 0;
60 list_for_each_entry(cur, &sys->virt_devs, devices) {
61 if (cur->sch == sch) {
62 found = 1;
63 break;
67 if (!found)
68 break;
71 if (found)
72 goto out_err;
74 memset(&crw, 0, sizeof(struct crw));
75 crw.rsc = 0x3;
76 crw.erc = 0x4;
77 crw.id = sch & ~0x10000;
79 /* add the device */
80 ret = alloc_virt_dev(sys, &dv, sch);
82 if (!ret)
83 guest_append_crw(sys, &crw);
85 mutex_unlock(&sys->virt_devs_lock);
86 return ret;
88 out_err:
89 mutex_unlock(&sys->virt_devs_lock);
90 return -EBUSY;