1410edd92SIsaku Yamahata /* 230dc600bSGonglei * QEMU Smram/pam logic implementation 3410edd92SIsaku Yamahata * 4410edd92SIsaku Yamahata * Copyright (c) 2006 Fabrice Bellard 5410edd92SIsaku Yamahata * Copyright (c) 2011 Isaku Yamahata <yamahata at valinux co jp> 6410edd92SIsaku Yamahata * VA Linux Systems Japan K.K. 7410edd92SIsaku Yamahata * Copyright (c) 2012 Jason Baron <jbaron@redhat.com> 8410edd92SIsaku Yamahata * 9ef9f7b58SGonglei * Split out from piix.c 10410edd92SIsaku Yamahata * 11410edd92SIsaku Yamahata * Permission is hereby granted, free of charge, to any person obtaining a copy 12410edd92SIsaku Yamahata * of this software and associated documentation files (the "Software"), to deal 13410edd92SIsaku Yamahata * in the Software without restriction, including without limitation the rights 14410edd92SIsaku Yamahata * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15410edd92SIsaku Yamahata * copies of the Software, and to permit persons to whom the Software is 16410edd92SIsaku Yamahata * furnished to do so, subject to the following conditions: 17410edd92SIsaku Yamahata * 18410edd92SIsaku Yamahata * The above copyright notice and this permission notice shall be included in 19410edd92SIsaku Yamahata * all copies or substantial portions of the Software. 20410edd92SIsaku Yamahata * 21410edd92SIsaku Yamahata * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22410edd92SIsaku Yamahata * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23410edd92SIsaku Yamahata * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24410edd92SIsaku Yamahata * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25410edd92SIsaku Yamahata * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26410edd92SIsaku Yamahata * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27410edd92SIsaku Yamahata * THE SOFTWARE. 28410edd92SIsaku Yamahata */ 293cd2cf43SPaolo Bonzini 30b6a0aa05SPeter Maydell #include "qemu/osdep.h" 310d09e41aSPaolo Bonzini #include "hw/pci-host/pam.h" 32410edd92SIsaku Yamahata 33*9e57b818SBernhard Beschow void init_pam(PAMMemoryRegion *mem, Object *owner, MemoryRegion *ram_memory, 343cd2cf43SPaolo Bonzini MemoryRegion *system_memory, MemoryRegion *pci_address_space, 35*9e57b818SBernhard Beschow uint32_t start, uint32_t size) 36410edd92SIsaku Yamahata { 37410edd92SIsaku Yamahata int i; 38410edd92SIsaku Yamahata 39410edd92SIsaku Yamahata /* RAM */ 40*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[3], owner, "pam-ram", ram_memory, 41410edd92SIsaku Yamahata start, size); 42410edd92SIsaku Yamahata /* ROM (XXX: not quite correct) */ 43*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[1], owner, "pam-rom", ram_memory, 44410edd92SIsaku Yamahata start, size); 45410edd92SIsaku Yamahata memory_region_set_readonly(&mem->alias[1], true); 46410edd92SIsaku Yamahata 47410edd92SIsaku Yamahata /* XXX: should distinguish read/write cases */ 48*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[0], owner, "pam-pci", pci_address_space, 49410edd92SIsaku Yamahata start, size); 50*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[2], owner, "pam-pci", ram_memory, 51410edd92SIsaku Yamahata start, size); 52410edd92SIsaku Yamahata 534ec37f90SPaolo Bonzini memory_region_transaction_begin(); 54410edd92SIsaku Yamahata for (i = 0; i < 4; ++i) { 55410edd92SIsaku Yamahata memory_region_set_enabled(&mem->alias[i], false); 56410edd92SIsaku Yamahata memory_region_add_subregion_overlap(system_memory, start, 57410edd92SIsaku Yamahata &mem->alias[i], 1); 58410edd92SIsaku Yamahata } 594ec37f90SPaolo Bonzini memory_region_transaction_commit(); 60410edd92SIsaku Yamahata mem->current = 0; 61410edd92SIsaku Yamahata } 62410edd92SIsaku Yamahata 63410edd92SIsaku Yamahata void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val) 64410edd92SIsaku Yamahata { 65f6a3c86eSPhilippe Mathieu-Daudé assert(0 <= idx && idx < PAM_REGIONS_COUNT); 66410edd92SIsaku Yamahata 67410edd92SIsaku Yamahata memory_region_set_enabled(&pam->alias[pam->current], false); 68410edd92SIsaku Yamahata pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK; 69410edd92SIsaku Yamahata memory_region_set_enabled(&pam->alias[pam->current], true); 70410edd92SIsaku Yamahata } 71