1c0907c9eSPaolo Bonzini /*
230dc600bSGonglei * QEMU Smram/pam logic implementation
3c0907c9eSPaolo Bonzini *
4c0907c9eSPaolo Bonzini * Copyright (c) 2006 Fabrice Bellard
5c0907c9eSPaolo Bonzini * Copyright (c) 2011 Isaku Yamahata <yamahata at valinux co jp>
6c0907c9eSPaolo Bonzini * VA Linux Systems Japan K.K.
7c0907c9eSPaolo Bonzini * Copyright (c) 2012 Jason Baron <jbaron@redhat.com>
8c0907c9eSPaolo Bonzini *
9ef9f7b58SGonglei * Split out from piix.c
10c0907c9eSPaolo Bonzini *
11c0907c9eSPaolo Bonzini * Permission is hereby granted, free of charge, to any person obtaining a copy
12c0907c9eSPaolo Bonzini * of this software and associated documentation files (the "Software"), to deal
13c0907c9eSPaolo Bonzini * in the Software without restriction, including without limitation the rights
14c0907c9eSPaolo Bonzini * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15c0907c9eSPaolo Bonzini * copies of the Software, and to permit persons to whom the Software is
16c0907c9eSPaolo Bonzini * furnished to do so, subject to the following conditions:
17c0907c9eSPaolo Bonzini *
18c0907c9eSPaolo Bonzini * The above copyright notice and this permission notice shall be included in
19c0907c9eSPaolo Bonzini * all copies or substantial portions of the Software.
20c0907c9eSPaolo Bonzini *
21c0907c9eSPaolo Bonzini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22c0907c9eSPaolo Bonzini * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23c0907c9eSPaolo Bonzini * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24c0907c9eSPaolo Bonzini * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25c0907c9eSPaolo Bonzini * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26c0907c9eSPaolo Bonzini * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27c0907c9eSPaolo Bonzini * THE SOFTWARE.
28c0907c9eSPaolo Bonzini */
293cd2cf43SPaolo Bonzini
30b6a0aa05SPeter Maydell #include "qemu/osdep.h"
31c0907c9eSPaolo Bonzini #include "hw/pci-host/pam.h"
32c0907c9eSPaolo Bonzini
init_pam(PAMMemoryRegion * mem,Object * owner,MemoryRegion * ram_memory,MemoryRegion * system_memory,MemoryRegion * pci_address_space,uint32_t start,uint32_t size)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)
36c0907c9eSPaolo Bonzini {
37c0907c9eSPaolo Bonzini int i;
38c0907c9eSPaolo Bonzini
39c0907c9eSPaolo Bonzini /* RAM */
40*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[3], owner, "pam-ram", ram_memory,
41c0907c9eSPaolo Bonzini start, size);
42c0907c9eSPaolo Bonzini /* ROM (XXX: not quite correct) */
43*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[1], owner, "pam-rom", ram_memory,
44c0907c9eSPaolo Bonzini start, size);
45c0907c9eSPaolo Bonzini memory_region_set_readonly(&mem->alias[1], true);
46c0907c9eSPaolo Bonzini
47c0907c9eSPaolo Bonzini /* XXX: should distinguish read/write cases */
48*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[0], owner, "pam-pci", pci_address_space,
49c0907c9eSPaolo Bonzini start, size);
50*9e57b818SBernhard Beschow memory_region_init_alias(&mem->alias[2], owner, "pam-pci", ram_memory,
51c0907c9eSPaolo Bonzini start, size);
52c0907c9eSPaolo Bonzini
534ec37f90SPaolo Bonzini memory_region_transaction_begin();
54c0907c9eSPaolo Bonzini for (i = 0; i < 4; ++i) {
55c0907c9eSPaolo Bonzini memory_region_set_enabled(&mem->alias[i], false);
56c0907c9eSPaolo Bonzini memory_region_add_subregion_overlap(system_memory, start,
57c0907c9eSPaolo Bonzini &mem->alias[i], 1);
58c0907c9eSPaolo Bonzini }
594ec37f90SPaolo Bonzini memory_region_transaction_commit();
60c0907c9eSPaolo Bonzini mem->current = 0;
61c0907c9eSPaolo Bonzini }
62c0907c9eSPaolo Bonzini
pam_update(PAMMemoryRegion * pam,int idx,uint8_t val)63c0907c9eSPaolo Bonzini void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val)
64c0907c9eSPaolo Bonzini {
65f6a3c86eSPhilippe Mathieu-Daudé assert(0 <= idx && idx < PAM_REGIONS_COUNT);
66c0907c9eSPaolo Bonzini
67c0907c9eSPaolo Bonzini memory_region_set_enabled(&pam->alias[pam->current], false);
68c0907c9eSPaolo Bonzini pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK;
69c0907c9eSPaolo Bonzini memory_region_set_enabled(&pam->alias[pam->current], true);
70c0907c9eSPaolo Bonzini }
71