From: Paolo Bonzini <pbonzini@redhat.com>
To: Jason Baron <jbaron@redhat.com>
Cc: aliguori@us.ibm.com, juzhang@redhat.com, mst@redhat.com,
jan.kiszka@siemens.com, qemu-devel@nongnu.org, agraf@suse.de,
blauwirbel@gmail.com, yamahata@valinux.co.jp,
alex.williamson@redhat.com, kevin@koconnor.net, avi@redhat.com,
mkletzan@redhat.com, lcapitulino@redhat.com, afaerber@suse.de,
armbru@redhat.com, kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 07/21] pc/piix_pci: factor out smram/pam logic
Date: Tue, 09 Oct 2012 09:47:23 +0200 [thread overview]
Message-ID: <5073D68B.7090407@redhat.com> (raw)
In-Reply-To: <2aa6c059709c97da6c7e436bb2e304064a06112c.1349749915.git.jbaron@redhat.com>
Il 09/10/2012 05:30, Jason Baron ha scritto:
> From: Isaku Yamahata <yamahata@valinux.co.jp>
>
> Factor out smram/pam logic for later use.
> Which will be used by q35 too.
>
> [jbaron@redhat.com: changes for updated memory API]
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> Signed-off-by: Jason Baron <jbaron@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> hw/i386/Makefile.objs | 1 +
> hw/pam.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++
> hw/pam.h | 98 ++++++++++++++++++++++++++++++++++++++++
> hw/piix_pci.c | 65 ++++----------------------
> 4 files changed, 229 insertions(+), 55 deletions(-)
> create mode 100644 hw/pam.c
> create mode 100644 hw/pam.h
>
> diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
> index 8c764bb..2f0c172 100644
> --- a/hw/i386/Makefile.objs
> +++ b/hw/i386/Makefile.objs
> @@ -6,6 +6,7 @@ obj-y += pci-hotplug.o smbios.o wdt_ib700.o
> obj-y += debugcon.o multiboot.o
> obj-y += pc_piix.o
> obj-y += pc_sysfw.o
> +obj-y += pam.o
> obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o
> obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
> obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
> diff --git a/hw/pam.c b/hw/pam.c
> new file mode 100644
> index 0000000..9ec5861
> --- /dev/null
> +++ b/hw/pam.c
> @@ -0,0 +1,120 @@
> +/*
> + * QEMU i440FX/PIIX3 PCI Bridge Emulation
> + *
> + * Copyright (c) 2006 Fabrice Bellard
> + *
> + * 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.
> + *
> + * Split out from piix_pci.c
> + * Copyright (c) 2011 Isaku Yamahata <yamahata at valinux co jp>
> + * VA Linux Systems Japan K.K.
> + * Copyright (c) 2012 Jason Baron <jbaron@redhat.com>
> + *
> + */
> +
> +#include "sysemu.h"
> +#include "pam.h"
> +
> +void smram_update(MemoryRegion *smram_region, uint8_t smram,
> + uint8_t smm_enabled)
> +{
> + bool smram_enabled;
> +
> + smram_enabled = ((smm_enabled && (smram & SMRAM_G_SMRAME)) ||
> + (smram & SMRAM_D_OPEN));
> + memory_region_set_enabled(smram_region, !smram_enabled);
> +}
> +
> +void smram_set_smm(uint8_t *host_smm_enabled, int smm, uint8_t smram,
> + MemoryRegion *smram_region)
> +{
> + uint8_t smm_enabled = (smm != 0);
> + if (*host_smm_enabled != smm_enabled) {
> + *host_smm_enabled = smm_enabled;
> + smram_update(smram_region, smram, *host_smm_enabled);
> + }
> +}
> +
> +static void pam_update_seg(PAMMemoryRegion *mem, uint32_t start, uint32_t size,
> + MemoryRegion *ram_memory,
> + MemoryRegion *pci_address_space,
> + MemoryRegion *system_memory, uint8_t attr)
> +{
> + if (mem->initialized) {
> + memory_region_del_subregion(system_memory, &mem->mem);
> + memory_region_destroy(&mem->mem);
> + }
> +
> + switch (attr) {
> + case PAM_ATTR_WE | PAM_ATTR_RE:
> + /* RAM */
> + memory_region_init_alias(&mem->mem, "pam-ram", ram_memory,
> + start, size);
> + break;
> + case PAM_ATTR_RE:
> + /* ROM (XXX: not quite correct) */
> + memory_region_init_alias(&mem->mem, "pam-rom", ram_memory,
> + start, size);
> + memory_region_set_readonly(&mem->mem, true);
> + break;
> + case PAM_ATTR_WE:
> + case 0:
> + /* XXX: should distinguish read/write cases */
> + memory_region_init_alias(&mem->mem, "pam-pci", pci_address_space,
> + start, size);
> + break;
> + default:
> + abort();
> + break;
> + }
> + memory_region_add_subregion_overlap(system_memory, start, &mem->mem, 1);
> + mem->initialized = true;
> +
> +}
> +
> +static uint8_t pam_attr(uint8_t val, int hi)
> +{
> + return (val >> ((!!hi) * 4)) & PAM_ATTR_MASK;
> +}
> +
> +void pam_update(PAMMemoryRegion *mem, int idx, uint8_t val,
> + MemoryRegion *ram_memory, MemoryRegion *pci_address_space,
> + MemoryRegion *system_memory)
> +{
> + uint32_t phys_addr;
> + int map_idx;
> +
> + assert(0 <= idx && idx <= PAM_IDX_MAX);
> +
> + if (idx == 0) {
> + pam_update_seg(&mem[0], PAM_BIOS_BASE, PAM_BIOS_SIZE, ram_memory,
> + pci_address_space, system_memory, pam_attr(val, 1));
> + return;
> + }
> +
> + map_idx = (idx - 1) * 2;
> +
> + phys_addr = PAM_EXPAN_BASE + PAM_EXPAN_SIZE * map_idx;
> + pam_update_seg(&mem[map_idx + 1], phys_addr, PAM_EXPAN_SIZE, ram_memory,
> + pci_address_space, system_memory, pam_attr(val, 0));
> +
> + phys_addr += PAM_EXPAN_SIZE;
> + pam_update_seg(&mem[map_idx + 2], phys_addr, PAM_EXPAN_SIZE, ram_memory,
> + pci_address_space, system_memory, pam_attr(val, 1));
> +}
> diff --git a/hw/pam.h b/hw/pam.h
> new file mode 100644
> index 0000000..ce89a2a
> --- /dev/null
> +++ b/hw/pam.h
> @@ -0,0 +1,98 @@
> +#ifndef QEMU_PAM_H
> +#define QEMU_PAM_H
> +
> +/*
> + * Copyright (c) 2006 Fabrice Bellard
> + *
> + * 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.
> + */
> +/*
> + * Split out from piix_pci.c
> + * Copyright (c) 2011 Isaku Yamahata <yamahata at valinux co jp>
> + * VA Linux Systems Japan K.K.
> + * Copyright (c) 2012 Jason Baron <jbaron@redhat.com>
> + *
> + * SMRAM memory area and PAM memory area in Legacy address range for PC.
> + * PAM: Programmable Attribute Map registers
> + *
> + * 0xa0000 - 0xbffff compatible SMRAM
> + *
> + * 0xc0000 - 0xc3fff Expansion area memory segments
> + * 0xc4000 - 0xc7fff
> + * 0xc8000 - 0xcbfff
> + * 0xcc000 - 0xcffff
> + * 0xd0000 - 0xd7fff
> + * 0xd8000 - 0xdbfff
> + * 0xdc000 - 0xdffff
> + * 0xe0000 - 0xe3fff Extended System BIOS Area Memory Segments
> + * 0xe4000 - 0xe7fff
> + * 0xe8000 - 0xebfff
> + * 0xec000 - 0xeffff
> + *
> + * 0xf0000 - 0xfffff System BIOS Area Memory Segments
> + */
> +
> +#include "qemu-common.h"
> +#include "memory.h"
> +
> +#define SMRAM_C_BASE 0xa0000
> +#define SMRAM_C_END 0xc0000
> +#define SMRAM_C_SIZE 0x20000
> +
> +
> +#define PAM_EXPAN_BASE 0xc0000
> +#define PAM_EXPAN_SIZE 0x04000
> +
> +#define PAM_EXBIOS_BASE 0xe0000
> +#define PAM_EXBIOS_SIZE 0x04000
> +
> +#define PAM_BIOS_BASE 0xf0000
> +#define PAM_BIOS_END 0xfffff
> +/* 64KB: Intel 3 series express chipset family p. 58*/
> +#define PAM_BIOS_SIZE 0x10000
> +
> +/* PAM registers: log nibble and high nibble*/
> +#define PAM_ATTR_WE ((uint8_t)2)
> +#define PAM_ATTR_RE ((uint8_t)1)
> +#define PAM_ATTR_MASK ((uint8_t)3)
> +
> +#define PAM_IDX_MAX 6 /* pam0 - pam6 */
> +
> +/* SMRAM register */
> +#define SMRAM_D_OPEN ((uint8_t)(1 << 6))
> +#define SMRAM_D_CLS ((uint8_t)(1 << 5))
> +#define SMRAM_D_LCK ((uint8_t)(1 << 4))
> +#define SMRAM_G_SMRAME ((uint8_t)(1 << 3))
> +#define SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7)
> +#define SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */
> +
> +typedef struct PAMMemoryRegion {
> + MemoryRegion mem;
> + bool initialized;
> +} PAMMemoryRegion;
> +
> +void smram_update(MemoryRegion *smram_region, uint8_t smram,
> + uint8_t smm_enabled);
> +void smram_set_smm(uint8_t *host_smm_enabled, int smm, uint8_t smram,
> + MemoryRegion *smram_region);
> +void pam_update(PAMMemoryRegion *mem, int idx, uint8_t val,
> + MemoryRegion *ram_memory, MemoryRegion *pci_address_space,
> + MemoryRegion *system_memory);
> +
> +#endif /* QEMU_PAM_H */
> diff --git a/hw/piix_pci.c b/hw/piix_pci.c
> index 537fc19..02b161d 100644
> --- a/hw/piix_pci.c
> +++ b/hw/piix_pci.c
> @@ -30,6 +30,7 @@
> #include "sysbus.h"
> #include "range.h"
> #include "xen.h"
> +#include "pam.h"
>
> /*
> * I440FX chipset data sheet.
> @@ -68,11 +69,6 @@ typedef struct PIIX3State {
> int32_t pci_irq_levels_vmstate[PIIX_NUM_PIRQS];
> } PIIX3State;
>
> -typedef struct PAMMemoryRegion {
> - MemoryRegion mem;
> - bool initialized;
> -} PAMMemoryRegion;
> -
> struct PCII440FXState {
> PCIDevice dev;
> MemoryRegion *system_memory;
> @@ -105,56 +101,16 @@ static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
> return (pci_intx + slot_addend) & 3;
> }
>
> -static void update_pam(PCII440FXState *d, uint32_t start, uint32_t end, int r,
> - PAMMemoryRegion *mem)
> -{
> - if (mem->initialized) {
> - memory_region_del_subregion(d->system_memory, &mem->mem);
> - memory_region_destroy(&mem->mem);
> - }
> -
> - // printf("ISA mapping %08x-0x%08x: %d\n", start, end, r);
> - switch(r) {
> - case 3:
> - /* RAM */
> - memory_region_init_alias(&mem->mem, "pam-ram", d->ram_memory,
> - start, end - start);
> - break;
> - case 1:
> - /* ROM (XXX: not quite correct) */
> - memory_region_init_alias(&mem->mem, "pam-rom", d->ram_memory,
> - start, end - start);
> - memory_region_set_readonly(&mem->mem, true);
> - break;
> - case 2:
> - case 0:
> - /* XXX: should distinguish read/write cases */
> - memory_region_init_alias(&mem->mem, "pam-pci", d->pci_address_space,
> - start, end - start);
> - break;
> - }
> - memory_region_add_subregion_overlap(d->system_memory,
> - start, &mem->mem, 1);
> - mem->initialized = true;
> -}
> -
> static void i440fx_update_memory_mappings(PCII440FXState *d)
> {
> - int i, r;
> - uint32_t smram;
> - bool smram_enabled;
> + int i;
>
> memory_region_transaction_begin();
> - update_pam(d, 0xf0000, 0x100000, (d->dev.config[I440FX_PAM] >> 4) & 3,
> - &d->pam_regions[0]);
> - for(i = 0; i < 12; i++) {
> - r = (d->dev.config[(i >> 1) + (I440FX_PAM + 1)] >> ((i & 1) * 4)) & 3;
> - update_pam(d, 0xc0000 + 0x4000 * i, 0xc0000 + 0x4000 * (i + 1), r,
> - &d->pam_regions[i+1]);
> + for (i = 0; i <= PAM_IDX_MAX; i++) {
> + pam_update(&d->pam_regions[0], i, d->dev.config[I440FX_PAM + i],
> + d->ram_memory, d->pci_address_space, d->system_memory);
> }
> - smram = d->dev.config[I440FX_SMRAM];
> - smram_enabled = (d->smm_enabled && (smram & 0x08)) || (smram & 0x40);
> - memory_region_set_enabled(&d->smram_region, !smram_enabled);
> + smram_update(&d->smram_region, d->dev.config[I440FX_SMRAM], d->smm_enabled);
> memory_region_transaction_commit();
> }
>
> @@ -162,11 +118,10 @@ static void i440fx_set_smm(int val, void *arg)
> {
> PCII440FXState *d = arg;
>
> - val = (val != 0);
> - if (d->smm_enabled != val) {
> - d->smm_enabled = val;
> - i440fx_update_memory_mappings(d);
> - }
> + memory_region_transaction_begin();
> + smram_set_smm(&d->smm_enabled, val, d->dev.config[I440FX_SMRAM],
> + &d->smram_region);
> + memory_region_transaction_commit();
> }
>
>
>
next prev parent reply other threads:[~2012-10-09 7:47 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-09 3:30 [Qemu-devel] [PATCH v2 00/21] q35 qemu support Jason Baron
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 01/21] blockdev: Introduce a default machine blockdev interface field, QEMUMachine->mach_if Jason Baron
2012-10-09 7:34 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 02/21] blockdev: Introduce IF_AHCI Jason Baron
2012-10-09 7:36 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 03/21] pci: pci capability must be in PCI space Jason Baron
2012-10-09 7:36 ` Paolo Bonzini
2012-10-13 8:29 ` Blue Swirl
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 04/21] pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt pin swizzle Jason Baron
2012-10-09 7:39 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 05/21] pc, pc_piix: split out pc nic initialization Jason Baron
2012-10-09 7:39 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 06/21] pc: Move ioapic_init() from pc_piix.c to pc.c Jason Baron
2012-10-09 7:44 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 07/21] pc/piix_pci: factor out smram/pam logic Jason Baron
2012-10-09 7:47 ` Paolo Bonzini [this message]
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 08/21] pci_ids: add intel 82801BA pci-to-pci bridge id and PCI_CLASS_SERIAL_SMBUS Jason Baron
2012-10-09 7:48 ` Paolo Bonzini
2012-10-13 8:31 ` Blue Swirl
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 10/21] pcie: pass pcie window size to pcie_host_mmcfg_update() Jason Baron
2012-10-09 7:52 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 09/21] pci: Add class 0xc05 as 'SMBus' Jason Baron
2012-10-09 7:49 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 12/21] q35: Introduce q35 pc based chipset emulator Jason Baron
2012-10-11 14:47 ` Michael S. Tsirkin
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 11/21] pcie: Convert PCIExpressHost to use the QOM Jason Baron
2012-10-09 7:52 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 13/21] q35: Re-base q35 Jason Baron
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 14/21] q35: Suppress SMM BIOS initialization under KVM Jason Baron
2012-10-09 7:53 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 15/21] q35: Fix non-PCI IRQ processing in ich9_lpc_update_apic Jason Baron
2012-10-09 7:53 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 16/21] q35: smbus: Remove PCI_STATUS_SIG_SYSTEM_ERROR and PCI_STATUS_DETECTED_PARITY from w1cmask Jason Baron
2012-10-09 7:54 ` Paolo Bonzini
2012-10-11 14:53 ` Michael S. Tsirkin
2012-10-19 15:13 ` Jason Baron
2012-10-19 16:17 ` Isaku Yamahata
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 17/21] q35: Add kvmclock support Jason Baron
2012-10-09 7:54 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 19/21] Add a fallback bios file search, if -L fails Jason Baron
2012-10-09 7:59 ` Paolo Bonzini
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 18/21] q35: Fix irr initialization for slots 25..31 Jason Baron
2012-10-09 7:58 ` Paolo Bonzini
2012-10-11 14:49 ` Michael S. Tsirkin
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 20/21] q35: automatically load the q35 dsdt table Jason Baron
2012-10-09 8:02 ` Paolo Bonzini
2012-10-09 8:29 ` Paolo Bonzini
2012-10-09 20:06 ` Jason Baron
2012-10-13 8:33 ` Blue Swirl
2012-10-09 3:30 ` [Qemu-devel] [PATCH v2 21/21] q35: add acpi-based pci hotplug Jason Baron
2012-10-09 8:04 ` Paolo Bonzini
2012-10-11 10:57 ` Michael S. Tsirkin
2012-10-11 14:21 ` Jason Baron
2012-10-11 14:46 ` Michael S. Tsirkin
2012-10-11 14:54 ` Paolo Bonzini
2012-10-11 15:40 ` Jason Baron
2012-10-11 15:34 ` Jason Baron
2012-10-11 20:40 ` Michael S. Tsirkin
2012-10-12 15:27 ` Jason Baron
2012-10-13 23:03 ` Michael S. Tsirkin
2012-10-12 7:27 ` Gerd Hoffmann
2012-10-12 9:39 ` Michael S. Tsirkin
2012-10-12 10:06 ` Gerd Hoffmann
2012-10-12 10:39 ` Michael S. Tsirkin
2012-10-12 15:00 ` Jason Baron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5073D68B.7090407@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=alex.williamson@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=avi@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=jan.kiszka@siemens.com \
--cc=jbaron@redhat.com \
--cc=juzhang@redhat.com \
--cc=kevin@koconnor.net \
--cc=kraxel@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mkletzan@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yamahata@valinux.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).