2
0

pam.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * QEMU i440FX/PIIX3 PCI Bridge Emulation
  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. *
  9. * Split out from piix_pci.c
  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. */
  29. #include "sysemu/sysemu.h"
  30. #include "pam.h"
  31. void smram_update(MemoryRegion *smram_region, uint8_t smram,
  32. uint8_t smm_enabled)
  33. {
  34. bool smram_enabled;
  35. smram_enabled = ((smm_enabled && (smram & SMRAM_G_SMRAME)) ||
  36. (smram & SMRAM_D_OPEN));
  37. memory_region_set_enabled(smram_region, !smram_enabled);
  38. }
  39. void smram_set_smm(uint8_t *host_smm_enabled, int smm, uint8_t smram,
  40. MemoryRegion *smram_region)
  41. {
  42. uint8_t smm_enabled = (smm != 0);
  43. if (*host_smm_enabled != smm_enabled) {
  44. *host_smm_enabled = smm_enabled;
  45. smram_update(smram_region, smram, *host_smm_enabled);
  46. }
  47. }
  48. void init_pam(MemoryRegion *ram_memory, MemoryRegion *system_memory,
  49. MemoryRegion *pci_address_space, PAMMemoryRegion *mem,
  50. uint32_t start, uint32_t size)
  51. {
  52. int i;
  53. /* RAM */
  54. memory_region_init_alias(&mem->alias[3], "pam-ram", ram_memory,
  55. start, size);
  56. /* ROM (XXX: not quite correct) */
  57. memory_region_init_alias(&mem->alias[1], "pam-rom", ram_memory,
  58. start, size);
  59. memory_region_set_readonly(&mem->alias[1], true);
  60. /* XXX: should distinguish read/write cases */
  61. memory_region_init_alias(&mem->alias[0], "pam-pci", pci_address_space,
  62. start, size);
  63. memory_region_init_alias(&mem->alias[2], "pam-pci", pci_address_space,
  64. start, size);
  65. for (i = 0; i < 4; ++i) {
  66. memory_region_set_enabled(&mem->alias[i], false);
  67. memory_region_add_subregion_overlap(system_memory, start,
  68. &mem->alias[i], 1);
  69. }
  70. mem->current = 0;
  71. }
  72. void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val)
  73. {
  74. assert(0 <= idx && idx <= 12);
  75. memory_region_set_enabled(&pam->alias[pam->current], false);
  76. pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK;
  77. memory_region_set_enabled(&pam->alias[pam->current], true);
  78. }