23 #include <linux/kernel.h>
24 #include <linux/pci.h>
32 #undef cpu_physical_id
33 #define cpu_physical_id(cpu) (cpuid_ebx(1) >> 24)
44 #define DCA_TAG_MAP_VALID 0x80
46 #define DCA3_TAG_MAP_BIT_TO_INV 0x80
47 #define DCA3_TAG_MAP_BIT_TO_SEL 0x40
48 #define DCA3_TAG_MAP_LITERAL_VAL 0x1
50 #define DCA_TAG_MAP_MASK 0xDF
53 #define DCA2_TAG_MAP_BYTE0 0x80
54 #define DCA2_TAG_MAP_BYTE1 0x0
55 #define DCA2_TAG_MAP_BYTE2 0x81
56 #define DCA2_TAG_MAP_BYTE3 0x82
57 #define DCA2_TAG_MAP_BYTE4 0x82
60 static inline int dca2_tag_map_valid(
u8 *tag_map)
74 #define APICID_BIT(x) (DCA_TAG_MAP_VALID | (x))
75 #define IOAT_TAG_MAP_LEN 8
86 static inline u16 dcaid_from_pcidev(
struct pci_dev *pci)
88 return (pci->
bus->number << 8) | pci->
devfn;
91 static int dca_enabled_in_bios(
struct pci_dev *pdev)
95 unsigned long cpuid_level_9;
98 cpuid_level_9 = cpuid_eax(9);
101 dev_dbg(&pdev->
dev,
"DCA is disabled in BIOS\n");
109 return dca_enabled_in_bios(pdev);
111 dev_dbg(&pdev->
dev,
"boot cpu doesn't have X86_FEATURE_DCA\n");
120 #define IOAT_DCA_MAX_REQ 6
121 #define IOAT3_DCA_MAX_REQ 2
153 id = dcaid_from_pcidev(pdev);
174 static int ioat_dca_remove_requester(
struct dca_provider *dca,
187 if (ioatdca->
req_slots[i].pdev == pdev) {
212 bit = entry & ~DCA_TAG_MAP_VALID;
213 value = (apic_id & (1 <<
bit)) ? 1 : 0;
215 value = entry ? 1 : 0;
222 static int ioat_dca_dev_managed(
struct dca_provider *dca,
237 static struct dca_ops ioat_dca_ops = {
238 .add_requester = ioat_dca_add_requester,
239 .remove_requester = ioat_dca_remove_requester,
240 .get_tag = ioat_dca_get_tag,
241 .dev_managed = ioat_dca_dev_managed,
264 tag_map = ioat_tag_map_BNB;
267 tag_map = ioat_tag_map_CNB;
270 tag_map = ioat_tag_map_SCNB;
277 tag_map = ioat_tag_map_UNISYS;
297 ioatdca = dca_priv(dca);
303 ioatdca->
tag_map[i] = tag_map[i];
321 u16 global_req_table;
327 id = dcaid_from_pcidev(pdev);
341 ioatdca->
iobase + global_req_table + (i * 4));
349 static int ioat2_dca_remove_requester(
struct dca_provider *dca,
355 u16 global_req_table;
363 if (ioatdca->
req_slots[i].pdev == pdev) {
366 writel(0, ioatdca->
iobase + global_req_table + (i * 4));
382 tag = ioat_dca_get_tag(dca, dev, cpu);
387 static struct dca_ops ioat2_dca_ops = {
388 .add_requester = ioat2_dca_add_requester,
389 .remove_requester = ioat2_dca_remove_requester,
390 .get_tag = ioat2_dca_get_tag,
391 .dev_managed = ioat_dca_dev_managed,
398 u16 global_req_table;
401 if (global_req_table == 0)
404 req =
readl(iobase + global_req_table + (slots *
sizeof(
u32)));
432 slots = ioat2_dca_count_dca_slots(iobase, dca_offset);
442 ioatdca = dca_priv(dca);
444 ioatdca->
dca_base = iobase + dca_offset;
466 for (i = 0; i < 5; i++) {
467 bit = (tag_map >> (4 *
i)) & 0x0f;
474 if (!dca2_tag_map_valid(ioatdca->
tag_map)) {
475 dev_err(&pdev->
dev,
"APICID_TAG_MAP set incorrectly by BIOS, "
496 u16 global_req_table;
502 id = dcaid_from_pcidev(pdev);
516 ioatdca->
iobase + global_req_table + (i * 4));
524 static int ioat3_dca_remove_requester(
struct dca_provider *dca,
530 u16 global_req_table;
538 if (ioatdca->
req_slots[i].pdev == pdev) {
541 writel(0, ioatdca->
iobase + global_req_table + (i * 4));
569 value = (apic_id & (1 <<
bit)) ? 1 : 0;
571 bit = entry & ~DCA3_TAG_MAP_BIT_TO_INV;
572 value = (apic_id & (1 <<
bit)) ? 0 : 1;
582 static struct dca_ops ioat3_dca_ops = {
583 .add_requester = ioat3_dca_add_requester,
584 .remove_requester = ioat3_dca_remove_requester,
585 .get_tag = ioat3_dca_get_tag,
586 .dev_managed = ioat_dca_dev_managed,
589 static int ioat3_dca_count_dca_slots(
void *iobase,
u16 dca_offset)
593 u16 global_req_table;
596 if (global_req_table == 0)
600 req =
readl(iobase + global_req_table + (slots *
sizeof(
u32)));
635 slots = ioat3_dca_count_dca_slots(iobase, dca_offset);
645 ioatdca = dca_priv(dca);
647 ioatdca->
dca_base = iobase + dca_offset;
672 for (i = 0; i < 8; i++) {
673 bit = tag_map.full >> (8 *
i);