2
0

pam.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * QEMU Smram/pam logic implementation
  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.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 "qemu/osdep.h"
  30. #include "hw/pci-host/pam.h"
  31. void init_pam(PAMMemoryRegion *mem, Object *owner, MemoryRegion *ram_memory,
  32. MemoryRegion *system_memory, MemoryRegion *pci_address_space,
  33. uint32_t start, uint32_t size)
  34. {
  35. int i;
  36. /* RAM */
  37. memory_region_init_alias(&mem->alias[3], owner, "pam-ram", ram_memory,
  38. start, size);
  39. /* ROM (XXX: not quite correct) */
  40. memory_region_init_alias(&mem->alias[1], owner, "pam-rom", ram_memory,
  41. start, size);
  42. memory_region_set_readonly(&mem->alias[1], true);
  43. /* XXX: should distinguish read/write cases */
  44. memory_region_init_alias(&mem->alias[0], owner, "pam-pci", pci_address_space,
  45. start, size);
  46. memory_region_init_alias(&mem->alias[2], owner, "pam-pci", ram_memory,
  47. start, size);
  48. memory_region_transaction_begin();
  49. for (i = 0; i < 4; ++i) {
  50. memory_region_set_enabled(&mem->alias[i], false);
  51. memory_region_add_subregion_overlap(system_memory, start,
  52. &mem->alias[i], 1);
  53. }
  54. memory_region_transaction_commit();
  55. mem->current = 0;
  56. }
  57. void pam_update(PAMMemoryRegion *pam, int idx, uint8_t val)
  58. {
  59. assert(0 <= idx && idx < PAM_REGIONS_COUNT);
  60. memory_region_set_enabled(&pam->alias[pam->current], false);
  61. pam->current = (val >> ((!(idx & 1)) * 4)) & PAM_ATTR_MASK;
  62. memory_region_set_enabled(&pam->alias[pam->current], true);
  63. }