Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 95762
b: refs/heads/master
c: 72e61eb
h: refs/heads/master
v: v3
  • Loading branch information
Rusty Russell committed May 2, 2008
1 parent d8d80da commit 14db457
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 37 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5539ae9613587e4a4eec42d420b8bdd9ff552a65
refs/heads/master: 72e61eb40b55dd57031ec5971e810649f82b0259
4 changes: 2 additions & 2 deletions trunk/drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ static int virtblk_probe(struct virtio_device *vdev)
blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL);

/* Host must always specify the capacity. */
__virtio_config_val(vdev, offsetof(struct virtio_blk_config, capacity),
&cap);
vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
&cap, sizeof(cap));

/* If capacity is too big, truncate with warning. */
if ((sector_t)cap != cap) {
Expand Down
6 changes: 3 additions & 3 deletions trunk/drivers/virtio/virtio_balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ static void virtballoon_changed(struct virtio_device *vdev)
static inline s64 towards_target(struct virtio_balloon *vb)
{
u32 v;
__virtio_config_val(vb->vdev,
offsetof(struct virtio_balloon_config, num_pages),
&v);
vb->vdev->config->get(vb->vdev,
offsetof(struct virtio_balloon_config, num_pages),
&v, sizeof(v));
return v - vb->num_pages;
}

Expand Down
47 changes: 16 additions & 31 deletions trunk/include/linux/virtio_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define VIRTIO_CONFIG_S_FAILED 0x80

#ifdef __KERNEL__
struct virtio_device;
#include <linux/virtio.h>

/**
* virtio_config_ops - operations for configuring a virtio device
Expand All @@ -30,13 +30,11 @@ struct virtio_device;
* offset: the offset of the configuration field
* buf: the buffer to write the field value into.
* len: the length of the buffer
* Note that contents are conventionally little-endian.
* @set: write the value of a configuration field
* vdev: the virtio_device
* offset: the offset of the configuration field
* buf: the buffer to read the field value from.
* len: the length of the buffer
* Note that contents are conventionally little-endian.
* @get_status: read the status byte
* vdev: the virtio_device
* Returns the status byte
Expand Down Expand Up @@ -70,40 +68,27 @@ struct virtio_config_ops
};

/**
* virtio_config_val - look for a feature and get a single virtio config.
* virtio_config_val - look for a feature and get a virtio config entry.
* @vdev: the virtio device
* @fbit: the feature bit
* @offset: the type to search for.
* @val: a pointer to the value to fill in.
*
* The return value is -ENOENT if the feature doesn't exist. Otherwise
* the value is endian-corrected and returned in v. */
#define virtio_config_val(vdev, fbit, offset, v) ({ \
int _err; \
if ((vdev)->config->feature((vdev), (fbit))) { \
__virtio_config_val((vdev), (offset), (v)); \
_err = 0; \
} else \
_err = -ENOENT; \
_err; \
})
* the config value is copied into whatever is pointed to by v. */
#define virtio_config_val(vdev, fbit, offset, v) \
virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v))

/**
* __virtio_config_val - get a single virtio config without feature check.
* @vdev: the virtio device
* @offset: the type to search for.
* @val: a pointer to the value to fill in.
*
* The value is endian-corrected and returned in v. */
#define __virtio_config_val(vdev, offset, v) do { \
BUILD_BUG_ON(sizeof(*(v)) != 1 && sizeof(*(v)) != 2 \
&& sizeof(*(v)) != 4 && sizeof(*(v)) != 8); \
(vdev)->config->get((vdev), (offset), (v), sizeof(*(v))); \
switch (sizeof(*(v))) { \
case 2: le16_to_cpus((__u16 *) v); break; \
case 4: le32_to_cpus((__u32 *) v); break; \
case 8: le64_to_cpus((__u64 *) v); break; \
} \
} while(0)
static inline int virtio_config_buf(struct virtio_device *vdev,
unsigned int fbit,
unsigned int offset,
void *buf, unsigned len)
{
if (!vdev->config->feature(vdev, fbit))
return -ENOENT;

vdev->config->get(vdev, offset, buf, len);
return 0;
}
#endif /* __KERNEL__ */
#endif /* _LINUX_VIRTIO_CONFIG_H */

0 comments on commit 14db457

Please sign in to comment.