i7300_idle.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * (C) Copyright 2008 Intel Corporation
  3. * Authors:
  4. * Andy Henroid <andrew.d.henroid@intel.com>
  5. * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
  6. */
  7. /*
  8. * Save DIMM power on Intel 7300-based platforms when all CPUs/cores
  9. * are idle, using the DIMM thermal throttling capability.
  10. *
  11. * This driver depends on the Intel integrated DMA controller (I/O AT).
  12. * If the driver for I/O AT (drivers/dma/ioatdma*) is also enabled,
  13. * this driver should work cooperatively.
  14. */
  15. /* #define DEBUG */
  16. #include <linux/module.h>
  17. #include <linux/pci.h>
  18. #include <linux/sched.h>
  19. #include <linux/notifier.h>
  20. #include <linux/cpumask.h>
  21. #include <linux/ktime.h>
  22. #include <linux/delay.h>
  23. #include <linux/debugfs.h>
  24. #include <linux/stop_machine.h>
  25. #include <asm/idle.h>
  26. #include "../dma/ioatdma_hw.h"
  27. #include "../dma/ioatdma_registers.h"
  28. #define I7300_IDLE_DRIVER_VERSION "1.55"
  29. #define I7300_PRINT "i7300_idle:"
  30. static int debug;
  31. module_param_named(debug, debug, uint, 0644);
  32. MODULE_PARM_DESC(debug, "Enable debug printks in this driver");
  33. #define dprintk(fmt, arg...) \
  34. do { if (debug) printk(KERN_INFO I7300_PRINT fmt, ##arg); } while (0)
  35. /*
  36. * Value to set THRTLOW to when initiating throttling
  37. * 0 = No throttling
  38. * 1 = Throttle when > 4 activations per eval window (Maximum throttling)
  39. * 2 = Throttle when > 8 activations
  40. * 168 = Throttle when > 168 activations (Minimum throttling)
  41. */
  42. #define MAX_THRTLWLIMIT 168
  43. static uint i7300_idle_thrtlowlm = 1;
  44. module_param_named(thrtlwlimit, i7300_idle_thrtlowlm, uint, 0644);
  45. MODULE_PARM_DESC(thrtlwlimit,
  46. "Value for THRTLOWLM activation field "
  47. "(0 = disable throttle, 1 = Max throttle, 168 = Min throttle)");
  48. /*
  49. * simple invocation and duration statistics
  50. */
  51. static unsigned long total_starts;
  52. static unsigned long total_us;
  53. #ifdef DEBUG
  54. static unsigned long past_skip;
  55. #endif
  56. static struct pci_dev *fbd_dev;
  57. static spinlock_t i7300_idle_lock;
  58. static int i7300_idle_active;
  59. static u8 i7300_idle_thrtctl_saved;
  60. static u8 i7300_idle_thrtlow_saved;
  61. static u32 i7300_idle_mc_saved;
  62. static cpumask_t idle_cpumask;
  63. static ktime_t start_ktime;
  64. static unsigned long avg_idle_us;
  65. static struct dentry *debugfs_dir;
  66. /* Begin: I/O AT Helper routines */
  67. #define IOAT_CHANBASE(ioat_ctl, chan) (ioat_ctl + 0x80 + 0x80 * chan)
  68. /* Snoop control (disable snoops when coherency is not important) */
  69. #define IOAT_DESC_SADDR_SNP_CTL (1UL << 1)
  70. #define IOAT_DESC_DADDR_SNP_CTL (1UL << 2)
  71. static struct pci_dev *ioat_dev;
  72. static struct ioat_dma_descriptor *ioat_desc; /* I/O AT desc & data (1 page) */
  73. static unsigned long ioat_desc_phys;
  74. static u8 *ioat_iomap; /* I/O AT memory-mapped control regs (aka CB_BAR) */
  75. static u8 *ioat_chanbase;
  76. /* Start I/O AT memory copy */
  77. static int i7300_idle_ioat_start(void)
  78. {
  79. u32 err;
  80. /* Clear error (due to circular descriptor pointer) */
  81. err = readl(ioat_chanbase + IOAT_CHANERR_OFFSET);
  82. if (err)
  83. writel(err, ioat_chanbase + IOAT_CHANERR_OFFSET);
  84. writeb(IOAT_CHANCMD_START, ioat_chanbase + IOAT1_CHANCMD_OFFSET);
  85. return 0;
  86. }
  87. /* Stop I/O AT memory copy */
  88. static void i7300_idle_ioat_stop(void)
  89. {
  90. int i;
  91. u8 sts;
  92. for (i = 0; i < 5; i++) {
  93. writeb(IOAT_CHANCMD_RESET,
  94. ioat_chanbase + IOAT1_CHANCMD_OFFSET);
  95. udelay(10);
  96. sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
  97. IOAT_CHANSTS_DMA_TRANSFER_STATUS;
  98. if (sts != IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE)
  99. break;
  100. }
  101. if (i == 5)
  102. dprintk("failed to suspend+reset I/O AT after 5 retries\n");
  103. }
  104. /* Test I/O AT by copying 1024 byte from 2k to 1k */
  105. static int __init i7300_idle_ioat_selftest(u8 *ctl,
  106. struct ioat_dma_descriptor *desc, unsigned long desc_phys)
  107. {
  108. u64 chan_sts;
  109. memset(desc, 0, 2048);
  110. memset((u8 *) desc + 2048, 0xab, 1024);
  111. desc[0].size = 1024;
  112. desc[0].ctl = 0;
  113. desc[0].src_addr = desc_phys + 2048;
  114. desc[0].dst_addr = desc_phys + 1024;
  115. desc[0].next = 0;
  116. writeb(IOAT_CHANCMD_RESET, ioat_chanbase + IOAT1_CHANCMD_OFFSET);
  117. writeb(IOAT_CHANCMD_START, ioat_chanbase + IOAT1_CHANCMD_OFFSET);
  118. udelay(1000);
  119. chan_sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
  120. IOAT_CHANSTS_DMA_TRANSFER_STATUS;
  121. if (chan_sts != IOAT_CHANSTS_DMA_TRANSFER_STATUS_DONE) {
  122. /* Not complete, reset the channel */
  123. writeb(IOAT_CHANCMD_RESET,
  124. ioat_chanbase + IOAT1_CHANCMD_OFFSET);
  125. return -1;
  126. }
  127. if (*(u32 *) ((u8 *) desc + 3068) != 0xabababab ||
  128. *(u32 *) ((u8 *) desc + 2044) != 0xabababab) {
  129. dprintk("Data values src 0x%x, dest 0x%x, memset 0x%x\n",
  130. *(u32 *) ((u8 *) desc + 2048),
  131. *(u32 *) ((u8 *) desc + 1024),
  132. *(u32 *) ((u8 *) desc + 3072));
  133. return -1;
  134. }
  135. return 0;
  136. }
  137. static struct device dummy_dma_dev = {
  138. .bus_id = "fallback device",
  139. .coherent_dma_mask = DMA_64BIT_MASK,
  140. .dma_mask = &dummy_dma_dev.coherent_dma_mask,
  141. };
  142. /* Setup and initialize I/O AT */
  143. /* This driver needs I/O AT as the throttling takes effect only when there is
  144. * some memory activity. We use I/O AT to set up a dummy copy, while all CPUs
  145. * go idle and memory is throttled.
  146. */
  147. static int __init i7300_idle_ioat_init(void)
  148. {
  149. u8 ver, chan_count, ioat_chan;
  150. u16 chan_ctl;
  151. ioat_iomap = (u8 *) ioremap_nocache(pci_resource_start(ioat_dev, 0),
  152. pci_resource_len(ioat_dev, 0));
  153. if (!ioat_iomap) {
  154. printk(KERN_ERR I7300_PRINT "failed to map I/O AT registers\n");
  155. goto err_ret;
  156. }
  157. ver = readb(ioat_iomap + IOAT_VER_OFFSET);
  158. if (ver != IOAT_VER_1_2) {
  159. printk(KERN_ERR I7300_PRINT "unknown I/O AT version (%u.%u)\n",
  160. ver >> 4, ver & 0xf);
  161. goto err_unmap;
  162. }
  163. chan_count = readb(ioat_iomap + IOAT_CHANCNT_OFFSET);
  164. if (!chan_count) {
  165. printk(KERN_ERR I7300_PRINT "unexpected # of I/O AT channels "
  166. "(%u)\n",
  167. chan_count);
  168. goto err_unmap;
  169. }
  170. ioat_chan = chan_count - 1;
  171. ioat_chanbase = IOAT_CHANBASE(ioat_iomap, ioat_chan);
  172. chan_ctl = readw(ioat_chanbase + IOAT_CHANCTRL_OFFSET);
  173. if (chan_ctl & IOAT_CHANCTRL_CHANNEL_IN_USE) {
  174. printk(KERN_ERR I7300_PRINT "channel %d in use\n", ioat_chan);
  175. goto err_unmap;
  176. }
  177. writew(IOAT_CHANCTRL_CHANNEL_IN_USE,
  178. ioat_chanbase + IOAT_CHANCTRL_OFFSET);
  179. ioat_desc = (struct ioat_dma_descriptor *)dma_alloc_coherent(
  180. &dummy_dma_dev, 4096,
  181. (dma_addr_t *)&ioat_desc_phys, GFP_KERNEL);
  182. if (!ioat_desc) {
  183. printk(KERN_ERR I7300_PRINT "failed to allocate I/O AT desc\n");
  184. goto err_mark_unused;
  185. }
  186. writel(ioat_desc_phys & 0xffffffffUL,
  187. ioat_chanbase + IOAT1_CHAINADDR_OFFSET_LOW);
  188. writel(ioat_desc_phys >> 32,
  189. ioat_chanbase + IOAT1_CHAINADDR_OFFSET_HIGH);
  190. if (i7300_idle_ioat_selftest(ioat_iomap, ioat_desc, ioat_desc_phys)) {
  191. printk(KERN_ERR I7300_PRINT "I/O AT self-test failed\n");
  192. goto err_free;
  193. }
  194. /* Setup circular I/O AT descriptor chain */
  195. ioat_desc[0].ctl = IOAT_DESC_SADDR_SNP_CTL | IOAT_DESC_DADDR_SNP_CTL;
  196. ioat_desc[0].src_addr = ioat_desc_phys + 2048;
  197. ioat_desc[0].dst_addr = ioat_desc_phys + 3072;
  198. ioat_desc[0].size = 128;
  199. ioat_desc[0].next = ioat_desc_phys + sizeof(struct ioat_dma_descriptor);
  200. ioat_desc[1].ctl = ioat_desc[0].ctl;
  201. ioat_desc[1].src_addr = ioat_desc[0].src_addr;
  202. ioat_desc[1].dst_addr = ioat_desc[0].dst_addr;
  203. ioat_desc[1].size = ioat_desc[0].size;
  204. ioat_desc[1].next = ioat_desc_phys;
  205. return 0;
  206. err_free:
  207. dma_free_coherent(&dummy_dma_dev, 4096, (void *)ioat_desc, 0);
  208. err_mark_unused:
  209. writew(0, ioat_chanbase + IOAT_CHANCTRL_OFFSET);
  210. err_unmap:
  211. iounmap(ioat_iomap);
  212. err_ret:
  213. return -ENODEV;
  214. }
  215. /* Cleanup I/O AT */
  216. static void __exit i7300_idle_ioat_exit(void)
  217. {
  218. int i;
  219. u64 chan_sts;
  220. i7300_idle_ioat_stop();
  221. /* Wait for a while for the channel to halt before releasing */
  222. for (i = 0; i < 10; i++) {
  223. writeb(IOAT_CHANCMD_RESET,
  224. ioat_chanbase + IOAT1_CHANCMD_OFFSET);
  225. chan_sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
  226. IOAT_CHANSTS_DMA_TRANSFER_STATUS;
  227. if (chan_sts != IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE) {
  228. writew(0, ioat_chanbase + IOAT_CHANCTRL_OFFSET);
  229. break;
  230. }
  231. udelay(1000);
  232. }
  233. chan_sts = readq(ioat_chanbase + IOAT1_CHANSTS_OFFSET) &
  234. IOAT_CHANSTS_DMA_TRANSFER_STATUS;
  235. /*
  236. * We tried to reset multiple times. If IO A/T channel is still active
  237. * flag an error and return without cleanup. Memory leak is better
  238. * than random corruption in that extreme error situation.
  239. */
  240. if (chan_sts == IOAT_CHANSTS_DMA_TRANSFER_STATUS_ACTIVE) {
  241. printk(KERN_ERR I7300_PRINT "Unable to stop IO A/T channels."
  242. " Not freeing resources\n");
  243. return;
  244. }
  245. dma_free_coherent(&dummy_dma_dev, 4096, (void *)ioat_desc, 0);
  246. iounmap(ioat_iomap);
  247. }
  248. /* End: I/O AT Helper routines */
  249. #define DIMM_THRTLOW 0x64
  250. #define DIMM_THRTCTL 0x67
  251. #define DIMM_THRTCTL_THRMHUNT (1UL << 0)
  252. #define DIMM_MC 0x40
  253. #define DIMM_GTW_MODE (1UL << 17)
  254. #define DIMM_GBLACT 0x60
  255. /*
  256. * Keep track of an exponential-decaying average of recent idle durations.
  257. * The latest duration gets DURATION_WEIGHT_PCT percentage weight
  258. * in this average, with the old average getting the remaining weight.
  259. *
  260. * High weights emphasize recent history, low weights include long history.
  261. */
  262. #define DURATION_WEIGHT_PCT 55
  263. /*
  264. * When the decaying average of recent durations or the predicted duration
  265. * of the next timer interrupt is shorter than duration_threshold, the
  266. * driver will decline to throttle.
  267. */
  268. #define DURATION_THRESHOLD_US 100
  269. /* Store DIMM thermal throttle configuration */
  270. static int i7300_idle_thrt_save(void)
  271. {
  272. u32 new_mc_val;
  273. u8 gblactlm;
  274. pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &i7300_idle_thrtctl_saved);
  275. pci_read_config_byte(fbd_dev, DIMM_THRTLOW, &i7300_idle_thrtlow_saved);
  276. pci_read_config_dword(fbd_dev, DIMM_MC, &i7300_idle_mc_saved);
  277. /*
  278. * Make sure we have Global Throttling Window Mode set to have a
  279. * "short" window. This (mostly) works around an issue where
  280. * throttling persists until the end of the global throttling window
  281. * size. On the tested system, this was resulting in a maximum of
  282. * 64 ms to exit throttling (average 32 ms). The actual numbers
  283. * depends on system frequencies. Setting the short window reduces
  284. * this by a factor of 4096.
  285. *
  286. * We will only do this only if the system is set for
  287. * unlimited-activations while in open-loop throttling (i.e., when
  288. * Global Activation Throttle Limit is zero).
  289. */
  290. pci_read_config_byte(fbd_dev, DIMM_GBLACT, &gblactlm);
  291. dprintk("thrtctl_saved = 0x%02x, thrtlow_saved = 0x%02x\n",
  292. i7300_idle_thrtctl_saved,
  293. i7300_idle_thrtlow_saved);
  294. dprintk("mc_saved = 0x%08x, gblactlm = 0x%02x\n",
  295. i7300_idle_mc_saved,
  296. gblactlm);
  297. if (gblactlm == 0) {
  298. new_mc_val = i7300_idle_mc_saved | DIMM_GTW_MODE;
  299. pci_write_config_dword(fbd_dev, DIMM_MC, new_mc_val);
  300. return 0;
  301. } else {
  302. dprintk("could not set GTW_MODE = 1 (OLTT enabled)\n");
  303. return -ENODEV;
  304. }
  305. }
  306. /* Restore DIMM thermal throttle configuration */
  307. static void i7300_idle_thrt_restore(void)
  308. {
  309. pci_write_config_dword(fbd_dev, DIMM_MC, i7300_idle_mc_saved);
  310. pci_write_config_byte(fbd_dev, DIMM_THRTLOW, i7300_idle_thrtlow_saved);
  311. pci_write_config_byte(fbd_dev, DIMM_THRTCTL, i7300_idle_thrtctl_saved);
  312. }
  313. /* Enable DIMM thermal throttling */
  314. static void i7300_idle_start(void)
  315. {
  316. u8 new_ctl;
  317. u8 limit;
  318. new_ctl = i7300_idle_thrtctl_saved & ~DIMM_THRTCTL_THRMHUNT;
  319. pci_write_config_byte(fbd_dev, DIMM_THRTCTL, new_ctl);
  320. limit = i7300_idle_thrtlowlm;
  321. if (unlikely(limit > MAX_THRTLWLIMIT))
  322. limit = MAX_THRTLWLIMIT;
  323. pci_write_config_byte(fbd_dev, DIMM_THRTLOW, limit);
  324. new_ctl = i7300_idle_thrtctl_saved | DIMM_THRTCTL_THRMHUNT;
  325. pci_write_config_byte(fbd_dev, DIMM_THRTCTL, new_ctl);
  326. }
  327. /* Disable DIMM thermal throttling */
  328. static void i7300_idle_stop(void)
  329. {
  330. u8 new_ctl;
  331. u8 got_ctl;
  332. new_ctl = i7300_idle_thrtctl_saved & ~DIMM_THRTCTL_THRMHUNT;
  333. pci_write_config_byte(fbd_dev, DIMM_THRTCTL, new_ctl);
  334. pci_write_config_byte(fbd_dev, DIMM_THRTLOW, i7300_idle_thrtlow_saved);
  335. pci_write_config_byte(fbd_dev, DIMM_THRTCTL, i7300_idle_thrtctl_saved);
  336. pci_read_config_byte(fbd_dev, DIMM_THRTCTL, &got_ctl);
  337. WARN_ON_ONCE(got_ctl != i7300_idle_thrtctl_saved);
  338. }
  339. /*
  340. * i7300_avg_duration_check()
  341. * return 0 if the decaying average of recent idle durations is
  342. * more than DURATION_THRESHOLD_US
  343. */
  344. static int i7300_avg_duration_check(void)
  345. {
  346. if (avg_idle_us >= DURATION_THRESHOLD_US)
  347. return 0;
  348. #ifdef DEBUG
  349. past_skip++;
  350. #endif
  351. return 1;
  352. }
  353. /* Idle notifier to look at idle CPUs */
  354. static int i7300_idle_notifier(struct notifier_block *nb, unsigned long val,
  355. void *data)
  356. {
  357. unsigned long flags;
  358. ktime_t now_ktime;
  359. static ktime_t idle_begin_time;
  360. static int time_init = 1;
  361. if (!i7300_idle_thrtlowlm)
  362. return 0;
  363. if (unlikely(time_init)) {
  364. time_init = 0;
  365. idle_begin_time = ktime_get();
  366. }
  367. spin_lock_irqsave(&i7300_idle_lock, flags);
  368. if (val == IDLE_START) {
  369. cpu_set(smp_processor_id(), idle_cpumask);
  370. if (cpus_weight(idle_cpumask) != num_online_cpus())
  371. goto end;
  372. now_ktime = ktime_get();
  373. idle_begin_time = now_ktime;
  374. if (i7300_avg_duration_check())
  375. goto end;
  376. i7300_idle_active = 1;
  377. total_starts++;
  378. start_ktime = now_ktime;
  379. i7300_idle_start();
  380. i7300_idle_ioat_start();
  381. } else if (val == IDLE_END) {
  382. cpu_clear(smp_processor_id(), idle_cpumask);
  383. if (cpus_weight(idle_cpumask) == (num_online_cpus() - 1)) {
  384. /* First CPU coming out of idle */
  385. u64 idle_duration_us;
  386. now_ktime = ktime_get();
  387. idle_duration_us = ktime_to_us(ktime_sub
  388. (now_ktime, idle_begin_time));
  389. avg_idle_us =
  390. ((100 - DURATION_WEIGHT_PCT) * avg_idle_us +
  391. DURATION_WEIGHT_PCT * idle_duration_us) / 100;
  392. if (i7300_idle_active) {
  393. ktime_t idle_ktime;
  394. idle_ktime = ktime_sub(now_ktime, start_ktime);
  395. total_us += ktime_to_us(idle_ktime);
  396. i7300_idle_ioat_stop();
  397. i7300_idle_stop();
  398. i7300_idle_active = 0;
  399. }
  400. }
  401. }
  402. end:
  403. spin_unlock_irqrestore(&i7300_idle_lock, flags);
  404. return 0;
  405. }
  406. static struct notifier_block i7300_idle_nb = {
  407. .notifier_call = i7300_idle_notifier,
  408. };
  409. /*
  410. * I/O AT controls (PCI bus 0 device 8 function 0)
  411. * DIMM controls (PCI bus 0 device 16 function 1)
  412. */
  413. #define IOAT_BUS 0
  414. #define IOAT_DEVFN PCI_DEVFN(8, 0)
  415. #define MEMCTL_BUS 0
  416. #define MEMCTL_DEVFN PCI_DEVFN(16, 1)
  417. struct fbd_ioat {
  418. unsigned int vendor;
  419. unsigned int ioat_dev;
  420. };
  421. /*
  422. * The i5000 chip-set has the same hooks as the i7300
  423. * but support is disabled by default because this driver
  424. * has not been validated on that platform.
  425. */
  426. #define SUPPORT_I5000 0
  427. static const struct fbd_ioat fbd_ioat_list[] = {
  428. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB},
  429. #if SUPPORT_I5000
  430. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT},
  431. #endif
  432. {0, 0}
  433. };
  434. /* table of devices that work with this driver */
  435. static const struct pci_device_id pci_tbl[] = {
  436. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_FBD_CNB) },
  437. #if SUPPORT_I5000
  438. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
  439. #endif
  440. { } /* Terminating entry */
  441. };
  442. MODULE_DEVICE_TABLE(pci, pci_tbl);
  443. /* Check for known platforms with I/O-AT */
  444. static int __init i7300_idle_platform_probe(void)
  445. {
  446. int i;
  447. fbd_dev = pci_get_bus_and_slot(MEMCTL_BUS, MEMCTL_DEVFN);
  448. if (!fbd_dev)
  449. return -ENODEV;
  450. for (i = 0; pci_tbl[i].vendor != 0; i++) {
  451. if (fbd_dev->vendor == pci_tbl[i].vendor &&
  452. fbd_dev->device == pci_tbl[i].device) {
  453. break;
  454. }
  455. }
  456. if (pci_tbl[i].vendor == 0)
  457. return -ENODEV;
  458. ioat_dev = pci_get_bus_and_slot(IOAT_BUS, IOAT_DEVFN);
  459. if (!ioat_dev)
  460. return -ENODEV;
  461. for (i = 0; fbd_ioat_list[i].vendor != 0; i++) {
  462. if (ioat_dev->vendor == fbd_ioat_list[i].vendor &&
  463. ioat_dev->device == fbd_ioat_list[i].ioat_dev) {
  464. return 0;
  465. }
  466. }
  467. return -ENODEV;
  468. }
  469. int stats_open_generic(struct inode *inode, struct file *fp)
  470. {
  471. fp->private_data = inode->i_private;
  472. return 0;
  473. }
  474. static ssize_t stats_read_ul(struct file *fp, char __user *ubuf, size_t count,
  475. loff_t *off)
  476. {
  477. unsigned long *p = fp->private_data;
  478. char buf[32];
  479. int len;
  480. len = snprintf(buf, 32, "%lu\n", *p);
  481. return simple_read_from_buffer(ubuf, count, off, buf, len);
  482. }
  483. static const struct file_operations idle_fops = {
  484. .open = stats_open_generic,
  485. .read = stats_read_ul,
  486. };
  487. struct debugfs_file_info {
  488. void *ptr;
  489. char name[32];
  490. struct dentry *file;
  491. } debugfs_file_list[] = {
  492. {&total_starts, "total_starts", NULL},
  493. {&total_us, "total_us", NULL},
  494. #ifdef DEBUG
  495. {&past_skip, "past_skip", NULL},
  496. #endif
  497. {NULL, "", NULL}
  498. };
  499. static int __init i7300_idle_init(void)
  500. {
  501. spin_lock_init(&i7300_idle_lock);
  502. cpus_clear(idle_cpumask);
  503. total_us = 0;
  504. if (i7300_idle_platform_probe())
  505. return -ENODEV;
  506. if (i7300_idle_thrt_save())
  507. return -ENODEV;
  508. if (i7300_idle_ioat_init())
  509. return -ENODEV;
  510. debugfs_dir = debugfs_create_dir("i7300_idle", NULL);
  511. if (debugfs_dir) {
  512. int i = 0;
  513. while (debugfs_file_list[i].ptr != NULL) {
  514. debugfs_file_list[i].file = debugfs_create_file(
  515. debugfs_file_list[i].name,
  516. S_IRUSR,
  517. debugfs_dir,
  518. debugfs_file_list[i].ptr,
  519. &idle_fops);
  520. i++;
  521. }
  522. }
  523. idle_notifier_register(&i7300_idle_nb);
  524. printk(KERN_INFO "i7300_idle: loaded v%s\n", I7300_IDLE_DRIVER_VERSION);
  525. return 0;
  526. }
  527. static void __exit i7300_idle_exit(void)
  528. {
  529. idle_notifier_unregister(&i7300_idle_nb);
  530. if (debugfs_dir) {
  531. int i = 0;
  532. while (debugfs_file_list[i].file != NULL) {
  533. debugfs_remove(debugfs_file_list[i].file);
  534. i++;
  535. }
  536. debugfs_remove(debugfs_dir);
  537. }
  538. i7300_idle_thrt_restore();
  539. i7300_idle_ioat_exit();
  540. }
  541. module_init(i7300_idle_init);
  542. module_exit(i7300_idle_exit);
  543. MODULE_AUTHOR("Andy Henroid <andrew.d.henroid@intel.com>");
  544. MODULE_DESCRIPTION("Intel Chipset DIMM Idle Power Saving Driver v"
  545. I7300_IDLE_DRIVER_VERSION);
  546. MODULE_LICENSE("GPL");