qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/audio/intel-hda: Use memory region alias to reduce .rodata by 4.34MB

The intel-hda model uses an array of register indexed by the
register address. This array also contains a pair of aliased
registers at offset 0x2000. This creates a huge hole in the
array, which ends up eating 4.6MiB of .rodata (size reported
on x86_64 host, building with --extra-cflags=-Os).

By using a memory region alias, we reduce this array to 132kB.

Before:

(qemu) info mtree
00000000febd4000-00000000febd7fff (prio 1, i/o): intel-hda

After:

(qemu) info mtree
00000000febd4000-00000000febd7fff (prio 1, i/o): intel-hda
00000000febd4000-00000000febd7fff (prio 1, i/o): intel-hda-container
00000000febd4000-00000000febd5fff (prio 0, i/o): intel-hda
00000000febd6000-00000000febd7fff (prio 0, i/o): alias intel-hda-alias @intel-hda 0000000000000000-0000000000001fff

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Philippe Mathieu-Daudé and committed by
Paolo Bonzini
a9d8ba2b 2eea51bd

+10 -14
+10 -14
hw/audio/intel-hda.c
··· 181 181 IntelHDAStream st[8]; 182 182 183 183 /* state */ 184 + MemoryRegion container; 184 185 MemoryRegion mmio; 186 + MemoryRegion alias; 185 187 uint32_t rirb_count; 186 188 int64_t wall_base_ns; 187 189 ··· 670 672 .offset = offsetof(IntelHDAState, wall_clk), 671 673 .rhandler = intel_hda_get_wall_clk, 672 674 }, 673 - [ ICH6_REG_WALLCLK + 0x2000 ] = { 674 - .name = "WALLCLK(alias)", 675 - .size = 4, 676 - .offset = offsetof(IntelHDAState, wall_clk), 677 - .rhandler = intel_hda_get_wall_clk, 678 - }, 679 675 680 676 /* dma engine */ 681 677 [ ICH6_REG_CORBLBASE ] = { ··· 834 830 [ ST_REG(_i, ICH6_REG_SD_LPIB) ] = { \ 835 831 .stream = _i, \ 836 832 .name = _t stringify(_i) " LPIB", \ 837 - .size = 4, \ 838 - .offset = offsetof(IntelHDAState, st[_i].lpib), \ 839 - }, \ 840 - [ ST_REG(_i, ICH6_REG_SD_LPIB) + 0x2000 ] = { \ 841 - .stream = _i, \ 842 - .name = _t stringify(_i) " LPIB(alias)", \ 843 833 .size = 4, \ 844 834 .offset = offsetof(IntelHDAState, st[_i].lpib), \ 845 835 }, \ ··· 1125 1115 error_free(err); 1126 1116 } 1127 1117 1118 + memory_region_init(&d->container, OBJECT(d), 1119 + "intel-hda-container", 0x4000); 1128 1120 memory_region_init_io(&d->mmio, OBJECT(d), &intel_hda_mmio_ops, d, 1129 - "intel-hda", 0x4000); 1130 - pci_register_bar(&d->pci, 0, 0, &d->mmio); 1121 + "intel-hda", 0x2000); 1122 + memory_region_add_subregion(&d->container, 0x0000, &d->mmio); 1123 + memory_region_init_alias(&d->alias, OBJECT(d), "intel-hda-alias", 1124 + &d->mmio, 0, 0x2000); 1125 + memory_region_add_subregion(&d->container, 0x2000, &d->alias); 1126 + pci_register_bar(&d->pci, 0, 0, &d->container); 1131 1127 1132 1128 hda_codec_bus_init(DEVICE(pci), &d->codecs, sizeof(d->codecs), 1133 1129 intel_hda_response, intel_hda_xfer);