aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/edac
diff options
context:
space:
mode:
authorChen, Gong <gong.chen@linux.intel.com>2013-10-18 17:29:07 -0400
committerTony Luck <tony.luck@intel.com>2013-10-21 18:12:01 -0400
commit10ef6b0dffe404bcc54e94cb2ca1a5b18445a66b (patch)
tree6450859ffdc4494f2211442dd411b7f189cf326d /drivers/edac
parent88f074f4871a8c212b212b725e4dcdcdb09613c1 (diff)
bitops: Introduce a more generic BITMASK macro
GENMASK is used to create a contiguous bitmask([hi:lo]). It is implemented twice in current kernel. One is in EDAC driver, the other is in SiS/XGI FB driver. Move it to a more generic place for other usage. Signed-off-by: Chen, Gong <gong.chen@linux.intel.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Thomas Winischhofer <thomas@winischhofer.net> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com> Acked-by: Borislav Petkov <bp@suse.de> Acked-by: Mauro Carvalho Chehab <m.chehab@samsung.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'drivers/edac')
-rw-r--r--drivers/edac/amd64_edac.c46
-rw-r--r--drivers/edac/amd64_edac.h8
-rw-r--r--drivers/edac/sb_edac.c2
3 files changed, 25 insertions, 31 deletions
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index 3c9e4e98c651..b53d0de17e15 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -339,8 +339,8 @@ static void get_cs_base_and_mask(struct amd64_pvt *pvt, int csrow, u8 dct,
339 if (pvt->fam == 0xf && pvt->ext_model < K8_REV_F) { 339 if (pvt->fam == 0xf && pvt->ext_model < K8_REV_F) {
340 csbase = pvt->csels[dct].csbases[csrow]; 340 csbase = pvt->csels[dct].csbases[csrow];
341 csmask = pvt->csels[dct].csmasks[csrow]; 341 csmask = pvt->csels[dct].csmasks[csrow];
342 base_bits = GENMASK(21, 31) | GENMASK(9, 15); 342 base_bits = GENMASK_ULL(31, 21) | GENMASK_ULL(15, 9);
343 mask_bits = GENMASK(21, 29) | GENMASK(9, 15); 343 mask_bits = GENMASK_ULL(29, 21) | GENMASK_ULL(15, 9);
344 addr_shift = 4; 344 addr_shift = 4;
345 345
346 /* 346 /*
@@ -352,16 +352,16 @@ static void get_cs_base_and_mask(struct amd64_pvt *pvt, int csrow, u8 dct,
352 csbase = pvt->csels[dct].csbases[csrow]; 352 csbase = pvt->csels[dct].csbases[csrow];
353 csmask = pvt->csels[dct].csmasks[csrow >> 1]; 353 csmask = pvt->csels[dct].csmasks[csrow >> 1];
354 354
355 *base = (csbase & GENMASK(5, 15)) << 6; 355 *base = (csbase & GENMASK_ULL(15, 5)) << 6;
356 *base |= (csbase & GENMASK(19, 30)) << 8; 356 *base |= (csbase & GENMASK_ULL(30, 19)) << 8;
357 357
358 *mask = ~0ULL; 358 *mask = ~0ULL;
359 /* poke holes for the csmask */ 359 /* poke holes for the csmask */
360 *mask &= ~((GENMASK(5, 15) << 6) | 360 *mask &= ~((GENMASK_ULL(15, 5) << 6) |
361 (GENMASK(19, 30) << 8)); 361 (GENMASK_ULL(30, 19) << 8));
362 362
363 *mask |= (csmask & GENMASK(5, 15)) << 6; 363 *mask |= (csmask & GENMASK_ULL(15, 5)) << 6;
364 *mask |= (csmask & GENMASK(19, 30)) << 8; 364 *mask |= (csmask & GENMASK_ULL(30, 19)) << 8;
365 365
366 return; 366 return;
367 } else { 367 } else {
@@ -370,9 +370,11 @@ static void get_cs_base_and_mask(struct amd64_pvt *pvt, int csrow, u8 dct,
370 addr_shift = 8; 370 addr_shift = 8;
371 371
372 if (pvt->fam == 0x15) 372 if (pvt->fam == 0x15)
373 base_bits = mask_bits = GENMASK(19,30) | GENMASK(5,13); 373 base_bits = mask_bits =
374 GENMASK_ULL(30,19) | GENMASK_ULL(13,5);
374 else 375 else
375 base_bits = mask_bits = GENMASK(19,28) | GENMASK(5,13); 376 base_bits = mask_bits =
377 GENMASK_ULL(28,19) | GENMASK_ULL(13,5);
376 } 378 }
377 379
378 *base = (csbase & base_bits) << addr_shift; 380 *base = (csbase & base_bits) << addr_shift;
@@ -561,7 +563,7 @@ static u64 sys_addr_to_dram_addr(struct mem_ctl_info *mci, u64 sys_addr)
561 * section 3.4.2 of AMD publication 24592: AMD x86-64 Architecture 563 * section 3.4.2 of AMD publication 24592: AMD x86-64 Architecture
562 * Programmer's Manual Volume 1 Application Programming. 564 * Programmer's Manual Volume 1 Application Programming.
563 */ 565 */
564 dram_addr = (sys_addr & GENMASK(0, 39)) - dram_base; 566 dram_addr = (sys_addr & GENMASK_ULL(39, 0)) - dram_base;
565 567
566 edac_dbg(2, "using DRAM Base register to translate SysAddr 0x%lx to DramAddr 0x%lx\n", 568 edac_dbg(2, "using DRAM Base register to translate SysAddr 0x%lx to DramAddr 0x%lx\n",
567 (unsigned long)sys_addr, (unsigned long)dram_addr); 569 (unsigned long)sys_addr, (unsigned long)dram_addr);
@@ -597,7 +599,7 @@ static u64 dram_addr_to_input_addr(struct mem_ctl_info *mci, u64 dram_addr)
597 * concerning translating a DramAddr to an InputAddr. 599 * concerning translating a DramAddr to an InputAddr.
598 */ 600 */
599 intlv_shift = num_node_interleave_bits(dram_intlv_en(pvt, 0)); 601 intlv_shift = num_node_interleave_bits(dram_intlv_en(pvt, 0));
600 input_addr = ((dram_addr >> intlv_shift) & GENMASK(12, 35)) + 602 input_addr = ((dram_addr >> intlv_shift) & GENMASK_ULL(35, 12)) +
601 (dram_addr & 0xfff); 603 (dram_addr & 0xfff);
602 604
603 edac_dbg(2, " Intlv Shift=%d DramAddr=0x%lx maps to InputAddr=0x%lx\n", 605 edac_dbg(2, " Intlv Shift=%d DramAddr=0x%lx maps to InputAddr=0x%lx\n",
@@ -849,7 +851,7 @@ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m)
849 end_bit = 39; 851 end_bit = 39;
850 } 852 }
851 853
852 addr = m->addr & GENMASK(start_bit, end_bit); 854 addr = m->addr & GENMASK_ULL(end_bit, start_bit);
853 855
854 /* 856 /*
855 * Erratum 637 workaround 857 * Erratum 637 workaround
@@ -861,7 +863,7 @@ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m)
861 u16 mce_nid; 863 u16 mce_nid;
862 u8 intlv_en; 864 u8 intlv_en;
863 865
864 if ((addr & GENMASK(24, 47)) >> 24 != 0x00fdf7) 866 if ((addr & GENMASK_ULL(47, 24)) >> 24 != 0x00fdf7)
865 return addr; 867 return addr;
866 868
867 mce_nid = amd_get_nb_id(m->extcpu); 869 mce_nid = amd_get_nb_id(m->extcpu);
@@ -871,7 +873,7 @@ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m)
871 intlv_en = tmp >> 21 & 0x7; 873 intlv_en = tmp >> 21 & 0x7;
872 874
873 /* add [47:27] + 3 trailing bits */ 875 /* add [47:27] + 3 trailing bits */
874 cc6_base = (tmp & GENMASK(0, 20)) << 3; 876 cc6_base = (tmp & GENMASK_ULL(20, 0)) << 3;
875 877
876 /* reverse and add DramIntlvEn */ 878 /* reverse and add DramIntlvEn */
877 cc6_base |= intlv_en ^ 0x7; 879 cc6_base |= intlv_en ^ 0x7;
@@ -880,18 +882,18 @@ static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m)
880 cc6_base <<= 24; 882 cc6_base <<= 24;
881 883
882 if (!intlv_en) 884 if (!intlv_en)
883 return cc6_base | (addr & GENMASK(0, 23)); 885 return cc6_base | (addr & GENMASK_ULL(23, 0));
884 886
885 amd64_read_pci_cfg(pvt->F1, DRAM_LOCAL_NODE_BASE, &tmp); 887 amd64_read_pci_cfg(pvt->F1, DRAM_LOCAL_NODE_BASE, &tmp);
886 888
887 /* faster log2 */ 889 /* faster log2 */
888 tmp_addr = (addr & GENMASK(12, 23)) << __fls(intlv_en + 1); 890 tmp_addr = (addr & GENMASK_ULL(23, 12)) << __fls(intlv_en + 1);
889 891
890 /* OR DramIntlvSel into bits [14:12] */ 892 /* OR DramIntlvSel into bits [14:12] */
891 tmp_addr |= (tmp & GENMASK(21, 23)) >> 9; 893 tmp_addr |= (tmp & GENMASK_ULL(23, 21)) >> 9;
892 894
893 /* add remaining [11:0] bits from original MC4_ADDR */ 895 /* add remaining [11:0] bits from original MC4_ADDR */
894 tmp_addr |= addr & GENMASK(0, 11); 896 tmp_addr |= addr & GENMASK_ULL(11, 0);
895 897
896 return cc6_base | tmp_addr; 898 return cc6_base | tmp_addr;
897 } 899 }
@@ -952,12 +954,12 @@ static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
952 954
953 amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim); 955 amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim);
954 956
955 pvt->ranges[range].lim.lo &= GENMASK(0, 15); 957 pvt->ranges[range].lim.lo &= GENMASK_ULL(15, 0);
956 958
957 /* {[39:27],111b} */ 959 /* {[39:27],111b} */
958 pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16; 960 pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16;
959 961
960 pvt->ranges[range].lim.hi &= GENMASK(0, 7); 962 pvt->ranges[range].lim.hi &= GENMASK_ULL(7, 0);
961 963
962 /* [47:40] */ 964 /* [47:40] */
963 pvt->ranges[range].lim.hi |= llim >> 13; 965 pvt->ranges[range].lim.hi |= llim >> 13;
@@ -1330,7 +1332,7 @@ static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
1330 chan_off = dram_base; 1332 chan_off = dram_base;
1331 } 1333 }
1332 1334
1333 return (sys_addr & GENMASK(6,47)) - (chan_off & GENMASK(23,47)); 1335 return (sys_addr & GENMASK_ULL(47,6)) - (chan_off & GENMASK_ULL(47,23));
1334} 1336}
1335 1337
1336/* 1338/*
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index d2443cfa0698..6dc1fcc25afb 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -160,14 +160,6 @@
160#define OFF false 160#define OFF false
161 161
162/* 162/*
163 * Create a contiguous bitmask starting at bit position @lo and ending at
164 * position @hi. For example
165 *
166 * GENMASK(21, 39) gives us the 64bit vector 0x000000ffffe00000.
167 */
168#define GENMASK(lo, hi) (((1ULL << ((hi) - (lo) + 1)) - 1) << (lo))
169
170/*
171 * PCI-defined configuration space registers 163 * PCI-defined configuration space registers
172 */ 164 */
173#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F1 0x141b 165#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F1 0x141b
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index e04462b60756..88f60c5fecbc 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -50,7 +50,7 @@ static int probed;
50 * Get a bit field at register value <v>, from bit <lo> to bit <hi> 50 * Get a bit field at register value <v>, from bit <lo> to bit <hi>
51 */ 51 */
52#define GET_BITFIELD(v, lo, hi) \ 52#define GET_BITFIELD(v, lo, hi) \
53 (((v) & ((1ULL << ((hi) - (lo) + 1)) - 1) << (lo)) >> (lo)) 53 (((v) & GENMASK_ULL(hi, lo)) >> (lo))
54 54
55/* 55/*
56 * sbridge Memory Controller Registers 56 * sbridge Memory Controller Registers