Commit 0ca49ca9 authored by Rusty Russell's avatar Rusty Russell

Remove old lguest bus and drivers.

This gets rid of the lguest bus, drivers and DMA mechanism, to make
way for a generic virtio mechanism.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent 0a8a69dd
......@@ -55,7 +55,6 @@
#include <linux/clockchips.h>
#include <linux/lguest.h>
#include <linux/lguest_launcher.h>
#include <linux/lguest_bus.h>
#include <asm/paravirt.h>
#include <asm/param.h>
#include <asm/page.h>
......@@ -162,46 +161,6 @@ void async_hcall(unsigned long call,
}
/*:*/
/* Wrappers for the SEND_DMA and BIND_DMA hypercalls. This is mainly because
* Jeff Garzik complained that __pa() should never appear in drivers, and this
* helps remove most of them. But also, it wraps some ugliness. */
void lguest_send_dma(unsigned long key, struct lguest_dma *dma)
{
/* The hcall might not write this if something goes wrong */
dma->used_len = 0;
hcall(LHCALL_SEND_DMA, key, __pa(dma), 0);
}
int lguest_bind_dma(unsigned long key, struct lguest_dma *dmas,
unsigned int num, u8 irq)
{
/* This is the only hypercall which actually wants 5 arguments, and we
* only support 4. Fortunately the interrupt number is always less
* than 256, so we can pack it with the number of dmas in the final
* argument. */
if (!hcall(LHCALL_BIND_DMA, key, __pa(dmas), (num << 8) | irq))
return -ENOMEM;
return 0;
}
/* Unbinding is the same hypercall as binding, but with 0 num & irq. */
void lguest_unbind_dma(unsigned long key, struct lguest_dma *dmas)
{
hcall(LHCALL_BIND_DMA, key, __pa(dmas), 0);
}
/* For guests, device memory can be used as normal memory, so we cast away the
* __iomem to quieten sparse. */
void *lguest_map(unsigned long phys_addr, unsigned long pages)
{
return (__force void *)ioremap(phys_addr, PAGE_SIZE*pages);
}
void lguest_unmap(void *addr)
{
iounmap((__force void __iomem *)addr);
}
/*G:033
* Here are our first native-instruction replacements: four functions for
* interrupt control.
......
......@@ -32,4 +32,3 @@ obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
obj-$(CONFIG_BLK_DEV_UB) += ub.o
obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
obj-$(CONFIG_LGUEST_BLOCK) += lguest_blk.o
This diff is collapsed.
......@@ -42,7 +42,6 @@ obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
obj-$(CONFIG_N_HDLC) += n_hdlc.o
obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
obj-$(CONFIG_SX) += sx.o generic_serial.o
obj-$(CONFIG_LGUEST_GUEST) += hvc_lguest.o
obj-$(CONFIG_RIO) += rio/ generic_serial.o
obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o
obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
......
/*D:300
* The Guest console driver
*
* This is a trivial console driver: we use lguest's DMA mechanism to send
* bytes out, and register a DMA buffer to receive bytes in. It is assumed to
* be present and available from the very beginning of boot.
*
* Writing console drivers is one of the few remaining Dark Arts in Linux.
* Fortunately for us, the path of virtual consoles has been well-trodden by
* the PowerPC folks, who wrote "hvc_console.c" to generically support any
* virtual console. We use that infrastructure which only requires us to write
* the basic put_chars and get_chars functions and call the right register
* functions.
:*/
/*M:002 The console can be flooded: while the Guest is processing input the
* Host can send more. Buffering in the Host could alleviate this, but it is a
* difficult problem in general. :*/
/* Copyright (C) 2006 Rusty Russell, IBM Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/err.h>
#include <linux/init.h>
#include <linux/lguest_bus.h>
#include <asm/paravirt.h>
#include "hvc_console.h"
/*D:340 This is our single console input buffer, with associated "struct
* lguest_dma" referring to it. Note the 0-terminated length array, and the
* use of physical address for the buffer itself. */
static char inbuf[256];
static struct lguest_dma cons_input = { .used_len = 0,
.addr[0] = __pa(inbuf),
.len[0] = sizeof(inbuf),
.len[1] = 0 };
/*D:310 The put_chars() callback is pretty straightforward.
*
* First we put the pointer and length in a "struct lguest_dma": we only have
* one pointer, so we set the second length to 0. Then we use SEND_DMA to send
* the data to (Host) buffers attached to the console key. Usually a device's
* key is a physical address within the device's memory, but because the
* console device doesn't have any associated physical memory, we use the
* LGUEST_CONSOLE_DMA_KEY constant (aka 0). */
static int put_chars(u32 vtermno, const char *buf, int count)
{
struct lguest_dma dma;
/* FIXME: DMA buffers in a "struct lguest_dma" are not allowed
* to go over page boundaries. This never seems to happen,
* but if it did we'd need to fix this code. */
dma.len[0] = count;
dma.len[1] = 0;
dma.addr[0] = __pa(buf);
lguest_send_dma(LGUEST_CONSOLE_DMA_KEY, &dma);
/* We're expected to return the amount of data we wrote: all of it. */
return count;
}
/*D:350 get_chars() is the callback from the hvc_console infrastructure when
* an interrupt is received.
*
* Firstly we see if our buffer has been filled: if not, we return. The rest
* of the code deals with the fact that the hvc_console() infrastructure only
* asks us for 16 bytes at a time. We keep a "cons_offset" variable for
* partially-read buffers. */
static int get_chars(u32 vtermno, char *buf, int count)
{
static int cons_offset;
/* Nothing left to see here... */
if (!cons_input.used_len)
return 0;
/* You want more than we have to give? Well, try wanting less! */
if (cons_input.used_len - cons_offset < count)
count = cons_input.used_len - cons_offset;
/* Copy across to their buffer and increment offset. */
memcpy(buf, inbuf + cons_offset, count);
cons_offset += count;
/* Finished? Zero offset, and reset cons_input so Host will use it
* again. */
if (cons_offset == cons_input.used_len) {
cons_offset = 0;
cons_input.used_len = 0;
}
return count;
}
/*:*/
static struct hv_ops lguest_cons = {
.get_chars = get_chars,
.put_chars = put_chars,
};
/*D:320 Console drivers are initialized very early so boot messages can go
* out. At this stage, the console is output-only. Our driver checks we're a
* Guest, and if so hands hvc_instantiate() the console number (0), priority
* (0), and the struct hv_ops containing the put_chars() function. */
static int __init cons_init(void)
{
if (strcmp(pv_info.name, "lguest") != 0)
return 0;
return hvc_instantiate(0, 0, &lguest_cons);
}
console_initcall(cons_init);
/*D:370 To set up and manage our virtual console, we call hvc_alloc() and
* stash the result in the private pointer of the "struct lguest_device".
* Since we never remove the console device we never need this pointer again,
* but using ->private is considered good form, and you never know who's going
* to copy your driver.
*
* Once the console is set up, we bind our input buffer ready for input. */
static int lguestcons_probe(struct lguest_device *lgdev)
{
int err;
/* The first argument of hvc_alloc() is the virtual console number, so
* we use zero. The second argument is the interrupt number.
*
* The third argument is a "struct hv_ops" containing the put_chars()
* and get_chars() pointers. The final argument is the output buffer
* size: we use 256 and expect the Host to have room for us to send
* that much. */
lgdev->private = hvc_alloc(0, lgdev_irq(lgdev), &lguest_cons, 256);
if (IS_ERR(lgdev->private))
return PTR_ERR(lgdev->private);
/* We bind a single DMA buffer at key LGUEST_CONSOLE_DMA_KEY.
* "cons_input" is that statically-initialized global DMA buffer we saw
* above, and we also give the interrupt we want. */
err = lguest_bind_dma(LGUEST_CONSOLE_DMA_KEY, &cons_input, 1,
lgdev_irq(lgdev));
if (err)
printk("lguest console: failed to bind buffer.\n");
return err;
}
/* Note the use of lgdev_irq() for the interrupt number. We tell hvc_alloc()
* to expect input when this interrupt is triggered, and then tell
* lguest_bind_dma() that is the interrupt to send us when input comes in. */
/*D:360 From now on the console driver follows standard Guest driver form:
* register_lguest_driver() registers the device type and probe function, and
* the probe function sets up the device.
*
* The standard "struct lguest_driver": */
static struct lguest_driver lguestcons_drv = {
.name = "lguestcons",
.owner = THIS_MODULE,
.device_type = LGUEST_DEVICE_T_CONSOLE,
.probe = lguestcons_probe,
};
/* The standard init function */
static int __init hvc_lguest_init(void)
{
return register_lguest_driver(&lguestcons_drv);
}
module_init(hvc_lguest_init);
......@@ -17,13 +17,3 @@ config LGUEST_GUEST
The guest needs code built-in, even if the host has lguest
support as a module. The drivers are tiny, so we build them
in too.
config LGUEST_NET
tristate
default y
depends on LGUEST_GUEST && NET
config LGUEST_BLOCK
tristate
default y
depends on LGUEST_GUEST && BLOCK
# Guest requires the bus driver.
obj-$(CONFIG_LGUEST_GUEST) += lguest_bus.o
# Host requires the other files, which can be a module.
obj-$(CONFIG_LGUEST) += lg.o
lg-y = core.o hypercalls.o page_tables.o interrupts_and_traps.o \
......
/*P:050 Lguest guests use a very simple bus for devices. It's a simple array
* of device descriptors contained just above the top of normal memory. The
* lguest bus is 80% tedious boilerplate code. :*/
#include <linux/init.h>
#include <linux/bootmem.h>
#include <linux/lguest_bus.h>
#include <asm/io.h>
#include <asm/paravirt.h>
struct lguest_device_desc *lguest_devices;
static ssize_t type_show(struct device *_dev,
struct device_attribute *attr, char *buf)
{
struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
return sprintf(buf, "%hu", lguest_devices[dev->index].type);
}
static ssize_t features_show(struct device *_dev,
struct device_attribute *attr, char *buf)
{
struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
return sprintf(buf, "%hx", lguest_devices[dev->index].features);
}
static ssize_t pfn_show(struct device *_dev,
struct device_attribute *attr, char *buf)
{
struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
return sprintf(buf, "%u", lguest_devices[dev->index].pfn);
}
static ssize_t status_show(struct device *_dev,
struct device_attribute *attr, char *buf)
{
struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
return sprintf(buf, "%hx", lguest_devices[dev->index].status);
}
static ssize_t status_store(struct device *_dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
if (sscanf(buf, "%hi", &lguest_devices[dev->index].status) != 1)
return -EINVAL;
return count;
}
static struct device_attribute lguest_dev_attrs[] = {
__ATTR_RO(type),
__ATTR_RO(features),
__ATTR_RO(pfn),
__ATTR(status, 0644, status_show, status_store),
__ATTR_NULL
};
/*D:130 The generic bus infrastructure requires a function which says whether a
* device matches a driver. For us, it is simple: "struct lguest_driver"
* contains a "device_type" field which indicates what type of device it can
* handle, so we just cast the args and compare: */
static int lguest_dev_match(struct device *_dev, struct device_driver *_drv)
{
struct lguest_device *dev = container_of(_dev,struct lguest_device,dev);
struct lguest_driver *drv = container_of(_drv,struct lguest_driver,drv);
return (drv->device_type == lguest_devices[dev->index].type);
}
/*:*/
struct lguest_bus {
struct bus_type bus;
struct device dev;
};
static struct lguest_bus lguest_bus = {
.bus = {
.name = "lguest",
.match = lguest_dev_match,
.dev_attrs = lguest_dev_attrs,
},
.dev = {
.parent = NULL,
.bus_id = "lguest",
}
};
/*D:140 This is the callback which occurs once the bus infrastructure matches
* up a device and driver, ie. in response to add_lguest_device() calling
* device_register(), or register_lguest_driver() calling driver_register().
*
* At the moment it's always the latter: the devices are added first, since
* scan_devices() is called from a "core_initcall", and the drivers themselves
* called later as a normal "initcall". But it would work the other way too.
*
* So now we have the happy couple, we add the status bit to indicate that we
* found a driver. If the driver truly loves the device, it will return
* happiness from its probe function (ok, perhaps this wasn't my greatest
* analogy), and we set the final "driver ok" bit so the Host sees it's all
* green. */
static int lguest_dev_probe(struct device *_dev)
{
int ret;
struct lguest_device*dev = container_of(_dev,struct lguest_device,dev);
struct lguest_driver*drv = container_of(dev->dev.driver,
struct lguest_driver, drv);
lguest_devices[dev->index].status |= LGUEST_DEVICE_S_DRIVER;
ret = drv->probe(dev);
if (ret == 0)
lguest_devices[dev->index].status |= LGUEST_DEVICE_S_DRIVER_OK;
return ret;
}
/* The last part of the bus infrastructure is the function lguest drivers use
* to register themselves. Firstly, we do nothing if there's no lguest bus
* (ie. this is not a Guest), otherwise we fill in the embedded generic "struct
* driver" fields and call the generic driver_register(). */
int register_lguest_driver(struct lguest_driver *drv)
{
if (!lguest_devices)
return 0;
drv->drv.bus = &lguest_bus.bus;
drv->drv.name = drv->name;
drv->drv.owner = drv->owner;
drv->drv.probe = lguest_dev_probe;
return driver_register(&drv->drv);
}
/* At the moment we build all the drivers into the kernel because they're so
* simple: 8144 bytes for all three of them as I type this. And as the console
* really needs to be built in, it's actually only 3527 bytes for the network
* and block drivers.
*
* If they get complex it will make sense for them to be modularized, so we
* need to explicitly export the symbol.
*
* I don't think non-GPL modules make sense, so it's a GPL-only export.
*/
EXPORT_SYMBOL_GPL(register_lguest_driver);
/*D:120 This is the core of the lguest bus: actually adding a new device.
* It's a separate function because it's neater that way, and because an
* earlier version of the code supported hotplug and unplug. They were removed
* early on because they were never used.
*
* As Andrew Tridgell says, "Untested code is buggy code".
*
* It's worth reading this carefully: we start with an index into the array of
* "struct lguest_device_desc"s indicating the device which is new: */
static void add_lguest_device(unsigned int index)
{
struct lguest_device *new;
/* Each "struct lguest_device_desc" has a "status" field, which the
* Guest updates as the device is probed. In the worst case, the Host
* can look at these bits to tell what part of device setup failed,
* even if the console isn't available. */
lguest_devices[index].status |= LGUEST_DEVICE_S_ACKNOWLEDGE;
new = kmalloc(sizeof(struct lguest_device), GFP_KERNEL);
if (!new) {
printk(KERN_EMERG "Cannot allocate lguest device %u\n", index);
lguest_devices[index].status |= LGUEST_DEVICE_S_FAILED;
return;
}
/* The "struct lguest_device" setup is pretty straight-forward example
* code. */
new->index = index;
new->private = NULL;
memset(&new->dev, 0, sizeof(new->dev));
new->dev.parent = &lguest_bus.dev;
new->dev.bus = &lguest_bus.bus;
sprintf(new->dev.bus_id, "%u", index);
/* device_register() causes the bus infrastructure to look for a
* matching driver. */
if (device_register(&new->dev) != 0) {
printk(KERN_EMERG "Cannot register lguest device %u\n", index);
lguest_devices[index].status |= LGUEST_DEVICE_S_FAILED;
kfree(new);
}
}
/*D:110 scan_devices() simply iterates through the device array. The type 0
* is reserved to mean "no device", and anything else means we have found a
* device: add it. */
static void scan_devices(void)
{
unsigned int i;
for (i = 0; i < LGUEST_MAX_DEVICES; i++)
if (lguest_devices[i].type)
add_lguest_device(i);
}
/*D:100 Fairly early in boot, lguest_bus_init() is called to set up the lguest
* bus. We check that we are a Guest by checking paravirt_ops.name: there are
* other ways of checking, but this seems most obvious to me.
*
* So we can access the array of "struct lguest_device_desc"s easily, we map
* that memory and store the pointer in the global "lguest_devices". Then we
* register the bus with the core. Doing two registrations seems clunky to me,
* but it seems to be the correct sysfs incantation.
*
* Finally we call scan_devices() which adds all the devices found in the
* "struct lguest_device_desc" array. */
static int __init lguest_bus_init(void)
{
if (strcmp(pv_info.name, "lguest") != 0)
return 0;
/* Devices are in a single page above top of "normal" mem */
lguest_devices = lguest_map(max_pfn<<PAGE_SHIFT, 1);
if (bus_register(&lguest_bus.bus) != 0
|| device_register(&lguest_bus.dev) != 0)
panic("lguest bus registration failed");
scan_devices();
return 0;
}
/* Do this after core stuff, before devices. */
postcore_initcall(lguest_bus_init);
......@@ -29,7 +29,6 @@
#include <linux/cpu.h>
#include <linux/lguest.h>
#include <linux/lguest_launcher.h>
#include <linux/lguest_bus.h>
#include <asm/paravirt.h>
#include <asm/param.h>
#include <asm/page.h>
......
......@@ -183,7 +183,6 @@ obj-$(CONFIG_ZORRO8390) += zorro8390.o
obj-$(CONFIG_HPLANCE) += hplance.o 7990.o
obj-$(CONFIG_MVME147_NET) += mvme147.o 7990.o
obj-$(CONFIG_EQUALIZER) += eql.o
obj-$(CONFIG_LGUEST_NET) += lguest_net.o
obj-$(CONFIG_MIPS_JAZZ_SONIC) += jazzsonic.o
obj-$(CONFIG_MIPS_AU1X00_ENET) += au1000_eth.o
obj-$(CONFIG_MIPS_SIM_NET) += mipsnet.o
......
This diff is collapsed.
#ifndef _ASM_LGUEST_DEVICE_H
#define _ASM_LGUEST_DEVICE_H
/* Everything you need to know about lguest devices. */
#include <linux/device.h>
#include <linux/lguest.h>
#include <linux/lguest_launcher.h>
struct lguest_device {
/* Unique busid, and index into lguest_page->devices[] */
unsigned int index;
struct device dev;
/* Driver can hang data off here. */
void *private;
};
/*D:380 Since interrupt numbers are arbitrary, we use a convention: each device
* can use the interrupt number corresponding to its index. The +1 is because
* interrupt 0 is not usable (it's actually the timer interrupt). */
static inline int lgdev_irq(const struct lguest_device *dev)
{
return dev->index + 1;
}
/*:*/
/* dma args must not be vmalloced! */
void lguest_send_dma(unsigned long key, struct lguest_dma *dma);
int lguest_bind_dma(unsigned long key, struct lguest_dma *dmas,
unsigned int num, u8 irq);
void lguest_unbind_dma(unsigned long key, struct lguest_dma *dmas);
/* Map the virtual device space */
void *lguest_map(unsigned long phys_addr, unsigned long pages);
void lguest_unmap(void *);
struct lguest_driver {
const char *name;
struct module *owner;
u16 device_type;
int (*probe)(struct lguest_device *dev);
void (*remove)(struct lguest_device *dev);
struct device_driver drv;
};
extern int register_lguest_driver(struct lguest_driver *drv);
extern void unregister_lguest_driver(struct lguest_driver *drv);
extern struct lguest_device_desc *lguest_devices; /* Just past max_pfn */
#endif /* _ASM_LGUEST_DEVICE_H */
......@@ -44,32 +44,6 @@ struct lguest_dma
};
/*:*/
/*D:460 This is the layout of a block device memory page. The Launcher sets up
* the num_sectors initially to tell the Guest the size of the disk. The Guest
* puts the type, sector and length of the request in the first three fields,
* then DMAs to the Host. The Host processes the request, sets up the result,
* then DMAs back to the Guest. */
struct lguest_block_page
{
/* 0 is a read, 1 is a write. */
int type;
__u32 sector; /* Offset in device = sector * 512. */
__u32 bytes; /* Length expected to be read/written in bytes */
/* 0 = pending, 1 = done, 2 = done, error */
int result;
__u32 num_sectors; /* Disk length = num_sectors * 512 */
};
/*D:520 The network device is basically a memory page where all the Guests on
* the network publish their MAC (ethernet) addresses: it's an array of "struct
* lguest_net": */
struct lguest_net
{
/* Simply the mac address (with multicast bit meaning promisc). */
unsigned char mac[6];
};
/*:*/
/* Where the Host expects the Guest to SEND_DMA console output to. */
#define LGUEST_CONSOLE_DMA_KEY 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment