19 #include <linux/module.h>
20 #include <linux/pci.h>
22 #include <linux/sched.h>
33 #include "../dma/ioat/hw.h"
34 #include "../dma/ioat/registers.h"
36 #define I7300_IDLE_DRIVER_VERSION "1.55"
37 #define I7300_PRINT "i7300_idle:"
39 #define MAX_STOP_RETRIES 10
49 #define dprintk(fmt, arg...) \
50 do { if (debug) printk(KERN_INFO I7300_PRINT fmt, ##arg); } while (0)
59 #define MAX_THROTTLE_LOW_LIMIT 168
60 static uint throttle_low_limit = 1;
63 "Value for THRTLOWLM activation field "
64 "(0 = disable throttle, 1 = Max throttle, 168 = Min throttle)");
69 static unsigned long total_starts;
70 static unsigned long total_us;
73 static unsigned long past_skip;
79 static int i7300_idle_active;
81 static u8 i7300_idle_thrtctl_saved;
82 static u8 i7300_idle_thrtlow_saved;
83 static u32 i7300_idle_mc_saved;
87 static unsigned long avg_idle_us;
89 static struct dentry *debugfs_dir;
93 #define IOAT_CHANBASE(ioat_ctl, chan) (ioat_ctl + 0x80 + 0x80 * chan)
95 #define IOAT_DESC_SADDR_SNP_CTL (1UL << 1)
96 #define IOAT_DESC_DADDR_SNP_CTL (1UL << 2)
98 static struct pci_dev *ioat_dev;
100 static unsigned long ioat_desc_phys;
101 static u8 *ioat_iomap;
102 static u8 *ioat_chanbase;
105 static int i7300_idle_ioat_start(
void)
118 static void i7300_idle_ioat_stop(
void)
137 if (i == MAX_STOP_RETRIES) {
138 dprintk(
"failed to stop I/O AT after %d retries\n",
144 static int __init i7300_idle_ioat_selftest(
u8 *
ctl,
150 memset((
u8 *) desc + 2048, 0xab, 1024);
154 desc[0].
src_addr = desc_phys + 2048;
155 desc[0].
dst_addr = desc_phys + 1024;
173 if (*(
u32 *) ((
u8 *) desc + 3068) != 0xabababab ||
174 *(
u32 *) ((
u8 *) desc + 2044) != 0xabababab) {
175 dprintk(
"Data values src 0x%x, dest 0x%x, memset 0x%x\n",
176 *(
u32 *) ((
u8 *) desc + 2048),
177 *(
u32 *) ((
u8 *) desc + 1024),
178 *(
u32 *) ((
u8 *) desc + 3072));
184 static struct device dummy_dma_dev = {
185 .init_name =
"fallback device",
195 static int __init i7300_idle_ioat_init(
void)
197 u8 ver, chan_count, ioat_chan;
211 ver >> 4, ver & 0xf);
223 ioat_chan = chan_count - 1;
232 writew(IOAT_CHANCTRL_CHANNEL_IN_USE,
236 &dummy_dma_dev, 4096,
240 goto err_mark_unused;
243 writel(ioat_desc_phys & 0xffffffffUL,
245 writel(ioat_desc_phys >> 32,
248 if (i7300_idle_ioat_selftest(ioat_iomap, ioat_desc, ioat_desc_phys)) {
255 ioat_desc[0].
src_addr = ioat_desc_phys + 2048;
256 ioat_desc[0].
dst_addr = ioat_desc_phys + 3072;
257 ioat_desc[0].
size = 128;
260 ioat_desc[1].
ctl = ioat_desc[0].
ctl;
263 ioat_desc[1].
size = ioat_desc[0].
size;
264 ioat_desc[1].
next = ioat_desc_phys;
279 static void __exit i7300_idle_ioat_exit(
void)
284 i7300_idle_ioat_stop();
311 " Not freeing resources\n");
321 #define DIMM_THRTLOW 0x64
322 #define DIMM_THRTCTL 0x67
323 #define DIMM_THRTCTL_THRMHUNT (1UL << 0)
325 #define DIMM_GTW_MODE (1UL << 17)
326 #define DIMM_GBLACT 0x60
335 #define DURATION_WEIGHT_PCT 55
342 #define DURATION_THRESHOLD_US 100
346 static int i7300_idle_thrt_save(
void)
351 pci_read_config_byte(fbd_dev,
DIMM_THRTCTL, &i7300_idle_thrtctl_saved);
352 pci_read_config_byte(fbd_dev,
DIMM_THRTLOW, &i7300_idle_thrtlow_saved);
353 pci_read_config_dword(fbd_dev,
DIMM_MC, &i7300_idle_mc_saved);
367 pci_read_config_byte(fbd_dev,
DIMM_GBLACT, &gblactlm);
368 dprintk(
"thrtctl_saved = 0x%02x, thrtlow_saved = 0x%02x\n",
369 i7300_idle_thrtctl_saved,
370 i7300_idle_thrtlow_saved);
371 dprintk(
"mc_saved = 0x%08x, gblactlm = 0x%02x\n",
376 pci_write_config_dword(fbd_dev,
DIMM_MC, new_mc_val);
379 dprintk(
"could not set GTW_MODE = 1 (OLTT enabled)\n");
385 static void i7300_idle_thrt_restore(
void)
387 pci_write_config_dword(fbd_dev,
DIMM_MC, i7300_idle_mc_saved);
388 pci_write_config_byte(fbd_dev,
DIMM_THRTLOW, i7300_idle_thrtlow_saved);
389 pci_write_config_byte(fbd_dev,
DIMM_THRTCTL, i7300_idle_thrtctl_saved);
393 static void i7300_idle_start(
void)
401 limit = throttle_low_limit;
412 static void i7300_idle_stop(
void)
420 pci_write_config_byte(fbd_dev,
DIMM_THRTLOW, i7300_idle_thrtlow_saved);
421 pci_write_config_byte(fbd_dev,
DIMM_THRTCTL, i7300_idle_thrtctl_saved);
432 static int i7300_avg_duration_check(
void)
449 static ktime_t idle_begin_time;
452 if (!throttle_low_limit)
469 idle_begin_time = now_ktime;
471 if (i7300_avg_duration_check())
474 i7300_idle_active = 1;
476 start_ktime = now_ktime;
479 i7300_idle_ioat_start();
485 u64 idle_duration_us;
489 idle_duration_us = ktime_to_us(ktime_sub
490 (now_ktime, idle_begin_time));
496 if (i7300_idle_active) {
499 idle_ktime = ktime_sub(now_ktime, start_ktime);
500 total_us += ktime_to_us(idle_ktime);
502 i7300_idle_ioat_stop();
504 i7300_idle_active = 0;
509 spin_unlock_irqrestore(&i7300_idle_lock, flags);
514 .notifier_call = i7300_idle_notifier,
526 len =
snprintf(buf, 32,
"%lu\n", *p);
532 .read = stats_read_ul,
541 {&total_starts,
"total_starts",
NULL},
542 {&total_us,
"total_us",
NULL},
544 {&past_skip,
"past_skip",
NULL},
549 static int __init i7300_idle_init(
void)
554 if (i7300_idle_platform_probe(&fbd_dev, &ioat_dev, forceload))
557 if (i7300_idle_thrt_save())
560 if (i7300_idle_ioat_init())
563 if (!zalloc_cpumask_var(&idle_cpumask,
GFP_KERNEL))
587 static void __exit i7300_idle_exit(
void)
590 free_cpumask_var(idle_cpumask);
602 i7300_idle_thrt_restore();
603 i7300_idle_ioat_exit();