rocker: add name field into WorldOps ale let world specify its name
[qemu/ar7.git] / hw / net / rocker / rocker_world.c
blob89777e9684c5e94904f2976efd354333bf032edc
1 /*
2 * QEMU rocker switch emulation - switch worlds
4 * Copyright (c) 2014 Scott Feldman <sfeldma@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include "qemu/osdep.h"
18 #include "qemu/iov.h"
20 #include "rocker.h"
21 #include "rocker_world.h"
23 struct world {
24 Rocker *r;
25 enum rocker_world_type type;
26 WorldOps *ops;
29 ssize_t world_ingress(World *world, uint32_t pport,
30 const struct iovec *iov, int iovcnt)
32 if (world->ops->ig) {
33 return world->ops->ig(world, pport, iov, iovcnt);
36 return -1;
39 int world_do_cmd(World *world, DescInfo *info,
40 char *buf, uint16_t cmd, RockerTlv *cmd_info_tlv)
42 if (world->ops->cmd) {
43 return world->ops->cmd(world, info, buf, cmd, cmd_info_tlv);
46 return -ROCKER_ENOTSUP;
49 World *world_alloc(Rocker *r, size_t sizeof_private,
50 enum rocker_world_type type, WorldOps *ops)
52 World *w = g_malloc0(sizeof(World) + sizeof_private);
54 if (w) {
55 w->r = r;
56 w->type = type;
57 w->ops = ops;
58 if (w->ops->init) {
59 w->ops->init(w);
63 return w;
66 void world_free(World *world)
68 if (world->ops->uninit) {
69 world->ops->uninit(world);
71 g_free(world);
74 void world_reset(World *world)
76 if (world->ops->uninit) {
77 world->ops->uninit(world);
79 if (world->ops->init) {
80 world->ops->init(world);
84 void *world_private(World *world)
86 return world + 1;
89 Rocker *world_rocker(World *world)
91 return world->r;
94 enum rocker_world_type world_type(World *world)
96 return world->type;
99 const char *world_name(World *world)
101 return world->ops->name;