ps3-lpm.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  1. /*
  2. * PS3 Logical Performance Monitor.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2007 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/uaccess.h>
  24. #include <asm/smp.h>
  25. #include <asm/time.h>
  26. #include <asm/ps3.h>
  27. #include <asm/lv1call.h>
  28. #include <asm/cell-pmu.h>
  29. /* BOOKMARK tag macros */
  30. #define PS3_PM_BOOKMARK_START 0x8000000000000000ULL
  31. #define PS3_PM_BOOKMARK_STOP 0x4000000000000000ULL
  32. #define PS3_PM_BOOKMARK_TAG_KERNEL 0x1000000000000000ULL
  33. #define PS3_PM_BOOKMARK_TAG_USER 0x3000000000000000ULL
  34. #define PS3_PM_BOOKMARK_TAG_MASK_HI 0xF000000000000000ULL
  35. #define PS3_PM_BOOKMARK_TAG_MASK_LO 0x0F00000000000000ULL
  36. /* CBE PM CONTROL register macros */
  37. #define PS3_PM_CONTROL_PPU_TH0_BOOKMARK 0x00001000
  38. #define PS3_PM_CONTROL_PPU_TH1_BOOKMARK 0x00000800
  39. #define PS3_PM_CONTROL_PPU_COUNT_MODE_MASK 0x000C0000
  40. #define PS3_PM_CONTROL_PPU_COUNT_MODE_PROBLEM 0x00080000
  41. #define PS3_WRITE_PM_MASK 0xFFFFFFFFFFFFFFFFULL
  42. /* CBE PM START STOP register macros */
  43. #define PS3_PM_START_STOP_PPU_TH0_BOOKMARK_START 0x02000000
  44. #define PS3_PM_START_STOP_PPU_TH1_BOOKMARK_START 0x01000000
  45. #define PS3_PM_START_STOP_PPU_TH0_BOOKMARK_STOP 0x00020000
  46. #define PS3_PM_START_STOP_PPU_TH1_BOOKMARK_STOP 0x00010000
  47. #define PS3_PM_START_STOP_START_MASK 0xFF000000
  48. #define PS3_PM_START_STOP_STOP_MASK 0x00FF0000
  49. /* CBE PM COUNTER register macres */
  50. #define PS3_PM_COUNTER_MASK_HI 0xFFFFFFFF00000000ULL
  51. #define PS3_PM_COUNTER_MASK_LO 0x00000000FFFFFFFFULL
  52. /* BASE SIGNAL GROUP NUMBER macros */
  53. #define PM_ISLAND2_BASE_SIGNAL_GROUP_NUMBER 0
  54. #define PM_ISLAND2_SIGNAL_GROUP_NUMBER1 6
  55. #define PM_ISLAND2_SIGNAL_GROUP_NUMBER2 7
  56. #define PM_ISLAND3_BASE_SIGNAL_GROUP_NUMBER 7
  57. #define PM_ISLAND4_BASE_SIGNAL_GROUP_NUMBER 15
  58. #define PM_SPU_TRIGGER_SIGNAL_GROUP_NUMBER 17
  59. #define PM_SPU_EVENT_SIGNAL_GROUP_NUMBER 18
  60. #define PM_ISLAND5_BASE_SIGNAL_GROUP_NUMBER 18
  61. #define PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER 24
  62. #define PM_ISLAND7_BASE_SIGNAL_GROUP_NUMBER 49
  63. #define PM_ISLAND8_BASE_SIGNAL_GROUP_NUMBER 52
  64. #define PM_SIG_GROUP_SPU 41
  65. #define PM_SIG_GROUP_SPU_TRIGGER 42
  66. #define PM_SIG_GROUP_SPU_EVENT 43
  67. #define PM_SIG_GROUP_MFC_MAX 60
  68. /**
  69. * struct ps3_lpm_shadow_regs - Performance monitor shadow registers.
  70. *
  71. * @pm_control: Shadow of the processor's pm_control register.
  72. * @pm_start_stop: Shadow of the processor's pm_start_stop register.
  73. * @group_control: Shadow of the processor's group_control register.
  74. * @debug_bus_control: Shadow of the processor's debug_bus_control register.
  75. *
  76. * The logical performance monitor provides a write-only interface to
  77. * these processor registers. These shadow variables cache the processor
  78. * register values for reading.
  79. *
  80. * The initial value of the shadow registers at lpm creation is
  81. * PS3_LPM_SHADOW_REG_INIT.
  82. */
  83. struct ps3_lpm_shadow_regs {
  84. u64 pm_control;
  85. u64 pm_start_stop;
  86. u64 group_control;
  87. u64 debug_bus_control;
  88. };
  89. #define PS3_LPM_SHADOW_REG_INIT 0xFFFFFFFF00000000ULL
  90. /**
  91. * struct ps3_lpm_priv - Private lpm device data.
  92. *
  93. * @open: An atomic variable indicating the lpm driver has been opened.
  94. * @rights: The lpm rigths granted by the system policy module. A logical
  95. * OR of enum ps3_lpm_rights.
  96. * @node_id: The node id of a BE prosessor whose performance monitor this
  97. * lpar has the right to use.
  98. * @pu_id: The lv1 id of the logical PU.
  99. * @lpm_id: The lv1 id of this lpm instance.
  100. * @outlet_id: The outlet created by lv1 for this lpm instance.
  101. * @tb_count: The number of bytes of data held in the lv1 trace buffer.
  102. * @tb_cache: Kernel buffer to receive the data from the lv1 trace buffer.
  103. * Must be 128 byte aligned.
  104. * @tb_cache_size: Size of the kernel @tb_cache buffer. Must be 128 byte
  105. * aligned.
  106. * @tb_cache_internal: An unaligned buffer allocated by this driver to be
  107. * used for the trace buffer cache when ps3_lpm_open() is called with a
  108. * NULL tb_cache argument. Otherwise unused.
  109. * @shadow: Processor register shadow of type struct ps3_lpm_shadow_regs.
  110. * @sbd: The struct ps3_system_bus_device attached to this driver.
  111. *
  112. * The trace buffer is a buffer allocated and used internally to the lv1
  113. * hypervisor to collect trace data. The trace buffer cache is a guest
  114. * buffer that accepts the trace data from the trace buffer.
  115. */
  116. struct ps3_lpm_priv {
  117. atomic_t open;
  118. u64 rights;
  119. u64 node_id;
  120. u64 pu_id;
  121. u64 lpm_id;
  122. u64 outlet_id;
  123. u64 tb_count;
  124. void *tb_cache;
  125. u64 tb_cache_size;
  126. void *tb_cache_internal;
  127. struct ps3_lpm_shadow_regs shadow;
  128. struct ps3_system_bus_device *sbd;
  129. };
  130. enum {
  131. PS3_LPM_DEFAULT_TB_CACHE_SIZE = 0x4000,
  132. };
  133. /**
  134. * lpm_priv - Static instance of the lpm data.
  135. *
  136. * Since the exported routines don't support the notion of a device
  137. * instance we need to hold the instance in this static variable
  138. * and then only allow at most one instance at a time to be created.
  139. */
  140. static struct ps3_lpm_priv *lpm_priv;
  141. static struct device *sbd_core(void)
  142. {
  143. BUG_ON(!lpm_priv || !lpm_priv->sbd);
  144. return &lpm_priv->sbd->core;
  145. }
  146. /**
  147. * use_start_stop_bookmark - Enable the PPU bookmark trace.
  148. *
  149. * And it enables PPU bookmark triggers ONLY if the other triggers are not set.
  150. * The start/stop bookmarks are inserted at ps3_enable_pm() and ps3_disable_pm()
  151. * to start/stop LPM.
  152. *
  153. * Used to get good quality of the performance counter.
  154. */
  155. enum {use_start_stop_bookmark = 1,};
  156. void ps3_set_bookmark(u64 bookmark)
  157. {
  158. /*
  159. * As per the PPE book IV, to avoid bookmark loss there must
  160. * not be a traced branch within 10 cycles of setting the
  161. * SPRN_BKMK register. The actual text is unclear if 'within'
  162. * includes cycles before the call.
  163. */
  164. asm volatile("nop;nop;nop;nop;nop;nop;nop;nop;nop;");
  165. mtspr(SPRN_BKMK, bookmark);
  166. asm volatile("nop;nop;nop;nop;nop;nop;nop;nop;nop;");
  167. }
  168. EXPORT_SYMBOL_GPL(ps3_set_bookmark);
  169. void ps3_set_pm_bookmark(u64 tag, u64 incident, u64 th_id)
  170. {
  171. u64 bookmark;
  172. bookmark = (get_tb() & 0x00000000FFFFFFFFULL) |
  173. PS3_PM_BOOKMARK_TAG_KERNEL;
  174. bookmark = ((tag << 56) & PS3_PM_BOOKMARK_TAG_MASK_LO) |
  175. (incident << 48) | (th_id << 32) | bookmark;
  176. ps3_set_bookmark(bookmark);
  177. }
  178. EXPORT_SYMBOL_GPL(ps3_set_pm_bookmark);
  179. /**
  180. * ps3_read_phys_ctr - Read physical counter registers.
  181. *
  182. * Each physical counter can act as one 32 bit counter or as two 16 bit
  183. * counters.
  184. */
  185. u32 ps3_read_phys_ctr(u32 cpu, u32 phys_ctr)
  186. {
  187. int result;
  188. u64 counter0415;
  189. u64 counter2637;
  190. if (phys_ctr >= NR_PHYS_CTRS) {
  191. dev_dbg(sbd_core(), "%s:%u: phys_ctr too big: %u\n", __func__,
  192. __LINE__, phys_ctr);
  193. return 0;
  194. }
  195. result = lv1_set_lpm_counter(lpm_priv->lpm_id, 0, 0, 0, 0, &counter0415,
  196. &counter2637);
  197. if (result) {
  198. dev_err(sbd_core(), "%s:%u: lv1_set_lpm_counter failed: "
  199. "phys_ctr %u, %s\n", __func__, __LINE__, phys_ctr,
  200. ps3_result(result));
  201. return 0;
  202. }
  203. switch (phys_ctr) {
  204. case 0:
  205. return counter0415 >> 32;
  206. case 1:
  207. return counter0415 & PS3_PM_COUNTER_MASK_LO;
  208. case 2:
  209. return counter2637 >> 32;
  210. case 3:
  211. return counter2637 & PS3_PM_COUNTER_MASK_LO;
  212. default:
  213. BUG();
  214. }
  215. return 0;
  216. }
  217. EXPORT_SYMBOL_GPL(ps3_read_phys_ctr);
  218. /**
  219. * ps3_write_phys_ctr - Write physical counter registers.
  220. *
  221. * Each physical counter can act as one 32 bit counter or as two 16 bit
  222. * counters.
  223. */
  224. void ps3_write_phys_ctr(u32 cpu, u32 phys_ctr, u32 val)
  225. {
  226. u64 counter0415;
  227. u64 counter0415_mask;
  228. u64 counter2637;
  229. u64 counter2637_mask;
  230. int result;
  231. if (phys_ctr >= NR_PHYS_CTRS) {
  232. dev_dbg(sbd_core(), "%s:%u: phys_ctr too big: %u\n", __func__,
  233. __LINE__, phys_ctr);
  234. return;
  235. }
  236. switch (phys_ctr) {
  237. case 0:
  238. counter0415 = (u64)val << 32;
  239. counter0415_mask = PS3_PM_COUNTER_MASK_HI;
  240. counter2637 = 0x0;
  241. counter2637_mask = 0x0;
  242. break;
  243. case 1:
  244. counter0415 = (u64)val;
  245. counter0415_mask = PS3_PM_COUNTER_MASK_LO;
  246. counter2637 = 0x0;
  247. counter2637_mask = 0x0;
  248. break;
  249. case 2:
  250. counter0415 = 0x0;
  251. counter0415_mask = 0x0;
  252. counter2637 = (u64)val << 32;
  253. counter2637_mask = PS3_PM_COUNTER_MASK_HI;
  254. break;
  255. case 3:
  256. counter0415 = 0x0;
  257. counter0415_mask = 0x0;
  258. counter2637 = (u64)val;
  259. counter2637_mask = PS3_PM_COUNTER_MASK_LO;
  260. break;
  261. default:
  262. BUG();
  263. }
  264. result = lv1_set_lpm_counter(lpm_priv->lpm_id,
  265. counter0415, counter0415_mask,
  266. counter2637, counter2637_mask,
  267. &counter0415, &counter2637);
  268. if (result)
  269. dev_err(sbd_core(), "%s:%u: lv1_set_lpm_counter failed: "
  270. "phys_ctr %u, val %u, %s\n", __func__, __LINE__,
  271. phys_ctr, val, ps3_result(result));
  272. }
  273. EXPORT_SYMBOL_GPL(ps3_write_phys_ctr);
  274. /**
  275. * ps3_read_ctr - Read counter.
  276. *
  277. * Read 16 or 32 bits depending on the current size of the counter.
  278. * Counters 4, 5, 6 & 7 are always 16 bit.
  279. */
  280. u32 ps3_read_ctr(u32 cpu, u32 ctr)
  281. {
  282. u32 val;
  283. u32 phys_ctr = ctr & (NR_PHYS_CTRS - 1);
  284. val = ps3_read_phys_ctr(cpu, phys_ctr);
  285. if (ps3_get_ctr_size(cpu, phys_ctr) == 16)
  286. val = (ctr < NR_PHYS_CTRS) ? (val >> 16) : (val & 0xffff);
  287. return val;
  288. }
  289. EXPORT_SYMBOL_GPL(ps3_read_ctr);
  290. /**
  291. * ps3_write_ctr - Write counter.
  292. *
  293. * Write 16 or 32 bits depending on the current size of the counter.
  294. * Counters 4, 5, 6 & 7 are always 16 bit.
  295. */
  296. void ps3_write_ctr(u32 cpu, u32 ctr, u32 val)
  297. {
  298. u32 phys_ctr;
  299. u32 phys_val;
  300. phys_ctr = ctr & (NR_PHYS_CTRS - 1);
  301. if (ps3_get_ctr_size(cpu, phys_ctr) == 16) {
  302. phys_val = ps3_read_phys_ctr(cpu, phys_ctr);
  303. if (ctr < NR_PHYS_CTRS)
  304. val = (val << 16) | (phys_val & 0xffff);
  305. else
  306. val = (val & 0xffff) | (phys_val & 0xffff0000);
  307. }
  308. ps3_write_phys_ctr(cpu, phys_ctr, val);
  309. }
  310. EXPORT_SYMBOL_GPL(ps3_write_ctr);
  311. /**
  312. * ps3_read_pm07_control - Read counter control registers.
  313. *
  314. * Each logical counter has a corresponding control register.
  315. */
  316. u32 ps3_read_pm07_control(u32 cpu, u32 ctr)
  317. {
  318. return 0;
  319. }
  320. EXPORT_SYMBOL_GPL(ps3_read_pm07_control);
  321. /**
  322. * ps3_write_pm07_control - Write counter control registers.
  323. *
  324. * Each logical counter has a corresponding control register.
  325. */
  326. void ps3_write_pm07_control(u32 cpu, u32 ctr, u32 val)
  327. {
  328. int result;
  329. static const u64 mask = 0xFFFFFFFFFFFFFFFFULL;
  330. u64 old_value;
  331. if (ctr >= NR_CTRS) {
  332. dev_dbg(sbd_core(), "%s:%u: ctr too big: %u\n", __func__,
  333. __LINE__, ctr);
  334. return;
  335. }
  336. result = lv1_set_lpm_counter_control(lpm_priv->lpm_id, ctr, val, mask,
  337. &old_value);
  338. if (result)
  339. dev_err(sbd_core(), "%s:%u: lv1_set_lpm_counter_control "
  340. "failed: ctr %u, %s\n", __func__, __LINE__, ctr,
  341. ps3_result(result));
  342. }
  343. EXPORT_SYMBOL_GPL(ps3_write_pm07_control);
  344. /**
  345. * ps3_read_pm - Read Other LPM control registers.
  346. */
  347. u32 ps3_read_pm(u32 cpu, enum pm_reg_name reg)
  348. {
  349. int result = 0;
  350. u64 val = 0;
  351. switch (reg) {
  352. case pm_control:
  353. return lpm_priv->shadow.pm_control;
  354. case trace_address:
  355. return CBE_PM_TRACE_BUF_EMPTY;
  356. case pm_start_stop:
  357. return lpm_priv->shadow.pm_start_stop;
  358. case pm_interval:
  359. result = lv1_set_lpm_interval(lpm_priv->lpm_id, 0, 0, &val);
  360. if (result) {
  361. val = 0;
  362. dev_dbg(sbd_core(), "%s:%u: lv1 set_inteval failed: "
  363. "reg %u, %s\n", __func__, __LINE__, reg,
  364. ps3_result(result));
  365. }
  366. return (u32)val;
  367. case group_control:
  368. return lpm_priv->shadow.group_control;
  369. case debug_bus_control:
  370. return lpm_priv->shadow.debug_bus_control;
  371. case pm_status:
  372. result = lv1_get_lpm_interrupt_status(lpm_priv->lpm_id,
  373. &val);
  374. if (result) {
  375. val = 0;
  376. dev_dbg(sbd_core(), "%s:%u: lv1 get_lpm_status failed: "
  377. "reg %u, %s\n", __func__, __LINE__, reg,
  378. ps3_result(result));
  379. }
  380. return (u32)val;
  381. case ext_tr_timer:
  382. return 0;
  383. default:
  384. dev_dbg(sbd_core(), "%s:%u: unknown reg: %d\n", __func__,
  385. __LINE__, reg);
  386. BUG();
  387. break;
  388. }
  389. return 0;
  390. }
  391. EXPORT_SYMBOL_GPL(ps3_read_pm);
  392. /**
  393. * ps3_write_pm - Write Other LPM control registers.
  394. */
  395. void ps3_write_pm(u32 cpu, enum pm_reg_name reg, u32 val)
  396. {
  397. int result = 0;
  398. u64 dummy;
  399. switch (reg) {
  400. case group_control:
  401. if (val != lpm_priv->shadow.group_control)
  402. result = lv1_set_lpm_group_control(lpm_priv->lpm_id,
  403. val,
  404. PS3_WRITE_PM_MASK,
  405. &dummy);
  406. lpm_priv->shadow.group_control = val;
  407. break;
  408. case debug_bus_control:
  409. if (val != lpm_priv->shadow.debug_bus_control)
  410. result = lv1_set_lpm_debug_bus_control(lpm_priv->lpm_id,
  411. val,
  412. PS3_WRITE_PM_MASK,
  413. &dummy);
  414. lpm_priv->shadow.debug_bus_control = val;
  415. break;
  416. case pm_control:
  417. if (use_start_stop_bookmark)
  418. val |= (PS3_PM_CONTROL_PPU_TH0_BOOKMARK |
  419. PS3_PM_CONTROL_PPU_TH1_BOOKMARK);
  420. if (val != lpm_priv->shadow.pm_control)
  421. result = lv1_set_lpm_general_control(lpm_priv->lpm_id,
  422. val,
  423. PS3_WRITE_PM_MASK,
  424. 0, 0, &dummy,
  425. &dummy);
  426. lpm_priv->shadow.pm_control = val;
  427. break;
  428. case pm_interval:
  429. result = lv1_set_lpm_interval(lpm_priv->lpm_id, val,
  430. PS3_WRITE_PM_MASK, &dummy);
  431. break;
  432. case pm_start_stop:
  433. if (val != lpm_priv->shadow.pm_start_stop)
  434. result = lv1_set_lpm_trigger_control(lpm_priv->lpm_id,
  435. val,
  436. PS3_WRITE_PM_MASK,
  437. &dummy);
  438. lpm_priv->shadow.pm_start_stop = val;
  439. break;
  440. case trace_address:
  441. case ext_tr_timer:
  442. case pm_status:
  443. break;
  444. default:
  445. dev_dbg(sbd_core(), "%s:%u: unknown reg: %d\n", __func__,
  446. __LINE__, reg);
  447. BUG();
  448. break;
  449. }
  450. if (result)
  451. dev_err(sbd_core(), "%s:%u: lv1 set_control failed: "
  452. "reg %u, %s\n", __func__, __LINE__, reg,
  453. ps3_result(result));
  454. }
  455. EXPORT_SYMBOL_GPL(ps3_write_pm);
  456. /**
  457. * ps3_get_ctr_size - Get the size of a physical counter.
  458. *
  459. * Returns either 16 or 32.
  460. */
  461. u32 ps3_get_ctr_size(u32 cpu, u32 phys_ctr)
  462. {
  463. u32 pm_ctrl;
  464. if (phys_ctr >= NR_PHYS_CTRS) {
  465. dev_dbg(sbd_core(), "%s:%u: phys_ctr too big: %u\n", __func__,
  466. __LINE__, phys_ctr);
  467. return 0;
  468. }
  469. pm_ctrl = ps3_read_pm(cpu, pm_control);
  470. return (pm_ctrl & CBE_PM_16BIT_CTR(phys_ctr)) ? 16 : 32;
  471. }
  472. EXPORT_SYMBOL_GPL(ps3_get_ctr_size);
  473. /**
  474. * ps3_set_ctr_size - Set the size of a physical counter to 16 or 32 bits.
  475. */
  476. void ps3_set_ctr_size(u32 cpu, u32 phys_ctr, u32 ctr_size)
  477. {
  478. u32 pm_ctrl;
  479. if (phys_ctr >= NR_PHYS_CTRS) {
  480. dev_dbg(sbd_core(), "%s:%u: phys_ctr too big: %u\n", __func__,
  481. __LINE__, phys_ctr);
  482. return;
  483. }
  484. pm_ctrl = ps3_read_pm(cpu, pm_control);
  485. switch (ctr_size) {
  486. case 16:
  487. pm_ctrl |= CBE_PM_16BIT_CTR(phys_ctr);
  488. ps3_write_pm(cpu, pm_control, pm_ctrl);
  489. break;
  490. case 32:
  491. pm_ctrl &= ~CBE_PM_16BIT_CTR(phys_ctr);
  492. ps3_write_pm(cpu, pm_control, pm_ctrl);
  493. break;
  494. default:
  495. BUG();
  496. }
  497. }
  498. EXPORT_SYMBOL_GPL(ps3_set_ctr_size);
  499. static u64 pm_translate_signal_group_number_on_island2(u64 subgroup)
  500. {
  501. if (subgroup == 2)
  502. subgroup = 3;
  503. if (subgroup <= 6)
  504. return PM_ISLAND2_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  505. else if (subgroup == 7)
  506. return PM_ISLAND2_SIGNAL_GROUP_NUMBER1;
  507. else
  508. return PM_ISLAND2_SIGNAL_GROUP_NUMBER2;
  509. }
  510. static u64 pm_translate_signal_group_number_on_island3(u64 subgroup)
  511. {
  512. switch (subgroup) {
  513. case 2:
  514. case 3:
  515. case 4:
  516. subgroup += 2;
  517. break;
  518. case 5:
  519. subgroup = 8;
  520. break;
  521. default:
  522. break;
  523. }
  524. return PM_ISLAND3_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  525. }
  526. static u64 pm_translate_signal_group_number_on_island4(u64 subgroup)
  527. {
  528. return PM_ISLAND4_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  529. }
  530. static u64 pm_translate_signal_group_number_on_island5(u64 subgroup)
  531. {
  532. switch (subgroup) {
  533. case 3:
  534. subgroup = 4;
  535. break;
  536. case 4:
  537. subgroup = 6;
  538. break;
  539. default:
  540. break;
  541. }
  542. return PM_ISLAND5_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  543. }
  544. static u64 pm_translate_signal_group_number_on_island6(u64 subgroup,
  545. u64 subsubgroup)
  546. {
  547. switch (subgroup) {
  548. case 3:
  549. case 4:
  550. case 5:
  551. subgroup += 1;
  552. break;
  553. default:
  554. break;
  555. }
  556. switch (subsubgroup) {
  557. case 4:
  558. case 5:
  559. case 6:
  560. subsubgroup += 2;
  561. break;
  562. case 7:
  563. case 8:
  564. case 9:
  565. case 10:
  566. subsubgroup += 4;
  567. break;
  568. case 11:
  569. case 12:
  570. case 13:
  571. subsubgroup += 5;
  572. break;
  573. default:
  574. break;
  575. }
  576. if (subgroup <= 5)
  577. return (PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER + subgroup);
  578. else
  579. return (PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER + subgroup
  580. + subsubgroup - 1);
  581. }
  582. static u64 pm_translate_signal_group_number_on_island7(u64 subgroup)
  583. {
  584. return PM_ISLAND7_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  585. }
  586. static u64 pm_translate_signal_group_number_on_island8(u64 subgroup)
  587. {
  588. return PM_ISLAND8_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  589. }
  590. static u64 pm_signal_group_to_ps3_lv1_signal_group(u64 group)
  591. {
  592. u64 island;
  593. u64 subgroup;
  594. u64 subsubgroup;
  595. subgroup = 0;
  596. subsubgroup = 0;
  597. island = 0;
  598. if (group < 1000) {
  599. if (group < 100) {
  600. if (20 <= group && group < 30) {
  601. island = 2;
  602. subgroup = group - 20;
  603. } else if (30 <= group && group < 40) {
  604. island = 3;
  605. subgroup = group - 30;
  606. } else if (40 <= group && group < 50) {
  607. island = 4;
  608. subgroup = group - 40;
  609. } else if (50 <= group && group < 60) {
  610. island = 5;
  611. subgroup = group - 50;
  612. } else if (60 <= group && group < 70) {
  613. island = 6;
  614. subgroup = group - 60;
  615. } else if (70 <= group && group < 80) {
  616. island = 7;
  617. subgroup = group - 70;
  618. } else if (80 <= group && group < 90) {
  619. island = 8;
  620. subgroup = group - 80;
  621. }
  622. } else if (200 <= group && group < 300) {
  623. island = 2;
  624. subgroup = group - 200;
  625. } else if (600 <= group && group < 700) {
  626. island = 6;
  627. subgroup = 5;
  628. subsubgroup = group - 650;
  629. }
  630. } else if (6000 <= group && group < 7000) {
  631. island = 6;
  632. subgroup = 5;
  633. subsubgroup = group - 6500;
  634. }
  635. switch (island) {
  636. case 2:
  637. return pm_translate_signal_group_number_on_island2(subgroup);
  638. case 3:
  639. return pm_translate_signal_group_number_on_island3(subgroup);
  640. case 4:
  641. return pm_translate_signal_group_number_on_island4(subgroup);
  642. case 5:
  643. return pm_translate_signal_group_number_on_island5(subgroup);
  644. case 6:
  645. return pm_translate_signal_group_number_on_island6(subgroup,
  646. subsubgroup);
  647. case 7:
  648. return pm_translate_signal_group_number_on_island7(subgroup);
  649. case 8:
  650. return pm_translate_signal_group_number_on_island8(subgroup);
  651. default:
  652. dev_dbg(sbd_core(), "%s:%u: island not found: %lu\n", __func__,
  653. __LINE__, group);
  654. BUG();
  655. break;
  656. }
  657. return 0;
  658. }
  659. static u64 pm_bus_word_to_ps3_lv1_bus_word(u8 word)
  660. {
  661. switch (word) {
  662. case 1:
  663. return 0xF000;
  664. case 2:
  665. return 0x0F00;
  666. case 4:
  667. return 0x00F0;
  668. case 8:
  669. default:
  670. return 0x000F;
  671. }
  672. }
  673. static int __ps3_set_signal(u64 lv1_signal_group, u64 bus_select,
  674. u64 signal_select, u64 attr1, u64 attr2, u64 attr3)
  675. {
  676. int ret;
  677. ret = lv1_set_lpm_signal(lpm_priv->lpm_id, lv1_signal_group, bus_select,
  678. signal_select, attr1, attr2, attr3);
  679. if (ret)
  680. dev_err(sbd_core(),
  681. "%s:%u: error:%d 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
  682. __func__, __LINE__, ret, lv1_signal_group, bus_select,
  683. signal_select, attr1, attr2, attr3);
  684. return ret;
  685. }
  686. int ps3_set_signal(u64 signal_group, u8 signal_bit, u16 sub_unit,
  687. u8 bus_word)
  688. {
  689. int ret;
  690. u64 lv1_signal_group;
  691. u64 bus_select;
  692. u64 signal_select;
  693. u64 attr1, attr2, attr3;
  694. if (signal_group == 0)
  695. return __ps3_set_signal(0, 0, 0, 0, 0, 0);
  696. lv1_signal_group =
  697. pm_signal_group_to_ps3_lv1_signal_group(signal_group);
  698. bus_select = pm_bus_word_to_ps3_lv1_bus_word(bus_word);
  699. switch (signal_group) {
  700. case PM_SIG_GROUP_SPU_TRIGGER:
  701. signal_select = 1;
  702. signal_select = signal_select << (63 - signal_bit);
  703. break;
  704. case PM_SIG_GROUP_SPU_EVENT:
  705. signal_select = 1;
  706. signal_select = (signal_select << (63 - signal_bit)) | 0x3;
  707. break;
  708. default:
  709. signal_select = 0;
  710. break;
  711. }
  712. /*
  713. * 0: physical object.
  714. * 1: logical object.
  715. * This parameter is only used for the PPE and SPE signals.
  716. */
  717. attr1 = 1;
  718. /*
  719. * This parameter is used to specify the target physical/logical
  720. * PPE/SPE object.
  721. */
  722. if (PM_SIG_GROUP_SPU <= signal_group &&
  723. signal_group < PM_SIG_GROUP_MFC_MAX)
  724. attr2 = sub_unit;
  725. else
  726. attr2 = lpm_priv->pu_id;
  727. /*
  728. * This parameter is only used for setting the SPE signal.
  729. */
  730. attr3 = 0;
  731. ret = __ps3_set_signal(lv1_signal_group, bus_select, signal_select,
  732. attr1, attr2, attr3);
  733. if (ret)
  734. dev_err(sbd_core(), "%s:%u: __ps3_set_signal failed: %d\n",
  735. __func__, __LINE__, ret);
  736. return ret;
  737. }
  738. EXPORT_SYMBOL_GPL(ps3_set_signal);
  739. u32 ps3_get_hw_thread_id(int cpu)
  740. {
  741. return get_hard_smp_processor_id(cpu);
  742. }
  743. EXPORT_SYMBOL_GPL(ps3_get_hw_thread_id);
  744. /**
  745. * ps3_enable_pm - Enable the entire performance monitoring unit.
  746. *
  747. * When we enable the LPM, all pending writes to counters get committed.
  748. */
  749. void ps3_enable_pm(u32 cpu)
  750. {
  751. int result;
  752. u64 tmp;
  753. int insert_bookmark = 0;
  754. lpm_priv->tb_count = 0;
  755. if (use_start_stop_bookmark) {
  756. if (!(lpm_priv->shadow.pm_start_stop &
  757. (PS3_PM_START_STOP_START_MASK
  758. | PS3_PM_START_STOP_STOP_MASK))) {
  759. result = lv1_set_lpm_trigger_control(lpm_priv->lpm_id,
  760. (PS3_PM_START_STOP_PPU_TH0_BOOKMARK_START |
  761. PS3_PM_START_STOP_PPU_TH1_BOOKMARK_START |
  762. PS3_PM_START_STOP_PPU_TH0_BOOKMARK_STOP |
  763. PS3_PM_START_STOP_PPU_TH1_BOOKMARK_STOP),
  764. 0xFFFFFFFFFFFFFFFFULL, &tmp);
  765. if (result)
  766. dev_err(sbd_core(), "%s:%u: "
  767. "lv1_set_lpm_trigger_control failed: "
  768. "%s\n", __func__, __LINE__,
  769. ps3_result(result));
  770. insert_bookmark = !result;
  771. }
  772. }
  773. result = lv1_start_lpm(lpm_priv->lpm_id);
  774. if (result)
  775. dev_err(sbd_core(), "%s:%u: lv1_start_lpm failed: %s\n",
  776. __func__, __LINE__, ps3_result(result));
  777. if (use_start_stop_bookmark && !result && insert_bookmark)
  778. ps3_set_bookmark(get_tb() | PS3_PM_BOOKMARK_START);
  779. }
  780. EXPORT_SYMBOL_GPL(ps3_enable_pm);
  781. /**
  782. * ps3_disable_pm - Disable the entire performance monitoring unit.
  783. */
  784. void ps3_disable_pm(u32 cpu)
  785. {
  786. int result;
  787. u64 tmp;
  788. ps3_set_bookmark(get_tb() | PS3_PM_BOOKMARK_STOP);
  789. result = lv1_stop_lpm(lpm_priv->lpm_id, &tmp);
  790. if (result) {
  791. if(result != LV1_WRONG_STATE)
  792. dev_err(sbd_core(), "%s:%u: lv1_stop_lpm failed: %s\n",
  793. __func__, __LINE__, ps3_result(result));
  794. return;
  795. }
  796. lpm_priv->tb_count = tmp;
  797. dev_dbg(sbd_core(), "%s:%u: tb_count %lu (%lxh)\n", __func__, __LINE__,
  798. lpm_priv->tb_count, lpm_priv->tb_count);
  799. }
  800. EXPORT_SYMBOL_GPL(ps3_disable_pm);
  801. /**
  802. * ps3_lpm_copy_tb - Copy data from the trace buffer to a kernel buffer.
  803. * @offset: Offset in bytes from the start of the trace buffer.
  804. * @buf: Copy destination.
  805. * @count: Maximum count of bytes to copy.
  806. * @bytes_copied: Pointer to a variable that will recieve the number of
  807. * bytes copied to @buf.
  808. *
  809. * On error @buf will contain any successfully copied trace buffer data
  810. * and bytes_copied will be set to the number of bytes successfully copied.
  811. */
  812. int ps3_lpm_copy_tb(unsigned long offset, void *buf, unsigned long count,
  813. unsigned long *bytes_copied)
  814. {
  815. int result;
  816. *bytes_copied = 0;
  817. if (!lpm_priv->tb_cache)
  818. return -EPERM;
  819. if (offset >= lpm_priv->tb_count)
  820. return 0;
  821. count = min(count, lpm_priv->tb_count - offset);
  822. while (*bytes_copied < count) {
  823. const unsigned long request = count - *bytes_copied;
  824. u64 tmp;
  825. result = lv1_copy_lpm_trace_buffer(lpm_priv->lpm_id, offset,
  826. request, &tmp);
  827. if (result) {
  828. dev_dbg(sbd_core(), "%s:%u: 0x%lx bytes at 0x%lx\n",
  829. __func__, __LINE__, request, offset);
  830. dev_err(sbd_core(), "%s:%u: lv1_copy_lpm_trace_buffer "
  831. "failed: %s\n", __func__, __LINE__,
  832. ps3_result(result));
  833. return result == LV1_WRONG_STATE ? -EBUSY : -EINVAL;
  834. }
  835. memcpy(buf, lpm_priv->tb_cache, tmp);
  836. buf += tmp;
  837. *bytes_copied += tmp;
  838. offset += tmp;
  839. }
  840. dev_dbg(sbd_core(), "%s:%u: copied %lxh bytes\n", __func__, __LINE__,
  841. *bytes_copied);
  842. return 0;
  843. }
  844. EXPORT_SYMBOL_GPL(ps3_lpm_copy_tb);
  845. /**
  846. * ps3_lpm_copy_tb_to_user - Copy data from the trace buffer to a user buffer.
  847. * @offset: Offset in bytes from the start of the trace buffer.
  848. * @buf: A __user copy destination.
  849. * @count: Maximum count of bytes to copy.
  850. * @bytes_copied: Pointer to a variable that will recieve the number of
  851. * bytes copied to @buf.
  852. *
  853. * On error @buf will contain any successfully copied trace buffer data
  854. * and bytes_copied will be set to the number of bytes successfully copied.
  855. */
  856. int ps3_lpm_copy_tb_to_user(unsigned long offset, void __user *buf,
  857. unsigned long count, unsigned long *bytes_copied)
  858. {
  859. int result;
  860. *bytes_copied = 0;
  861. if (!lpm_priv->tb_cache)
  862. return -EPERM;
  863. if (offset >= lpm_priv->tb_count)
  864. return 0;
  865. count = min(count, lpm_priv->tb_count - offset);
  866. while (*bytes_copied < count) {
  867. const unsigned long request = count - *bytes_copied;
  868. u64 tmp;
  869. result = lv1_copy_lpm_trace_buffer(lpm_priv->lpm_id, offset,
  870. request, &tmp);
  871. if (result) {
  872. dev_dbg(sbd_core(), "%s:%u: 0x%lx bytes at 0x%lx\n",
  873. __func__, __LINE__, request, offset);
  874. dev_err(sbd_core(), "%s:%u: lv1_copy_lpm_trace_buffer "
  875. "failed: %s\n", __func__, __LINE__,
  876. ps3_result(result));
  877. return result == LV1_WRONG_STATE ? -EBUSY : -EINVAL;
  878. }
  879. result = copy_to_user(buf, lpm_priv->tb_cache, tmp);
  880. if (result) {
  881. dev_dbg(sbd_core(), "%s:%u: 0x%lx bytes at 0x%p\n",
  882. __func__, __LINE__, tmp, buf);
  883. dev_err(sbd_core(), "%s:%u: copy_to_user failed: %d\n",
  884. __func__, __LINE__, result);
  885. return -EFAULT;
  886. }
  887. buf += tmp;
  888. *bytes_copied += tmp;
  889. offset += tmp;
  890. }
  891. dev_dbg(sbd_core(), "%s:%u: copied %lxh bytes\n", __func__, __LINE__,
  892. *bytes_copied);
  893. return 0;
  894. }
  895. EXPORT_SYMBOL_GPL(ps3_lpm_copy_tb_to_user);
  896. /**
  897. * ps3_get_and_clear_pm_interrupts -
  898. *
  899. * Clearing interrupts for the entire performance monitoring unit.
  900. * Reading pm_status clears the interrupt bits.
  901. */
  902. u32 ps3_get_and_clear_pm_interrupts(u32 cpu)
  903. {
  904. return ps3_read_pm(cpu, pm_status);
  905. }
  906. EXPORT_SYMBOL_GPL(ps3_get_and_clear_pm_interrupts);
  907. /**
  908. * ps3_enable_pm_interrupts -
  909. *
  910. * Enabling interrupts for the entire performance monitoring unit.
  911. * Enables the interrupt bits in the pm_status register.
  912. */
  913. void ps3_enable_pm_interrupts(u32 cpu, u32 thread, u32 mask)
  914. {
  915. if (mask)
  916. ps3_write_pm(cpu, pm_status, mask);
  917. }
  918. EXPORT_SYMBOL_GPL(ps3_enable_pm_interrupts);
  919. /**
  920. * ps3_enable_pm_interrupts -
  921. *
  922. * Disabling interrupts for the entire performance monitoring unit.
  923. */
  924. void ps3_disable_pm_interrupts(u32 cpu)
  925. {
  926. ps3_get_and_clear_pm_interrupts(cpu);
  927. ps3_write_pm(cpu, pm_status, 0);
  928. }
  929. EXPORT_SYMBOL_GPL(ps3_disable_pm_interrupts);
  930. /**
  931. * ps3_lpm_open - Open the logical performance monitor device.
  932. * @tb_type: Specifies the type of trace buffer lv1 sould use for this lpm
  933. * instance, specified by one of enum ps3_lpm_tb_type.
  934. * @tb_cache: Optional user supplied buffer to use as the trace buffer cache.
  935. * If NULL, the driver will allocate and manage an internal buffer.
  936. * Unused when when @tb_type is PS3_LPM_TB_TYPE_NONE.
  937. * @tb_cache_size: The size in bytes of the user supplied @tb_cache buffer.
  938. * Unused when @tb_cache is NULL or @tb_type is PS3_LPM_TB_TYPE_NONE.
  939. */
  940. int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
  941. u64 tb_cache_size)
  942. {
  943. int result;
  944. u64 tb_size;
  945. BUG_ON(!lpm_priv);
  946. BUG_ON(tb_type != PS3_LPM_TB_TYPE_NONE
  947. && tb_type != PS3_LPM_TB_TYPE_INTERNAL);
  948. if (tb_type == PS3_LPM_TB_TYPE_NONE && tb_cache)
  949. dev_dbg(sbd_core(), "%s:%u: bad in vals\n", __func__, __LINE__);
  950. if (!atomic_add_unless(&lpm_priv->open, 1, 1)) {
  951. dev_dbg(sbd_core(), "%s:%u: busy\n", __func__, __LINE__);
  952. return -EBUSY;
  953. }
  954. /* Note tb_cache needs 128 byte alignment. */
  955. if (tb_type == PS3_LPM_TB_TYPE_NONE) {
  956. lpm_priv->tb_cache_size = 0;
  957. lpm_priv->tb_cache_internal = NULL;
  958. lpm_priv->tb_cache = NULL;
  959. } else if (tb_cache) {
  960. if (tb_cache != (void *)_ALIGN_UP((unsigned long)tb_cache, 128)
  961. || tb_cache_size != _ALIGN_UP(tb_cache_size, 128)) {
  962. dev_err(sbd_core(), "%s:%u: unaligned tb_cache\n",
  963. __func__, __LINE__);
  964. result = -EINVAL;
  965. goto fail_align;
  966. }
  967. lpm_priv->tb_cache_size = tb_cache_size;
  968. lpm_priv->tb_cache_internal = NULL;
  969. lpm_priv->tb_cache = tb_cache;
  970. } else {
  971. lpm_priv->tb_cache_size = PS3_LPM_DEFAULT_TB_CACHE_SIZE;
  972. lpm_priv->tb_cache_internal = kzalloc(
  973. lpm_priv->tb_cache_size + 127, GFP_KERNEL);
  974. if (!lpm_priv->tb_cache_internal) {
  975. dev_err(sbd_core(), "%s:%u: alloc internal tb_cache "
  976. "failed\n", __func__, __LINE__);
  977. result = -ENOMEM;
  978. goto fail_malloc;
  979. }
  980. lpm_priv->tb_cache = (void *)_ALIGN_UP(
  981. (unsigned long)lpm_priv->tb_cache_internal, 128);
  982. }
  983. result = lv1_construct_lpm(lpm_priv->node_id, tb_type, 0, 0,
  984. ps3_mm_phys_to_lpar(__pa(lpm_priv->tb_cache)),
  985. lpm_priv->tb_cache_size, &lpm_priv->lpm_id,
  986. &lpm_priv->outlet_id, &tb_size);
  987. if (result) {
  988. dev_err(sbd_core(), "%s:%u: lv1_construct_lpm failed: %s\n",
  989. __func__, __LINE__, ps3_result(result));
  990. result = -EINVAL;
  991. goto fail_construct;
  992. }
  993. lpm_priv->shadow.pm_control = PS3_LPM_SHADOW_REG_INIT;
  994. lpm_priv->shadow.pm_start_stop = PS3_LPM_SHADOW_REG_INIT;
  995. lpm_priv->shadow.group_control = PS3_LPM_SHADOW_REG_INIT;
  996. lpm_priv->shadow.debug_bus_control = PS3_LPM_SHADOW_REG_INIT;
  997. dev_dbg(sbd_core(), "%s:%u: lpm_id 0x%lx, outlet_id 0x%lx, "
  998. "tb_size 0x%lx\n", __func__, __LINE__, lpm_priv->lpm_id,
  999. lpm_priv->outlet_id, tb_size);
  1000. return 0;
  1001. fail_construct:
  1002. kfree(lpm_priv->tb_cache_internal);
  1003. lpm_priv->tb_cache_internal = NULL;
  1004. fail_malloc:
  1005. fail_align:
  1006. atomic_dec(&lpm_priv->open);
  1007. return result;
  1008. }
  1009. EXPORT_SYMBOL_GPL(ps3_lpm_open);
  1010. /**
  1011. * ps3_lpm_close - Close the lpm device.
  1012. *
  1013. */
  1014. int ps3_lpm_close(void)
  1015. {
  1016. dev_dbg(sbd_core(), "%s:%u\n", __func__, __LINE__);
  1017. lv1_destruct_lpm(lpm_priv->lpm_id);
  1018. lpm_priv->lpm_id = 0;
  1019. kfree(lpm_priv->tb_cache_internal);
  1020. lpm_priv->tb_cache_internal = NULL;
  1021. atomic_dec(&lpm_priv->open);
  1022. return 0;
  1023. }
  1024. EXPORT_SYMBOL_GPL(ps3_lpm_close);
  1025. static int __devinit ps3_lpm_probe(struct ps3_system_bus_device *dev)
  1026. {
  1027. dev_dbg(&dev->core, " -> %s:%u\n", __func__, __LINE__);
  1028. if (lpm_priv) {
  1029. dev_info(&dev->core, "%s:%u: called twice\n",
  1030. __func__, __LINE__);
  1031. return -EBUSY;
  1032. }
  1033. lpm_priv = kzalloc(sizeof(*lpm_priv), GFP_KERNEL);
  1034. if (!lpm_priv)
  1035. return -ENOMEM;
  1036. lpm_priv->sbd = dev;
  1037. lpm_priv->node_id = dev->lpm.node_id;
  1038. lpm_priv->pu_id = dev->lpm.pu_id;
  1039. lpm_priv->rights = dev->lpm.rights;
  1040. dev_info(&dev->core, " <- %s:%u:\n", __func__, __LINE__);
  1041. return 0;
  1042. }
  1043. static int ps3_lpm_remove(struct ps3_system_bus_device *dev)
  1044. {
  1045. dev_dbg(&dev->core, " -> %s:%u:\n", __func__, __LINE__);
  1046. ps3_lpm_close();
  1047. kfree(lpm_priv);
  1048. lpm_priv = NULL;
  1049. dev_info(&dev->core, " <- %s:%u:\n", __func__, __LINE__);
  1050. return 0;
  1051. }
  1052. static struct ps3_system_bus_driver ps3_lpm_driver = {
  1053. .match_id = PS3_MATCH_ID_LPM,
  1054. .core.name = "ps3-lpm",
  1055. .core.owner = THIS_MODULE,
  1056. .probe = ps3_lpm_probe,
  1057. .remove = ps3_lpm_remove,
  1058. .shutdown = ps3_lpm_remove,
  1059. };
  1060. static int __init ps3_lpm_init(void)
  1061. {
  1062. pr_debug("%s:%d:\n", __func__, __LINE__);
  1063. return ps3_system_bus_driver_register(&ps3_lpm_driver);
  1064. }
  1065. static void __exit ps3_lpm_exit(void)
  1066. {
  1067. pr_debug("%s:%d:\n", __func__, __LINE__);
  1068. ps3_system_bus_driver_unregister(&ps3_lpm_driver);
  1069. }
  1070. module_init(ps3_lpm_init);
  1071. module_exit(ps3_lpm_exit);
  1072. MODULE_LICENSE("GPL v2");
  1073. MODULE_DESCRIPTION("PS3 Logical Performance Monitor Driver");
  1074. MODULE_AUTHOR("Sony Corporation");
  1075. MODULE_ALIAS(PS3_MODULE_ALIAS_LPM);