21 #include <linux/slab.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
34 #define PS3_PM_BOOKMARK_START 0x8000000000000000ULL
35 #define PS3_PM_BOOKMARK_STOP 0x4000000000000000ULL
36 #define PS3_PM_BOOKMARK_TAG_KERNEL 0x1000000000000000ULL
37 #define PS3_PM_BOOKMARK_TAG_USER 0x3000000000000000ULL
38 #define PS3_PM_BOOKMARK_TAG_MASK_HI 0xF000000000000000ULL
39 #define PS3_PM_BOOKMARK_TAG_MASK_LO 0x0F00000000000000ULL
42 #define PS3_PM_CONTROL_PPU_TH0_BOOKMARK 0x00001000
43 #define PS3_PM_CONTROL_PPU_TH1_BOOKMARK 0x00000800
44 #define PS3_PM_CONTROL_PPU_COUNT_MODE_MASK 0x000C0000
45 #define PS3_PM_CONTROL_PPU_COUNT_MODE_PROBLEM 0x00080000
46 #define PS3_WRITE_PM_MASK 0xFFFFFFFFFFFFFFFFULL
49 #define PS3_PM_START_STOP_PPU_TH0_BOOKMARK_START 0x02000000
50 #define PS3_PM_START_STOP_PPU_TH1_BOOKMARK_START 0x01000000
51 #define PS3_PM_START_STOP_PPU_TH0_BOOKMARK_STOP 0x00020000
52 #define PS3_PM_START_STOP_PPU_TH1_BOOKMARK_STOP 0x00010000
53 #define PS3_PM_START_STOP_START_MASK 0xFF000000
54 #define PS3_PM_START_STOP_STOP_MASK 0x00FF0000
57 #define PS3_PM_COUNTER_MASK_HI 0xFFFFFFFF00000000ULL
58 #define PS3_PM_COUNTER_MASK_LO 0x00000000FFFFFFFFULL
61 #define PM_ISLAND2_BASE_SIGNAL_GROUP_NUMBER 0
62 #define PM_ISLAND2_SIGNAL_GROUP_NUMBER1 6
63 #define PM_ISLAND2_SIGNAL_GROUP_NUMBER2 7
64 #define PM_ISLAND3_BASE_SIGNAL_GROUP_NUMBER 7
65 #define PM_ISLAND4_BASE_SIGNAL_GROUP_NUMBER 15
66 #define PM_SPU_TRIGGER_SIGNAL_GROUP_NUMBER 17
67 #define PM_SPU_EVENT_SIGNAL_GROUP_NUMBER 18
68 #define PM_ISLAND5_BASE_SIGNAL_GROUP_NUMBER 18
69 #define PM_ISLAND6_BASE_SIGNAL_GROUP_NUMBER 24
70 #define PM_ISLAND7_BASE_SIGNAL_GROUP_NUMBER 49
71 #define PM_ISLAND8_BASE_SIGNAL_GROUP_NUMBER 52
72 #define PM_SIG_GROUP_SPU 41
73 #define PM_SIG_GROUP_SPU_TRIGGER 42
74 #define PM_SIG_GROUP_SPU_EVENT 43
75 #define PM_SIG_GROUP_MFC_MAX 60
100 #define PS3_LPM_SHADOW_REG_INIT 0xFFFFFFFF00000000ULL
158 static struct device *sbd_core(
void)
161 return &lpm_priv->
sbd->core;
185 asm volatile(
"nop;nop;nop;nop;nop;nop;nop;nop;nop;");
186 mtspr(SPRN_BKMK, bookmark);
187 asm volatile(
"nop;nop;nop;nop;nop;nop;nop;nop;nop;");
195 bookmark = (get_tb() & 0x00000000FFFFFFFFULL) |
198 (incident << 48) | (th_id << 32) | bookmark;
217 dev_dbg(sbd_core(),
"%s:%u: phys_ctr too big: %u\n", __func__,
222 result = lv1_set_lpm_counter(lpm_priv->
lpm_id, 0, 0, 0, 0, &counter0415,
225 dev_err(sbd_core(),
"%s:%u: lv1_set_lpm_counter failed: "
226 "phys_ctr %u, %s\n", __func__, __LINE__, phys_ctr,
233 return counter0415 >> 32;
237 return counter2637 >> 32;
257 u64 counter0415_mask;
259 u64 counter2637_mask;
263 dev_dbg(sbd_core(),
"%s:%u: phys_ctr too big: %u\n", __func__,
270 counter0415 = (
u64)val << 32;
273 counter2637_mask = 0x0;
276 counter0415 = (
u64)val;
279 counter2637_mask = 0x0;
283 counter0415_mask = 0x0;
284 counter2637 = (
u64)val << 32;
289 counter0415_mask = 0x0;
290 counter2637 = (
u64)val;
297 result = lv1_set_lpm_counter(lpm_priv->
lpm_id,
298 counter0415, counter0415_mask,
299 counter2637, counter2637_mask,
300 &counter0415, &counter2637);
302 dev_err(sbd_core(),
"%s:%u: lv1_set_lpm_counter failed: "
303 "phys_ctr %u, val %u, %s\n", __func__, __LINE__,
304 phys_ctr, val, ps3_result(result));
323 val = (ctr < NR_PHYS_CTRS) ? (val >> 16) : (val & 0xffff);
347 val = (val << 16) | (phys_val & 0xffff);
349 val = (val & 0xffff) | (phys_val & 0xffff0000);
377 static const u64 mask = 0xFFFFFFFFFFFFFFFFULL;
381 dev_dbg(sbd_core(),
"%s:%u: ctr too big: %u\n", __func__,
386 result = lv1_set_lpm_counter_control(lpm_priv->
lpm_id, ctr, val, mask,
389 dev_err(sbd_core(),
"%s:%u: lv1_set_lpm_counter_control "
390 "failed: ctr %u, %s\n", __func__, __LINE__, ctr,
406 return lpm_priv->
shadow.pm_control;
410 return lpm_priv->
shadow.pm_start_stop;
412 result = lv1_set_lpm_interval(lpm_priv->
lpm_id, 0, 0, &val);
415 dev_dbg(sbd_core(),
"%s:%u: lv1 set_inteval failed: "
416 "reg %u, %s\n", __func__, __LINE__, reg,
421 return lpm_priv->
shadow.group_control;
423 return lpm_priv->
shadow.debug_bus_control;
425 result = lv1_get_lpm_interrupt_status(lpm_priv->
lpm_id,
429 dev_dbg(sbd_core(),
"%s:%u: lv1 get_lpm_status failed: "
430 "reg %u, %s\n", __func__, __LINE__, reg,
437 dev_dbg(sbd_core(),
"%s:%u: unknown reg: %d\n", __func__,
458 if (val != lpm_priv->
shadow.group_control)
459 result = lv1_set_lpm_group_control(lpm_priv->
lpm_id,
466 if (val != lpm_priv->
shadow.debug_bus_control)
467 result = lv1_set_lpm_debug_bus_control(lpm_priv->
lpm_id,
471 lpm_priv->
shadow.debug_bus_control =
val;
477 if (val != lpm_priv->
shadow.pm_control)
478 result = lv1_set_lpm_general_control(lpm_priv->
lpm_id,
486 result = lv1_set_lpm_interval(lpm_priv->
lpm_id, val,
490 if (val != lpm_priv->
shadow.pm_start_stop)
491 result = lv1_set_lpm_trigger_control(lpm_priv->
lpm_id,
502 dev_dbg(sbd_core(),
"%s:%u: unknown reg: %d\n", __func__,
509 dev_err(sbd_core(),
"%s:%u: lv1 set_control failed: "
510 "reg %u, %s\n", __func__, __LINE__, reg,
526 dev_dbg(sbd_core(),
"%s:%u: phys_ctr too big: %u\n", __func__,
545 dev_dbg(sbd_core(),
"%s:%u: phys_ctr too big: %u\n", __func__,
568 static u64 pm_translate_signal_group_number_on_island2(
u64 subgroup)
576 else if (subgroup == 7)
582 static u64 pm_translate_signal_group_number_on_island3(
u64 subgroup)
600 static u64 pm_translate_signal_group_number_on_island4(
u64 subgroup)
605 static u64 pm_translate_signal_group_number_on_island5(
u64 subgroup)
621 static u64 pm_translate_signal_group_number_on_island6(
u64 subgroup,
634 switch (subsubgroup) {
662 static u64 pm_translate_signal_group_number_on_island7(
u64 subgroup)
667 static u64 pm_translate_signal_group_number_on_island8(
u64 subgroup)
672 static u64 pm_signal_group_to_ps3_lv1_signal_group(
u64 group)
683 if (20 <= group && group < 30) {
685 subgroup = group - 20;
686 }
else if (30 <= group && group < 40) {
688 subgroup = group - 30;
689 }
else if (40 <= group && group < 50) {
691 subgroup = group - 40;
692 }
else if (50 <= group && group < 60) {
694 subgroup = group - 50;
695 }
else if (60 <= group && group < 70) {
697 subgroup = group - 60;
698 }
else if (70 <= group && group < 80) {
700 subgroup = group - 70;
701 }
else if (80 <= group && group < 90) {
703 subgroup = group - 80;
705 }
else if (200 <= group && group < 300) {
707 subgroup = group - 200;
708 }
else if (600 <= group && group < 700) {
711 subsubgroup = group - 650;
713 }
else if (6000 <= group && group < 7000) {
716 subsubgroup = group - 6500;
721 return pm_translate_signal_group_number_on_island2(subgroup);
723 return pm_translate_signal_group_number_on_island3(subgroup);
725 return pm_translate_signal_group_number_on_island4(subgroup);
727 return pm_translate_signal_group_number_on_island5(subgroup);
729 return pm_translate_signal_group_number_on_island6(subgroup,
732 return pm_translate_signal_group_number_on_island7(subgroup);
734 return pm_translate_signal_group_number_on_island8(subgroup);
736 dev_dbg(sbd_core(),
"%s:%u: island not found: %llu\n", __func__,
744 static u64 pm_bus_word_to_ps3_lv1_bus_word(
u8 word)
760 static int __ps3_set_signal(
u64 lv1_signal_group,
u64 bus_select,
765 ret = lv1_set_lpm_signal(lpm_priv->
lpm_id, lv1_signal_group, bus_select,
766 signal_select, attr1, attr2, attr3);
769 "%s:%u: error:%d 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx 0x%llx\n",
770 __func__, __LINE__, ret, lv1_signal_group, bus_select,
771 signal_select, attr1, attr2, attr3);
780 u64 lv1_signal_group;
783 u64 attr1, attr2, attr3;
785 if (signal_group == 0)
786 return __ps3_set_signal(0, 0, 0, 0, 0, 0);
789 pm_signal_group_to_ps3_lv1_signal_group(signal_group);
790 bus_select = pm_bus_word_to_ps3_lv1_bus_word(bus_word);
792 switch (signal_group) {
795 signal_select = signal_select << (63 - signal_bit);
799 signal_select = (signal_select << (63 - signal_bit)) | 0x3;
821 attr2 = lpm_priv->
pu_id;
828 ret = __ps3_set_signal(lv1_signal_group, bus_select, signal_select,
829 attr1, attr2, attr3);
831 dev_err(sbd_core(),
"%s:%u: __ps3_set_signal failed: %d\n",
832 __func__, __LINE__, ret);
840 return get_hard_smp_processor_id(cpu);
854 int insert_bookmark = 0;
859 if (!(lpm_priv->
shadow.pm_start_stop &
862 result = lv1_set_lpm_trigger_control(lpm_priv->
lpm_id,
867 0xFFFFFFFFFFFFFFFFULL, &tmp);
871 "lv1_set_lpm_trigger_control failed: "
872 "%s\n", __func__, __LINE__,
875 insert_bookmark = !
result;
879 result = lv1_start_lpm(lpm_priv->
lpm_id);
882 dev_err(sbd_core(),
"%s:%u: lv1_start_lpm failed: %s\n",
883 __func__, __LINE__, ps3_result(result));
901 result = lv1_stop_lpm(lpm_priv->
lpm_id, &tmp);
905 dev_err(sbd_core(),
"%s:%u: lv1_stop_lpm failed: %s\n",
906 __func__, __LINE__, ps3_result(result));
912 dev_dbg(sbd_core(),
"%s:%u: tb_count %llu (%llxh)\n", __func__, __LINE__,
930 unsigned long *bytes_copied)
944 while (*bytes_copied < count) {
945 const unsigned long request = count - *bytes_copied;
948 result = lv1_copy_lpm_trace_buffer(lpm_priv->
lpm_id, offset,
951 dev_dbg(sbd_core(),
"%s:%u: 0x%lx bytes at 0x%lx\n",
952 __func__, __LINE__, request, offset);
954 dev_err(sbd_core(),
"%s:%u: lv1_copy_lpm_trace_buffer "
955 "failed: %s\n", __func__, __LINE__,
962 *bytes_copied +=
tmp;
965 dev_dbg(sbd_core(),
"%s:%u: copied %lxh bytes\n", __func__, __LINE__,
985 unsigned long count,
unsigned long *bytes_copied)
999 while (*bytes_copied < count) {
1000 const unsigned long request = count - *bytes_copied;
1003 result = lv1_copy_lpm_trace_buffer(lpm_priv->
lpm_id, offset,
1006 dev_dbg(sbd_core(),
"%s:%u: 0x%lx bytes at 0x%lx\n",
1007 __func__, __LINE__, request, offset);
1008 dev_err(sbd_core(),
"%s:%u: lv1_copy_lpm_trace_buffer "
1009 "failed: %s\n", __func__, __LINE__,
1010 ps3_result(result));
1017 dev_dbg(sbd_core(),
"%s:%u: 0x%llx bytes at 0x%p\n",
1018 __func__, __LINE__, tmp, buf);
1019 dev_err(sbd_core(),
"%s:%u: copy_to_user failed: %d\n",
1020 __func__, __LINE__, result);
1025 *bytes_copied +=
tmp;
1028 dev_dbg(sbd_core(),
"%s:%u: copied %lxh bytes\n", __func__, __LINE__,
1097 dev_dbg(sbd_core(),
"%s:%u: bad in vals\n", __func__, __LINE__);
1099 if (!atomic_add_unless(&lpm_priv->
open, 1, 1)) {
1100 dev_dbg(sbd_core(),
"%s:%u: busy\n", __func__, __LINE__);
1110 }
else if (tb_cache) {
1111 if (tb_cache != (
void *)
_ALIGN_UP((
unsigned long)tb_cache, 128)
1112 || tb_cache_size !=
_ALIGN_UP(tb_cache_size, 128)) {
1113 dev_err(sbd_core(),
"%s:%u: unaligned tb_cache\n",
1114 __func__, __LINE__);
1126 dev_err(sbd_core(),
"%s:%u: alloc internal tb_cache "
1127 "failed\n", __func__, __LINE__);
1135 result = lv1_construct_lpm(lpm_priv->
node_id, tb_type, 0, 0,
1141 dev_err(sbd_core(),
"%s:%u: lv1_construct_lpm failed: %s\n",
1142 __func__, __LINE__, ps3_result(result));
1144 goto fail_construct;
1152 dev_dbg(sbd_core(),
"%s:%u: lpm_id 0x%llx, outlet_id 0x%llx, "
1153 "tb_size 0x%llx\n", __func__, __LINE__, lpm_priv->
lpm_id,
1175 dev_dbg(sbd_core(),
"%s:%u\n", __func__, __LINE__);
1177 lv1_destruct_lpm(lpm_priv->
lpm_id);
1190 dev_dbg(&dev->
core,
" -> %s:%u\n", __func__, __LINE__);
1194 __func__, __LINE__);
1198 lpm_priv = kzalloc(
sizeof(*lpm_priv),
GFP_KERNEL);
1208 dev_info(&dev->
core,
" <- %s:%u:\n", __func__, __LINE__);
1215 dev_dbg(&dev->
core,
" -> %s:%u:\n", __func__, __LINE__);
1222 dev_info(&dev->
core,
" <- %s:%u:\n", __func__, __LINE__);
1228 .core.name =
"ps3-lpm",
1230 .probe = ps3_lpm_probe,
1231 .remove = ps3_lpm_remove,
1232 .shutdown = ps3_lpm_remove,
1235 static int __init ps3_lpm_init(
void)
1237 pr_debug(
"%s:%d:\n", __func__, __LINE__);
1241 static void __exit ps3_lpm_exit(
void)
1243 pr_debug(
"%s:%d:\n", __func__, __LINE__);