cp: guest layer revamp, part 1
[hvf.git] / cp / shell / cmd_enable.c
bloba46f4a969e119123a182a6c84a0b6cc7edd7374d
1 /*
2 * (C) Copyright 2007-2010 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 /*
9 *!!! ENABLE
10 *!! SYNTAX
11 *! \tok{\sc ENAble}
12 *! \begin{stack} \tok{ALL} \\ <rdev> \end{stack}
13 *!! XATNYS
14 *!! AUTH A
15 *!! PURPOSE
16 *! Enables a real device.
18 static int cmd_enable(struct virt_sys *sys, char *cmd, int len)
20 u64 devnum;
21 struct device *dev;
22 struct console *con;
24 SHELL_CMD_AUTH(sys, A);
26 if (!strcasecmp(cmd, "ALL")) {
27 con_printf(sys->con, "ENABLE ALL not yet implemented!\n");
28 return 0;
31 cmd = __extract_hex(cmd, &devnum);
32 if (IS_ERR(cmd))
33 return PTR_ERR(cmd);
35 /* device number must be 16-bit */
36 if (devnum & ~0xffffUL)
37 return -EINVAL;
39 dev = find_device_by_ccuu(devnum);
40 if (IS_ERR(dev)) {
41 con_printf(sys->con, "Device %04llX not found in configuration\n", devnum);
42 return 0;
45 mutex_lock(&dev->lock);
47 if (dev->in_use) {
48 con_printf(sys->con, "Device %04llX is already in use\n", devnum);
49 goto out_err;
52 if (!dev->dev->enable) {
53 con_printf(sys->con, "Device type %-4s cannot be enabled\n",
54 type2name(dev->type));
55 goto out_err;
58 con = dev->dev->enable(dev);
59 if (IS_ERR(con)) {
60 con_printf(sys->con, "Failed to enable %04llX: %s\n",
61 devnum, errstrings[-PTR_ERR(con)]);
62 goto out_err;
65 mutex_unlock(&dev->lock);
66 return 0;
68 out_err:
69 mutex_unlock(&dev->lock);
70 dev_put(dev);
71 return 0;