ce4100.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * GPL LICENSE SUMMARY
  3. *
  4. * Copyright(c) 2010 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  18. * The full GNU General Public License is included in this distribution
  19. * in the file called LICENSE.GPL.
  20. *
  21. * Contact Information:
  22. * Intel Corporation
  23. * 2200 Mission College Blvd.
  24. * Santa Clara, CA 97052
  25. *
  26. * This provides access methods for PCI registers that mis-behave on
  27. * the CE4100. Each register can be assigned a private init, read and
  28. * write routine. The exception to this is the bridge device. The
  29. * bridge device is the only device on bus zero (0) that requires any
  30. * fixup so it is a special case ATM
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/pci.h>
  34. #include <linux/init.h>
  35. #include <asm/ce4100.h>
  36. #include <asm/pci_x86.h>
  37. struct sim_reg {
  38. u32 value;
  39. u32 mask;
  40. };
  41. struct sim_dev_reg {
  42. int dev_func;
  43. int reg;
  44. void (*init)(struct sim_dev_reg *reg);
  45. void (*read)(struct sim_dev_reg *reg, u32 *value);
  46. void (*write)(struct sim_dev_reg *reg, u32 value);
  47. struct sim_reg sim_reg;
  48. };
  49. struct sim_reg_op {
  50. void (*init)(struct sim_dev_reg *reg);
  51. void (*read)(struct sim_dev_reg *reg, u32 value);
  52. void (*write)(struct sim_dev_reg *reg, u32 value);
  53. };
  54. #define MB (1024 * 1024)
  55. #define KB (1024)
  56. #define SIZE_TO_MASK(size) (~(size - 1))
  57. #define DEFINE_REG(device, func, offset, size, init_op, read_op, write_op)\
  58. { PCI_DEVFN(device, func), offset, init_op, read_op, write_op,\
  59. {0, SIZE_TO_MASK(size)} },
  60. /*
  61. * All read/write functions are called with pci_config_lock held.
  62. */
  63. static void reg_init(struct sim_dev_reg *reg)
  64. {
  65. pci_direct_conf1.read(0, 1, reg->dev_func, reg->reg, 4,
  66. &reg->sim_reg.value);
  67. }
  68. static void reg_read(struct sim_dev_reg *reg, u32 *value)
  69. {
  70. *value = reg->sim_reg.value;
  71. }
  72. static void reg_write(struct sim_dev_reg *reg, u32 value)
  73. {
  74. reg->sim_reg.value = (value & reg->sim_reg.mask) |
  75. (reg->sim_reg.value & ~reg->sim_reg.mask);
  76. }
  77. static void sata_reg_init(struct sim_dev_reg *reg)
  78. {
  79. pci_direct_conf1.read(0, 1, PCI_DEVFN(14, 0), 0x10, 4,
  80. &reg->sim_reg.value);
  81. reg->sim_reg.value += 0x400;
  82. }
  83. static void ehci_reg_read(struct sim_dev_reg *reg, u32 *value)
  84. {
  85. reg_read(reg, value);
  86. if (*value != reg->sim_reg.mask)
  87. *value |= 0x100;
  88. }
  89. void sata_revid_init(struct sim_dev_reg *reg)
  90. {
  91. reg->sim_reg.value = 0x01060100;
  92. reg->sim_reg.mask = 0;
  93. }
  94. static void sata_revid_read(struct sim_dev_reg *reg, u32 *value)
  95. {
  96. reg_read(reg, value);
  97. }
  98. static void reg_noirq_read(struct sim_dev_reg *reg, u32 *value)
  99. {
  100. /* force interrupt pin value to 0 */
  101. *value = reg->sim_reg.value & 0xfff00ff;
  102. }
  103. static struct sim_dev_reg bus1_fixups[] = {
  104. DEFINE_REG(2, 0, 0x10, (16*MB), reg_init, reg_read, reg_write)
  105. DEFINE_REG(2, 0, 0x14, (256), reg_init, reg_read, reg_write)
  106. DEFINE_REG(2, 1, 0x10, (64*KB), reg_init, reg_read, reg_write)
  107. DEFINE_REG(3, 0, 0x10, (64*KB), reg_init, reg_read, reg_write)
  108. DEFINE_REG(4, 0, 0x10, (128*KB), reg_init, reg_read, reg_write)
  109. DEFINE_REG(4, 1, 0x10, (128*KB), reg_init, reg_read, reg_write)
  110. DEFINE_REG(6, 0, 0x10, (512*KB), reg_init, reg_read, reg_write)
  111. DEFINE_REG(6, 1, 0x10, (512*KB), reg_init, reg_read, reg_write)
  112. DEFINE_REG(6, 2, 0x10, (64*KB), reg_init, reg_read, reg_write)
  113. DEFINE_REG(8, 0, 0x10, (1*MB), reg_init, reg_read, reg_write)
  114. DEFINE_REG(8, 1, 0x10, (64*KB), reg_init, reg_read, reg_write)
  115. DEFINE_REG(8, 2, 0x10, (64*KB), reg_init, reg_read, reg_write)
  116. DEFINE_REG(9, 0, 0x10 , (1*MB), reg_init, reg_read, reg_write)
  117. DEFINE_REG(9, 0, 0x14, (64*KB), reg_init, reg_read, reg_write)
  118. DEFINE_REG(10, 0, 0x10, (256), reg_init, reg_read, reg_write)
  119. DEFINE_REG(10, 0, 0x14, (256*MB), reg_init, reg_read, reg_write)
  120. DEFINE_REG(11, 0, 0x10, (256), reg_init, reg_read, reg_write)
  121. DEFINE_REG(11, 0, 0x14, (256), reg_init, reg_read, reg_write)
  122. DEFINE_REG(11, 1, 0x10, (256), reg_init, reg_read, reg_write)
  123. DEFINE_REG(11, 2, 0x10, (256), reg_init, reg_read, reg_write)
  124. DEFINE_REG(11, 2, 0x14, (256), reg_init, reg_read, reg_write)
  125. DEFINE_REG(11, 2, 0x18, (256), reg_init, reg_read, reg_write)
  126. DEFINE_REG(11, 3, 0x10, (256), reg_init, reg_read, reg_write)
  127. DEFINE_REG(11, 3, 0x14, (256), reg_init, reg_read, reg_write)
  128. DEFINE_REG(11, 4, 0x10, (256), reg_init, reg_read, reg_write)
  129. DEFINE_REG(11, 5, 0x10, (64*KB), reg_init, reg_read, reg_write)
  130. DEFINE_REG(11, 6, 0x10, (256), reg_init, reg_read, reg_write)
  131. DEFINE_REG(11, 7, 0x10, (64*KB), reg_init, reg_read, reg_write)
  132. DEFINE_REG(11, 7, 0x3c, 256, reg_init, reg_noirq_read, reg_write)
  133. DEFINE_REG(12, 0, 0x10, (128*KB), reg_init, reg_read, reg_write)
  134. DEFINE_REG(12, 0, 0x14, (256), reg_init, reg_read, reg_write)
  135. DEFINE_REG(12, 1, 0x10, (1024), reg_init, reg_read, reg_write)
  136. DEFINE_REG(13, 0, 0x10, (32*KB), reg_init, ehci_reg_read, reg_write)
  137. DEFINE_REG(13, 1, 0x10, (32*KB), reg_init, ehci_reg_read, reg_write)
  138. DEFINE_REG(14, 0, 0x8, 0, sata_revid_init, sata_revid_read, 0)
  139. DEFINE_REG(14, 0, 0x10, 0, reg_init, reg_read, reg_write)
  140. DEFINE_REG(14, 0, 0x14, 0, reg_init, reg_read, reg_write)
  141. DEFINE_REG(14, 0, 0x18, 0, reg_init, reg_read, reg_write)
  142. DEFINE_REG(14, 0, 0x1C, 0, reg_init, reg_read, reg_write)
  143. DEFINE_REG(14, 0, 0x20, 0, reg_init, reg_read, reg_write)
  144. DEFINE_REG(14, 0, 0x24, (0x200), sata_reg_init, reg_read, reg_write)
  145. DEFINE_REG(15, 0, 0x10, (64*KB), reg_init, reg_read, reg_write)
  146. DEFINE_REG(15, 0, 0x14, (64*KB), reg_init, reg_read, reg_write)
  147. DEFINE_REG(16, 0, 0x10, (64*KB), reg_init, reg_read, reg_write)
  148. DEFINE_REG(16, 0, 0x14, (64*MB), reg_init, reg_read, reg_write)
  149. DEFINE_REG(16, 0, 0x18, (64*MB), reg_init, reg_read, reg_write)
  150. DEFINE_REG(16, 0, 0x3c, 256, reg_init, reg_noirq_read, reg_write)
  151. DEFINE_REG(17, 0, 0x10, (128*KB), reg_init, reg_read, reg_write)
  152. DEFINE_REG(18, 0, 0x10, (1*KB), reg_init, reg_read, reg_write)
  153. DEFINE_REG(18, 0, 0x3c, 256, reg_init, reg_noirq_read, reg_write)
  154. };
  155. static void __init init_sim_regs(void)
  156. {
  157. int i;
  158. for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
  159. if (bus1_fixups[i].init)
  160. bus1_fixups[i].init(&bus1_fixups[i]);
  161. }
  162. }
  163. static inline void extract_bytes(u32 *value, int reg, int len)
  164. {
  165. uint32_t mask;
  166. *value >>= ((reg & 3) * 8);
  167. mask = 0xFFFFFFFF >> ((4 - len) * 8);
  168. *value &= mask;
  169. }
  170. int bridge_read(unsigned int devfn, int reg, int len, u32 *value)
  171. {
  172. u32 av_bridge_base, av_bridge_limit;
  173. int retval = 0;
  174. switch (reg) {
  175. /* Make BARs appear to not request any memory. */
  176. case PCI_BASE_ADDRESS_0:
  177. case PCI_BASE_ADDRESS_0 + 1:
  178. case PCI_BASE_ADDRESS_0 + 2:
  179. case PCI_BASE_ADDRESS_0 + 3:
  180. *value = 0;
  181. break;
  182. /* Since subordinate bus number register is hardwired
  183. * to zero and read only, so do the simulation.
  184. */
  185. case PCI_PRIMARY_BUS:
  186. if (len == 4)
  187. *value = 0x00010100;
  188. break;
  189. case PCI_SUBORDINATE_BUS:
  190. *value = 1;
  191. break;
  192. case PCI_MEMORY_BASE:
  193. case PCI_MEMORY_LIMIT:
  194. /* Get the A/V bridge base address. */
  195. pci_direct_conf1.read(0, 0, devfn,
  196. PCI_BASE_ADDRESS_0, 4, &av_bridge_base);
  197. av_bridge_limit = av_bridge_base + (512*MB - 1);
  198. av_bridge_limit >>= 16;
  199. av_bridge_limit &= 0xFFF0;
  200. av_bridge_base >>= 16;
  201. av_bridge_base &= 0xFFF0;
  202. if (reg == PCI_MEMORY_LIMIT)
  203. *value = av_bridge_limit;
  204. else if (len == 2)
  205. *value = av_bridge_base;
  206. else
  207. *value = (av_bridge_limit << 16) | av_bridge_base;
  208. break;
  209. /* Make prefetchable memory limit smaller than prefetchable
  210. * memory base, so not claim prefetchable memory space.
  211. */
  212. case PCI_PREF_MEMORY_BASE:
  213. *value = 0xFFF0;
  214. break;
  215. case PCI_PREF_MEMORY_LIMIT:
  216. *value = 0x0;
  217. break;
  218. /* Make IO limit smaller than IO base, so not claim IO space. */
  219. case PCI_IO_BASE:
  220. *value = 0xF0;
  221. break;
  222. case PCI_IO_LIMIT:
  223. *value = 0;
  224. break;
  225. default:
  226. retval = 1;
  227. }
  228. return retval;
  229. }
  230. static int ce4100_bus1_read(unsigned int devfn, int reg, int len, u32 *value)
  231. {
  232. unsigned long flags;
  233. int i;
  234. for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
  235. if (bus1_fixups[i].dev_func == devfn &&
  236. bus1_fixups[i].reg == (reg & ~3) &&
  237. bus1_fixups[i].read) {
  238. raw_spin_lock_irqsave(&pci_config_lock, flags);
  239. bus1_fixups[i].read(&(bus1_fixups[i]), value);
  240. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  241. extract_bytes(value, reg, len);
  242. return 0;
  243. }
  244. }
  245. return -1;
  246. }
  247. static int ce4100_conf_read(unsigned int seg, unsigned int bus,
  248. unsigned int devfn, int reg, int len, u32 *value)
  249. {
  250. WARN_ON(seg);
  251. if (bus == 1 && !ce4100_bus1_read(devfn, reg, len, value))
  252. return 0;
  253. if (bus == 0 && (PCI_DEVFN(1, 0) == devfn) &&
  254. !bridge_read(devfn, reg, len, value))
  255. return 0;
  256. return pci_direct_conf1.read(seg, bus, devfn, reg, len, value);
  257. }
  258. static int ce4100_bus1_write(unsigned int devfn, int reg, int len, u32 value)
  259. {
  260. unsigned long flags;
  261. int i;
  262. for (i = 0; i < ARRAY_SIZE(bus1_fixups); i++) {
  263. if (bus1_fixups[i].dev_func == devfn &&
  264. bus1_fixups[i].reg == (reg & ~3) &&
  265. bus1_fixups[i].write) {
  266. raw_spin_lock_irqsave(&pci_config_lock, flags);
  267. bus1_fixups[i].write(&(bus1_fixups[i]), value);
  268. raw_spin_unlock_irqrestore(&pci_config_lock, flags);
  269. return 0;
  270. }
  271. }
  272. return -1;
  273. }
  274. static int ce4100_conf_write(unsigned int seg, unsigned int bus,
  275. unsigned int devfn, int reg, int len, u32 value)
  276. {
  277. WARN_ON(seg);
  278. if (bus == 1 && !ce4100_bus1_write(devfn, reg, len, value))
  279. return 0;
  280. /* Discard writes to A/V bridge BAR. */
  281. if (bus == 0 && PCI_DEVFN(1, 0) == devfn &&
  282. ((reg & ~3) == PCI_BASE_ADDRESS_0))
  283. return 0;
  284. return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
  285. }
  286. static const struct pci_raw_ops ce4100_pci_conf = {
  287. .read = ce4100_conf_read,
  288. .write = ce4100_conf_write,
  289. };
  290. int __init ce4100_pci_init(void)
  291. {
  292. init_sim_regs();
  293. raw_pci_ops = &ce4100_pci_conf;
  294. /* Indicate caller that it should invoke pci_legacy_init() */
  295. return 1;
  296. }