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
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
= {
23 .u
.dedicate
.rdev
= rdev
,
25 struct virt_device
*cur
;
31 mutex_lock(&sys
->virt_devs_lock
);
33 /* are we supposed to pick a vdev number? */
35 /* TODO: this is a super-stupid algorithm - fix it */
36 for(vdev
=0x0000; vdev
<=0xffff; vdev
++) {
38 list_for_each_entry(cur
, &sys
->virt_devs
, devices
) {
39 if (cur
->pmcw
.dev_num
== vdev
) {
55 /* pick a subchannel number
56 * TODO: this is a super-stupid algorithm - fix it
58 for(sch
=0x10000; sch
<=0x1ffff; sch
++) {
60 list_for_each_entry(cur
, &sys
->virt_devs
, devices
) {
61 if (cur
->sch
== sch
) {
74 memset(&crw
, 0, sizeof(struct crw
));
77 crw
.id
= sch
& ~0x10000;
80 ret
= alloc_virt_dev(sys
, &dv
, sch
);
83 guest_append_crw(sys
, &crw
);
85 mutex_unlock(&sys
->virt_devs_lock
);
89 mutex_unlock(&sys
->virt_devs_lock
);