Commit 5a053d1f2e75e6a87c483bb3ff5cc6cdf29e1569
1 parent
636aa70a
qdev: add 64 bit type
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Showing
2 changed files
with
62 additions
and
0 deletions
hw/qdev-properties.c
@@ -88,6 +88,59 @@ PropertyInfo qdev_prop_hex32 = { | @@ -88,6 +88,59 @@ PropertyInfo qdev_prop_hex32 = { | ||
88 | .print = print_hex32, | 88 | .print = print_hex32, |
89 | }; | 89 | }; |
90 | 90 | ||
91 | +/* --- 64bit integer --- */ | ||
92 | + | ||
93 | +static int parse_uint64(DeviceState *dev, Property *prop, const char *str) | ||
94 | +{ | ||
95 | + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); | ||
96 | + const char *fmt; | ||
97 | + | ||
98 | + /* accept both hex and decimal */ | ||
99 | + fmt = strncasecmp(str, "0x",2) == 0 ? "%" PRIx64 : "%" PRIu64; | ||
100 | + if (sscanf(str, fmt, ptr) != 1) | ||
101 | + return -1; | ||
102 | + return 0; | ||
103 | +} | ||
104 | + | ||
105 | +static int print_uint64(DeviceState *dev, Property *prop, char *dest, size_t len) | ||
106 | +{ | ||
107 | + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); | ||
108 | + return snprintf(dest, len, "%" PRIu64, *ptr); | ||
109 | +} | ||
110 | + | ||
111 | +PropertyInfo qdev_prop_uint64 = { | ||
112 | + .name = "uint64", | ||
113 | + .type = PROP_TYPE_UINT64, | ||
114 | + .size = sizeof(uint64_t), | ||
115 | + .parse = parse_uint64, | ||
116 | + .print = print_uint64, | ||
117 | +}; | ||
118 | + | ||
119 | +/* --- 64bit hex value --- */ | ||
120 | + | ||
121 | +static int parse_hex64(DeviceState *dev, Property *prop, const char *str) | ||
122 | +{ | ||
123 | + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); | ||
124 | + | ||
125 | + if (sscanf(str, "%" PRIx64, ptr) != 1) | ||
126 | + return -1; | ||
127 | + return 0; | ||
128 | +} | ||
129 | + | ||
130 | +static int print_hex64(DeviceState *dev, Property *prop, char *dest, size_t len) | ||
131 | +{ | ||
132 | + uint64_t *ptr = qdev_get_prop_ptr(dev, prop); | ||
133 | + return snprintf(dest, len, "0x%" PRIx64, *ptr); | ||
134 | +} | ||
135 | + | ||
136 | +PropertyInfo qdev_prop_hex64 = { | ||
137 | + .name = "hex64", | ||
138 | + .type = PROP_TYPE_UINT64, | ||
139 | + .size = sizeof(uint64_t), | ||
140 | + .parse = parse_hex64, | ||
141 | + .print = print_hex64, | ||
142 | +}; | ||
143 | + | ||
91 | /* --- pointer --- */ | 144 | /* --- pointer --- */ |
92 | 145 | ||
93 | static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len) | 146 | static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len) |
@@ -224,6 +277,11 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value) | @@ -224,6 +277,11 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value) | ||
224 | qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32); | 277 | qdev_prop_set(dev, name, &value, PROP_TYPE_UINT32); |
225 | } | 278 | } |
226 | 279 | ||
280 | +void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value) | ||
281 | +{ | ||
282 | + qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64); | ||
283 | +} | ||
284 | + | ||
227 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) | 285 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) |
228 | { | 286 | { |
229 | qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); | 287 | qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); |
hw/qdev.h
@@ -58,6 +58,7 @@ enum PropertyType { | @@ -58,6 +58,7 @@ enum PropertyType { | ||
58 | PROP_TYPE_UNSPEC = 0, | 58 | PROP_TYPE_UNSPEC = 0, |
59 | PROP_TYPE_UINT16, | 59 | PROP_TYPE_UINT16, |
60 | PROP_TYPE_UINT32, | 60 | PROP_TYPE_UINT32, |
61 | + PROP_TYPE_UINT64, | ||
61 | PROP_TYPE_TADDR, | 62 | PROP_TYPE_TADDR, |
62 | PROP_TYPE_MACADDR, | 63 | PROP_TYPE_MACADDR, |
63 | PROP_TYPE_PTR, | 64 | PROP_TYPE_PTR, |
@@ -145,7 +146,9 @@ void do_info_qtree(Monitor *mon); | @@ -145,7 +146,9 @@ void do_info_qtree(Monitor *mon); | ||
145 | 146 | ||
146 | extern PropertyInfo qdev_prop_uint16; | 147 | extern PropertyInfo qdev_prop_uint16; |
147 | extern PropertyInfo qdev_prop_uint32; | 148 | extern PropertyInfo qdev_prop_uint32; |
149 | +extern PropertyInfo qdev_prop_uint64; | ||
148 | extern PropertyInfo qdev_prop_hex32; | 150 | extern PropertyInfo qdev_prop_hex32; |
151 | +extern PropertyInfo qdev_prop_hex64; | ||
149 | extern PropertyInfo qdev_prop_ptr; | 152 | extern PropertyInfo qdev_prop_ptr; |
150 | extern PropertyInfo qdev_prop_macaddr; | 153 | extern PropertyInfo qdev_prop_macaddr; |
151 | 154 | ||
@@ -155,6 +158,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); | @@ -155,6 +158,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); | ||
155 | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); | 158 | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); |
156 | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); | 159 | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); |
157 | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); | 160 | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); |
161 | +void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); | ||
158 | /* FIXME: Remove opaque pointer properties. */ | 162 | /* FIXME: Remove opaque pointer properties. */ |
159 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); | 163 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); |
160 | void qdev_prop_set_defaults(DeviceState *dev, Property *props); | 164 | void qdev_prop_set_defaults(DeviceState *dev, Property *props); |