ps3-lpm.c 31 KB

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