#!/bin/sh

PATH=$PATH:/sbin:/usr/sbin

sync
sleep 1
sync

# scrub address and redirect clear
setpci -s 00:18.3 5C.L=0
setpci -s 00:18.3 60.L=0

# Make sure Chip-Kill is off, as that bit determines what
# way the scrubbing writes memory.
setpci -s 00:18.3 44.L=00000040

# Set data cache and level 2 cache scrubbing speed as fast
setpci -s 00:18.3 58.L=00010100
sleep 1

# Slow those down
setpci -s 00:18.3 58.L=000F0F00
sleep 1

# Now set dram scrubbing on, very fast setting
# (1.6 GBytes / s)
setpci -s 00:18.3 58.L=000F0F01

# Wait that it surely has walked all memory.  Increase this if
# you have more than 4 GBytes of memory.
sleep 10

# Set ECC on!
setpci -s 00:18.3 44.L=00400040
# setpci -s 00:18.3 44.L=00C00040
sleep 10

# scrub address clear and redirect on
setpci -s 00:18.3 5C.L=1
setpci -s 00:18.3 60.L=0

# Slow down scrubbing. Value 0xF == 655.4 µs / 64 Bytes means 
# it takes 3 hours / GByte to scrub.
setpci -s 00:18.3 58.L=000F0F0F

