Revision 5a053d1f hw/qdev-properties.c
b/hw/qdev-properties.c | ||
---|---|---|
88 | 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 | 144 |
/* --- pointer --- */ |
92 | 145 |
|
93 | 146 |
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len) |
... | ... | |
224 | 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 | 285 |
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) |
228 | 286 |
{ |
229 | 287 |
qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); |
Also available in: Unified diff