1*859cdc01SPeter 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 719d3a4736SAvi Kivity split apart into discontiguous regions. Examples of uses are memory banks 729d3a4736SAvi Kivity used when the guest address space is smaller than the amount of RAM 739d3a4736SAvi Kivity addressed, or a memory controller that splits main memory to expose a "PCI 749d3a4736SAvi Kivity hole". Aliases may point to any type of region, including other aliases, 759d3a4736SAvi Kivity but an alias may not point back to itself, directly or indirectly. 765056c0c3SPeter Maydell You initialize these with memory_region_init_alias(). 775056c0c3SPeter Maydell 785056c0c3SPeter Maydell- reservation region: a reservation region is primarily for debugging. 795056c0c3SPeter Maydell It claims I/O space that is not supposed to be handled by QEMU itself. 805056c0c3SPeter Maydell The typical use is to track parts of the address space which will be 81257a7430SPaolo Bonzini handled by the host kernel when KVM is enabled. You initialize these 82257a7430SPaolo Bonzini by passing a NULL callback parameter to memory_region_init_io(). 839d3a4736SAvi Kivity 846f1ce94aSPeter MaydellIt is valid to add subregions to a region which is not a pure container 856f1ce94aSPeter Maydell(that is, to an MMIO, RAM or ROM region). This means that the region 866f1ce94aSPeter Maydellwill act like a container, except that any addresses within the container's 876f1ce94aSPeter Maydellregion which are not claimed by any subregion are handled by the 886f1ce94aSPeter Maydellcontainer itself (ie by its MMIO callbacks or RAM backing). However 896f1ce94aSPeter Maydellit is generally possible to achieve the same effect with a pure container 906f1ce94aSPeter Maydellone of whose subregions is a low priority "background" region covering 916f1ce94aSPeter Maydellthe whole address range; this is often clearer and is preferred. 926f1ce94aSPeter MaydellSubregions cannot be added to an alias region. 939d3a4736SAvi Kivity 942286468fSPeter MaydellMigration 952286468fSPeter Maydell--------- 962286468fSPeter Maydell 972286468fSPeter MaydellWhere the memory region is backed by host memory (RAM, ROM and 982286468fSPeter MaydellROM device memory region types), this host memory needs to be 992286468fSPeter Maydellcopied to the destination on migration. These APIs which allocate 1002286468fSPeter Maydellthe host memory for you will also register the memory so it is 1012286468fSPeter Maydellmigrated: 102*859cdc01SPeter Maydell 1032286468fSPeter Maydell- memory_region_init_ram() 1042286468fSPeter Maydell- memory_region_init_rom() 1052286468fSPeter Maydell- memory_region_init_rom_device() 1062286468fSPeter Maydell 1072286468fSPeter MaydellFor most devices and boards this is the correct thing. If you 1082286468fSPeter Maydellhave a special case where you need to manage the migration of 1092286468fSPeter Maydellthe backing memory yourself, you can call the functions: 110*859cdc01SPeter Maydell 1112286468fSPeter Maydell- memory_region_init_ram_nomigrate() 1122286468fSPeter Maydell- memory_region_init_rom_nomigrate() 1132286468fSPeter Maydell- memory_region_init_rom_device_nomigrate() 114*859cdc01SPeter Maydell 1152286468fSPeter Maydellwhich only initialize the MemoryRegion and leave handling 1162286468fSPeter Maydellmigration to the caller. 1172286468fSPeter Maydell 1182286468fSPeter MaydellThe functions: 119*859cdc01SPeter Maydell 1202286468fSPeter Maydell- memory_region_init_resizeable_ram() 1212286468fSPeter Maydell- memory_region_init_ram_from_file() 1222286468fSPeter Maydell- memory_region_init_ram_from_fd() 1232286468fSPeter Maydell- memory_region_init_ram_ptr() 1242286468fSPeter Maydell- memory_region_init_ram_device_ptr() 125*859cdc01SPeter Maydell 1262286468fSPeter Maydellare for special cases only, and so they do not automatically 1272286468fSPeter Maydellregister the backing memory for migration; the caller must 1282286468fSPeter Maydellmanage migration if necessary. 1292286468fSPeter Maydell 1309d3a4736SAvi KivityRegion names 1319d3a4736SAvi Kivity------------ 1329d3a4736SAvi Kivity 1339d3a4736SAvi KivityRegions are assigned names by the constructor. For most regions these are 1349d3a4736SAvi Kivityonly used for debugging purposes, but RAM regions also use the name to identify 1359d3a4736SAvi Kivitylive migration sections. This means that RAM region names need to have ABI 1369d3a4736SAvi Kivitystability. 1379d3a4736SAvi Kivity 1389d3a4736SAvi KivityRegion lifecycle 1399d3a4736SAvi Kivity---------------- 1409d3a4736SAvi Kivity 1418b5c2160SPaolo BonziniA region is created by one of the memory_region_init*() functions and 1428b5c2160SPaolo Bonziniattached to an object, which acts as its owner or parent. QEMU ensures 1438b5c2160SPaolo Bonzinithat the owner object remains alive as long as the region is visible to 1448b5c2160SPaolo Bonzinithe guest, or as long as the region is in use by a virtual CPU or another 1458b5c2160SPaolo Bonzinidevice. For example, the owner object will not die between an 1468b5c2160SPaolo Bonziniaddress_space_map operation and the corresponding address_space_unmap. 147d8d95814SPaolo Bonzini 1488b5c2160SPaolo BonziniAfter creation, a region can be added to an address space or a 1498b5c2160SPaolo Bonzinicontainer with memory_region_add_subregion(), and removed using 1508b5c2160SPaolo Bonzinimemory_region_del_subregion(). 151d8d95814SPaolo Bonzini 1528b5c2160SPaolo BonziniVarious region attributes (read-only, dirty logging, coalesced mmio, 1538b5c2160SPaolo Bonziniioeventfd) can be changed during the region lifecycle. They take effect 1548b5c2160SPaolo Bonzinias soon as the region is made visible. This can be immediately, later, 1558b5c2160SPaolo Bonzinior never. 1568b5c2160SPaolo Bonzini 1578b5c2160SPaolo BonziniDestruction of a memory region happens automatically when the owner 1588b5c2160SPaolo Bonziniobject dies. 1598b5c2160SPaolo Bonzini 1608b5c2160SPaolo BonziniIf however the memory region is part of a dynamically allocated data 1618b5c2160SPaolo Bonzinistructure, you should call object_unparent() to destroy the memory region 1628b5c2160SPaolo Bonzinibefore the data structure is freed. For an example see VFIOMSIXInfo 1638b5c2160SPaolo Bonziniand VFIOQuirk in hw/vfio/pci.c. 1648b5c2160SPaolo Bonzini 1658b5c2160SPaolo BonziniYou must not destroy a memory region as long as it may be in use by a 1668b5c2160SPaolo Bonzinidevice or CPU. In order to do this, as a general rule do not create or 1678b5c2160SPaolo Bonzinidestroy memory regions dynamically during a device's lifetime, and only 1688b5c2160SPaolo Bonzinicall object_unparent() in the memory region owner's instance_finalize 1698b5c2160SPaolo Bonzinicallback. The dynamically allocated data structure that contains the 1708b5c2160SPaolo Bonzinimemory region then should obviously be freed in the instance_finalize 1718b5c2160SPaolo Bonzinicallback as well. 1728b5c2160SPaolo Bonzini 1738b5c2160SPaolo BonziniIf you break this rule, the following situation can happen: 1748b5c2160SPaolo Bonzini 1758b5c2160SPaolo Bonzini- the memory region's owner had a reference taken via memory_region_ref 1768b5c2160SPaolo Bonzini (for example by address_space_map) 1778b5c2160SPaolo Bonzini 1788b5c2160SPaolo Bonzini- the region is unparented, and has no owner anymore 1798b5c2160SPaolo Bonzini 1808b5c2160SPaolo Bonzini- when address_space_unmap is called, the reference to the memory region's 1818b5c2160SPaolo Bonzini owner is leaked. 1828b5c2160SPaolo Bonzini 1838b5c2160SPaolo Bonzini 1848b5c2160SPaolo BonziniThere is an exception to the above rule: it is okay to call 1858b5c2160SPaolo Bonziniobject_unparent at any time for an alias or a container region. It is 1868b5c2160SPaolo Bonzinitherefore also okay to create or destroy alias and container regions 1878b5c2160SPaolo Bonzinidynamically during a device's lifetime. 1888b5c2160SPaolo Bonzini 1898b5c2160SPaolo BonziniThis exceptional usage is valid because aliases and containers only help 1908b5c2160SPaolo BonziniQEMU building the guest's memory map; they are never accessed directly. 1918b5c2160SPaolo Bonzinimemory_region_ref and memory_region_unref are never called on aliases 1928b5c2160SPaolo Bonzinior containers, and the above situation then cannot happen. Exploiting 1938b5c2160SPaolo Bonzinithis exception is rarely necessary, and therefore it is discouraged, 1948b5c2160SPaolo Bonzinibut nevertheless it is used in a few places. 1958b5c2160SPaolo Bonzini 1968b5c2160SPaolo BonziniFor regions that "have no owner" (NULL is passed at creation time), the 1978b5c2160SPaolo Bonzinimachine object is actually used as the owner. Since instance_finalize is 1988b5c2160SPaolo Bonzininever called for the machine object, you must never call object_unparent 1998b5c2160SPaolo Bonzinion regions that have no owner, unless they are aliases or containers. 2008b5c2160SPaolo Bonzini 2019d3a4736SAvi Kivity 2029d3a4736SAvi KivityOverlapping regions and priority 2039d3a4736SAvi Kivity-------------------------------- 2049d3a4736SAvi KivityUsually, regions may not overlap each other; a memory address decodes into 2059d3a4736SAvi Kivityexactly one target. In some cases it is useful to allow regions to overlap, 2069d3a4736SAvi Kivityand sometimes to control which of an overlapping regions is visible to the 2079d3a4736SAvi Kivityguest. This is done with memory_region_add_subregion_overlap(), which 2089d3a4736SAvi Kivityallows the region to overlap any other region in the same container, and 2099d3a4736SAvi Kivityspecifies a priority that allows the core to decide which of two regions at 2109d3a4736SAvi Kivitythe same address are visible (highest wins). 2118002ccd6SMarcel ApfelbaumPriority values are signed, and the default value is zero. This means that 2128002ccd6SMarcel Apfelbaumyou can use memory_region_add_subregion_overlap() both to specify a region 2138002ccd6SMarcel Apfelbaumthat must sit 'above' any others (with a positive priority) and also a 2148002ccd6SMarcel Apfelbaumbackground region that sits 'below' others (with a negative priority). 2159d3a4736SAvi Kivity 2166f1ce94aSPeter MaydellIf the higher priority region in an overlap is a container or alias, then 2176f1ce94aSPeter Maydellthe lower priority region will appear in any "holes" that the higher priority 2186f1ce94aSPeter Maydellregion has left by not mapping subregions to that area of its address range. 2196f1ce94aSPeter Maydell(This applies recursively -- if the subregions are themselves containers or 2206f1ce94aSPeter Maydellaliases that leave holes then the lower priority region will appear in these 2216f1ce94aSPeter Maydellholes too.) 2226f1ce94aSPeter Maydell 2236f1ce94aSPeter MaydellFor example, suppose we have a container A of size 0x8000 with two subregions 2248210f5f6Sxiaoqiang zhaoB and C. B is a container mapped at 0x2000, size 0x4000, priority 2; C is 2258210f5f6Sxiaoqiang zhaoan MMIO region mapped at 0x0, size 0x6000, priority 1. B currently has two 2266f1ce94aSPeter Maydellof its own subregions: D of size 0x1000 at offset 0 and E of size 0x1000 at 227*859cdc01SPeter Maydelloffset 0x2000. As a diagram:: 2286f1ce94aSPeter Maydell 2296f1ce94aSPeter Maydell 0 1000 2000 3000 4000 5000 6000 7000 8000 230b3f3fdebSWei Jiangang |------|------|------|------|------|------|------|------| 2316f1ce94aSPeter Maydell A: [ ] 2326f1ce94aSPeter Maydell C: [CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC] 2336f1ce94aSPeter Maydell B: [ ] 2346f1ce94aSPeter Maydell D: [DDDDD] 2356f1ce94aSPeter Maydell E: [EEEEE] 2366f1ce94aSPeter Maydell 237*859cdc01SPeter MaydellThe regions that will be seen within this address range then are:: 238*859cdc01SPeter Maydell 2396f1ce94aSPeter Maydell [CCCCCCCCCCCC][DDDDD][CCCCC][EEEEE][CCCCC] 2406f1ce94aSPeter Maydell 2416f1ce94aSPeter MaydellSince B has higher priority than C, its subregions appear in the flat map 2426f1ce94aSPeter Maydelleven where they overlap with C. In ranges where B has not mapped anything 2436f1ce94aSPeter MaydellC's region appears. 2446f1ce94aSPeter Maydell 2456f1ce94aSPeter MaydellIf B had provided its own MMIO operations (ie it was not a pure container) 2466f1ce94aSPeter Maydellthen these would be used for any addresses in its range not handled by 247*859cdc01SPeter MaydellD or E, and the result would be:: 248*859cdc01SPeter Maydell 2496f1ce94aSPeter Maydell [CCCCCCCCCCCC][DDDDD][BBBBB][EEEEE][BBBBB] 2506f1ce94aSPeter Maydell 2516f1ce94aSPeter MaydellPriority values are local to a container, because the priorities of two 2526f1ce94aSPeter Maydellregions are only compared when they are both children of the same container. 2536f1ce94aSPeter MaydellThis means that the device in charge of the container (typically modelling 2546f1ce94aSPeter Maydella bus or a memory controller) can use them to manage the interaction of 2556f1ce94aSPeter Maydellits child regions without any side effects on other parts of the system. 2566f1ce94aSPeter MaydellIn the example above, the priorities of D and E are unimportant because 2576f1ce94aSPeter Maydellthey do not overlap each other. It is the relative priority of B and C 2586f1ce94aSPeter Maydellthat causes D and E to appear on top of C: D and E's priorities are never 2596f1ce94aSPeter Maydellcompared against the priority of C. 2606f1ce94aSPeter Maydell 2619d3a4736SAvi KivityVisibility 2629d3a4736SAvi Kivity---------- 2639d3a4736SAvi KivityThe memory core uses the following rules to select a memory region when the 2649d3a4736SAvi Kivityguest accesses an address: 2659d3a4736SAvi Kivity 2669d3a4736SAvi Kivity- all direct subregions of the root region are matched against the address, in 2679d3a4736SAvi Kivity descending priority order 268*859cdc01SPeter Maydell 2699d3a4736SAvi Kivity - if the address lies outside the region offset/size, the subregion is 2709d3a4736SAvi Kivity discarded 2716f1ce94aSPeter Maydell - if the subregion is a leaf (RAM or MMIO), the search terminates, returning 2726f1ce94aSPeter Maydell this leaf region 2739d3a4736SAvi Kivity - if the subregion is a container, the same algorithm is used within the 2749d3a4736SAvi Kivity subregion (after the address is adjusted by the subregion offset) 2756f1ce94aSPeter Maydell - if the subregion is an alias, the search is continued at the alias target 2769d3a4736SAvi Kivity (after the address is adjusted by the subregion offset and alias offset) 2776f1ce94aSPeter Maydell - if a recursive search within a container or alias subregion does not 2786f1ce94aSPeter Maydell find a match (because of a "hole" in the container's coverage of its 2796f1ce94aSPeter Maydell address range), then if this is a container with its own MMIO or RAM 2806f1ce94aSPeter Maydell backing the search terminates, returning the container itself. Otherwise 2816f1ce94aSPeter Maydell we continue with the next subregion in priority order 282*859cdc01SPeter Maydell 2836f1ce94aSPeter Maydell- if none of the subregions match the address then the search terminates 2846f1ce94aSPeter Maydell with no match found 2859d3a4736SAvi Kivity 2869d3a4736SAvi KivityExample memory map 2879d3a4736SAvi Kivity------------------ 2889d3a4736SAvi Kivity 289*859cdc01SPeter Maydell:: 290*859cdc01SPeter Maydell 2919d3a4736SAvi Kivity system_memory: container@0-2^48-1 2929d3a4736SAvi Kivity | 2939d3a4736SAvi Kivity +---- lomem: alias@0-0xdfffffff ---> #ram (0-0xdfffffff) 2949d3a4736SAvi Kivity | 2959d3a4736SAvi Kivity +---- himem: alias@0x100000000-0x11fffffff ---> #ram (0xe0000000-0xffffffff) 2969d3a4736SAvi Kivity | 297b3f3fdebSWei Jiangang +---- vga-window: alias@0xa0000-0xbffff ---> #pci (0xa0000-0xbffff) 2989d3a4736SAvi Kivity | (prio 1) 2999d3a4736SAvi Kivity | 3009d3a4736SAvi Kivity +---- pci-hole: alias@0xe0000000-0xffffffff ---> #pci (0xe0000000-0xffffffff) 3019d3a4736SAvi Kivity 3029d3a4736SAvi Kivity pci (0-2^32-1) 3039d3a4736SAvi Kivity | 3049d3a4736SAvi Kivity +--- vga-area: container@0xa0000-0xbffff 3059d3a4736SAvi Kivity | | 3069d3a4736SAvi Kivity | +--- alias@0x00000-0x7fff ---> #vram (0x010000-0x017fff) 3079d3a4736SAvi Kivity | | 3089d3a4736SAvi Kivity | +--- alias@0x08000-0xffff ---> #vram (0x020000-0x027fff) 3099d3a4736SAvi Kivity | 3109d3a4736SAvi Kivity +---- vram: ram@0xe1000000-0xe1ffffff 3119d3a4736SAvi Kivity | 3129d3a4736SAvi Kivity +---- vga-mmio: mmio@0xe2000000-0xe200ffff 3139d3a4736SAvi Kivity 3149d3a4736SAvi Kivity ram: ram@0x00000000-0xffffffff 3159d3a4736SAvi Kivity 31669ddaf66SAdemar de Souza Reis JrThis is a (simplified) PC memory map. The 4GB RAM block is mapped into the 3179d3a4736SAvi Kivitysystem address space via two aliases: "lomem" is a 1:1 mapping of the first 3189d3a4736SAvi Kivity3.5GB; "himem" maps the last 0.5GB at address 4GB. This leaves 0.5GB for the 3199d3a4736SAvi Kivityso-called PCI hole, that allows a 32-bit PCI bus to exist in a system with 3209d3a4736SAvi Kivity4GB of memory. 3219d3a4736SAvi Kivity 3229d3a4736SAvi KivityThe memory controller diverts addresses in the range 640K-768K to the PCI 3237075ba30SAvi Kivityaddress space. This is modelled using the "vga-window" alias, mapped at a 3249d3a4736SAvi Kivityhigher priority so it obscures the RAM at the same addresses. The vga window 3259d3a4736SAvi Kivitycan be removed by programming the memory controller; this is modelled by 3269d3a4736SAvi Kivityremoving the alias and exposing the RAM underneath. 3279d3a4736SAvi Kivity 3289d3a4736SAvi KivityThe pci address space is not a direct child of the system address space, since 3299d3a4736SAvi Kivitywe only want parts of it to be visible (we accomplish this using aliases). 3309d3a4736SAvi KivityIt has two subregions: vga-area models the legacy vga window and is occupied 3319d3a4736SAvi Kivityby two 32K memory banks pointing at two sections of the framebuffer. 3329d3a4736SAvi KivityIn addition the vram is mapped as a BAR at address e1000000, and an additional 3339d3a4736SAvi KivityBAR containing MMIO registers is mapped after it. 3349d3a4736SAvi Kivity 3359d3a4736SAvi KivityNote that if the guest maps a BAR outside the PCI hole, it would not be 3369d3a4736SAvi Kivityvisible as the pci-hole alias clips it to a 0.5GB range. 3379d3a4736SAvi Kivity 3389d3a4736SAvi KivityMMIO Operations 3399d3a4736SAvi Kivity--------------- 3409d3a4736SAvi Kivity 341687ac05dSPeter MaydellMMIO regions are provided with ->read() and ->write() callbacks, 342687ac05dSPeter Maydellwhich are sufficient for most devices. Some devices change behaviour 343687ac05dSPeter Maydellbased on the attributes used for the memory transaction, or need 344687ac05dSPeter Maydellto be able to respond that the access should provoke a bus error 345687ac05dSPeter Maydellrather than completing successfully; those devices can use the 346687ac05dSPeter Maydell->read_with_attrs() and ->write_with_attrs() callbacks instead. 347687ac05dSPeter Maydell 348687ac05dSPeter MaydellIn addition various constraints can be supplied to control how these 349687ac05dSPeter Maydellcallbacks are called: 3509d3a4736SAvi Kivity 3519d3a4736SAvi Kivity- .valid.min_access_size, .valid.max_access_size define the access sizes 3529d3a4736SAvi Kivity (in bytes) which the device accepts; accesses outside this range will 3539d3a4736SAvi Kivity have device and bus specific behaviour (ignored, or machine check) 354ef00bdafSPeter Maydell- .valid.unaligned specifies that the *device being modelled* supports 355ef00bdafSPeter Maydell unaligned accesses; if false, unaligned accesses will invoke the 356ef00bdafSPeter Maydell appropriate bus or CPU specific behaviour. 3579d3a4736SAvi Kivity- .impl.min_access_size, .impl.max_access_size define the access sizes 3589d3a4736SAvi Kivity (in bytes) supported by the *implementation*; other access sizes will be 3599d3a4736SAvi Kivity emulated using the ones available. For example a 4-byte write will be 36069ddaf66SAdemar de Souza Reis Jr emulated using four 1-byte writes, if .impl.max_access_size = 1. 361edc1ba7aSFam Zheng- .impl.unaligned specifies that the *implementation* supports unaligned 362edc1ba7aSFam Zheng accesses; if false, unaligned accesses will be emulated by two aligned 363edc1ba7aSFam Zheng accesses. 364