ps3-lpm.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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/ps3.h>
  25. #include <asm/lv1call.h>
  26. #include <asm/cell-pmu.h>
  27. /* BOOKMARK tag macros */
  28. #define PS3_PM_BOOKMARK_START 0x8000000000000000ULL
  29. #define PS3_PM_BOOKMARK_STOP 0x4000000000000000ULL
  30. #define PS3_PM_BOOKMARK_TAG_KERNEL 0x1000000000000000ULL
  31. #define PS3_PM_BOOKMARK_TAG_USER 0x3000000000000000ULL
  32. #define PS3_PM_BOOKMARK_TAG_MASK_HI 0xF000000000000000ULL
  33. #define PS3_PM_BOOKMARK_TAG_MASK_LO 0x0F00000000000000ULL
  34. /* CBE PM CONTROL register macros */
  35. #define PS3_PM_CONTROL_PPU_TH0_BOOKMARK 0x00001000
  36. #define PS3_PM_CONTROL_PPU_TH1_BOOKMARK 0x00000800
  37. #define PS3_PM_CONTROL_PPU_COUNT_MODE_MASK 0x000C0000
  38. #define PS3_PM_CONTROL_PPU_COUNT_MODE_PROBLEM 0x00080000
  39. #define PS3_WRITE_PM_MASK 0xFFFFFFFFFFFFFFFFULL
  40. /* CBE PM START STOP register macros */
  41. #define PS3_PM_START_STOP_PPU_TH0_BOOKMARK_START 0x02000000
  42. #define PS3_PM_START_STOP_PPU_TH1_BOOKMARK_START 0x01000000
  43. #define PS3_PM_START_STOP_PPU_TH0_BOOKMARK_STOP 0x00020000
  44. #define PS3_PM_START_STOP_PPU_TH1_BOOKMARK_STOP 0x00010000
  45. #define PS3_PM_START_STOP_START_MASK 0xFF000000
  46. #define PS3_PM_START_STOP_STOP_MASK 0x00FF0000
  47. /* CBE PM COUNTER register macres */
  48. #define PS3_PM_COUNTER_MASK_HI 0xFFFFFFFF00000000ULL
  49. #define PS3_PM_COUNTER_MASK_LO 0x00000000FFFFFFFFULL
  50. /* BASE SIGNAL GROUP NUMBER macros */
  51. #define PM_ISLAND2_BASE_SIGNAL_GROUP_NUMBER 0
  52. #define PM_ISLAND2_SIGNAL_GROUP_NUMBER1 6
  53. #define PM_ISLAND2_SIGNAL_GROUP_NUMBER2 7
  54. #define PM_ISLAND3_BASE_SIGNAL_GROUP_NUMBER 7
  55. #define PM_ISLAND4_BASE_SIGNAL_GROUP_NUMBER 15
  56. #define PM_SPU_TRIGGER_SIGNAL_GROUP_NUMBER 17
  57. #define PM_SPU_EVENT_SIGNAL_GROUP_NUMBER 18
  58. #define PM_ISLAND5_BASE_SIGNAL_GROUP_NUMBER 18
  59. #define PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER 24
  60. #define PM_ISLAND7_BASE_SIGNAL_GROUP_NUMBER 49
  61. #define PM_ISLAND8_BASE_SIGNAL_GROUP_NUMBER 52
  62. #define PM_SIG_GROUP_SPU 41
  63. #define PM_SIG_GROUP_SPU_TRIGGER 42
  64. #define PM_SIG_GROUP_SPU_EVENT 43
  65. #define PM_SIG_GROUP_MFC_MAX 60
  66. /**
  67. * struct ps3_lpm_shadow_regs - Performance monitor shadow registers.
  68. *
  69. * @pm_control: Shadow of the processor's pm_control register.
  70. * @pm_start_stop: Shadow of the processor's pm_start_stop register.
  71. * @pm_interval: Shadow of the processor's pm_interval register.
  72. * @group_control: Shadow of the processor's group_control register.
  73. * @debug_bus_control: Shadow of the processor's debug_bus_control register.
  74. *
  75. * The logical performance monitor provides a write-only interface to
  76. * these processor registers. These shadow variables cache the processor
  77. * register values for reading.
  78. *
  79. * The initial value of the shadow registers at lpm creation is
  80. * PS3_LPM_SHADOW_REG_INIT.
  81. */
  82. struct ps3_lpm_shadow_regs {
  83. u64 pm_control;
  84. u64 pm_start_stop;
  85. u64 pm_interval;
  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("or 29, 29, 29;"); /* db10cyc */
  165. mtspr(SPRN_BKMK, bookmark);
  166. asm volatile("or 29, 29, 29;"); /* db10cyc */
  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. return lpm_priv->shadow.pm_interval;
  360. case group_control:
  361. return lpm_priv->shadow.group_control;
  362. case debug_bus_control:
  363. return lpm_priv->shadow.debug_bus_control;
  364. case pm_status:
  365. result = lv1_get_lpm_interrupt_status(lpm_priv->lpm_id,
  366. &val);
  367. if (result) {
  368. val = 0;
  369. dev_dbg(sbd_core(), "%s:%u: lv1 get_lpm_status failed: "
  370. "reg %u, %s\n", __func__, __LINE__, reg,
  371. ps3_result(result));
  372. }
  373. return (u32)val;
  374. case ext_tr_timer:
  375. return 0;
  376. default:
  377. dev_dbg(sbd_core(), "%s:%u: unknown reg: %d\n", __func__,
  378. __LINE__, reg);
  379. BUG();
  380. break;
  381. }
  382. return 0;
  383. }
  384. EXPORT_SYMBOL_GPL(ps3_read_pm);
  385. /**
  386. * ps3_write_pm - Write Other LPM control registers.
  387. */
  388. void ps3_write_pm(u32 cpu, enum pm_reg_name reg, u32 val)
  389. {
  390. int result = 0;
  391. u64 dummy;
  392. switch (reg) {
  393. case group_control:
  394. if (val != lpm_priv->shadow.group_control)
  395. result = lv1_set_lpm_group_control(lpm_priv->lpm_id,
  396. val,
  397. PS3_WRITE_PM_MASK,
  398. &dummy);
  399. lpm_priv->shadow.group_control = val;
  400. break;
  401. case debug_bus_control:
  402. if (val != lpm_priv->shadow.debug_bus_control)
  403. result = lv1_set_lpm_debug_bus_control(lpm_priv->lpm_id,
  404. val,
  405. PS3_WRITE_PM_MASK,
  406. &dummy);
  407. lpm_priv->shadow.debug_bus_control = val;
  408. break;
  409. case pm_control:
  410. if (use_start_stop_bookmark)
  411. val |= (PS3_PM_CONTROL_PPU_TH0_BOOKMARK |
  412. PS3_PM_CONTROL_PPU_TH1_BOOKMARK);
  413. if (val != lpm_priv->shadow.pm_control)
  414. result = lv1_set_lpm_general_control(lpm_priv->lpm_id,
  415. val,
  416. PS3_WRITE_PM_MASK,
  417. 0, 0, &dummy,
  418. &dummy);
  419. lpm_priv->shadow.pm_control = val;
  420. break;
  421. case pm_interval:
  422. if (val != lpm_priv->shadow.pm_interval)
  423. result = lv1_set_lpm_interval(lpm_priv->lpm_id, val,
  424. PS3_WRITE_PM_MASK, &dummy);
  425. lpm_priv->shadow.pm_interval = val;
  426. break;
  427. case pm_start_stop:
  428. if (val != lpm_priv->shadow.pm_start_stop)
  429. result = lv1_set_lpm_trigger_control(lpm_priv->lpm_id,
  430. val,
  431. PS3_WRITE_PM_MASK,
  432. &dummy);
  433. lpm_priv->shadow.pm_start_stop = val;
  434. break;
  435. case trace_address:
  436. case ext_tr_timer:
  437. case pm_status:
  438. break;
  439. default:
  440. dev_dbg(sbd_core(), "%s:%u: unknown reg: %d\n", __func__,
  441. __LINE__, reg);
  442. BUG();
  443. break;
  444. }
  445. if (result)
  446. dev_err(sbd_core(), "%s:%u: lv1 set_control failed: "
  447. "reg %u, %s\n", __func__, __LINE__, reg,
  448. ps3_result(result));
  449. }
  450. EXPORT_SYMBOL_GPL(ps3_write_pm);
  451. /**
  452. * ps3_get_ctr_size - Get the size of a physical counter.
  453. *
  454. * Returns either 16 or 32.
  455. */
  456. u32 ps3_get_ctr_size(u32 cpu, u32 phys_ctr)
  457. {
  458. u32 pm_ctrl;
  459. if (phys_ctr >= NR_PHYS_CTRS) {
  460. dev_dbg(sbd_core(), "%s:%u: phys_ctr too big: %u\n", __func__,
  461. __LINE__, phys_ctr);
  462. return 0;
  463. }
  464. pm_ctrl = ps3_read_pm(cpu, pm_control);
  465. return (pm_ctrl & CBE_PM_16BIT_CTR(phys_ctr)) ? 16 : 32;
  466. }
  467. EXPORT_SYMBOL_GPL(ps3_get_ctr_size);
  468. /**
  469. * ps3_set_ctr_size - Set the size of a physical counter to 16 or 32 bits.
  470. */
  471. void ps3_set_ctr_size(u32 cpu, u32 phys_ctr, u32 ctr_size)
  472. {
  473. u32 pm_ctrl;
  474. if (phys_ctr >= NR_PHYS_CTRS) {
  475. dev_dbg(sbd_core(), "%s:%u: phys_ctr too big: %u\n", __func__,
  476. __LINE__, phys_ctr);
  477. return;
  478. }
  479. pm_ctrl = ps3_read_pm(cpu, pm_control);
  480. switch (ctr_size) {
  481. case 16:
  482. pm_ctrl |= CBE_PM_16BIT_CTR(phys_ctr);
  483. ps3_write_pm(cpu, pm_control, pm_ctrl);
  484. break;
  485. case 32:
  486. pm_ctrl &= ~CBE_PM_16BIT_CTR(phys_ctr);
  487. ps3_write_pm(cpu, pm_control, pm_ctrl);
  488. break;
  489. default:
  490. BUG();
  491. }
  492. }
  493. EXPORT_SYMBOL_GPL(ps3_set_ctr_size);
  494. static u64 pm_translate_signal_group_number_on_island2(u64 subgroup)
  495. {
  496. if (subgroup == 2)
  497. subgroup = 3;
  498. if (subgroup <= 6)
  499. return PM_ISLAND2_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  500. else if (subgroup == 7)
  501. return PM_ISLAND2_SIGNAL_GROUP_NUMBER1;
  502. else
  503. return PM_ISLAND2_SIGNAL_GROUP_NUMBER2;
  504. }
  505. static u64 pm_translate_signal_group_number_on_island3(u64 subgroup)
  506. {
  507. switch (subgroup) {
  508. case 2:
  509. case 3:
  510. case 4:
  511. subgroup += 2;
  512. break;
  513. case 5:
  514. subgroup = 8;
  515. break;
  516. default:
  517. break;
  518. }
  519. return PM_ISLAND3_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  520. }
  521. static u64 pm_translate_signal_group_number_on_island4(u64 subgroup)
  522. {
  523. return PM_ISLAND4_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  524. }
  525. static u64 pm_translate_signal_group_number_on_island5(u64 subgroup)
  526. {
  527. switch (subgroup) {
  528. case 3:
  529. subgroup = 4;
  530. break;
  531. case 4:
  532. subgroup = 6;
  533. break;
  534. default:
  535. break;
  536. }
  537. return PM_ISLAND5_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  538. }
  539. static u64 pm_translate_signal_group_number_on_island6(u64 subgroup,
  540. u64 subsubgroup)
  541. {
  542. switch (subgroup) {
  543. case 3:
  544. case 4:
  545. case 5:
  546. subgroup += 1;
  547. break;
  548. default:
  549. break;
  550. }
  551. switch (subsubgroup) {
  552. case 4:
  553. case 5:
  554. case 6:
  555. subsubgroup += 2;
  556. break;
  557. case 7:
  558. case 8:
  559. case 9:
  560. case 10:
  561. subsubgroup += 4;
  562. break;
  563. case 11:
  564. case 12:
  565. case 13:
  566. subsubgroup += 5;
  567. break;
  568. default:
  569. break;
  570. }
  571. if (subgroup <= 5)
  572. return (PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER + subgroup);
  573. else
  574. return (PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER + subgroup
  575. + subsubgroup - 1);
  576. }
  577. static u64 pm_translate_signal_group_number_on_island7(u64 subgroup)
  578. {
  579. return PM_ISLAND7_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  580. }
  581. static u64 pm_translate_signal_group_number_on_island8(u64 subgroup)
  582. {
  583. return PM_ISLAND8_BASE_SIGNAL_GROUP_NUMBER + subgroup;
  584. }
  585. static u64 pm_signal_group_to_ps3_lv1_signal_group(u64 group)
  586. {
  587. u64 island;
  588. u64 subgroup;
  589. u64 subsubgroup;
  590. subgroup = 0;
  591. subsubgroup = 0;
  592. island = 0;
  593. if (group < 1000) {
  594. if (group < 100) {
  595. if (20 <= group && group < 30) {
  596. island = 2;
  597. subgroup = group - 20;
  598. } else if (30 <= group && group < 40) {
  599. island = 3;
  600. subgroup = group - 30;
  601. } else if (40 <= group && group < 50) {
  602. island = 4;
  603. subgroup = group - 40;
  604. } else if (50 <= group && group < 60) {
  605. island = 5;
  606. subgroup = group - 50;
  607. } else if (60 <= group && group < 70) {
  608. island = 6;
  609. subgroup = group - 60;
  610. } else if (70 <= group && group < 80) {
  611. island = 7;
  612. subgroup = group - 70;
  613. } else if (80 <= group && group < 90) {
  614. island = 8;
  615. subgroup = group - 80;
  616. }
  617. } else if (200 <= group && group < 300) {
  618. island = 2;
  619. subgroup = group - 200;
  620. } else if (600 <= group && group < 700) {
  621. island = 6;
  622. subgroup = 5;
  623. subsubgroup = group - 650;
  624. }
  625. } else if (6000 <= group && group < 7000) {
  626. island = 6;
  627. subgroup = 5;
  628. subsubgroup = group - 6500;
  629. }
  630. switch (island) {
  631. case 2:
  632. return pm_translate_signal_group_number_on_island2(subgroup);
  633. case 3:
  634. return pm_translate_signal_group_number_on_island3(subgroup);
  635. case 4:
  636. return pm_translate_signal_group_number_on_island4(subgroup);
  637. case 5:
  638. return pm_translate_signal_group_number_on_island5(subgroup);
  639. case 6:
  640. return pm_translate_signal_group_number_on_island6(subgroup,
  641. subsubgroup);
  642. case 7:
  643. return pm_translate_signal_group_number_on_island7(subgroup);
  644. case 8:
  645. return pm_translate_signal_group_number_on_island8(subgroup);
  646. default:
  647. dev_dbg(sbd_core(), "%s:%u: island not found: %lu\n", __func__,
  648. __LINE__, group);
  649. BUG();
  650. break;
  651. }
  652. return 0;
  653. }
  654. static u64 pm_bus_word_to_ps3_lv1_bus_word(u8 word)
  655. {
  656. switch (word) {
  657. case 1:
  658. return 0xF000;
  659. case 2:
  660. return 0x0F00;
  661. case 4:
  662. return 0x00F0;
  663. case 8:
  664. default:
  665. return 0x000F;
  666. }
  667. }
  668. static int __ps3_set_signal(u64 lv1_signal_group, u64 bus_select,
  669. u64 signal_select, u64 attr1, u64 attr2, u64 attr3)
  670. {
  671. int ret;
  672. ret = lv1_set_lpm_signal(lpm_priv->lpm_id, lv1_signal_group, bus_select,
  673. signal_select, attr1, attr2, attr3);
  674. if (ret)
  675. dev_err(sbd_core(),
  676. "%s:%u: error:%d 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx 0x%lx\n",
  677. __func__, __LINE__, ret, lv1_signal_group, bus_select,
  678. signal_select, attr1, attr2, attr3);
  679. return ret;
  680. }
  681. int ps3_set_signal(u64 signal_group, u8 signal_bit, u16 sub_unit,
  682. u8 bus_word)
  683. {
  684. int ret;
  685. u64 lv1_signal_group;
  686. u64 bus_select;
  687. u64 signal_select;
  688. u64 attr1, attr2, attr3;
  689. if (signal_group == 0)
  690. return __ps3_set_signal(0, 0, 0, 0, 0, 0);
  691. lv1_signal_group =
  692. pm_signal_group_to_ps3_lv1_signal_group(signal_group);
  693. bus_select = pm_bus_word_to_ps3_lv1_bus_word(bus_word);
  694. switch (signal_group) {
  695. case PM_SIG_GROUP_SPU_TRIGGER:
  696. signal_select = 1;
  697. signal_select = signal_select << (63 - signal_bit);
  698. break;
  699. case PM_SIG_GROUP_SPU_EVENT:
  700. signal_select = 1;
  701. signal_select = (signal_select << (63 - signal_bit)) | 0x3;
  702. break;
  703. default:
  704. signal_select = 0;
  705. break;
  706. }
  707. /*
  708. * 0: physical object.
  709. * 1: logical object.
  710. * This parameter is only used for the PPE and SPE signals.
  711. */
  712. attr1 = 1;
  713. /*
  714. * This parameter is used to specify the target physical/logical
  715. * PPE/SPE object.
  716. */
  717. if (PM_SIG_GROUP_SPU <= signal_group &&
  718. signal_group < PM_SIG_GROUP_MFC_MAX)
  719. attr2 = sub_unit;
  720. else
  721. attr2 = lpm_priv->pu_id;
  722. /*
  723. * This parameter is only used for setting the SPE signal.
  724. */
  725. attr3 = 0;
  726. ret = __ps3_set_signal(lv1_signal_group, bus_select, signal_select,
  727. attr1, attr2, attr3);
  728. if (ret)
  729. dev_err(sbd_core(), "%s:%u: __ps3_set_signal failed: %d\n",
  730. __func__, __LINE__, ret);
  731. return ret;
  732. }
  733. EXPORT_SYMBOL_GPL(ps3_set_signal);
  734. u32 ps3_get_hw_thread_id(int cpu)
  735. {
  736. return get_hard_smp_processor_id(cpu);
  737. }
  738. EXPORT_SYMBOL_GPL(ps3_get_hw_thread_id);
  739. /**
  740. * ps3_enable_pm - Enable the entire performance monitoring unit.
  741. *
  742. * When we enable the LPM, all pending writes to counters get committed.
  743. */
  744. void ps3_enable_pm(u32 cpu)
  745. {
  746. int result;
  747. u64 tmp;
  748. int insert_bookmark = 0;
  749. lpm_priv->tb_count = 0;
  750. if (use_start_stop_bookmark) {
  751. if (!(lpm_priv->shadow.pm_start_stop &
  752. (PS3_PM_START_STOP_START_MASK
  753. | PS3_PM_START_STOP_STOP_MASK))) {
  754. result = lv1_set_lpm_trigger_control(lpm_priv->lpm_id,
  755. (PS3_PM_START_STOP_PPU_TH0_BOOKMARK_START |
  756. PS3_PM_START_STOP_PPU_TH1_BOOKMARK_START |
  757. PS3_PM_START_STOP_PPU_TH0_BOOKMARK_STOP |
  758. PS3_PM_START_STOP_PPU_TH1_BOOKMARK_STOP),
  759. 0xFFFFFFFFFFFFFFFFULL, &tmp);
  760. if (result)
  761. dev_err(sbd_core(), "%s:%u: "
  762. "lv1_set_lpm_trigger_control failed: "
  763. "%s\n", __func__, __LINE__,
  764. ps3_result(result));
  765. insert_bookmark = !result;
  766. }
  767. }
  768. result = lv1_start_lpm(lpm_priv->lpm_id);
  769. if (result)
  770. dev_err(sbd_core(), "%s:%u: lv1_start_lpm failed: %s\n",
  771. __func__, __LINE__, ps3_result(result));
  772. if (use_start_stop_bookmark && !result && insert_bookmark)
  773. ps3_set_bookmark(get_tb() | PS3_PM_BOOKMARK_START);
  774. }
  775. EXPORT_SYMBOL_GPL(ps3_enable_pm);
  776. /**
  777. * ps3_disable_pm - Disable the entire performance monitoring unit.
  778. */
  779. void ps3_disable_pm(u32 cpu)
  780. {
  781. int result;
  782. u64 tmp;
  783. ps3_set_bookmark(get_tb() | PS3_PM_BOOKMARK_STOP);
  784. result = lv1_stop_lpm(lpm_priv->lpm_id, &tmp);
  785. if (result) {
  786. if(result != LV1_WRONG_STATE)
  787. dev_err(sbd_core(), "%s:%u: lv1_stop_lpm failed: %s\n",
  788. __func__, __LINE__, ps3_result(result));
  789. return;
  790. }
  791. lpm_priv->tb_count = tmp;
  792. dev_dbg(sbd_core(), "%s:%u: tb_count %lu (%lxh)\n", __func__, __LINE__,
  793. lpm_priv->tb_count, lpm_priv->tb_count);
  794. }
  795. EXPORT_SYMBOL_GPL(ps3_disable_pm);
  796. /**
  797. * ps3_lpm_copy_tb - Copy data from the trace buffer to a kernel buffer.
  798. * @offset: Offset in bytes from the start of the trace buffer.
  799. * @buf: Copy destination.
  800. * @count: Maximum count of bytes to copy.
  801. * @bytes_copied: Pointer to a variable that will recieve the number of
  802. * bytes copied to @buf.
  803. *
  804. * On error @buf will contain any successfully copied trace buffer data
  805. * and bytes_copied will be set to the number of bytes successfully copied.
  806. */
  807. int ps3_lpm_copy_tb(unsigned long offset, void *buf, unsigned long count,
  808. unsigned long *bytes_copied)
  809. {
  810. int result;
  811. *bytes_copied = 0;
  812. if (!lpm_priv->tb_cache)
  813. return -EPERM;
  814. if (offset >= lpm_priv->tb_count)
  815. return 0;
  816. count = min(count, lpm_priv->tb_count - offset);
  817. while (*bytes_copied < count) {
  818. const unsigned long request = count - *bytes_copied;
  819. u64 tmp;
  820. result = lv1_copy_lpm_trace_buffer(lpm_priv->lpm_id, offset,
  821. request, &tmp);
  822. if (result) {
  823. dev_dbg(sbd_core(), "%s:%u: 0x%lx bytes at 0x%lx\n",
  824. __func__, __LINE__, request, offset);
  825. dev_err(sbd_core(), "%s:%u: lv1_copy_lpm_trace_buffer "
  826. "failed: %s\n", __func__, __LINE__,
  827. ps3_result(result));
  828. return result == LV1_WRONG_STATE ? -EBUSY : -EINVAL;
  829. }
  830. memcpy(buf, lpm_priv->tb_cache, tmp);
  831. buf += tmp;
  832. *bytes_copied += tmp;
  833. offset += tmp;
  834. }
  835. dev_dbg(sbd_core(), "%s:%u: copied %lxh bytes\n", __func__, __LINE__,
  836. *bytes_copied);
  837. return 0;
  838. }
  839. EXPORT_SYMBOL_GPL(ps3_lpm_copy_tb);
  840. /**
  841. * ps3_lpm_copy_tb_to_user - Copy data from the trace buffer to a user buffer.
  842. * @offset: Offset in bytes from the start of the trace buffer.
  843. * @buf: A __user copy destination.
  844. * @count: Maximum count of bytes to copy.
  845. * @bytes_copied: Pointer to a variable that will recieve the number of
  846. * bytes copied to @buf.
  847. *
  848. * On error @buf will contain any successfully copied trace buffer data
  849. * and bytes_copied will be set to the number of bytes successfully copied.
  850. */
  851. int ps3_lpm_copy_tb_to_user(unsigned long offset, void __user *buf,
  852. unsigned long count, unsigned long *bytes_copied)
  853. {
  854. int result;
  855. *bytes_copied = 0;
  856. if (!lpm_priv->tb_cache)
  857. return -EPERM;
  858. if (offset >= lpm_priv->tb_count)
  859. return 0;
  860. count = min(count, lpm_priv->tb_count - offset);
  861. while (*bytes_copied < count) {
  862. const unsigned long request = count - *bytes_copied;
  863. u64 tmp;
  864. result = lv1_copy_lpm_trace_buffer(lpm_priv->lpm_id, offset,
  865. request, &tmp);
  866. if (result) {
  867. dev_dbg(sbd_core(), "%s:%u: 0x%lx bytes at 0x%lx\n",
  868. __func__, __LINE__, request, offset);
  869. dev_err(sbd_core(), "%s:%u: lv1_copy_lpm_trace_buffer "
  870. "failed: %s\n", __func__, __LINE__,
  871. ps3_result(result));
  872. return result == LV1_WRONG_STATE ? -EBUSY : -EINVAL;
  873. }
  874. result = copy_to_user(buf, lpm_priv->tb_cache, tmp);
  875. if (result) {
  876. dev_dbg(sbd_core(), "%s:%u: 0x%lx bytes at 0x%p\n",
  877. __func__, __LINE__, tmp, buf);
  878. dev_err(sbd_core(), "%s:%u: copy_to_user failed: %d\n",
  879. __func__, __LINE__, result);
  880. return -EFAULT;
  881. }
  882. buf += tmp;
  883. *bytes_copied += tmp;
  884. offset += tmp;
  885. }
  886. dev_dbg(sbd_core(), "%s:%u: copied %lxh bytes\n", __func__, __LINE__,
  887. *bytes_copied);
  888. return 0;
  889. }
  890. EXPORT_SYMBOL_GPL(ps3_lpm_copy_tb_to_user);
  891. /**
  892. * ps3_get_and_clear_pm_interrupts -
  893. *
  894. * Clearing interrupts for the entire performance monitoring unit.
  895. * Reading pm_status clears the interrupt bits.
  896. */
  897. u32 ps3_get_and_clear_pm_interrupts(u32 cpu)
  898. {
  899. return ps3_read_pm(cpu, pm_status);
  900. }
  901. EXPORT_SYMBOL_GPL(ps3_get_and_clear_pm_interrupts);
  902. /**
  903. * ps3_enable_pm_interrupts -
  904. *
  905. * Enabling interrupts for the entire performance monitoring unit.
  906. * Enables the interrupt bits in the pm_status register.
  907. */
  908. void ps3_enable_pm_interrupts(u32 cpu, u32 thread, u32 mask)
  909. {
  910. if (mask)
  911. ps3_write_pm(cpu, pm_status, mask);
  912. }
  913. EXPORT_SYMBOL_GPL(ps3_enable_pm_interrupts);
  914. /**
  915. * ps3_enable_pm_interrupts -
  916. *
  917. * Disabling interrupts for the entire performance monitoring unit.
  918. */
  919. void ps3_disable_pm_interrupts(u32 cpu)
  920. {
  921. ps3_get_and_clear_pm_interrupts(cpu);
  922. ps3_write_pm(cpu, pm_status, 0);
  923. }
  924. EXPORT_SYMBOL_GPL(ps3_disable_pm_interrupts);
  925. /**
  926. * ps3_lpm_open - Open the logical performance monitor device.
  927. * @tb_type: Specifies the type of trace buffer lv1 sould use for this lpm
  928. * instance, specified by one of enum ps3_lpm_tb_type.
  929. * @tb_cache: Optional user supplied buffer to use as the trace buffer cache.
  930. * If NULL, the driver will allocate and manage an internal buffer.
  931. * Unused when when @tb_type is PS3_LPM_TB_TYPE_NONE.
  932. * @tb_cache_size: The size in bytes of the user supplied @tb_cache buffer.
  933. * Unused when @tb_cache is NULL or @tb_type is PS3_LPM_TB_TYPE_NONE.
  934. */
  935. int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
  936. u64 tb_cache_size)
  937. {
  938. int result;
  939. u64 tb_size;
  940. BUG_ON(!lpm_priv);
  941. BUG_ON(tb_type != PS3_LPM_TB_TYPE_NONE
  942. && tb_type != PS3_LPM_TB_TYPE_INTERNAL);
  943. if (tb_type == PS3_LPM_TB_TYPE_NONE && tb_cache)
  944. dev_dbg(sbd_core(), "%s:%u: bad in vals\n", __func__, __LINE__);
  945. if (!atomic_add_unless(&lpm_priv->open, 1, 1)) {
  946. dev_dbg(sbd_core(), "%s:%u: busy\n", __func__, __LINE__);
  947. return -EBUSY;
  948. }
  949. /* Note tb_cache needs 128 byte alignment. */
  950. if (tb_type == PS3_LPM_TB_TYPE_NONE) {
  951. lpm_priv->tb_cache_size = 0;
  952. lpm_priv->tb_cache_internal = NULL;
  953. lpm_priv->tb_cache = NULL;
  954. } else if (tb_cache) {
  955. if (tb_cache != (void *)_ALIGN_UP((unsigned long)tb_cache, 128)
  956. || tb_cache_size != _ALIGN_UP(tb_cache_size, 128)) {
  957. dev_err(sbd_core(), "%s:%u: unaligned tb_cache\n",
  958. __func__, __LINE__);
  959. result = -EINVAL;
  960. goto fail_align;
  961. }
  962. lpm_priv->tb_cache_size = tb_cache_size;
  963. lpm_priv->tb_cache_internal = NULL;
  964. lpm_priv->tb_cache = tb_cache;
  965. } else {
  966. lpm_priv->tb_cache_size = PS3_LPM_DEFAULT_TB_CACHE_SIZE;
  967. lpm_priv->tb_cache_internal = kzalloc(
  968. lpm_priv->tb_cache_size + 127, GFP_KERNEL);
  969. if (!lpm_priv->tb_cache_internal) {
  970. dev_err(sbd_core(), "%s:%u: alloc internal tb_cache "
  971. "failed\n", __func__, __LINE__);
  972. result = -ENOMEM;
  973. goto fail_malloc;
  974. }
  975. lpm_priv->tb_cache = (void *)_ALIGN_UP(
  976. (unsigned long)lpm_priv->tb_cache_internal, 128);
  977. }
  978. result = lv1_construct_lpm(lpm_priv->node_id, tb_type, 0, 0,
  979. ps3_mm_phys_to_lpar(__pa(lpm_priv->tb_cache)),
  980. lpm_priv->tb_cache_size, &lpm_priv->lpm_id,
  981. &lpm_priv->outlet_id, &tb_size);
  982. if (result) {
  983. dev_err(sbd_core(), "%s:%u: lv1_construct_lpm failed: %s\n",
  984. __func__, __LINE__, ps3_result(result));
  985. result = -EINVAL;
  986. goto fail_construct;
  987. }
  988. lpm_priv->shadow.pm_control = PS3_LPM_SHADOW_REG_INIT;
  989. lpm_priv->shadow.pm_start_stop = PS3_LPM_SHADOW_REG_INIT;
  990. lpm_priv->shadow.pm_interval = PS3_LPM_SHADOW_REG_INIT;
  991. lpm_priv->shadow.group_control = PS3_LPM_SHADOW_REG_INIT;
  992. lpm_priv->shadow.debug_bus_control = PS3_LPM_SHADOW_REG_INIT;
  993. dev_dbg(sbd_core(), "%s:%u: lpm_id 0x%lx, outlet_id 0x%lx, "
  994. "tb_size 0x%lx\n", __func__, __LINE__, lpm_priv->lpm_id,
  995. lpm_priv->outlet_id, tb_size);
  996. return 0;
  997. fail_construct:
  998. kfree(lpm_priv->tb_cache_internal);
  999. lpm_priv->tb_cache_internal = NULL;
  1000. fail_malloc:
  1001. fail_align:
  1002. atomic_dec(&lpm_priv->open);
  1003. return result;
  1004. }
  1005. EXPORT_SYMBOL_GPL(ps3_lpm_open);
  1006. /**
  1007. * ps3_lpm_close - Close the lpm device.
  1008. *
  1009. */
  1010. int ps3_lpm_close(void)
  1011. {
  1012. dev_dbg(sbd_core(), "%s:%u\n", __func__, __LINE__);
  1013. lv1_destruct_lpm(lpm_priv->lpm_id);
  1014. lpm_priv->lpm_id = 0;
  1015. kfree(lpm_priv->tb_cache_internal);
  1016. lpm_priv->tb_cache_internal = NULL;
  1017. atomic_dec(&lpm_priv->open);
  1018. return 0;
  1019. }
  1020. EXPORT_SYMBOL_GPL(ps3_lpm_close);
  1021. static int __devinit ps3_lpm_probe(struct ps3_system_bus_device *dev)
  1022. {
  1023. dev_dbg(&dev->core, " -> %s:%u\n", __func__, __LINE__);
  1024. if (lpm_priv) {
  1025. dev_info(&dev->core, "%s:%u: called twice\n",
  1026. __func__, __LINE__);
  1027. return -EBUSY;
  1028. }
  1029. lpm_priv = kzalloc(sizeof(*lpm_priv), GFP_KERNEL);
  1030. if (!lpm_priv)
  1031. return -ENOMEM;
  1032. lpm_priv->sbd = dev;
  1033. lpm_priv->node_id = dev->lpm.node_id;
  1034. lpm_priv->pu_id = dev->lpm.pu_id;
  1035. lpm_priv->rights = dev->lpm.rights;
  1036. dev_info(&dev->core, " <- %s:%u:\n", __func__, __LINE__);
  1037. return 0;
  1038. }
  1039. static int ps3_lpm_remove(struct ps3_system_bus_device *dev)
  1040. {
  1041. dev_dbg(&dev->core, " -> %s:%u:\n", __func__, __LINE__);
  1042. ps3_lpm_close();
  1043. kfree(lpm_priv);
  1044. lpm_priv = NULL;
  1045. dev_info(&dev->core, " <- %s:%u:\n", __func__, __LINE__);
  1046. return 0;
  1047. }
  1048. static struct ps3_system_bus_driver ps3_lpm_driver = {
  1049. .match_id = PS3_MATCH_ID_LPM,
  1050. .core.name = "ps3-lpm",
  1051. .core.owner = THIS_MODULE,
  1052. .probe = ps3_lpm_probe,
  1053. .remove = ps3_lpm_remove,
  1054. .shutdown = ps3_lpm_remove,
  1055. };
  1056. static int __init ps3_lpm_init(void)
  1057. {
  1058. pr_debug("%s:%d:\n", __func__, __LINE__);
  1059. return ps3_system_bus_driver_register(&ps3_lpm_driver);
  1060. }
  1061. static void __exit ps3_lpm_exit(void)
  1062. {
  1063. pr_debug("%s:%d:\n", __func__, __LINE__);
  1064. ps3_system_bus_driver_unregister(&ps3_lpm_driver);
  1065. }
  1066. module_init(ps3_lpm_init);
  1067. module_exit(ps3_lpm_exit);
  1068. MODULE_LICENSE("GPL v2");
  1069. MODULE_DESCRIPTION("PS3 Logical Performance Monitor Driver");
  1070. MODULE_AUTHOR("Sony Corporation");
  1071. MODULE_ALIAS(PS3_MODULE_ALIAS_LPM);