Commit 18be51872917e70e00cb21e018b6bff33162c4f7
1 parent
9656f324
Remove duplicate device index calculations.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4818 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
12 changed files
with
21 additions
and
44 deletions
hw/ads7846.c
... | ... | @@ -140,8 +140,6 @@ static int ads7846_load(QEMUFile *f, void *opaque, int version_id) |
140 | 140 | return 0; |
141 | 141 | } |
142 | 142 | |
143 | -static int ads7846_iid = 0; | |
144 | - | |
145 | 143 | struct ads7846_state_s *ads7846_init(qemu_irq penirq) |
146 | 144 | { |
147 | 145 | struct ads7846_state_s *s; |
... | ... | @@ -162,8 +160,7 @@ struct ads7846_state_s *ads7846_init(qemu_irq penirq) |
162 | 160 | |
163 | 161 | ads7846_int_update(s); |
164 | 162 | |
165 | - register_savevm("ads7846", ads7846_iid ++, 0, | |
166 | - ads7846_save, ads7846_load, s); | |
163 | + register_savevm("ads7846", -1, 0, ads7846_save, ads7846_load, s); | |
167 | 164 | |
168 | 165 | return s; |
169 | 166 | } | ... | ... |
hw/ide.c
... | ... | @@ -3596,8 +3596,6 @@ static int md_load(QEMUFile *f, void *opaque, int version_id) |
3596 | 3596 | return 0; |
3597 | 3597 | } |
3598 | 3598 | |
3599 | -static int md_iid = 0; | |
3600 | - | |
3601 | 3599 | static const uint8_t dscm1xxxx_cis[0x14a] = { |
3602 | 3600 | [0x000] = CISTPL_DEVICE, /* 5V Device Information */ |
3603 | 3601 | [0x002] = 0x03, /* Tuple length = 4 bytes */ |
... | ... | @@ -3824,7 +3822,7 @@ struct pcmcia_card_s *dscm1xxxx_init(BlockDriverState *bdrv) |
3824 | 3822 | md->ide->mdata_size = METADATA_SIZE; |
3825 | 3823 | md->ide->mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE); |
3826 | 3824 | |
3827 | - register_savevm("microdrive", md_iid ++, 0, md_save, md_load, md); | |
3825 | + register_savevm("microdrive", -1, 0, md_save, md_load, md); | |
3828 | 3826 | |
3829 | 3827 | return &md->card; |
3830 | 3828 | } | ... | ... |
hw/lm832x.c
... | ... | @@ -490,8 +490,6 @@ static int lm_kbd_load(QEMUFile *f, void *opaque, int version_id) |
490 | 490 | return 0; |
491 | 491 | } |
492 | 492 | |
493 | -static int lm_kbd_iid = 0; | |
494 | - | |
495 | 493 | struct i2c_slave *lm8323_init(i2c_bus *bus, qemu_irq nirq) |
496 | 494 | { |
497 | 495 | struct lm_kbd_s *s; |
... | ... | @@ -510,8 +508,7 @@ struct i2c_slave *lm8323_init(i2c_bus *bus, qemu_irq nirq) |
510 | 508 | lm_kbd_reset(s); |
511 | 509 | |
512 | 510 | qemu_register_reset((void *) lm_kbd_reset, s); |
513 | - register_savevm("LM8323", lm_kbd_iid ++, 0, | |
514 | - lm_kbd_save, lm_kbd_load, s); | |
511 | + register_savevm("LM8323", -1, 0, lm_kbd_save, lm_kbd_load, s); | |
515 | 512 | |
516 | 513 | return &s->i2c; |
517 | 514 | } | ... | ... |
hw/max111x.c
... | ... | @@ -121,8 +121,6 @@ static int max111x_load(QEMUFile *f, void *opaque, int version_id) |
121 | 121 | return 0; |
122 | 122 | } |
123 | 123 | |
124 | -static int max111x_iid = 0; | |
125 | - | |
126 | 124 | static struct max111x_s *max111x_init(qemu_irq cb) |
127 | 125 | { |
128 | 126 | struct max111x_s *s; |
... | ... | @@ -143,8 +141,7 @@ static struct max111x_s *max111x_init(qemu_irq cb) |
143 | 141 | s->input[7] = 0x80; |
144 | 142 | s->com = 0; |
145 | 143 | |
146 | - register_savevm("max111x", max111x_iid ++, 0, | |
147 | - max111x_save, max111x_load, s); | |
144 | + register_savevm("max111x", -1, 0, max111x_save, max111x_load, s); | |
148 | 145 | |
149 | 146 | return s; |
150 | 147 | } | ... | ... |
hw/max7310.c
... | ... | @@ -177,8 +177,6 @@ static int max7310_load(QEMUFile *f, void *opaque, int version_id) |
177 | 177 | return 0; |
178 | 178 | } |
179 | 179 | |
180 | -static int max7310_iid = 0; | |
181 | - | |
182 | 180 | static void max7310_gpio_set(void *opaque, int line, int level) |
183 | 181 | { |
184 | 182 | struct max7310_s *s = (struct max7310_s *) opaque; |
... | ... | @@ -205,8 +203,7 @@ struct i2c_slave *max7310_init(i2c_bus *bus) |
205 | 203 | |
206 | 204 | max7310_reset(&s->i2c); |
207 | 205 | |
208 | - register_savevm("max7310", max7310_iid ++, 0, | |
209 | - max7310_save, max7310_load, s); | |
206 | + register_savevm("max7310", -1, 0, max7310_save, max7310_load, s); | |
210 | 207 | |
211 | 208 | return &s->i2c; |
212 | 209 | } | ... | ... |
hw/nand.c
... | ... | @@ -319,8 +319,6 @@ static int nand_load(QEMUFile *f, void *opaque, int version_id) |
319 | 319 | return 0; |
320 | 320 | } |
321 | 321 | |
322 | -static int nand_iid = 0; | |
323 | - | |
324 | 322 | /* |
325 | 323 | * Chip inputs are CLE, ALE, CE, WP, GND and eight I/O pins. Chip |
326 | 324 | * outputs are R/B and eight I/O pins. |
... | ... | @@ -495,7 +493,7 @@ struct nand_flash_s *nand_init(int manf_id, int chip_id) |
495 | 493 | s->storage = (uint8_t *) memset(qemu_malloc(s->pages * pagesize), |
496 | 494 | 0xff, s->pages * pagesize); |
497 | 495 | |
498 | - register_savevm("nand", nand_iid ++, 0, nand_save, nand_load, s); | |
496 | + register_savevm("nand", -1, 0, nand_save, nand_load, s); | |
499 | 497 | |
500 | 498 | return s; |
501 | 499 | } | ... | ... |
hw/tmp105.c
... | ... | @@ -228,8 +228,6 @@ void tmp105_reset(i2c_slave *i2c) |
228 | 228 | tmp105_interrupt_update(s); |
229 | 229 | } |
230 | 230 | |
231 | -static int tmp105_iid = 0; | |
232 | - | |
233 | 231 | struct i2c_slave *tmp105_init(i2c_bus *bus, qemu_irq alarm) |
234 | 232 | { |
235 | 233 | struct tmp105_s *s = (struct tmp105_s *) |
... | ... | @@ -242,8 +240,7 @@ struct i2c_slave *tmp105_init(i2c_bus *bus, qemu_irq alarm) |
242 | 240 | |
243 | 241 | tmp105_reset(&s->i2c); |
244 | 242 | |
245 | - register_savevm("TMP105", tmp105_iid ++, 0, | |
246 | - tmp105_save, tmp105_load, s); | |
243 | + register_savevm("TMP105", -1, 0, tmp105_save, tmp105_load, s); | |
247 | 244 | |
248 | 245 | return &s->i2c; |
249 | 246 | } | ... | ... |
hw/tsc2005.c
... | ... | @@ -520,8 +520,6 @@ static int tsc2005_load(QEMUFile *f, void *opaque, int version_id) |
520 | 520 | return 0; |
521 | 521 | } |
522 | 522 | |
523 | -static int tsc2005_iid = 0; | |
524 | - | |
525 | 523 | void *tsc2005_init(qemu_irq pintdav) |
526 | 524 | { |
527 | 525 | struct tsc2005_state_s *s; |
... | ... | @@ -551,8 +549,7 @@ void *tsc2005_init(qemu_irq pintdav) |
551 | 549 | "QEMU TSC2005-driven Touchscreen"); |
552 | 550 | |
553 | 551 | qemu_register_reset((void *) tsc2005_reset, s); |
554 | - register_savevm("tsc2005", tsc2005_iid ++, 0, | |
555 | - tsc2005_save, tsc2005_load, s); | |
552 | + register_savevm("tsc2005", -1, 0, tsc2005_save, tsc2005_load, s); | |
556 | 553 | |
557 | 554 | return s; |
558 | 555 | } | ... | ... |
hw/tsc210x.c
... | ... | @@ -1107,8 +1107,6 @@ static int tsc210x_load(QEMUFile *f, void *opaque, int version_id) |
1107 | 1107 | return 0; |
1108 | 1108 | } |
1109 | 1109 | |
1110 | -static int tsc2102_iid = 0; | |
1111 | - | |
1112 | 1110 | struct uwire_slave_s *tsc2102_init(qemu_irq pint, AudioState *audio) |
1113 | 1111 | { |
1114 | 1112 | struct tsc210x_state_s *s; |
... | ... | @@ -1154,7 +1152,7 @@ struct uwire_slave_s *tsc2102_init(qemu_irq pint, AudioState *audio) |
1154 | 1152 | AUD_register_card(s->audio, s->name, &s->card); |
1155 | 1153 | |
1156 | 1154 | qemu_register_reset((void *) tsc210x_reset, s); |
1157 | - register_savevm(s->name, tsc2102_iid ++, 0, | |
1155 | + register_savevm(s->name, -1, 0, | |
1158 | 1156 | tsc210x_save, tsc210x_load, s); |
1159 | 1157 | |
1160 | 1158 | return &s->chip; |
... | ... | @@ -1208,8 +1206,7 @@ struct uwire_slave_s *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, |
1208 | 1206 | AUD_register_card(s->audio, s->name, &s->card); |
1209 | 1207 | |
1210 | 1208 | qemu_register_reset((void *) tsc210x_reset, s); |
1211 | - register_savevm(s->name, tsc2102_iid ++, 0, | |
1212 | - tsc210x_save, tsc210x_load, s); | |
1209 | + register_savevm(s->name, -1, 0, tsc210x_save, tsc210x_load, s); | |
1213 | 1210 | |
1214 | 1211 | return &s->chip; |
1215 | 1212 | } | ... | ... |
hw/twl92230.c
... | ... | @@ -876,8 +876,6 @@ static int menelaus_load(QEMUFile *f, void *opaque, int version_id) |
876 | 876 | return 0; |
877 | 877 | } |
878 | 878 | |
879 | -static int menelaus_iid = 0; | |
880 | - | |
881 | 879 | i2c_slave *twl92230_init(i2c_bus *bus, qemu_irq irq) |
882 | 880 | { |
883 | 881 | struct menelaus_s *s = (struct menelaus_s *) |
... | ... | @@ -894,8 +892,7 @@ i2c_slave *twl92230_init(i2c_bus *bus, qemu_irq irq) |
894 | 892 | |
895 | 893 | menelaus_reset(&s->i2c); |
896 | 894 | |
897 | - register_savevm("menelaus", menelaus_iid ++, | |
898 | - 0, menelaus_save, menelaus_load, s); | |
895 | + register_savevm("menelaus", -1, 0, menelaus_save, menelaus_load, s); | |
899 | 896 | |
900 | 897 | return &s->i2c; |
901 | 898 | } | ... | ... |
hw/wm8750.c
... | ... | @@ -646,8 +646,6 @@ static int wm8750_load(QEMUFile *f, void *opaque, int version_id) |
646 | 646 | return 0; |
647 | 647 | } |
648 | 648 | |
649 | -static int wm8750_iid = 0; | |
650 | - | |
651 | 649 | i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio) |
652 | 650 | { |
653 | 651 | struct wm8750_s *s = (struct wm8750_s *) |
... | ... | @@ -659,7 +657,7 @@ i2c_slave *wm8750_init(i2c_bus *bus, AudioState *audio) |
659 | 657 | AUD_register_card(audio, CODEC, &s->card); |
660 | 658 | wm8750_reset(&s->i2c); |
661 | 659 | |
662 | - register_savevm(CODEC, wm8750_iid ++, 0, wm8750_save, wm8750_load, s); | |
660 | + register_savevm(CODEC, -1, 0, wm8750_save, wm8750_load, s); | |
663 | 661 | |
664 | 662 | return &s->i2c; |
665 | 663 | } | ... | ... |
vl.c
... | ... | @@ -6060,6 +6060,8 @@ typedef struct SaveStateEntry { |
6060 | 6060 | |
6061 | 6061 | static SaveStateEntry *first_se; |
6062 | 6062 | |
6063 | +/* TODO: Individual devices generally have very little idea about the rest | |
6064 | + of the system, so instance_id should be removed/replaced. */ | |
6063 | 6065 | int register_savevm(const char *idstr, |
6064 | 6066 | int instance_id, |
6065 | 6067 | int version_id, |
... | ... | @@ -6073,7 +6075,7 @@ int register_savevm(const char *idstr, |
6073 | 6075 | if (!se) |
6074 | 6076 | return -1; |
6075 | 6077 | pstrcpy(se->idstr, sizeof(se->idstr), idstr); |
6076 | - se->instance_id = instance_id; | |
6078 | + se->instance_id = (instance_id == -1) ? 0 : instance_id; | |
6077 | 6079 | se->version_id = version_id; |
6078 | 6080 | se->save_state = save_state; |
6079 | 6081 | se->load_state = load_state; |
... | ... | @@ -6082,8 +6084,13 @@ int register_savevm(const char *idstr, |
6082 | 6084 | |
6083 | 6085 | /* add at the end of list */ |
6084 | 6086 | pse = &first_se; |
6085 | - while (*pse != NULL) | |
6087 | + while (*pse != NULL) { | |
6088 | + if (instance_id == -1 | |
6089 | + && strcmp(se->idstr, (*pse)->idstr) == 0 | |
6090 | + && se->instance_id <= (*pse)->instance_id) | |
6091 | + se->instance_id = (*pse)->instance_id + 1; | |
6086 | 6092 | pse = &(*pse)->next; |
6093 | + } | |
6087 | 6094 | *pse = se; |
6088 | 6095 | return 0; |
6089 | 6096 | } | ... | ... |