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