ps3-lpm.c 31 KB

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