Skip to content

Commit 25fe563

Browse files
chejianjjren1
authored andcommitted
dm: virtio-input: implement callbacks of virtio_input_ops
This patch implements the callbacks required by virtio_input_ops: reset/cfgread/cfgwrite/apply_features/set_status. Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Reviewed-by: Hao Li <hao.l.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 9741e1a commit 25fe563

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

devicemodel/hw/pci/virtio/virtio_input.c

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ static void virtio_input_neg_features(void *, uint64_t);
157157
static void virtio_input_set_status(void *, uint64_t);
158158
static int virtio_input_cfgread(void *, int, int, uint32_t *);
159159
static int virtio_input_cfgwrite(void *, int, int, uint32_t);
160+
static bool virtio_input_get_config(struct virtio_input *, uint8_t, uint8_t,
161+
struct virtio_input_config *);
160162

161163
static struct virtio_ops virtio_input_ops = {
162164
"virtio_input", /* our name */
@@ -174,32 +176,63 @@ static struct virtio_ops virtio_input_ops = {
174176
static void
175177
virtio_input_reset(void *vdev)
176178
{
177-
/* to be implemented */
179+
struct virtio_input *vi;
180+
181+
vi = vdev;
182+
183+
DPRINTF(("vtinput: device reset requested!\n"));
184+
vi->ready = false;
185+
virtio_reset_dev(&vi->base);
178186
}
179187

180188
static void
181189
virtio_input_neg_features(void *vdev, uint64_t negotiated_features)
182190
{
183-
/* to be implemented */
191+
struct virtio_input *vi = vdev;
192+
193+
vi->features = negotiated_features;
184194
}
185195

186196
static void
187197
virtio_input_set_status(void *vdev, uint64_t status)
188198
{
189-
/* to be implemented */
199+
struct virtio_input *vi = vdev;
200+
201+
if (status & VIRTIO_CR_STATUS_DRIVER_OK) {
202+
if (!vi->ready)
203+
vi->ready = true;
204+
}
190205
}
191206

192207
static int
193208
virtio_input_cfgread(void *vdev, int offset, int size, uint32_t *retval)
194209
{
195-
/* to be implemented */
210+
struct virtio_input *vi = vdev;
211+
struct virtio_input_config cfg;
212+
bool rc;
213+
214+
rc = virtio_input_get_config(vi, vi->cfg.select,
215+
vi->cfg.subsel, &cfg);
216+
if (rc)
217+
memcpy(retval, (uint8_t *)&cfg + offset, size);
218+
else
219+
memset(retval, 0, size);
220+
196221
return 0;
197222
}
198223

199224
static int
200225
virtio_input_cfgwrite(void *vdev, int offset, int size, uint32_t val)
201226
{
202-
/* to be implemented */
227+
struct virtio_input *vi = vdev;
228+
229+
if (offset == offsetof(struct virtio_input_config, select))
230+
vi->cfg.select = (uint8_t)val;
231+
else if (offset == offsetof(struct virtio_input_config, subsel))
232+
vi->cfg.subsel = (uint8_t)val;
233+
else
234+
DPRINTF(("vtinput: write to readonly reg %d\n", offset));
235+
203236
return 0;
204237
}
205238

@@ -223,6 +256,14 @@ virtio_input_read_event(int fd __attribute__((unused)),
223256
/* to be implemented */
224257
}
225258

259+
static bool
260+
virtio_input_get_config(struct virtio_input *vi, uint8_t select,
261+
uint8_t subsel, struct virtio_input_config *cfg)
262+
{
263+
/* to be implemented */
264+
return false;
265+
}
266+
226267
static int
227268
virtio_input_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
228269
{

0 commit comments

Comments
 (0)