xref: /qemu/docs/devel/memory.rst (revision 8be545ba5a315a9aaf7307f143a4a7926a6e605c)
1859cdc01SPeter Maydell==============
29d3a4736SAvi KivityThe memory API
39d3a4736SAvi Kivity==============
49d3a4736SAvi Kivity
59d3a4736SAvi KivityThe memory API models the memory and I/O buses and controllers of a QEMU
69d3a4736SAvi Kivitymachine.  It attempts to allow modelling of:
79d3a4736SAvi Kivity
89d3a4736SAvi Kivity- ordinary RAM
99d3a4736SAvi Kivity- memory-mapped I/O (MMIO)
109d3a4736SAvi Kivity- memory controllers that can dynamically reroute physical memory regions
119d3a4736SAvi Kivity  to different destinations
129d3a4736SAvi Kivity
139d3a4736SAvi KivityThe memory model provides support for
149d3a4736SAvi Kivity
159d3a4736SAvi Kivity- tracking RAM changes by the guest
169d3a4736SAvi Kivity- setting up coalesced memory for kvm
179d3a4736SAvi Kivity- setting up ioeventfd regions for kvm
189d3a4736SAvi Kivity
192d40178aSPaolo BonziniMemory is modelled as an acyclic graph of MemoryRegion objects.  Sinks
202d40178aSPaolo Bonzini(leaves) are RAM and MMIO regions, while other nodes represent
212d40178aSPaolo Bonzinibuses, memory controllers, and memory regions that have been rerouted.
222d40178aSPaolo Bonzini
232d40178aSPaolo BonziniIn addition to MemoryRegion objects, the memory API provides AddressSpace
242d40178aSPaolo Bonziniobjects for every root and possibly for intermediate MemoryRegions too.
252d40178aSPaolo BonziniThese represent memory as seen from the CPU or a device's viewpoint.
269d3a4736SAvi Kivity
279d3a4736SAvi KivityTypes of regions
289d3a4736SAvi Kivity----------------
299d3a4736SAvi Kivity
305056c0c3SPeter MaydellThere are multiple types of memory regions (all represented by a single C type
319d3a4736SAvi KivityMemoryRegion):
329d3a4736SAvi Kivity
339d3a4736SAvi Kivity- RAM: a RAM region is simply a range of host memory that can be made available
349d3a4736SAvi Kivity  to the guest.
355056c0c3SPeter Maydell  You typically initialize these with memory_region_init_ram().  Some special
365056c0c3SPeter Maydell  purposes require the variants memory_region_init_resizeable_ram(),
375056c0c3SPeter Maydell  memory_region_init_ram_from_file(), or memory_region_init_ram_ptr().
389d3a4736SAvi Kivity
399d3a4736SAvi Kivity- MMIO: a range of guest memory that is implemented by host callbacks;
409d3a4736SAvi Kivity  each read or write causes a callback to be called on the host.
410c52a80eSCao jin  You initialize these with memory_region_init_io(), passing it a
420c52a80eSCao jin  MemoryRegionOps structure describing the callbacks.
435056c0c3SPeter Maydell
445056c0c3SPeter Maydell- ROM: a ROM memory region works like RAM for reads (directly accessing
45a1777f7fSPeter Maydell  a region of host memory), and forbids writes. You initialize these with
46a1777f7fSPeter Maydell  memory_region_init_rom().
47a1777f7fSPeter Maydell
48a1777f7fSPeter Maydell- ROM device: a ROM device memory region works like RAM for reads
49a1777f7fSPeter Maydell  (directly accessing a region of host memory), but like MMIO for
50a1777f7fSPeter Maydell  writes (invoking a callback).  You initialize these with
51a1777f7fSPeter Maydell  memory_region_init_rom_device().
525056c0c3SPeter Maydell
535056c0c3SPeter Maydell- IOMMU region: an IOMMU region translates addresses of accesses made to it
545056c0c3SPeter Maydell  and forwards them to some other target memory region.  As the name suggests,
555056c0c3SPeter Maydell  these are only needed for modelling an IOMMU, not for simple devices.
565056c0c3SPeter Maydell  You initialize these with memory_region_init_iommu().
579d3a4736SAvi Kivity
589d3a4736SAvi Kivity- container: a container simply includes other memory regions, each at
599d3a4736SAvi Kivity  a different offset.  Containers are useful for grouping several regions
609d3a4736SAvi Kivity  into one unit.  For example, a PCI BAR may be composed of a RAM region
619d3a4736SAvi Kivity  and an MMIO region.
629d3a4736SAvi Kivity
639d3a4736SAvi Kivity  A container's subregions are usually non-overlapping.  In some cases it is
649d3a4736SAvi Kivity  useful to have overlapping regions; for example a memory controller that
659d3a4736SAvi Kivity  can overlay a subregion of RAM with MMIO or ROM, or a PCI controller
669d3a4736SAvi Kivity  that does not prevent card from claiming overlapping BARs.
679d3a4736SAvi Kivity
685056c0c3SPeter Maydell  You initialize a pure container with memory_region_init().
695056c0c3SPeter Maydell
709d3a4736SAvi Kivity- alias: a subsection of another region. Aliases allow a region to be
719d696cd5SAlex Bennée  split apart into discontiguous regions. Examples of uses are memory
729d696cd5SAlex Bennée  banks used when the guest address space is smaller than the amount
739d696cd5SAlex Bennée  of RAM addressed, or a memory controller that splits main memory to
749d696cd5SAlex Bennée  expose a "PCI hole". You can also create aliases to avoid trying to
759d696cd5SAlex Bennée  add the original region to multiple parents via
769d696cd5SAlex Bennée  `memory_region_add_subregion`.
779d696cd5SAlex Bennée
789d696cd5SAlex Bennée  Aliases may point to any type of region, including other aliases,
799d3a4736SAvi Kivity  but an alias may not point back to itself, directly or indirectly.
805056c0c3SPeter Maydell  You initialize these with memory_region_init_alias().
815056c0c3SPeter Maydell
825056c0c3SPeter Maydell- reservation region: a reservation region is primarily for debugging.
835056c0c3SPeter Maydell  It claims I/O space that is not supposed to be handled by QEMU itself.
845056c0c3SPeter Maydell  The typical use is to track parts of the address space which will be
85257a7430SPaolo Bonzini  handled by the host kernel when KVM is enabled.  You initialize these
86257a7430SPaolo Bonzini  by passing a NULL callback parameter to memory_region_init_io().
879d3a4736SAvi Kivity
886f1ce94aSPeter MaydellIt is valid to add subregions to a region which is not a pure container
896f1ce94aSPeter Maydell(that is, to an MMIO, RAM or ROM region). This means that the region
906f1ce94aSPeter Maydellwill act like a container, except that any addresses within the container's
916f1ce94aSPeter Maydellregion which are not claimed by any subregion are handled by the
926f1ce94aSPeter Maydellcontainer itself (ie by its MMIO callbacks or RAM backing). However
936f1ce94aSPeter Maydellit is generally possible to achieve the same effect with a pure container
946f1ce94aSPeter Maydellone of whose subregions is a low priority "background" region covering
956f1ce94aSPeter Maydellthe whole address range; this is often clearer and is preferred.
966f1ce94aSPeter MaydellSubregions cannot be added to an alias region.
979d3a4736SAvi Kivity
982286468fSPeter MaydellMigration
992286468fSPeter Maydell---------
1002286468fSPeter Maydell
1012286468fSPeter MaydellWhere the memory region is backed by host memory (RAM, ROM and
1022286468fSPeter MaydellROM device memory region types), this host memory needs to be
1032286468fSPeter Maydellcopied to the destination on migration. These APIs which allocate
1042286468fSPeter Maydellthe host memory for you will also register the memory so it is
1052286468fSPeter Maydellmigrated:
106859cdc01SPeter Maydell
1072286468fSPeter Maydell- memory_region_init_ram()
1082286468fSPeter Maydell- memory_region_init_rom()
1092286468fSPeter Maydell- memory_region_init_rom_device()
1102286468fSPeter Maydell
1112286468fSPeter MaydellFor most devices and boards this is the correct thing. If you
1122286468fSPeter Maydellhave a special case where you need to manage the migration of
1132286468fSPeter Maydellthe backing memory yourself, you can call the functions:
114859cdc01SPeter Maydell
1152286468fSPeter Maydell- memory_region_init_ram_nomigrate()
1162286468fSPeter Maydell- memory_region_init_rom_nomigrate()
1172286468fSPeter Maydell- memory_region_init_rom_device_nomigrate()
118859cdc01SPeter Maydell
1192286468fSPeter Maydellwhich only initialize the MemoryRegion and leave handling
1202286468fSPeter Maydellmigration to the caller.
1212286468fSPeter Maydell
1222286468fSPeter MaydellThe functions:
123859cdc01SPeter Maydell
1242286468fSPeter Maydell- memory_region_init_resizeable_ram()
1252286468fSPeter Maydell- memory_region_init_ram_from_file()
1262286468fSPeter Maydell- memory_region_init_ram_from_fd()
1272286468fSPeter Maydell- memory_region_init_ram_ptr()
1282286468fSPeter Maydell- memory_region_init_ram_device_ptr()
129859cdc01SPeter Maydell
1302286468fSPeter Maydellare for special cases only, and so they do not automatically
1312286468fSPeter Maydellregister the backing memory for migration; the caller must
1322286468fSPeter Maydellmanage migration if necessary.
1332286468fSPeter Maydell
1349d3a4736SAvi KivityRegion names
1359d3a4736SAvi Kivity------------
1369d3a4736SAvi Kivity
1379d3a4736SAvi KivityRegions are assigned names by the constructor.  For most regions these are
1389d3a4736SAvi Kivityonly used for debugging purposes, but RAM regions also use the name to identify
1399d3a4736SAvi Kivitylive migration sections.  This means that RAM region names need to have ABI
1409d3a4736SAvi Kivitystability.
1419d3a4736SAvi Kivity
1429d3a4736SAvi KivityRegion lifecycle
1439d3a4736SAvi Kivity----------------
1449d3a4736SAvi Kivity
1458b5c2160SPaolo BonziniA region is created by one of the memory_region_init*() functions and
1468b5c2160SPaolo Bonziniattached to an object, which acts as its owner or parent.  QEMU ensures
1478b5c2160SPaolo Bonzinithat the owner object remains alive as long as the region is visible to
1488b5c2160SPaolo Bonzinithe guest, or as long as the region is in use by a virtual CPU or another
1498b5c2160SPaolo Bonzinidevice.  For example, the owner object will not die between an
1508b5c2160SPaolo Bonziniaddress_space_map operation and the corresponding address_space_unmap.
151d8d95814SPaolo Bonzini
1528b5c2160SPaolo BonziniAfter creation, a region can be added to an address space or a
1538b5c2160SPaolo Bonzinicontainer with memory_region_add_subregion(), and removed using
1548b5c2160SPaolo Bonzinimemory_region_del_subregion().
155d8d95814SPaolo Bonzini
1568b5c2160SPaolo BonziniVarious region attributes (read-only, dirty logging, coalesced mmio,
1578b5c2160SPaolo Bonziniioeventfd) can be changed during the region lifecycle.  They take effect
1588b5c2160SPaolo Bonzinias soon as the region is made visible.  This can be immediately, later,
1598b5c2160SPaolo Bonzinior never.
1608b5c2160SPaolo Bonzini
1618b5c2160SPaolo BonziniDestruction of a memory region happens automatically when the owner
1628b5c2160SPaolo Bonziniobject dies.
1638b5c2160SPaolo Bonzini
1648b5c2160SPaolo BonziniIf however the memory region is part of a dynamically allocated data
1658b5c2160SPaolo Bonzinistructure, you should call object_unparent() to destroy the memory region
1668b5c2160SPaolo Bonzinibefore the data structure is freed.  For an example see VFIOMSIXInfo
1678b5c2160SPaolo Bonziniand VFIOQuirk in hw/vfio/pci.c.
1688b5c2160SPaolo Bonzini
1698b5c2160SPaolo BonziniYou must not destroy a memory region as long as it may be in use by a
1708b5c2160SPaolo Bonzinidevice or CPU.  In order to do this, as a general rule do not create or
1718b5c2160SPaolo Bonzinidestroy memory regions dynamically during a device's lifetime, and only
1728b5c2160SPaolo Bonzinicall object_unparent() in the memory region owner's instance_finalize
1738b5c2160SPaolo Bonzinicallback.  The dynamically allocated data structure that contains the
1748b5c2160SPaolo Bonzinimemory region then should obviously be freed in the instance_finalize
1758b5c2160SPaolo Bonzinicallback as well.
1768b5c2160SPaolo Bonzini
1778b5c2160SPaolo BonziniIf you break this rule, the following situation can happen:
1788b5c2160SPaolo Bonzini
1798b5c2160SPaolo Bonzini- the memory region's owner had a reference taken via memory_region_ref
1808b5c2160SPaolo Bonzini  (for example by address_space_map)
1818b5c2160SPaolo Bonzini
1828b5c2160SPaolo Bonzini- the region is unparented, and has no owner anymore
1838b5c2160SPaolo Bonzini
1848b5c2160SPaolo Bonzini- when address_space_unmap is called, the reference to the memory region's
1858b5c2160SPaolo Bonzini  owner is leaked.
1868b5c2160SPaolo Bonzini
1878b5c2160SPaolo Bonzini
1888b5c2160SPaolo BonziniThere is an exception to the above rule: it is okay to call
1898b5c2160SPaolo Bonziniobject_unparent at any time for an alias or a container region.  It is
1908b5c2160SPaolo Bonzinitherefore also okay to create or destroy alias and container regions
1918b5c2160SPaolo Bonzinidynamically during a device's lifetime.
1928b5c2160SPaolo Bonzini
1938b5c2160SPaolo BonziniThis exceptional usage is valid because aliases and containers only help
1948b5c2160SPaolo BonziniQEMU building the guest's memory map; they are never accessed directly.
1958b5c2160SPaolo Bonzinimemory_region_ref and memory_region_unref are never called on aliases
1968b5c2160SPaolo Bonzinior containers, and the above situation then cannot happen.  Exploiting
1978b5c2160SPaolo Bonzinithis exception is rarely necessary, and therefore it is discouraged,
1988b5c2160SPaolo Bonzinibut nevertheless it is used in a few places.
1998b5c2160SPaolo Bonzini
2008b5c2160SPaolo BonziniFor regions that "have no owner" (NULL is passed at creation time), the
2018b5c2160SPaolo Bonzinimachine object is actually used as the owner.  Since instance_finalize is
2028b5c2160SPaolo Bonzininever called for the machine object, you must never call object_unparent
2038b5c2160SPaolo Bonzinion regions that have no owner, unless they are aliases or containers.
2048b5c2160SPaolo Bonzini
2059d3a4736SAvi Kivity
2069d3a4736SAvi KivityOverlapping regions and priority
2079d3a4736SAvi Kivity--------------------------------
2089d3a4736SAvi KivityUsually, regions may not overlap each other; a memory address decodes into
2099d3a4736SAvi Kivityexactly one target.  In some cases it is useful to allow regions to overlap,
2109d3a4736SAvi Kivityand sometimes to control which of an overlapping regions is visible to the
2119d3a4736SAvi Kivityguest.  This is done with memory_region_add_subregion_overlap(), which
2129d3a4736SAvi Kivityallows the region to overlap any other region in the same container, and
2139d3a4736SAvi Kivityspecifies a priority that allows the core to decide which of two regions at
2149d3a4736SAvi Kivitythe same address are visible (highest wins).
2158002ccd6SMarcel ApfelbaumPriority values are signed, and the default value is zero. This means that
2168002ccd6SMarcel Apfelbaumyou can use memory_region_add_subregion_overlap() both to specify a region
2178002ccd6SMarcel Apfelbaumthat must sit 'above' any others (with a positive priority) and also a
2188002ccd6SMarcel Apfelbaumbackground region that sits 'below' others (with a negative priority).
2199d3a4736SAvi Kivity
2206f1ce94aSPeter MaydellIf the higher priority region in an overlap is a container or alias, then
2216f1ce94aSPeter Maydellthe lower priority region will appear in any "holes" that the higher priority
2226f1ce94aSPeter Maydellregion has left by not mapping subregions to that area of its address range.
2236f1ce94aSPeter Maydell(This applies recursively -- if the subregions are themselves containers or
2246f1ce94aSPeter Maydellaliases that leave holes then the lower priority region will appear in these
2256f1ce94aSPeter Maydellholes too.)
2266f1ce94aSPeter Maydell
2276f1ce94aSPeter MaydellFor example, suppose we have a container A of size 0x8000 with two subregions
2288210f5f6Sxiaoqiang zhaoB and C. B is a container mapped at 0x2000, size 0x4000, priority 2; C is
2298210f5f6Sxiaoqiang zhaoan MMIO region mapped at 0x0, size 0x6000, priority 1. B currently has two
2306f1ce94aSPeter Maydellof its own subregions: D of size 0x1000 at offset 0 and E of size 0x1000 at
231859cdc01SPeter Maydelloffset 0x2000. As a diagram::
2326f1ce94aSPeter Maydell
2336f1ce94aSPeter Maydell        0      1000   2000   3000   4000   5000   6000   7000   8000
234b3f3fdebSWei Jiangang        |------|------|------|------|------|------|------|------|
2356f1ce94aSPeter Maydell  A:    [                                                      ]
2366f1ce94aSPeter Maydell  C:    [CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC]
2376f1ce94aSPeter Maydell  B:                  [                          ]
2386f1ce94aSPeter Maydell  D:                  [DDDDD]
2396f1ce94aSPeter Maydell  E:                                [EEEEE]
2406f1ce94aSPeter Maydell
241859cdc01SPeter MaydellThe regions that will be seen within this address range then are::
242859cdc01SPeter Maydell
2436f1ce94aSPeter Maydell  [CCCCCCCCCCCC][DDDDD][CCCCC][EEEEE][CCCCC]
2446f1ce94aSPeter Maydell
2456f1ce94aSPeter MaydellSince B has higher priority than C, its subregions appear in the flat map
2466f1ce94aSPeter Maydelleven where they overlap with C. In ranges where B has not mapped anything
2476f1ce94aSPeter MaydellC's region appears.
2486f1ce94aSPeter Maydell
2496f1ce94aSPeter MaydellIf B had provided its own MMIO operations (ie it was not a pure container)
2506f1ce94aSPeter Maydellthen these would be used for any addresses in its range not handled by
251859cdc01SPeter MaydellD or E, and the result would be::
252859cdc01SPeter Maydell
2536f1ce94aSPeter Maydell  [CCCCCCCCCCCC][DDDDD][BBBBB][EEEEE][BBBBB]
2546f1ce94aSPeter Maydell
2556f1ce94aSPeter MaydellPriority values are local to a container, because the priorities of two
2566f1ce94aSPeter Maydellregions are only compared when they are both children of the same container.
2576f1ce94aSPeter MaydellThis means that the device in charge of the container (typically modelling
2586f1ce94aSPeter Maydella bus or a memory controller) can use them to manage the interaction of
2596f1ce94aSPeter Maydellits child regions without any side effects on other parts of the system.
2606f1ce94aSPeter MaydellIn the example above, the priorities of D and E are unimportant because
2616f1ce94aSPeter Maydellthey do not overlap each other. It is the relative priority of B and C
2626f1ce94aSPeter Maydellthat causes D and E to appear on top of C: D and E's priorities are never
2636f1ce94aSPeter Maydellcompared against the priority of C.
2646f1ce94aSPeter Maydell
2659d3a4736SAvi KivityVisibility
2669d3a4736SAvi Kivity----------
2679d3a4736SAvi KivityThe memory core uses the following rules to select a memory region when the
2689d3a4736SAvi Kivityguest accesses an address:
2699d3a4736SAvi Kivity
2709d3a4736SAvi Kivity- all direct subregions of the root region are matched against the address, in
2719d3a4736SAvi Kivity  descending priority order
272859cdc01SPeter Maydell
2739d3a4736SAvi Kivity  - if the address lies outside the region offset/size, the subregion is
2749d3a4736SAvi Kivity    discarded
2756f1ce94aSPeter Maydell  - if the subregion is a leaf (RAM or MMIO), the search terminates, returning
2766f1ce94aSPeter Maydell    this leaf region
2779d3a4736SAvi Kivity  - if the subregion is a container, the same algorithm is used within the
2789d3a4736SAvi Kivity    subregion (after the address is adjusted by the subregion offset)
2796f1ce94aSPeter Maydell  - if the subregion is an alias, the search is continued at the alias target
2809d3a4736SAvi Kivity    (after the address is adjusted by the subregion offset and alias offset)
2816f1ce94aSPeter Maydell  - if a recursive search within a container or alias subregion does not
2826f1ce94aSPeter Maydell    find a match (because of a "hole" in the container's coverage of its
2836f1ce94aSPeter Maydell    address range), then if this is a container with its own MMIO or RAM
2846f1ce94aSPeter Maydell    backing the search terminates, returning the container itself. Otherwise
2856f1ce94aSPeter Maydell    we continue with the next subregion in priority order
286859cdc01SPeter Maydell
2876f1ce94aSPeter Maydell- if none of the subregions match the address then the search terminates
2886f1ce94aSPeter Maydell  with no match found
2899d3a4736SAvi Kivity
2909d3a4736SAvi KivityExample memory map
2919d3a4736SAvi Kivity------------------
2929d3a4736SAvi Kivity
293859cdc01SPeter Maydell::
294859cdc01SPeter Maydell
2959d3a4736SAvi Kivity  system_memory: container@0-2^48-1
2969d3a4736SAvi Kivity   |
2979d3a4736SAvi Kivity   +---- lomem: alias@0-0xdfffffff ---> #ram (0-0xdfffffff)
2989d3a4736SAvi Kivity   |
2999d3a4736SAvi Kivity   +---- himem: alias@0x100000000-0x11fffffff ---> #ram (0xe0000000-0xffffffff)
3009d3a4736SAvi Kivity   |
301b3f3fdebSWei Jiangang   +---- vga-window: alias@0xa0000-0xbffff ---> #pci (0xa0000-0xbffff)
3029d3a4736SAvi Kivity   |      (prio 1)
3039d3a4736SAvi Kivity   |
3049d3a4736SAvi Kivity   +---- pci-hole: alias@0xe0000000-0xffffffff ---> #pci (0xe0000000-0xffffffff)
3059d3a4736SAvi Kivity
3069d3a4736SAvi Kivity  pci (0-2^32-1)
3079d3a4736SAvi Kivity   |
3089d3a4736SAvi Kivity   +--- vga-area: container@0xa0000-0xbffff
3099d3a4736SAvi Kivity   |      |
3109d3a4736SAvi Kivity   |      +--- alias@0x00000-0x7fff  ---> #vram (0x010000-0x017fff)
3119d3a4736SAvi Kivity   |      |
3129d3a4736SAvi Kivity   |      +--- alias@0x08000-0xffff  ---> #vram (0x020000-0x027fff)
3139d3a4736SAvi Kivity   |
3149d3a4736SAvi Kivity   +---- vram: ram@0xe1000000-0xe1ffffff
3159d3a4736SAvi Kivity   |
3169d3a4736SAvi Kivity   +---- vga-mmio: mmio@0xe2000000-0xe200ffff
3179d3a4736SAvi Kivity
3189d3a4736SAvi Kivity  ram: ram@0x00000000-0xffffffff
3199d3a4736SAvi Kivity
32069ddaf66SAdemar de Souza Reis JrThis is a (simplified) PC memory map. The 4GB RAM block is mapped into the
3219d3a4736SAvi Kivitysystem address space via two aliases: "lomem" is a 1:1 mapping of the first
3229d3a4736SAvi Kivity3.5GB; "himem" maps the last 0.5GB at address 4GB.  This leaves 0.5GB for the
3239d3a4736SAvi Kivityso-called PCI hole, that allows a 32-bit PCI bus to exist in a system with
3249d3a4736SAvi Kivity4GB of memory.
3259d3a4736SAvi Kivity
3269d3a4736SAvi KivityThe memory controller diverts addresses in the range 640K-768K to the PCI
3277075ba30SAvi Kivityaddress space.  This is modelled using the "vga-window" alias, mapped at a
3289d3a4736SAvi Kivityhigher priority so it obscures the RAM at the same addresses.  The vga window
3299d3a4736SAvi Kivitycan be removed by programming the memory controller; this is modelled by
3309d3a4736SAvi Kivityremoving the alias and exposing the RAM underneath.
3319d3a4736SAvi Kivity
3329d3a4736SAvi KivityThe pci address space is not a direct child of the system address space, since
3339d3a4736SAvi Kivitywe only want parts of it to be visible (we accomplish this using aliases).
3349d3a4736SAvi KivityIt has two subregions: vga-area models the legacy vga window and is occupied
3359d3a4736SAvi Kivityby two 32K memory banks pointing at two sections of the framebuffer.
3369d3a4736SAvi KivityIn addition the vram is mapped as a BAR at address e1000000, and an additional
3379d3a4736SAvi KivityBAR containing MMIO registers is mapped after it.
3389d3a4736SAvi Kivity
3399d3a4736SAvi KivityNote that if the guest maps a BAR outside the PCI hole, it would not be
3409d3a4736SAvi Kivityvisible as the pci-hole alias clips it to a 0.5GB range.
3419d3a4736SAvi Kivity
3429d3a4736SAvi KivityMMIO Operations
3439d3a4736SAvi Kivity---------------
3449d3a4736SAvi Kivity
345687ac05dSPeter MaydellMMIO regions are provided with ->read() and ->write() callbacks,
346687ac05dSPeter Maydellwhich are sufficient for most devices. Some devices change behaviour
347687ac05dSPeter Maydellbased on the attributes used for the memory transaction, or need
348687ac05dSPeter Maydellto be able to respond that the access should provoke a bus error
349687ac05dSPeter Maydellrather than completing successfully; those devices can use the
350687ac05dSPeter Maydell->read_with_attrs() and ->write_with_attrs() callbacks instead.
351687ac05dSPeter Maydell
352687ac05dSPeter MaydellIn addition various constraints can be supplied to control how these
353687ac05dSPeter Maydellcallbacks are called:
3549d3a4736SAvi Kivity
3559d3a4736SAvi Kivity- .valid.min_access_size, .valid.max_access_size define the access sizes
3569d3a4736SAvi Kivity  (in bytes) which the device accepts; accesses outside this range will
3579d3a4736SAvi Kivity  have device and bus specific behaviour (ignored, or machine check)
358ef00bdafSPeter Maydell- .valid.unaligned specifies that the *device being modelled* supports
359ef00bdafSPeter Maydell  unaligned accesses; if false, unaligned accesses will invoke the
360ef00bdafSPeter Maydell  appropriate bus or CPU specific behaviour.
3619d3a4736SAvi Kivity- .impl.min_access_size, .impl.max_access_size define the access sizes
3629d3a4736SAvi Kivity  (in bytes) supported by the *implementation*; other access sizes will be
3639d3a4736SAvi Kivity  emulated using the ones available.  For example a 4-byte write will be
36469ddaf66SAdemar de Souza Reis Jr  emulated using four 1-byte writes, if .impl.max_access_size = 1.
365edc1ba7aSFam Zheng- .impl.unaligned specifies that the *implementation* supports unaligned
366edc1ba7aSFam Zheng  accesses; if false, unaligned accesses will be emulated by two aligned
367edc1ba7aSFam Zheng  accesses.
368f3224c52SPaolo Bonzini
369f3224c52SPaolo BonziniAPI Reference
370f3224c52SPaolo Bonzini-------------
371f3224c52SPaolo Bonzini
372*8be545baSRichard Henderson.. kernel-doc:: include/system/memory.h
373