Deleted Added
full compact
virtio_balloon.c (228301) virtio_balloon.c (234270)
1/*-
2 * Copyright (c) 2011, Bryan Venteicher <bryanv@daemoninthecloset.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27/* Driver for VirtIO memory balloon devices. */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2011, Bryan Venteicher <bryanv@daemoninthecloset.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27/* Driver for VirtIO memory balloon devices. */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/dev/virtio/balloon/virtio_balloon.c 228301 2011-12-06 06:28:32Z grehan $");
30__FBSDID("$FreeBSD: head/sys/dev/virtio/balloon/virtio_balloon.c 234270 2012-04-14 05:48:04Z grehan $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/endian.h>
36#include <sys/kthread.h>
37#include <sys/malloc.h>
38#include <sys/module.h>

--- 78 unchanged lines hidden (view full) ---

117
118/*
119 * Maximum number of pages we'll request to inflate or deflate
120 * the balloon in one virtqueue request. Both Linux and NetBSD
121 * have settled on 256, doing up to 1MB at a time.
122 */
123#define VTBALLOON_PAGES_PER_REQUEST 256
124
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/endian.h>
36#include <sys/kthread.h>
37#include <sys/malloc.h>
38#include <sys/module.h>

--- 78 unchanged lines hidden (view full) ---

117
118/*
119 * Maximum number of pages we'll request to inflate or deflate
120 * the balloon in one virtqueue request. Both Linux and NetBSD
121 * have settled on 256, doing up to 1MB at a time.
122 */
123#define VTBALLOON_PAGES_PER_REQUEST 256
124
125/* Must be able to fix all pages frames in one page (segment). */
126CTASSERT(VTBALLOON_PAGES_PER_REQUEST * sizeof(uint32_t) <= PAGE_SIZE);
127
125#define VTBALLOON_MTX(_sc) &(_sc)->vtballoon_mtx
126#define VTBALLOON_LOCK_INIT(_sc, _name) mtx_init(VTBALLOON_MTX((_sc)), _name, \
127 "VirtIO Balloon Lock", MTX_SPIN)
128#define VTBALLOON_LOCK(_sc) mtx_lock_spin(VTBALLOON_MTX((_sc)))
129#define VTBALLOON_UNLOCK(_sc) mtx_unlock_spin(VTBALLOON_MTX((_sc)))
130#define VTBALLOON_LOCK_DESTROY(_sc) mtx_destroy(VTBALLOON_MTX((_sc)))
131
132static device_method_t vtballoon_methods[] = {
133 /* Device methods. */
134 DEVMETHOD(device_probe, vtballoon_probe),
135 DEVMETHOD(device_attach, vtballoon_attach),
136 DEVMETHOD(device_detach, vtballoon_detach),
137
138 /* VirtIO methods. */
139 DEVMETHOD(virtio_config_change, vtballoon_config_change),
140
128#define VTBALLOON_MTX(_sc) &(_sc)->vtballoon_mtx
129#define VTBALLOON_LOCK_INIT(_sc, _name) mtx_init(VTBALLOON_MTX((_sc)), _name, \
130 "VirtIO Balloon Lock", MTX_SPIN)
131#define VTBALLOON_LOCK(_sc) mtx_lock_spin(VTBALLOON_MTX((_sc)))
132#define VTBALLOON_UNLOCK(_sc) mtx_unlock_spin(VTBALLOON_MTX((_sc)))
133#define VTBALLOON_LOCK_DESTROY(_sc) mtx_destroy(VTBALLOON_MTX((_sc)))
134
135static device_method_t vtballoon_methods[] = {
136 /* Device methods. */
137 DEVMETHOD(device_probe, vtballoon_probe),
138 DEVMETHOD(device_attach, vtballoon_attach),
139 DEVMETHOD(device_detach, vtballoon_detach),
140
141 /* VirtIO methods. */
142 DEVMETHOD(virtio_config_change, vtballoon_config_change),
143
141 { 0, 0 }
144 DEVMETHOD_END
142};
143
144static driver_t vtballoon_driver = {
145 "vtballoon",
146 vtballoon_methods,
147 sizeof(struct vtballoon_softc)
148};
149static devclass_t vtballoon_devclass;

--- 247 unchanged lines hidden (view full) ---

397 sglist_init(&sg, 1, segs);
398
399 error = sglist_append(&sg, sc->vtballoon_page_frames,
400 npages * sizeof(uint32_t));
401 KASSERT(error == 0, ("error adding page frames to sglist"));
402
403 error = virtqueue_enqueue(vq, vq, &sg, 1, 0);
404 KASSERT(error == 0, ("error enqueuing page frames to virtqueue"));
145};
146
147static driver_t vtballoon_driver = {
148 "vtballoon",
149 vtballoon_methods,
150 sizeof(struct vtballoon_softc)
151};
152static devclass_t vtballoon_devclass;

--- 247 unchanged lines hidden (view full) ---

400 sglist_init(&sg, 1, segs);
401
402 error = sglist_append(&sg, sc->vtballoon_page_frames,
403 npages * sizeof(uint32_t));
404 KASSERT(error == 0, ("error adding page frames to sglist"));
405
406 error = virtqueue_enqueue(vq, vq, &sg, 1, 0);
407 KASSERT(error == 0, ("error enqueuing page frames to virtqueue"));
408 virtqueue_notify(vq);
405
406 /*
407 * Inflate and deflate operations are done synchronously. The
408 * interrupt handler will wake us up.
409 */
410 VTBALLOON_LOCK(sc);
409
410 /*
411 * Inflate and deflate operations are done synchronously. The
412 * interrupt handler will wake us up.
413 */
414 VTBALLOON_LOCK(sc);
411 virtqueue_notify(vq);
412
413 while ((c = virtqueue_dequeue(vq, NULL)) == NULL)
414 msleep_spin(sc, VTBALLOON_MTX(sc), "vtbspf", 0);
415 VTBALLOON_UNLOCK(sc);
416
417 KASSERT(c == vq, ("unexpected balloon operation response"));
418}
419

--- 149 unchanged lines hidden ---
415
416 while ((c = virtqueue_dequeue(vq, NULL)) == NULL)
417 msleep_spin(sc, VTBALLOON_MTX(sc), "vtbspf", 0);
418 VTBALLOON_UNLOCK(sc);
419
420 KASSERT(c == vq, ("unexpected balloon operation response"));
421}
422

--- 149 unchanged lines hidden ---