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" 313cd2cf43SPaolo Bonzini #include "qom/object.h" 329c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 330d09e41aSPaolo Bonzini #include "hw/pci-host/pam.h" 34410edd92SIsaku Yamahata 353cd2cf43SPaolo Bonzini void init_pam(DeviceState *dev, MemoryRegion *ram_memory, 363cd2cf43SPaolo Bonzini MemoryRegion *system_memory, MemoryRegion *pci_address_space, 373cd2cf43SPaolo Bonzini PAMMemoryRegion *mem, uint32_t start, uint32_t size) 38410edd92SIsaku Yamahata { 39410edd92SIsaku Yamahata int i; 40410edd92SIsaku Yamahata 41410edd92SIsaku Yamahata /* RAM */ 423cd2cf43SPaolo Bonzini memory_region_init_alias(&mem->alias[3], OBJECT(dev), "pam-ram", ram_memory, 43410edd92SIsaku Yamahata start, size); 44410edd92SIsaku Yamahata /* ROM (XXX: not quite correct) */ 453cd2cf43SPaolo Bonzini memory_region_init_alias(&mem->alias[1], OBJECT(dev), "pam-rom", ram_memory, 46410edd92SIsaku Yamahata start, size); 47410edd92SIsaku Yamahata memory_region_set_readonly(&mem->alias[1], true); 48410edd92SIsaku Yamahata 49410edd92SIsaku Yamahata /* XXX: should distinguish read/write cases */ 503cd2cf43SPaolo Bonzini memory_region_init_alias(&mem->alias[0], OBJECT(dev), "pam-pci", pci_address_space, 51410edd92SIsaku Yamahata start, size); 52175f099bSHervé Poussineau memory_region_init_alias(&mem->alias[2], OBJECT(dev), "pam-pci", ram_memory, 53410edd92SIsaku Yamahata start, size); 54410edd92SIsaku Yamahata 55*4ec37f90SPaolo Bonzini memory_region_transaction_begin(); 56410edd92SIsaku Yamahata for (i = 0; i < 4; ++i) { 57410edd92SIsaku Yamahata memory_region_set_enabled(&mem->alias[i], false); 58410edd92SIsaku Yamahata memory_region_add_subregion_overlap(system_memory, start, 59410edd92SIsaku Yamahata &mem->alias[i], 1); 60410edd92SIsaku Yamahata } 61*4ec37f90SPaolo Bonzini memory_region_transaction_commit(); 62410edd92SIsaku Yamahata mem->current = 0; 63410edd92SIsaku Yamahata } 64410edd92SIsaku Yamahata 65410edd92SIsaku Yamahata void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val) 66410edd92SIsaku Yamahata { 67410edd92SIsaku Yamahata assert(0 <= idx && idx <= 12); 68410edd92SIsaku Yamahata 69410edd92SIsaku Yamahata memory_region_set_enabled(&pam->alias[pam->current], false); 70410edd92SIsaku Yamahata pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK; 71410edd92SIsaku Yamahata memory_region_set_enabled(&pam->alias[pam->current], true); 72410edd92SIsaku Yamahata } 73