2
0

q35.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * q35.h
  3. *
  4. * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
  5. * VA Linux Systems Japan K.K.
  6. * Copyright (C) 2012 Jason Baron <jbaron@redhat.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, see <http://www.gnu.org/licenses/>
  20. */
  21. #ifndef HW_Q35_H
  22. #define HW_Q35_H
  23. #include "hw/pci/pci_device.h"
  24. #include "hw/pci/pcie_host.h"
  25. #include "hw/pci-host/pam.h"
  26. #include "qemu/units.h"
  27. #include "qemu/range.h"
  28. #include "qom/object.h"
  29. #define TYPE_Q35_HOST_DEVICE "q35-pcihost"
  30. OBJECT_DECLARE_SIMPLE_TYPE(Q35PCIHost, Q35_HOST_DEVICE)
  31. #define TYPE_MCH_PCI_DEVICE "mch"
  32. OBJECT_DECLARE_SIMPLE_TYPE(MCHPCIState, MCH_PCI_DEVICE)
  33. struct MCHPCIState {
  34. /*< private >*/
  35. PCIDevice parent_obj;
  36. /*< public >*/
  37. MemoryRegion *ram_memory;
  38. MemoryRegion *pci_address_space;
  39. MemoryRegion *system_memory;
  40. MemoryRegion *address_space_io;
  41. PAMMemoryRegion pam_regions[PAM_REGIONS_COUNT];
  42. MemoryRegion smram_region, open_high_smram;
  43. MemoryRegion smram, low_smram, high_smram;
  44. MemoryRegion tseg_blackhole, tseg_window;
  45. MemoryRegion smbase_blackhole, smbase_window;
  46. bool has_smram_at_smbase;
  47. Range pci_hole;
  48. uint64_t below_4g_mem_size;
  49. uint64_t above_4g_mem_size;
  50. uint64_t pci_hole64_size;
  51. uint32_t short_root_bus;
  52. uint16_t ext_tseg_mbytes;
  53. };
  54. struct Q35PCIHost {
  55. /*< private >*/
  56. PCIExpressHost parent_obj;
  57. /*< public >*/
  58. bool pci_hole64_fix;
  59. MCHPCIState mch;
  60. };
  61. #define Q35_MASK(bit, ms_bit, ls_bit) \
  62. ((uint##bit##_t)(((1ULL << ((ms_bit) + 1)) - 1) & ~((1ULL << ls_bit) - 1)))
  63. /*
  64. * gmch part
  65. */
  66. #define MCH_HOST_PROP_RAM_MEM "ram-mem"
  67. #define MCH_HOST_PROP_PCI_MEM "pci-mem"
  68. #define MCH_HOST_PROP_SYSTEM_MEM "system-mem"
  69. #define MCH_HOST_PROP_IO_MEM "io-mem"
  70. /* PCI configuration */
  71. #define MCH_HOST_BRIDGE "MCH"
  72. #define MCH_HOST_BRIDGE_CONFIG_ADDR 0xcf8
  73. #define MCH_HOST_BRIDGE_CONFIG_DATA 0xcfc
  74. /* D0:F0 configuration space */
  75. #define MCH_HOST_BRIDGE_REVISION_DEFAULT 0x0
  76. #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES 0x50
  77. #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_SIZE 2
  78. #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_QUERY 0xffff
  79. #define MCH_HOST_BRIDGE_EXT_TSEG_MBYTES_MAX 0xfff
  80. #define MCH_HOST_BRIDGE_SMBASE_SIZE (128 * KiB)
  81. #define MCH_HOST_BRIDGE_SMBASE_ADDR 0x30000
  82. #define MCH_HOST_BRIDGE_F_SMBASE 0x9c
  83. #define MCH_HOST_BRIDGE_F_SMBASE_QUERY 0xff
  84. #define MCH_HOST_BRIDGE_F_SMBASE_IN_RAM 0x01
  85. #define MCH_HOST_BRIDGE_F_SMBASE_LCK 0x02
  86. #define MCH_HOST_BRIDGE_PCIEXBAR 0x60 /* 64bit register */
  87. #define MCH_HOST_BRIDGE_PCIEXBAR_SIZE 8 /* 64bit register */
  88. #define MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT 0xb0000000
  89. #define MCH_HOST_BRIDGE_PCIEXBAR_MAX (0x10000000) /* 256M */
  90. #define MCH_HOST_BRIDGE_PCIEXBAR_ADMSK Q35_MASK(64, 35, 28)
  91. #define MCH_HOST_BRIDGE_PCIEXBAR_128ADMSK ((uint64_t)(1 << 26))
  92. #define MCH_HOST_BRIDGE_PCIEXBAR_64ADMSK ((uint64_t)(1 << 25))
  93. #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_MASK ((uint64_t)(0x3 << 1))
  94. #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_256M ((uint64_t)(0x0 << 1))
  95. #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_128M ((uint64_t)(0x1 << 1))
  96. #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_64M ((uint64_t)(0x2 << 1))
  97. #define MCH_HOST_BRIDGE_PCIEXBAR_LENGTH_RVD ((uint64_t)(0x3 << 1))
  98. #define MCH_HOST_BRIDGE_PCIEXBAREN ((uint64_t)1)
  99. #define MCH_HOST_BRIDGE_PAM_NB 7
  100. #define MCH_HOST_BRIDGE_PAM_SIZE 7
  101. #define MCH_HOST_BRIDGE_PAM0 0x90
  102. #define MCH_HOST_BRIDGE_PAM_BIOS_AREA 0xf0000
  103. #define MCH_HOST_BRIDGE_PAM_AREA_SIZE 0x10000 /* 16KB */
  104. #define MCH_HOST_BRIDGE_PAM1 0x91
  105. #define MCH_HOST_BRIDGE_PAM_EXPAN_AREA 0xc0000
  106. #define MCH_HOST_BRIDGE_PAM_EXPAN_SIZE 0x04000
  107. #define MCH_HOST_BRIDGE_PAM2 0x92
  108. #define MCH_HOST_BRIDGE_PAM3 0x93
  109. #define MCH_HOST_BRIDGE_PAM4 0x94
  110. #define MCH_HOST_BRIDGE_PAM_EXBIOS_AREA 0xe0000
  111. #define MCH_HOST_BRIDGE_PAM_EXBIOS_SIZE 0x04000
  112. #define MCH_HOST_BRIDGE_PAM5 0x95
  113. #define MCH_HOST_BRIDGE_PAM6 0x96
  114. #define MCH_HOST_BRIDGE_PAM_WE_HI ((uint8_t)(0x2 << 4))
  115. #define MCH_HOST_BRIDGE_PAM_RE_HI ((uint8_t)(0x1 << 4))
  116. #define MCH_HOST_BRIDGE_PAM_HI_MASK ((uint8_t)(0x3 << 4))
  117. #define MCH_HOST_BRIDGE_PAM_WE_LO ((uint8_t)0x2)
  118. #define MCH_HOST_BRIDGE_PAM_RE_LO ((uint8_t)0x1)
  119. #define MCH_HOST_BRIDGE_PAM_LO_MASK ((uint8_t)0x3)
  120. #define MCH_HOST_BRIDGE_PAM_WE ((uint8_t)0x2)
  121. #define MCH_HOST_BRIDGE_PAM_RE ((uint8_t)0x1)
  122. #define MCH_HOST_BRIDGE_PAM_MASK ((uint8_t)0x3)
  123. #define MCH_HOST_BRIDGE_SMRAM 0x9d
  124. #define MCH_HOST_BRIDGE_SMRAM_SIZE 2
  125. #define MCH_HOST_BRIDGE_SMRAM_D_OPEN ((uint8_t)(1 << 6))
  126. #define MCH_HOST_BRIDGE_SMRAM_D_CLS ((uint8_t)(1 << 5))
  127. #define MCH_HOST_BRIDGE_SMRAM_D_LCK ((uint8_t)(1 << 4))
  128. #define MCH_HOST_BRIDGE_SMRAM_G_SMRAME ((uint8_t)(1 << 3))
  129. #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG_MASK ((uint8_t)0x7)
  130. #define MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG ((uint8_t)0x2) /* hardwired to b010 */
  131. #define MCH_HOST_BRIDGE_SMRAM_C_BASE 0xa0000
  132. #define MCH_HOST_BRIDGE_SMRAM_C_END 0xc0000
  133. #define MCH_HOST_BRIDGE_SMRAM_C_SIZE 0x20000
  134. #define MCH_HOST_BRIDGE_UPPER_SYSTEM_BIOS_END 0x100000
  135. #define MCH_HOST_BRIDGE_SMRAM_DEFAULT \
  136. MCH_HOST_BRIDGE_SMRAM_C_BASE_SEG
  137. #define MCH_HOST_BRIDGE_SMRAM_WMASK \
  138. (MCH_HOST_BRIDGE_SMRAM_D_OPEN | \
  139. MCH_HOST_BRIDGE_SMRAM_D_CLS | \
  140. MCH_HOST_BRIDGE_SMRAM_D_LCK | \
  141. MCH_HOST_BRIDGE_SMRAM_G_SMRAME)
  142. #define MCH_HOST_BRIDGE_SMRAM_WMASK_LCK \
  143. MCH_HOST_BRIDGE_SMRAM_D_CLS
  144. #define MCH_HOST_BRIDGE_ESMRAMC 0x9e
  145. #define MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME ((uint8_t)(1 << 7))
  146. #define MCH_HOST_BRIDGE_ESMRAMC_E_SMERR ((uint8_t)(1 << 6))
  147. #define MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE ((uint8_t)(1 << 5))
  148. #define MCH_HOST_BRIDGE_ESMRAMC_SM_L1 ((uint8_t)(1 << 4))
  149. #define MCH_HOST_BRIDGE_ESMRAMC_SM_L2 ((uint8_t)(1 << 3))
  150. #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK ((uint8_t)(0x3 << 1))
  151. #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_1MB ((uint8_t)(0x0 << 1))
  152. #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_2MB ((uint8_t)(0x1 << 1))
  153. #define MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_8MB ((uint8_t)(0x2 << 1))
  154. #define MCH_HOST_BRIDGE_ESMRAMC_T_EN ((uint8_t)1)
  155. #define MCH_HOST_BRIDGE_ESMRAMC_DEFAULT \
  156. (MCH_HOST_BRIDGE_ESMRAMC_SM_CACHE | \
  157. MCH_HOST_BRIDGE_ESMRAMC_SM_L1 | \
  158. MCH_HOST_BRIDGE_ESMRAMC_SM_L2)
  159. #define MCH_HOST_BRIDGE_ESMRAMC_WMASK \
  160. (MCH_HOST_BRIDGE_ESMRAMC_H_SMRAME | \
  161. MCH_HOST_BRIDGE_ESMRAMC_TSEG_SZ_MASK | \
  162. MCH_HOST_BRIDGE_ESMRAMC_T_EN)
  163. #define MCH_HOST_BRIDGE_ESMRAMC_WMASK_LCK 0
  164. /* D1:F0 PCIE* port*/
  165. #define MCH_PCIE_DEV 1
  166. #define MCH_PCIE_FUNC 0
  167. uint64_t mch_mcfg_base(void);
  168. /*
  169. * Arbitrary but unique BNF number for IOAPIC device.
  170. *
  171. * TODO: make sure there would have no conflict with real PCI bus
  172. */
  173. #define Q35_PSEUDO_BUS_PLATFORM (0xff)
  174. #define Q35_PSEUDO_DEVFN_IOAPIC (0x00)
  175. #endif /* HW_Q35_H */