2012-11-15 00:54:02 +04:00
|
|
|
/*
|
2014-08-11 12:10:26 +04:00
|
|
|
* QEMU Smram/pam logic implementation
|
2012-11-15 00:54:02 +04:00
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
|
|
|
* Copyright (c) 2011 Isaku Yamahata <yamahata at valinux co jp>
|
|
|
|
* VA Linux Systems Japan K.K.
|
|
|
|
* Copyright (c) 2012 Jason Baron <jbaron@redhat.com>
|
|
|
|
*
|
2014-08-11 12:10:25 +04:00
|
|
|
* Split out from piix.c
|
2012-11-15 00:54:02 +04:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2013-06-25 14:33:01 +04:00
|
|
|
|
2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/pci-host/pam.h"
|
2012-11-15 00:54:02 +04:00
|
|
|
|
2013-06-25 14:33:01 +04:00
|
|
|
void init_pam(DeviceState *dev, MemoryRegion *ram_memory,
|
|
|
|
MemoryRegion *system_memory, MemoryRegion *pci_address_space,
|
|
|
|
PAMMemoryRegion *mem, uint32_t start, uint32_t size)
|
2012-11-15 00:54:02 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* RAM */
|
2013-06-25 14:33:01 +04:00
|
|
|
memory_region_init_alias(&mem->alias[3], OBJECT(dev), "pam-ram", ram_memory,
|
2012-11-15 00:54:02 +04:00
|
|
|
start, size);
|
|
|
|
/* ROM (XXX: not quite correct) */
|
2013-06-25 14:33:01 +04:00
|
|
|
memory_region_init_alias(&mem->alias[1], OBJECT(dev), "pam-rom", ram_memory,
|
2012-11-15 00:54:02 +04:00
|
|
|
start, size);
|
|
|
|
memory_region_set_readonly(&mem->alias[1], true);
|
|
|
|
|
|
|
|
/* XXX: should distinguish read/write cases */
|
2013-06-25 14:33:01 +04:00
|
|
|
memory_region_init_alias(&mem->alias[0], OBJECT(dev), "pam-pci", pci_address_space,
|
2012-11-15 00:54:02 +04:00
|
|
|
start, size);
|
2014-02-12 02:46:02 +04:00
|
|
|
memory_region_init_alias(&mem->alias[2], OBJECT(dev), "pam-pci", ram_memory,
|
2012-11-15 00:54:02 +04:00
|
|
|
start, size);
|
|
|
|
|
2018-11-28 19:22:25 +03:00
|
|
|
memory_region_transaction_begin();
|
2012-11-15 00:54:02 +04:00
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
memory_region_set_enabled(&mem->alias[i], false);
|
|
|
|
memory_region_add_subregion_overlap(system_memory, start,
|
|
|
|
&mem->alias[i], 1);
|
|
|
|
}
|
2018-11-28 19:22:25 +03:00
|
|
|
memory_region_transaction_commit();
|
2012-11-15 00:54:02 +04:00
|
|
|
mem->current = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val)
|
|
|
|
{
|
|
|
|
assert(0 <= idx && idx <= 12);
|
|
|
|
|
|
|
|
memory_region_set_enabled(&pam->alias[pam->current], false);
|
|
|
|
pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK;
|
|
|
|
memory_region_set_enabled(&pam->alias[pam->current], true);
|
|
|
|
}
|