dca.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 2007 - 2009 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/pci.h>
  24. #include <linux/smp.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/dca.h>
  27. /* either a kernel change is needed, or we need something like this in kernel */
  28. #ifndef CONFIG_SMP
  29. #include <asm/smp.h>
  30. #undef cpu_physical_id
  31. #define cpu_physical_id(cpu) (cpuid_ebx(1) >> 24)
  32. #endif
  33. #include "dma.h"
  34. #include "registers.h"
  35. /*
  36. * Bit 7 of a tag map entry is the "valid" bit, if it is set then bits 0:6
  37. * contain the bit number of the APIC ID to map into the DCA tag. If the valid
  38. * bit is not set, then the value must be 0 or 1 and defines the bit in the tag.
  39. */
  40. #define DCA_TAG_MAP_VALID 0x80
  41. #define DCA3_TAG_MAP_BIT_TO_INV 0x80
  42. #define DCA3_TAG_MAP_BIT_TO_SEL 0x40
  43. #define DCA3_TAG_MAP_LITERAL_VAL 0x1
  44. #define DCA_TAG_MAP_MASK 0xDF
  45. /* expected tag map bytes for I/OAT ver.2 */
  46. #define DCA2_TAG_MAP_BYTE0 0x80
  47. #define DCA2_TAG_MAP_BYTE1 0x0
  48. #define DCA2_TAG_MAP_BYTE2 0x81
  49. #define DCA2_TAG_MAP_BYTE3 0x82
  50. #define DCA2_TAG_MAP_BYTE4 0x82
  51. /* verify if tag map matches expected values */
  52. static inline int dca2_tag_map_valid(u8 *tag_map)
  53. {
  54. return ((tag_map[0] == DCA2_TAG_MAP_BYTE0) &&
  55. (tag_map[1] == DCA2_TAG_MAP_BYTE1) &&
  56. (tag_map[2] == DCA2_TAG_MAP_BYTE2) &&
  57. (tag_map[3] == DCA2_TAG_MAP_BYTE3) &&
  58. (tag_map[4] == DCA2_TAG_MAP_BYTE4));
  59. }
  60. /*
  61. * "Legacy" DCA systems do not implement the DCA register set in the
  62. * I/OAT device. Software needs direct support for their tag mappings.
  63. */
  64. #define APICID_BIT(x) (DCA_TAG_MAP_VALID | (x))
  65. #define IOAT_TAG_MAP_LEN 8
  66. static u8 ioat_tag_map_BNB[IOAT_TAG_MAP_LEN] = {
  67. 1, APICID_BIT(1), APICID_BIT(2), APICID_BIT(2), };
  68. static u8 ioat_tag_map_SCNB[IOAT_TAG_MAP_LEN] = {
  69. 1, APICID_BIT(1), APICID_BIT(2), APICID_BIT(2), };
  70. static u8 ioat_tag_map_CNB[IOAT_TAG_MAP_LEN] = {
  71. 1, APICID_BIT(1), APICID_BIT(3), APICID_BIT(4), APICID_BIT(2), };
  72. static u8 ioat_tag_map_UNISYS[IOAT_TAG_MAP_LEN] = { 0 };
  73. /* pack PCI B/D/F into a u16 */
  74. static inline u16 dcaid_from_pcidev(struct pci_dev *pci)
  75. {
  76. return (pci->bus->number << 8) | pci->devfn;
  77. }
  78. static int dca_enabled_in_bios(struct pci_dev *pdev)
  79. {
  80. /* CPUID level 9 returns DCA configuration */
  81. /* Bit 0 indicates DCA enabled by the BIOS */
  82. unsigned long cpuid_level_9;
  83. int res;
  84. cpuid_level_9 = cpuid_eax(9);
  85. res = test_bit(0, &cpuid_level_9);
  86. if (!res)
  87. dev_dbg(&pdev->dev, "DCA is disabled in BIOS\n");
  88. return res;
  89. }
  90. int system_has_dca_enabled(struct pci_dev *pdev)
  91. {
  92. if (boot_cpu_has(X86_FEATURE_DCA))
  93. return dca_enabled_in_bios(pdev);
  94. dev_dbg(&pdev->dev, "boot cpu doesn't have X86_FEATURE_DCA\n");
  95. return 0;
  96. }
  97. struct ioat_dca_slot {
  98. struct pci_dev *pdev; /* requester device */
  99. u16 rid; /* requester id, as used by IOAT */
  100. };
  101. #define IOAT_DCA_MAX_REQ 6
  102. #define IOAT3_DCA_MAX_REQ 2
  103. struct ioat_dca_priv {
  104. void __iomem *iobase;
  105. void __iomem *dca_base;
  106. int max_requesters;
  107. int requester_count;
  108. u8 tag_map[IOAT_TAG_MAP_LEN];
  109. struct ioat_dca_slot req_slots[0];
  110. };
  111. /* 5000 series chipset DCA Port Requester ID Table Entry Format
  112. * [15:8] PCI-Express Bus Number
  113. * [7:3] PCI-Express Device Number
  114. * [2:0] PCI-Express Function Number
  115. *
  116. * 5000 series chipset DCA control register format
  117. * [7:1] Reserved (0)
  118. * [0] Ignore Function Number
  119. */
  120. static int ioat_dca_add_requester(struct dca_provider *dca, struct device *dev)
  121. {
  122. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  123. struct pci_dev *pdev;
  124. int i;
  125. u16 id;
  126. /* This implementation only supports PCI-Express */
  127. if (dev->bus != &pci_bus_type)
  128. return -ENODEV;
  129. pdev = to_pci_dev(dev);
  130. id = dcaid_from_pcidev(pdev);
  131. if (ioatdca->requester_count == ioatdca->max_requesters)
  132. return -ENODEV;
  133. for (i = 0; i < ioatdca->max_requesters; i++) {
  134. if (ioatdca->req_slots[i].pdev == NULL) {
  135. /* found an empty slot */
  136. ioatdca->requester_count++;
  137. ioatdca->req_slots[i].pdev = pdev;
  138. ioatdca->req_slots[i].rid = id;
  139. writew(id, ioatdca->dca_base + (i * 4));
  140. /* make sure the ignore function bit is off */
  141. writeb(0, ioatdca->dca_base + (i * 4) + 2);
  142. return i;
  143. }
  144. }
  145. /* Error, ioatdma->requester_count is out of whack */
  146. return -EFAULT;
  147. }
  148. static int ioat_dca_remove_requester(struct dca_provider *dca,
  149. struct device *dev)
  150. {
  151. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  152. struct pci_dev *pdev;
  153. int i;
  154. /* This implementation only supports PCI-Express */
  155. if (dev->bus != &pci_bus_type)
  156. return -ENODEV;
  157. pdev = to_pci_dev(dev);
  158. for (i = 0; i < ioatdca->max_requesters; i++) {
  159. if (ioatdca->req_slots[i].pdev == pdev) {
  160. writew(0, ioatdca->dca_base + (i * 4));
  161. ioatdca->req_slots[i].pdev = NULL;
  162. ioatdca->req_slots[i].rid = 0;
  163. ioatdca->requester_count--;
  164. return i;
  165. }
  166. }
  167. return -ENODEV;
  168. }
  169. static u8 ioat_dca_get_tag(struct dca_provider *dca,
  170. struct device *dev,
  171. int cpu)
  172. {
  173. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  174. int i, apic_id, bit, value;
  175. u8 entry, tag;
  176. tag = 0;
  177. apic_id = cpu_physical_id(cpu);
  178. for (i = 0; i < IOAT_TAG_MAP_LEN; i++) {
  179. entry = ioatdca->tag_map[i];
  180. if (entry & DCA_TAG_MAP_VALID) {
  181. bit = entry & ~DCA_TAG_MAP_VALID;
  182. value = (apic_id & (1 << bit)) ? 1 : 0;
  183. } else {
  184. value = entry ? 1 : 0;
  185. }
  186. tag |= (value << i);
  187. }
  188. return tag;
  189. }
  190. static int ioat_dca_dev_managed(struct dca_provider *dca,
  191. struct device *dev)
  192. {
  193. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  194. struct pci_dev *pdev;
  195. int i;
  196. pdev = to_pci_dev(dev);
  197. for (i = 0; i < ioatdca->max_requesters; i++) {
  198. if (ioatdca->req_slots[i].pdev == pdev)
  199. return 1;
  200. }
  201. return 0;
  202. }
  203. static struct dca_ops ioat_dca_ops = {
  204. .add_requester = ioat_dca_add_requester,
  205. .remove_requester = ioat_dca_remove_requester,
  206. .get_tag = ioat_dca_get_tag,
  207. .dev_managed = ioat_dca_dev_managed,
  208. };
  209. struct dca_provider * __devinit
  210. ioat_dca_init(struct pci_dev *pdev, void __iomem *iobase)
  211. {
  212. struct dca_provider *dca;
  213. struct ioat_dca_priv *ioatdca;
  214. u8 *tag_map = NULL;
  215. int i;
  216. int err;
  217. u8 version;
  218. u8 max_requesters;
  219. if (!system_has_dca_enabled(pdev))
  220. return NULL;
  221. /* I/OAT v1 systems must have a known tag_map to support DCA */
  222. switch (pdev->vendor) {
  223. case PCI_VENDOR_ID_INTEL:
  224. switch (pdev->device) {
  225. case PCI_DEVICE_ID_INTEL_IOAT:
  226. tag_map = ioat_tag_map_BNB;
  227. break;
  228. case PCI_DEVICE_ID_INTEL_IOAT_CNB:
  229. tag_map = ioat_tag_map_CNB;
  230. break;
  231. case PCI_DEVICE_ID_INTEL_IOAT_SCNB:
  232. tag_map = ioat_tag_map_SCNB;
  233. break;
  234. }
  235. break;
  236. case PCI_VENDOR_ID_UNISYS:
  237. switch (pdev->device) {
  238. case PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR:
  239. tag_map = ioat_tag_map_UNISYS;
  240. break;
  241. }
  242. break;
  243. }
  244. if (tag_map == NULL)
  245. return NULL;
  246. version = readb(iobase + IOAT_VER_OFFSET);
  247. if (version == IOAT_VER_3_0)
  248. max_requesters = IOAT3_DCA_MAX_REQ;
  249. else
  250. max_requesters = IOAT_DCA_MAX_REQ;
  251. dca = alloc_dca_provider(&ioat_dca_ops,
  252. sizeof(*ioatdca) +
  253. (sizeof(struct ioat_dca_slot) * max_requesters));
  254. if (!dca)
  255. return NULL;
  256. ioatdca = dca_priv(dca);
  257. ioatdca->max_requesters = max_requesters;
  258. ioatdca->dca_base = iobase + 0x54;
  259. /* copy over the APIC ID to DCA tag mapping */
  260. for (i = 0; i < IOAT_TAG_MAP_LEN; i++)
  261. ioatdca->tag_map[i] = tag_map[i];
  262. err = register_dca_provider(dca, &pdev->dev);
  263. if (err) {
  264. free_dca_provider(dca);
  265. return NULL;
  266. }
  267. return dca;
  268. }
  269. static int ioat2_dca_add_requester(struct dca_provider *dca, struct device *dev)
  270. {
  271. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  272. struct pci_dev *pdev;
  273. int i;
  274. u16 id;
  275. u16 global_req_table;
  276. /* This implementation only supports PCI-Express */
  277. if (dev->bus != &pci_bus_type)
  278. return -ENODEV;
  279. pdev = to_pci_dev(dev);
  280. id = dcaid_from_pcidev(pdev);
  281. if (ioatdca->requester_count == ioatdca->max_requesters)
  282. return -ENODEV;
  283. for (i = 0; i < ioatdca->max_requesters; i++) {
  284. if (ioatdca->req_slots[i].pdev == NULL) {
  285. /* found an empty slot */
  286. ioatdca->requester_count++;
  287. ioatdca->req_slots[i].pdev = pdev;
  288. ioatdca->req_slots[i].rid = id;
  289. global_req_table =
  290. readw(ioatdca->dca_base + IOAT_DCA_GREQID_OFFSET);
  291. writel(id | IOAT_DCA_GREQID_VALID,
  292. ioatdca->iobase + global_req_table + (i * 4));
  293. return i;
  294. }
  295. }
  296. /* Error, ioatdma->requester_count is out of whack */
  297. return -EFAULT;
  298. }
  299. static int ioat2_dca_remove_requester(struct dca_provider *dca,
  300. struct device *dev)
  301. {
  302. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  303. struct pci_dev *pdev;
  304. int i;
  305. u16 global_req_table;
  306. /* This implementation only supports PCI-Express */
  307. if (dev->bus != &pci_bus_type)
  308. return -ENODEV;
  309. pdev = to_pci_dev(dev);
  310. for (i = 0; i < ioatdca->max_requesters; i++) {
  311. if (ioatdca->req_slots[i].pdev == pdev) {
  312. global_req_table =
  313. readw(ioatdca->dca_base + IOAT_DCA_GREQID_OFFSET);
  314. writel(0, ioatdca->iobase + global_req_table + (i * 4));
  315. ioatdca->req_slots[i].pdev = NULL;
  316. ioatdca->req_slots[i].rid = 0;
  317. ioatdca->requester_count--;
  318. return i;
  319. }
  320. }
  321. return -ENODEV;
  322. }
  323. static u8 ioat2_dca_get_tag(struct dca_provider *dca,
  324. struct device *dev,
  325. int cpu)
  326. {
  327. u8 tag;
  328. tag = ioat_dca_get_tag(dca, dev, cpu);
  329. tag = (~tag) & 0x1F;
  330. return tag;
  331. }
  332. static struct dca_ops ioat2_dca_ops = {
  333. .add_requester = ioat2_dca_add_requester,
  334. .remove_requester = ioat2_dca_remove_requester,
  335. .get_tag = ioat2_dca_get_tag,
  336. .dev_managed = ioat_dca_dev_managed,
  337. };
  338. static int ioat2_dca_count_dca_slots(void __iomem *iobase, u16 dca_offset)
  339. {
  340. int slots = 0;
  341. u32 req;
  342. u16 global_req_table;
  343. global_req_table = readw(iobase + dca_offset + IOAT_DCA_GREQID_OFFSET);
  344. if (global_req_table == 0)
  345. return 0;
  346. do {
  347. req = readl(iobase + global_req_table + (slots * sizeof(u32)));
  348. slots++;
  349. } while ((req & IOAT_DCA_GREQID_LASTID) == 0);
  350. return slots;
  351. }
  352. struct dca_provider * __devinit
  353. ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase)
  354. {
  355. struct dca_provider *dca;
  356. struct ioat_dca_priv *ioatdca;
  357. int slots;
  358. int i;
  359. int err;
  360. u32 tag_map;
  361. u16 dca_offset;
  362. u16 csi_fsb_control;
  363. u16 pcie_control;
  364. u8 bit;
  365. if (!system_has_dca_enabled(pdev))
  366. return NULL;
  367. dca_offset = readw(iobase + IOAT_DCAOFFSET_OFFSET);
  368. if (dca_offset == 0)
  369. return NULL;
  370. slots = ioat2_dca_count_dca_slots(iobase, dca_offset);
  371. if (slots == 0)
  372. return NULL;
  373. dca = alloc_dca_provider(&ioat2_dca_ops,
  374. sizeof(*ioatdca)
  375. + (sizeof(struct ioat_dca_slot) * slots));
  376. if (!dca)
  377. return NULL;
  378. ioatdca = dca_priv(dca);
  379. ioatdca->iobase = iobase;
  380. ioatdca->dca_base = iobase + dca_offset;
  381. ioatdca->max_requesters = slots;
  382. /* some bios might not know to turn these on */
  383. csi_fsb_control = readw(ioatdca->dca_base + IOAT_FSB_CAP_ENABLE_OFFSET);
  384. if ((csi_fsb_control & IOAT_FSB_CAP_ENABLE_PREFETCH) == 0) {
  385. csi_fsb_control |= IOAT_FSB_CAP_ENABLE_PREFETCH;
  386. writew(csi_fsb_control,
  387. ioatdca->dca_base + IOAT_FSB_CAP_ENABLE_OFFSET);
  388. }
  389. pcie_control = readw(ioatdca->dca_base + IOAT_PCI_CAP_ENABLE_OFFSET);
  390. if ((pcie_control & IOAT_PCI_CAP_ENABLE_MEMWR) == 0) {
  391. pcie_control |= IOAT_PCI_CAP_ENABLE_MEMWR;
  392. writew(pcie_control,
  393. ioatdca->dca_base + IOAT_PCI_CAP_ENABLE_OFFSET);
  394. }
  395. /* TODO version, compatibility and configuration checks */
  396. /* copy out the APIC to DCA tag map */
  397. tag_map = readl(ioatdca->dca_base + IOAT_APICID_TAG_MAP_OFFSET);
  398. for (i = 0; i < 5; i++) {
  399. bit = (tag_map >> (4 * i)) & 0x0f;
  400. if (bit < 8)
  401. ioatdca->tag_map[i] = bit | DCA_TAG_MAP_VALID;
  402. else
  403. ioatdca->tag_map[i] = 0;
  404. }
  405. if (!dca2_tag_map_valid(ioatdca->tag_map)) {
  406. dev_err(&pdev->dev, "APICID_TAG_MAP set incorrectly by BIOS, "
  407. "disabling DCA\n");
  408. free_dca_provider(dca);
  409. return NULL;
  410. }
  411. err = register_dca_provider(dca, &pdev->dev);
  412. if (err) {
  413. free_dca_provider(dca);
  414. return NULL;
  415. }
  416. return dca;
  417. }
  418. static int ioat3_dca_add_requester(struct dca_provider *dca, struct device *dev)
  419. {
  420. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  421. struct pci_dev *pdev;
  422. int i;
  423. u16 id;
  424. u16 global_req_table;
  425. /* This implementation only supports PCI-Express */
  426. if (dev->bus != &pci_bus_type)
  427. return -ENODEV;
  428. pdev = to_pci_dev(dev);
  429. id = dcaid_from_pcidev(pdev);
  430. if (ioatdca->requester_count == ioatdca->max_requesters)
  431. return -ENODEV;
  432. for (i = 0; i < ioatdca->max_requesters; i++) {
  433. if (ioatdca->req_slots[i].pdev == NULL) {
  434. /* found an empty slot */
  435. ioatdca->requester_count++;
  436. ioatdca->req_slots[i].pdev = pdev;
  437. ioatdca->req_slots[i].rid = id;
  438. global_req_table =
  439. readw(ioatdca->dca_base + IOAT3_DCA_GREQID_OFFSET);
  440. writel(id | IOAT_DCA_GREQID_VALID,
  441. ioatdca->iobase + global_req_table + (i * 4));
  442. return i;
  443. }
  444. }
  445. /* Error, ioatdma->requester_count is out of whack */
  446. return -EFAULT;
  447. }
  448. static int ioat3_dca_remove_requester(struct dca_provider *dca,
  449. struct device *dev)
  450. {
  451. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  452. struct pci_dev *pdev;
  453. int i;
  454. u16 global_req_table;
  455. /* This implementation only supports PCI-Express */
  456. if (dev->bus != &pci_bus_type)
  457. return -ENODEV;
  458. pdev = to_pci_dev(dev);
  459. for (i = 0; i < ioatdca->max_requesters; i++) {
  460. if (ioatdca->req_slots[i].pdev == pdev) {
  461. global_req_table =
  462. readw(ioatdca->dca_base + IOAT3_DCA_GREQID_OFFSET);
  463. writel(0, ioatdca->iobase + global_req_table + (i * 4));
  464. ioatdca->req_slots[i].pdev = NULL;
  465. ioatdca->req_slots[i].rid = 0;
  466. ioatdca->requester_count--;
  467. return i;
  468. }
  469. }
  470. return -ENODEV;
  471. }
  472. static u8 ioat3_dca_get_tag(struct dca_provider *dca,
  473. struct device *dev,
  474. int cpu)
  475. {
  476. u8 tag;
  477. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  478. int i, apic_id, bit, value;
  479. u8 entry;
  480. tag = 0;
  481. apic_id = cpu_physical_id(cpu);
  482. for (i = 0; i < IOAT_TAG_MAP_LEN; i++) {
  483. entry = ioatdca->tag_map[i];
  484. if (entry & DCA3_TAG_MAP_BIT_TO_SEL) {
  485. bit = entry &
  486. ~(DCA3_TAG_MAP_BIT_TO_SEL | DCA3_TAG_MAP_BIT_TO_INV);
  487. value = (apic_id & (1 << bit)) ? 1 : 0;
  488. } else if (entry & DCA3_TAG_MAP_BIT_TO_INV) {
  489. bit = entry & ~DCA3_TAG_MAP_BIT_TO_INV;
  490. value = (apic_id & (1 << bit)) ? 0 : 1;
  491. } else {
  492. value = (entry & DCA3_TAG_MAP_LITERAL_VAL) ? 1 : 0;
  493. }
  494. tag |= (value << i);
  495. }
  496. return tag;
  497. }
  498. static struct dca_ops ioat3_dca_ops = {
  499. .add_requester = ioat3_dca_add_requester,
  500. .remove_requester = ioat3_dca_remove_requester,
  501. .get_tag = ioat3_dca_get_tag,
  502. .dev_managed = ioat_dca_dev_managed,
  503. };
  504. static int ioat3_dca_count_dca_slots(void *iobase, u16 dca_offset)
  505. {
  506. int slots = 0;
  507. u32 req;
  508. u16 global_req_table;
  509. global_req_table = readw(iobase + dca_offset + IOAT3_DCA_GREQID_OFFSET);
  510. if (global_req_table == 0)
  511. return 0;
  512. do {
  513. req = readl(iobase + global_req_table + (slots * sizeof(u32)));
  514. slots++;
  515. } while ((req & IOAT_DCA_GREQID_LASTID) == 0);
  516. return slots;
  517. }
  518. struct dca_provider * __devinit
  519. ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase)
  520. {
  521. struct dca_provider *dca;
  522. struct ioat_dca_priv *ioatdca;
  523. int slots;
  524. int i;
  525. int err;
  526. u16 dca_offset;
  527. u16 csi_fsb_control;
  528. u16 pcie_control;
  529. u8 bit;
  530. union {
  531. u64 full;
  532. struct {
  533. u32 low;
  534. u32 high;
  535. };
  536. } tag_map;
  537. if (!system_has_dca_enabled(pdev))
  538. return NULL;
  539. dca_offset = readw(iobase + IOAT_DCAOFFSET_OFFSET);
  540. if (dca_offset == 0)
  541. return NULL;
  542. slots = ioat3_dca_count_dca_slots(iobase, dca_offset);
  543. if (slots == 0)
  544. return NULL;
  545. dca = alloc_dca_provider(&ioat3_dca_ops,
  546. sizeof(*ioatdca)
  547. + (sizeof(struct ioat_dca_slot) * slots));
  548. if (!dca)
  549. return NULL;
  550. ioatdca = dca_priv(dca);
  551. ioatdca->iobase = iobase;
  552. ioatdca->dca_base = iobase + dca_offset;
  553. ioatdca->max_requesters = slots;
  554. /* some bios might not know to turn these on */
  555. csi_fsb_control = readw(ioatdca->dca_base + IOAT3_CSI_CONTROL_OFFSET);
  556. if ((csi_fsb_control & IOAT3_CSI_CONTROL_PREFETCH) == 0) {
  557. csi_fsb_control |= IOAT3_CSI_CONTROL_PREFETCH;
  558. writew(csi_fsb_control,
  559. ioatdca->dca_base + IOAT3_CSI_CONTROL_OFFSET);
  560. }
  561. pcie_control = readw(ioatdca->dca_base + IOAT3_PCI_CONTROL_OFFSET);
  562. if ((pcie_control & IOAT3_PCI_CONTROL_MEMWR) == 0) {
  563. pcie_control |= IOAT3_PCI_CONTROL_MEMWR;
  564. writew(pcie_control,
  565. ioatdca->dca_base + IOAT3_PCI_CONTROL_OFFSET);
  566. }
  567. /* TODO version, compatibility and configuration checks */
  568. /* copy out the APIC to DCA tag map */
  569. tag_map.low =
  570. readl(ioatdca->dca_base + IOAT3_APICID_TAG_MAP_OFFSET_LOW);
  571. tag_map.high =
  572. readl(ioatdca->dca_base + IOAT3_APICID_TAG_MAP_OFFSET_HIGH);
  573. for (i = 0; i < 8; i++) {
  574. bit = tag_map.full >> (8 * i);
  575. ioatdca->tag_map[i] = bit & DCA_TAG_MAP_MASK;
  576. }
  577. err = register_dca_provider(dca, &pdev->dev);
  578. if (err) {
  579. free_dca_provider(dca);
  580. return NULL;
  581. }
  582. return dca;
  583. }