1 #include "amd64_edac.h"
3 static ssize_t
amd64_inject_section_show(struct device
*dev
,
4 struct device_attribute
*mattr
,
7 struct mem_ctl_info
*mci
= to_mci(dev
);
8 struct amd64_pvt
*pvt
= mci
->pvt_info
;
9 return sprintf(buf
, "0x%x\n", pvt
->injection
.section
);
13 * store error injection section value which refers to one of 4 16-byte sections
14 * within a 64-byte cacheline
18 static ssize_t
amd64_inject_section_store(struct device
*dev
,
19 struct device_attribute
*mattr
,
20 const char *data
, size_t count
)
22 struct mem_ctl_info
*mci
= to_mci(dev
);
23 struct amd64_pvt
*pvt
= mci
->pvt_info
;
27 ret
= strict_strtoul(data
, 10, &value
);
31 amd64_warn("%s: invalid section 0x%lx\n", __func__
, value
);
35 pvt
->injection
.section
= (u32
) value
;
41 static ssize_t
amd64_inject_word_show(struct device
*dev
,
42 struct device_attribute
*mattr
,
45 struct mem_ctl_info
*mci
= to_mci(dev
);
46 struct amd64_pvt
*pvt
= mci
->pvt_info
;
47 return sprintf(buf
, "0x%x\n", pvt
->injection
.word
);
51 * store error injection word value which refers to one of 9 16-bit word of the
52 * 16-byte (128-bit + ECC bits) section
56 static ssize_t
amd64_inject_word_store(struct device
*dev
,
57 struct device_attribute
*mattr
,
58 const char *data
, size_t count
)
60 struct mem_ctl_info
*mci
= to_mci(dev
);
61 struct amd64_pvt
*pvt
= mci
->pvt_info
;
65 ret
= strict_strtoul(data
, 10, &value
);
69 amd64_warn("%s: invalid word 0x%lx\n", __func__
, value
);
73 pvt
->injection
.word
= (u32
) value
;
79 static ssize_t
amd64_inject_ecc_vector_show(struct device
*dev
,
80 struct device_attribute
*mattr
,
83 struct mem_ctl_info
*mci
= to_mci(dev
);
84 struct amd64_pvt
*pvt
= mci
->pvt_info
;
85 return sprintf(buf
, "0x%x\n", pvt
->injection
.bit_map
);
89 * store 16 bit error injection vector which enables injecting errors to the
90 * corresponding bit within the error injection word above. When used during a
91 * DRAM ECC read, it holds the contents of the of the DRAM ECC bits.
93 static ssize_t
amd64_inject_ecc_vector_store(struct device
*dev
,
94 struct device_attribute
*mattr
,
95 const char *data
, size_t count
)
97 struct mem_ctl_info
*mci
= to_mci(dev
);
98 struct amd64_pvt
*pvt
= mci
->pvt_info
;
102 ret
= strict_strtoul(data
, 16, &value
);
103 if (ret
!= -EINVAL
) {
105 if (value
& 0xFFFF0000) {
106 amd64_warn("%s: invalid EccVector: 0x%lx\n",
111 pvt
->injection
.bit_map
= (u32
) value
;
118 * Do a DRAM ECC read. Assemble staged values in the pvt area, format into
119 * fields needed by the injection registers and read the NB Array Data Port.
121 static ssize_t
amd64_inject_read_store(struct device
*dev
,
122 struct device_attribute
*mattr
,
123 const char *data
, size_t count
)
125 struct mem_ctl_info
*mci
= to_mci(dev
);
126 struct amd64_pvt
*pvt
= mci
->pvt_info
;
128 u32 section
, word_bits
;
131 ret
= strict_strtoul(data
, 10, &value
);
132 if (ret
!= -EINVAL
) {
134 /* Form value to choose 16-byte section of cacheline */
135 section
= F10_NB_ARRAY_DRAM_ECC
|
136 SET_NB_ARRAY_ADDRESS(pvt
->injection
.section
);
137 amd64_write_pci_cfg(pvt
->F3
, F10_NB_ARRAY_ADDR
, section
);
139 word_bits
= SET_NB_DRAM_INJECTION_READ(pvt
->injection
.word
,
140 pvt
->injection
.bit_map
);
142 /* Issue 'word' and 'bit' along with the READ request */
143 amd64_write_pci_cfg(pvt
->F3
, F10_NB_ARRAY_DATA
, word_bits
);
145 edac_dbg(0, "section=0x%x word_bits=0x%x\n",
154 * Do a DRAM ECC write. Assemble staged values in the pvt area and format into
155 * fields needed by the injection registers.
157 static ssize_t
amd64_inject_write_store(struct device
*dev
,
158 struct device_attribute
*mattr
,
159 const char *data
, size_t count
)
161 struct mem_ctl_info
*mci
= to_mci(dev
);
162 struct amd64_pvt
*pvt
= mci
->pvt_info
;
164 u32 section
, word_bits
;
167 ret
= strict_strtoul(data
, 10, &value
);
168 if (ret
!= -EINVAL
) {
170 /* Form value to choose 16-byte section of cacheline */
171 section
= F10_NB_ARRAY_DRAM_ECC
|
172 SET_NB_ARRAY_ADDRESS(pvt
->injection
.section
);
173 amd64_write_pci_cfg(pvt
->F3
, F10_NB_ARRAY_ADDR
, section
);
175 word_bits
= SET_NB_DRAM_INJECTION_WRITE(pvt
->injection
.word
,
176 pvt
->injection
.bit_map
);
178 /* Issue 'word' and 'bit' along with the READ request */
179 amd64_write_pci_cfg(pvt
->F3
, F10_NB_ARRAY_DATA
, word_bits
);
181 edac_dbg(0, "section=0x%x word_bits=0x%x\n",
190 * update NUM_INJ_ATTRS in case you add new members
193 static DEVICE_ATTR(inject_section
, S_IRUGO
| S_IWUSR
,
194 amd64_inject_section_show
, amd64_inject_section_store
);
195 static DEVICE_ATTR(inject_word
, S_IRUGO
| S_IWUSR
,
196 amd64_inject_word_show
, amd64_inject_word_store
);
197 static DEVICE_ATTR(inject_ecc_vector
, S_IRUGO
| S_IWUSR
,
198 amd64_inject_ecc_vector_show
, amd64_inject_ecc_vector_store
);
199 static DEVICE_ATTR(inject_write
, S_IRUGO
| S_IWUSR
,
200 NULL
, amd64_inject_write_store
);
201 static DEVICE_ATTR(inject_read
, S_IRUGO
| S_IWUSR
,
202 NULL
, amd64_inject_read_store
);
205 int amd64_create_sysfs_inject_files(struct mem_ctl_info
*mci
)
209 rc
= device_create_file(&mci
->dev
, &dev_attr_inject_section
);
212 rc
= device_create_file(&mci
->dev
, &dev_attr_inject_word
);
215 rc
= device_create_file(&mci
->dev
, &dev_attr_inject_ecc_vector
);
218 rc
= device_create_file(&mci
->dev
, &dev_attr_inject_write
);
221 rc
= device_create_file(&mci
->dev
, &dev_attr_inject_read
);
228 void amd64_remove_sysfs_inject_files(struct mem_ctl_info
*mci
)
230 device_remove_file(&mci
->dev
, &dev_attr_inject_section
);
231 device_remove_file(&mci
->dev
, &dev_attr_inject_word
);
232 device_remove_file(&mci
->dev
, &dev_attr_inject_ecc_vector
);
233 device_remove_file(&mci
->dev
, &dev_attr_inject_write
);
234 device_remove_file(&mci
->dev
, &dev_attr_inject_read
);