cp: define a FIXME macro that leaves a sclp message
[hvf.git] / cp / drivers / vdevice.c
blobaf1ef70d936b83ce604df15d257df2ea1c96469d
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 <slab.h>
9 #include <list.h>
10 #include <vcpu.h>
11 #include <vdevice.h>
13 static int __setup_vdev_ded(struct virt_sys *sys,
14 struct directory_vdev *dirdev,
15 struct virt_device *vdev)
17 struct device *rdev;
18 int ret;
20 rdev = find_device_by_ccuu(dirdev->u.dedicate.rdev);
21 if (IS_ERR(rdev))
22 return PTR_ERR(rdev);
24 mutex_lock(&rdev->lock);
26 if (rdev->in_use) {
27 ret = -EBUSY;
28 goto out;
31 rdev->in_use = 1;
33 vdev->u.dedicate.rdev = rdev;
34 vdev->type = rdev->type;
35 vdev->model = rdev->model;
37 ret = 0;
39 out:
40 mutex_unlock(&rdev->lock);
41 return ret;
44 static LOCK_CLASS(vdev_lc);
46 /* assumes sys->virt_devs_lock is held */
47 int alloc_virt_dev(struct virt_sys *sys, struct directory_vdev *dirdev,
48 u32 sch)
50 struct virt_device *vdev;
51 int ret = 0;
53 vdev = malloc(sizeof(struct virt_device), ZONE_NORMAL);
54 if (!vdev)
55 return -ENOMEM;
57 mutex_init(&vdev->lock, &vdev_lc);
59 vdev->vtype = dirdev->type;
60 vdev->sch = sch;
61 vdev->pmcw.v = 1;
62 vdev->pmcw.dev_num = dirdev->vdev;
63 vdev->pmcw.lpm = 0x80;
64 vdev->pmcw.pim = 0x80;
65 vdev->pmcw.pom = 0xff;
66 vdev->pmcw.pam = 0x80;
68 switch(dirdev->type) {
69 case VDEV_CONS:
70 /* CONS is really just a special case of SPOOL */
71 vdev->u.spool.file = NULL;
72 vdev->u.spool.ops = &spool_cons_ops;
73 vdev->type = 0x3215;
74 vdev->model = 0;
75 break;
76 case VDEV_SPOOL:
77 vdev->u.spool.file = NULL;
78 vdev->u.spool.ops = NULL;
79 vdev->type = dirdev->u.spool.type;
80 vdev->model = dirdev->u.spool.model;
81 break;
82 case VDEV_DED:
83 ret = __setup_vdev_ded(sys, dirdev, vdev);
84 break;
85 case VDEV_MDISK:
86 vdev->type = 0x3390;
87 vdev->model = 3;
88 FIXME("hook it up to mdisk driver");
89 break;
90 case VDEV_LINK:
91 case VDEV_INVAL:
92 ret = -EINVAL;
93 break;
96 if (!ret)
97 list_add_tail(&vdev->devices, &sys->virt_devs);
98 else
99 free(vdev);
101 return ret;