Skip to content

Commit 21ae3e7

Browse files
yliu80wenlingz
authored andcommitted
DM: virtio-gpio: add print log
if the gpio debug is enabled, print gpio mapping information about virtual gpio and native gpio, also print virtio-gpio data, which shows the gpio operations flow. Tracked-On: #2512 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 6b0643b commit 21ae3e7

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

devicemodel/hw/pci/virtio/virtio_gpio.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ struct virtio_gpio {
196196
struct virtio_gpio_config config;
197197
};
198198

199+
static void print_gpio_info(struct virtio_gpio *gpio);
200+
static void print_virtio_gpio_info(struct virtio_gpio_request *req,
201+
struct virtio_gpio_response *rsp, bool in);
202+
199203
static void
200204
native_gpio_update_line_info(struct gpio_line *line)
201205
{
@@ -408,6 +412,7 @@ gpio_request_handler(struct virtio_gpio *gpio, struct virtio_gpio_request *req,
408412
return;
409413
}
410414

415+
print_virtio_gpio_info(req, rsp, true);
411416
switch (req->cmd) {
412417
case GPIO_REQ_SET_VALUE:
413418
rc = gpio_set_value(gpio, req->offset, req->data);
@@ -439,6 +444,7 @@ gpio_request_handler(struct virtio_gpio *gpio, struct virtio_gpio_request *req,
439444
}
440445

441446
rsp->err = rc < 0 ? -1 : 0;
447+
print_virtio_gpio_info(req, rsp, false);
442448
}
443449

444450
static void virtio_gpio_reset(void *vdev)
@@ -819,6 +825,9 @@ virtio_gpio_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
819825
virtio_set_io_bar(&gpio->base, 0);
820826

821827
virtio_gpio_is_active = true;
828+
829+
/* dump gpio information */
830+
print_gpio_info(gpio);
822831
return 0;
823832

824833
fail:
@@ -865,4 +874,70 @@ struct pci_vdev_ops pci_ops_virtio_gpio = {
865874
.vdev_barread = virtio_pci_read,
866875
};
867876

877+
static void
878+
print_gpio_info(struct virtio_gpio *gpio)
879+
{
880+
struct native_gpio_chip *chip;
881+
struct gpio_line *line;
882+
int i;
883+
884+
DPRINTF("=== virtual lines(%u) mapping ===\n", gpio->nvline);
885+
for (i = 0; i < gpio->nvline; i++) {
886+
line = gpio->vlines[i];
887+
DPRINTF("%d: (vname:%8s, name:%8s) <=> %s, gpio=%d\n",
888+
i,
889+
line->vname,
890+
line->name,
891+
line->chip->dev_name,
892+
line->offset);
893+
}
894+
895+
DPRINTF("=== native gpio chips(%u) info ===\n", gpio->nchip);
896+
for (i = 0; i < gpio->nchip; i++) {
897+
chip = &gpio->chips[i];
898+
DPRINTF("index:%d, name:%s, dev_name:%s, label:%s, ngpio:%u\n",
899+
i,
900+
chip->name,
901+
chip->dev_name,
902+
chip->label,
903+
chip->ngpio);
904+
}
905+
}
906+
907+
static void
908+
print_virtio_gpio_info(struct virtio_gpio_request *req,
909+
struct virtio_gpio_response *rsp, bool in)
910+
{
911+
const char *item;
912+
const char *const cmd_map[] = {
913+
"GPIO_REQ_SET_VALUE",
914+
"GPIO_REQ_GET_VALUE",
915+
"GPIO_REQ_INPUT_DIRECTION",
916+
"GPIO_REQ_OUTPUT_DIRECTION",
917+
"GPIO_REQ_GET_DIRECTION",
918+
"GPIO_REQ_SET_CONFIG",
919+
};
920+
921+
if (req->cmd == GPIO_REQ_SET_VALUE || req->cmd == GPIO_REQ_GET_VALUE)
922+
item = "value";
923+
else if (req->cmd == GPIO_REQ_SET_CONFIG)
924+
item = "config";
925+
else if (req->cmd == GPIO_REQ_GET_DIRECTION)
926+
item = "direction";
927+
else
928+
item = "data";
929+
if (in)
930+
DPRINTF("<<<< gpio=%u, %s, %s=%lu\n",
931+
req->offset,
932+
cmd_map[req->cmd],
933+
item,
934+
req->data);
935+
else
936+
DPRINTF(">>>> gpio=%u, err=%d, %s=%d\n",
937+
req->offset,
938+
rsp->err,
939+
item,
940+
rsp->data);
941+
}
942+
868943
DEFINE_PCI_DEVTYPE(pci_ops_virtio_gpio);

0 commit comments

Comments
 (0)