ioat_dca.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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 "ioatdma.h"
  34. #include "ioatdma_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_err(&pdev->dev, "DCA is disabled in BIOS\n");
  88. return res;
  89. }
  90. static 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_err(&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 *ioat_dca_init(struct pci_dev *pdev, void __iomem *iobase)
  210. {
  211. struct dca_provider *dca;
  212. struct ioat_dca_priv *ioatdca;
  213. u8 *tag_map = NULL;
  214. int i;
  215. int err;
  216. u8 version;
  217. u8 max_requesters;
  218. if (!system_has_dca_enabled(pdev))
  219. return NULL;
  220. /* I/OAT v1 systems must have a known tag_map to support DCA */
  221. switch (pdev->vendor) {
  222. case PCI_VENDOR_ID_INTEL:
  223. switch (pdev->device) {
  224. case PCI_DEVICE_ID_INTEL_IOAT:
  225. tag_map = ioat_tag_map_BNB;
  226. break;
  227. case PCI_DEVICE_ID_INTEL_IOAT_CNB:
  228. tag_map = ioat_tag_map_CNB;
  229. break;
  230. case PCI_DEVICE_ID_INTEL_IOAT_SCNB:
  231. tag_map = ioat_tag_map_SCNB;
  232. break;
  233. }
  234. break;
  235. case PCI_VENDOR_ID_UNISYS:
  236. switch (pdev->device) {
  237. case PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR:
  238. tag_map = ioat_tag_map_UNISYS;
  239. break;
  240. }
  241. break;
  242. }
  243. if (tag_map == NULL)
  244. return NULL;
  245. version = readb(iobase + IOAT_VER_OFFSET);
  246. if (version == IOAT_VER_3_0)
  247. max_requesters = IOAT3_DCA_MAX_REQ;
  248. else
  249. max_requesters = IOAT_DCA_MAX_REQ;
  250. dca = alloc_dca_provider(&ioat_dca_ops,
  251. sizeof(*ioatdca) +
  252. (sizeof(struct ioat_dca_slot) * max_requesters));
  253. if (!dca)
  254. return NULL;
  255. ioatdca = dca_priv(dca);
  256. ioatdca->max_requesters = max_requesters;
  257. ioatdca->dca_base = iobase + 0x54;
  258. /* copy over the APIC ID to DCA tag mapping */
  259. for (i = 0; i < IOAT_TAG_MAP_LEN; i++)
  260. ioatdca->tag_map[i] = tag_map[i];
  261. err = register_dca_provider(dca, &pdev->dev);
  262. if (err) {
  263. free_dca_provider(dca);
  264. return NULL;
  265. }
  266. return dca;
  267. }
  268. static int ioat2_dca_add_requester(struct dca_provider *dca, struct device *dev)
  269. {
  270. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  271. struct pci_dev *pdev;
  272. int i;
  273. u16 id;
  274. u16 global_req_table;
  275. /* This implementation only supports PCI-Express */
  276. if (dev->bus != &pci_bus_type)
  277. return -ENODEV;
  278. pdev = to_pci_dev(dev);
  279. id = dcaid_from_pcidev(pdev);
  280. if (ioatdca->requester_count == ioatdca->max_requesters)
  281. return -ENODEV;
  282. for (i = 0; i < ioatdca->max_requesters; i++) {
  283. if (ioatdca->req_slots[i].pdev == NULL) {
  284. /* found an empty slot */
  285. ioatdca->requester_count++;
  286. ioatdca->req_slots[i].pdev = pdev;
  287. ioatdca->req_slots[i].rid = id;
  288. global_req_table =
  289. readw(ioatdca->dca_base + IOAT_DCA_GREQID_OFFSET);
  290. writel(id | IOAT_DCA_GREQID_VALID,
  291. ioatdca->iobase + global_req_table + (i * 4));
  292. return i;
  293. }
  294. }
  295. /* Error, ioatdma->requester_count is out of whack */
  296. return -EFAULT;
  297. }
  298. static int ioat2_dca_remove_requester(struct dca_provider *dca,
  299. struct device *dev)
  300. {
  301. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  302. struct pci_dev *pdev;
  303. int i;
  304. u16 global_req_table;
  305. /* This implementation only supports PCI-Express */
  306. if (dev->bus != &pci_bus_type)
  307. return -ENODEV;
  308. pdev = to_pci_dev(dev);
  309. for (i = 0; i < ioatdca->max_requesters; i++) {
  310. if (ioatdca->req_slots[i].pdev == pdev) {
  311. global_req_table =
  312. readw(ioatdca->dca_base + IOAT_DCA_GREQID_OFFSET);
  313. writel(0, ioatdca->iobase + global_req_table + (i * 4));
  314. ioatdca->req_slots[i].pdev = NULL;
  315. ioatdca->req_slots[i].rid = 0;
  316. ioatdca->requester_count--;
  317. return i;
  318. }
  319. }
  320. return -ENODEV;
  321. }
  322. static u8 ioat2_dca_get_tag(struct dca_provider *dca,
  323. struct device *dev,
  324. int cpu)
  325. {
  326. u8 tag;
  327. tag = ioat_dca_get_tag(dca, dev, cpu);
  328. tag = (~tag) & 0x1F;
  329. return tag;
  330. }
  331. static struct dca_ops ioat2_dca_ops = {
  332. .add_requester = ioat2_dca_add_requester,
  333. .remove_requester = ioat2_dca_remove_requester,
  334. .get_tag = ioat2_dca_get_tag,
  335. .dev_managed = ioat_dca_dev_managed,
  336. };
  337. static int ioat2_dca_count_dca_slots(void __iomem *iobase, u16 dca_offset)
  338. {
  339. int slots = 0;
  340. u32 req;
  341. u16 global_req_table;
  342. global_req_table = readw(iobase + dca_offset + IOAT_DCA_GREQID_OFFSET);
  343. if (global_req_table == 0)
  344. return 0;
  345. do {
  346. req = readl(iobase + global_req_table + (slots * sizeof(u32)));
  347. slots++;
  348. } while ((req & IOAT_DCA_GREQID_LASTID) == 0);
  349. return slots;
  350. }
  351. struct dca_provider *ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase)
  352. {
  353. struct dca_provider *dca;
  354. struct ioat_dca_priv *ioatdca;
  355. int slots;
  356. int i;
  357. int err;
  358. u32 tag_map;
  359. u16 dca_offset;
  360. u16 csi_fsb_control;
  361. u16 pcie_control;
  362. u8 bit;
  363. if (!system_has_dca_enabled(pdev))
  364. return NULL;
  365. dca_offset = readw(iobase + IOAT_DCAOFFSET_OFFSET);
  366. if (dca_offset == 0)
  367. return NULL;
  368. slots = ioat2_dca_count_dca_slots(iobase, dca_offset);
  369. if (slots == 0)
  370. return NULL;
  371. dca = alloc_dca_provider(&ioat2_dca_ops,
  372. sizeof(*ioatdca)
  373. + (sizeof(struct ioat_dca_slot) * slots));
  374. if (!dca)
  375. return NULL;
  376. ioatdca = dca_priv(dca);
  377. ioatdca->iobase = iobase;
  378. ioatdca->dca_base = iobase + dca_offset;
  379. ioatdca->max_requesters = slots;
  380. /* some bios might not know to turn these on */
  381. csi_fsb_control = readw(ioatdca->dca_base + IOAT_FSB_CAP_ENABLE_OFFSET);
  382. if ((csi_fsb_control & IOAT_FSB_CAP_ENABLE_PREFETCH) == 0) {
  383. csi_fsb_control |= IOAT_FSB_CAP_ENABLE_PREFETCH;
  384. writew(csi_fsb_control,
  385. ioatdca->dca_base + IOAT_FSB_CAP_ENABLE_OFFSET);
  386. }
  387. pcie_control = readw(ioatdca->dca_base + IOAT_PCI_CAP_ENABLE_OFFSET);
  388. if ((pcie_control & IOAT_PCI_CAP_ENABLE_MEMWR) == 0) {
  389. pcie_control |= IOAT_PCI_CAP_ENABLE_MEMWR;
  390. writew(pcie_control,
  391. ioatdca->dca_base + IOAT_PCI_CAP_ENABLE_OFFSET);
  392. }
  393. /* TODO version, compatibility and configuration checks */
  394. /* copy out the APIC to DCA tag map */
  395. tag_map = readl(ioatdca->dca_base + IOAT_APICID_TAG_MAP_OFFSET);
  396. for (i = 0; i < 5; i++) {
  397. bit = (tag_map >> (4 * i)) & 0x0f;
  398. if (bit < 8)
  399. ioatdca->tag_map[i] = bit | DCA_TAG_MAP_VALID;
  400. else
  401. ioatdca->tag_map[i] = 0;
  402. }
  403. if (!dca2_tag_map_valid(ioatdca->tag_map)) {
  404. dev_err(&pdev->dev, "APICID_TAG_MAP set incorrectly by BIOS, "
  405. "disabling DCA\n");
  406. free_dca_provider(dca);
  407. return NULL;
  408. }
  409. err = register_dca_provider(dca, &pdev->dev);
  410. if (err) {
  411. free_dca_provider(dca);
  412. return NULL;
  413. }
  414. return dca;
  415. }
  416. static int ioat3_dca_add_requester(struct dca_provider *dca, struct device *dev)
  417. {
  418. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  419. struct pci_dev *pdev;
  420. int i;
  421. u16 id;
  422. u16 global_req_table;
  423. /* This implementation only supports PCI-Express */
  424. if (dev->bus != &pci_bus_type)
  425. return -ENODEV;
  426. pdev = to_pci_dev(dev);
  427. id = dcaid_from_pcidev(pdev);
  428. if (ioatdca->requester_count == ioatdca->max_requesters)
  429. return -ENODEV;
  430. for (i = 0; i < ioatdca->max_requesters; i++) {
  431. if (ioatdca->req_slots[i].pdev == NULL) {
  432. /* found an empty slot */
  433. ioatdca->requester_count++;
  434. ioatdca->req_slots[i].pdev = pdev;
  435. ioatdca->req_slots[i].rid = id;
  436. global_req_table =
  437. readw(ioatdca->dca_base + IOAT3_DCA_GREQID_OFFSET);
  438. writel(id | IOAT_DCA_GREQID_VALID,
  439. ioatdca->iobase + global_req_table + (i * 4));
  440. return i;
  441. }
  442. }
  443. /* Error, ioatdma->requester_count is out of whack */
  444. return -EFAULT;
  445. }
  446. static int ioat3_dca_remove_requester(struct dca_provider *dca,
  447. struct device *dev)
  448. {
  449. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  450. struct pci_dev *pdev;
  451. int i;
  452. u16 global_req_table;
  453. /* This implementation only supports PCI-Express */
  454. if (dev->bus != &pci_bus_type)
  455. return -ENODEV;
  456. pdev = to_pci_dev(dev);
  457. for (i = 0; i < ioatdca->max_requesters; i++) {
  458. if (ioatdca->req_slots[i].pdev == pdev) {
  459. global_req_table =
  460. readw(ioatdca->dca_base + IOAT3_DCA_GREQID_OFFSET);
  461. writel(0, ioatdca->iobase + global_req_table + (i * 4));
  462. ioatdca->req_slots[i].pdev = NULL;
  463. ioatdca->req_slots[i].rid = 0;
  464. ioatdca->requester_count--;
  465. return i;
  466. }
  467. }
  468. return -ENODEV;
  469. }
  470. static u8 ioat3_dca_get_tag(struct dca_provider *dca,
  471. struct device *dev,
  472. int cpu)
  473. {
  474. u8 tag;
  475. struct ioat_dca_priv *ioatdca = dca_priv(dca);
  476. int i, apic_id, bit, value;
  477. u8 entry;
  478. tag = 0;
  479. apic_id = cpu_physical_id(cpu);
  480. for (i = 0; i < IOAT_TAG_MAP_LEN; i++) {
  481. entry = ioatdca->tag_map[i];
  482. if (entry & DCA3_TAG_MAP_BIT_TO_SEL) {
  483. bit = entry &
  484. ~(DCA3_TAG_MAP_BIT_TO_SEL | DCA3_TAG_MAP_BIT_TO_INV);
  485. value = (apic_id & (1 << bit)) ? 1 : 0;
  486. } else if (entry & DCA3_TAG_MAP_BIT_TO_INV) {
  487. bit = entry & ~DCA3_TAG_MAP_BIT_TO_INV;
  488. value = (apic_id & (1 << bit)) ? 0 : 1;
  489. } else {
  490. value = (entry & DCA3_TAG_MAP_LITERAL_VAL) ? 1 : 0;
  491. }
  492. tag |= (value << i);
  493. }
  494. return tag;
  495. }
  496. static struct dca_ops ioat3_dca_ops = {
  497. .add_requester = ioat3_dca_add_requester,
  498. .remove_requester = ioat3_dca_remove_requester,
  499. .get_tag = ioat3_dca_get_tag,
  500. .dev_managed = ioat_dca_dev_managed,
  501. };
  502. static int ioat3_dca_count_dca_slots(void *iobase, u16 dca_offset)
  503. {
  504. int slots = 0;
  505. u32 req;
  506. u16 global_req_table;
  507. global_req_table = readw(iobase + dca_offset + IOAT3_DCA_GREQID_OFFSET);
  508. if (global_req_table == 0)
  509. return 0;
  510. do {
  511. req = readl(iobase + global_req_table + (slots * sizeof(u32)));
  512. slots++;
  513. } while ((req & IOAT_DCA_GREQID_LASTID) == 0);
  514. return slots;
  515. }
  516. struct dca_provider *ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase)
  517. {
  518. struct dca_provider *dca;
  519. struct ioat_dca_priv *ioatdca;
  520. int slots;
  521. int i;
  522. int err;
  523. u16 dca_offset;
  524. u16 csi_fsb_control;
  525. u16 pcie_control;
  526. u8 bit;
  527. union {
  528. u64 full;
  529. struct {
  530. u32 low;
  531. u32 high;
  532. };
  533. } tag_map;
  534. if (!system_has_dca_enabled(pdev))
  535. return NULL;
  536. dca_offset = readw(iobase + IOAT_DCAOFFSET_OFFSET);
  537. if (dca_offset == 0)
  538. return NULL;
  539. slots = ioat3_dca_count_dca_slots(iobase, dca_offset);
  540. if (slots == 0)
  541. return NULL;
  542. dca = alloc_dca_provider(&ioat3_dca_ops,
  543. sizeof(*ioatdca)
  544. + (sizeof(struct ioat_dca_slot) * slots));
  545. if (!dca)
  546. return NULL;
  547. ioatdca = dca_priv(dca);
  548. ioatdca->iobase = iobase;
  549. ioatdca->dca_base = iobase + dca_offset;
  550. ioatdca->max_requesters = slots;
  551. /* some bios might not know to turn these on */
  552. csi_fsb_control = readw(ioatdca->dca_base + IOAT3_CSI_CONTROL_OFFSET);
  553. if ((csi_fsb_control & IOAT3_CSI_CONTROL_PREFETCH) == 0) {
  554. csi_fsb_control |= IOAT3_CSI_CONTROL_PREFETCH;
  555. writew(csi_fsb_control,
  556. ioatdca->dca_base + IOAT3_CSI_CONTROL_OFFSET);
  557. }
  558. pcie_control = readw(ioatdca->dca_base + IOAT3_PCI_CONTROL_OFFSET);
  559. if ((pcie_control & IOAT3_PCI_CONTROL_MEMWR) == 0) {
  560. pcie_control |= IOAT3_PCI_CONTROL_MEMWR;
  561. writew(pcie_control,
  562. ioatdca->dca_base + IOAT3_PCI_CONTROL_OFFSET);
  563. }
  564. /* TODO version, compatibility and configuration checks */
  565. /* copy out the APIC to DCA tag map */
  566. tag_map.low =
  567. readl(ioatdca->dca_base + IOAT3_APICID_TAG_MAP_OFFSET_LOW);
  568. tag_map.high =
  569. readl(ioatdca->dca_base + IOAT3_APICID_TAG_MAP_OFFSET_HIGH);
  570. for (i = 0; i < 8; i++) {
  571. bit = tag_map.full >> (8 * i);
  572. ioatdca->tag_map[i] = bit & DCA_TAG_MAP_MASK;
  573. }
  574. err = register_dca_provider(dca, &pdev->dev);
  575. if (err) {
  576. free_dca_provider(dca);
  577. return NULL;
  578. }
  579. return dca;
  580. }