xgene_pmu.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * APM X-Gene SoC PMU (Performance Monitor Unit)
  4. *
  5. * Copyright (c) 2016, Applied Micro Circuits Corporation
  6. * Author: Hoan Tran <hotran@apm.com>
  7. * Tai Nguyen <ttnguyen@apm.com>
  8. */
  9. #include <linux/acpi.h>
  10. #include <linux/clk.h>
  11. #include <linux/cpuhotplug.h>
  12. #include <linux/cpumask.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/mfd/syscon.h>
  16. #include <linux/module.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_fdt.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of_platform.h>
  21. #include <linux/perf_event.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regmap.h>
  24. #include <linux/slab.h>
  25. #define CSW_CSWCR 0x0000
  26. #define CSW_CSWCR_DUALMCB_MASK BIT(0)
  27. #define CSW_CSWCR_MCB0_ROUTING(x) (((x) & 0x0C) >> 2)
  28. #define CSW_CSWCR_MCB1_ROUTING(x) (((x) & 0x30) >> 4)
  29. #define MCBADDRMR 0x0000
  30. #define MCBADDRMR_DUALMCU_MODE_MASK BIT(2)
  31. #define PCPPMU_INTSTATUS_REG 0x000
  32. #define PCPPMU_INTMASK_REG 0x004
  33. #define PCPPMU_INTMASK 0x0000000F
  34. #define PCPPMU_INTENMASK 0xFFFFFFFF
  35. #define PCPPMU_INTCLRMASK 0xFFFFFFF0
  36. #define PCPPMU_INT_MCU BIT(0)
  37. #define PCPPMU_INT_MCB BIT(1)
  38. #define PCPPMU_INT_L3C BIT(2)
  39. #define PCPPMU_INT_IOB BIT(3)
  40. #define PCPPMU_V3_INTMASK 0x00FF33FF
  41. #define PCPPMU_V3_INTENMASK 0xFFFFFFFF
  42. #define PCPPMU_V3_INTCLRMASK 0xFF00CC00
  43. #define PCPPMU_V3_INT_MCU 0x000000FF
  44. #define PCPPMU_V3_INT_MCB 0x00000300
  45. #define PCPPMU_V3_INT_L3C 0x00FF0000
  46. #define PCPPMU_V3_INT_IOB 0x00003000
  47. #define PMU_MAX_COUNTERS 4
  48. #define PMU_CNT_MAX_PERIOD 0xFFFFFFFFULL
  49. #define PMU_V3_CNT_MAX_PERIOD 0xFFFFFFFFFFFFFFFFULL
  50. #define PMU_OVERFLOW_MASK 0xF
  51. #define PMU_PMCR_E BIT(0)
  52. #define PMU_PMCR_P BIT(1)
  53. #define PMU_PMEVCNTR0 0x000
  54. #define PMU_PMEVCNTR1 0x004
  55. #define PMU_PMEVCNTR2 0x008
  56. #define PMU_PMEVCNTR3 0x00C
  57. #define PMU_PMEVTYPER0 0x400
  58. #define PMU_PMEVTYPER1 0x404
  59. #define PMU_PMEVTYPER2 0x408
  60. #define PMU_PMEVTYPER3 0x40C
  61. #define PMU_PMAMR0 0xA00
  62. #define PMU_PMAMR1 0xA04
  63. #define PMU_PMCNTENSET 0xC00
  64. #define PMU_PMCNTENCLR 0xC20
  65. #define PMU_PMINTENSET 0xC40
  66. #define PMU_PMINTENCLR 0xC60
  67. #define PMU_PMOVSR 0xC80
  68. #define PMU_PMCR 0xE04
  69. /* PMU registers for V3 */
  70. #define PMU_PMOVSCLR 0xC80
  71. #define PMU_PMOVSSET 0xCC0
  72. #define to_pmu_dev(p) container_of(p, struct xgene_pmu_dev, pmu)
  73. #define GET_CNTR(ev) (ev->hw.idx)
  74. #define GET_EVENTID(ev) (ev->hw.config & 0xFFULL)
  75. #define GET_AGENTID(ev) (ev->hw.config_base & 0xFFFFFFFFUL)
  76. #define GET_AGENT1ID(ev) ((ev->hw.config_base >> 32) & 0xFFFFFFFFUL)
  77. struct hw_pmu_info {
  78. u32 type;
  79. u32 enable_mask;
  80. void __iomem *csr;
  81. };
  82. struct xgene_pmu_dev {
  83. struct hw_pmu_info *inf;
  84. struct xgene_pmu *parent;
  85. struct pmu pmu;
  86. u8 max_counters;
  87. DECLARE_BITMAP(cntr_assign_mask, PMU_MAX_COUNTERS);
  88. u64 max_period;
  89. const struct attribute_group **attr_groups;
  90. struct perf_event *pmu_counter_event[PMU_MAX_COUNTERS];
  91. };
  92. struct xgene_pmu_ops {
  93. void (*mask_int)(struct xgene_pmu *pmu);
  94. void (*unmask_int)(struct xgene_pmu *pmu);
  95. u64 (*read_counter)(struct xgene_pmu_dev *pmu, int idx);
  96. void (*write_counter)(struct xgene_pmu_dev *pmu, int idx, u64 val);
  97. void (*write_evttype)(struct xgene_pmu_dev *pmu_dev, int idx, u32 val);
  98. void (*write_agentmsk)(struct xgene_pmu_dev *pmu_dev, u32 val);
  99. void (*write_agent1msk)(struct xgene_pmu_dev *pmu_dev, u32 val);
  100. void (*enable_counter)(struct xgene_pmu_dev *pmu_dev, int idx);
  101. void (*disable_counter)(struct xgene_pmu_dev *pmu_dev, int idx);
  102. void (*enable_counter_int)(struct xgene_pmu_dev *pmu_dev, int idx);
  103. void (*disable_counter_int)(struct xgene_pmu_dev *pmu_dev, int idx);
  104. void (*reset_counters)(struct xgene_pmu_dev *pmu_dev);
  105. void (*start_counters)(struct xgene_pmu_dev *pmu_dev);
  106. void (*stop_counters)(struct xgene_pmu_dev *pmu_dev);
  107. };
  108. struct xgene_pmu {
  109. struct device *dev;
  110. struct hlist_node node;
  111. int version;
  112. void __iomem *pcppmu_csr;
  113. u32 mcb_active_mask;
  114. u32 mc_active_mask;
  115. u32 l3c_active_mask;
  116. cpumask_t cpu;
  117. int irq;
  118. raw_spinlock_t lock;
  119. const struct xgene_pmu_ops *ops;
  120. struct list_head l3cpmus;
  121. struct list_head iobpmus;
  122. struct list_head mcbpmus;
  123. struct list_head mcpmus;
  124. };
  125. struct xgene_pmu_dev_ctx {
  126. char *name;
  127. struct list_head next;
  128. struct xgene_pmu_dev *pmu_dev;
  129. struct hw_pmu_info inf;
  130. };
  131. struct xgene_pmu_data {
  132. int id;
  133. u32 data;
  134. };
  135. enum xgene_pmu_version {
  136. PCP_PMU_V1 = 1,
  137. PCP_PMU_V2,
  138. PCP_PMU_V3,
  139. };
  140. enum xgene_pmu_dev_type {
  141. PMU_TYPE_L3C = 0,
  142. PMU_TYPE_IOB,
  143. PMU_TYPE_IOB_SLOW,
  144. PMU_TYPE_MCB,
  145. PMU_TYPE_MC,
  146. };
  147. /*
  148. * sysfs format attributes
  149. */
  150. static ssize_t xgene_pmu_format_show(struct device *dev,
  151. struct device_attribute *attr, char *buf)
  152. {
  153. struct dev_ext_attribute *eattr;
  154. eattr = container_of(attr, struct dev_ext_attribute, attr);
  155. return sprintf(buf, "%s\n", (char *) eattr->var);
  156. }
  157. #define XGENE_PMU_FORMAT_ATTR(_name, _config) \
  158. (&((struct dev_ext_attribute[]) { \
  159. { .attr = __ATTR(_name, S_IRUGO, xgene_pmu_format_show, NULL), \
  160. .var = (void *) _config, } \
  161. })[0].attr.attr)
  162. static struct attribute *l3c_pmu_format_attrs[] = {
  163. XGENE_PMU_FORMAT_ATTR(l3c_eventid, "config:0-7"),
  164. XGENE_PMU_FORMAT_ATTR(l3c_agentid, "config1:0-9"),
  165. NULL,
  166. };
  167. static struct attribute *iob_pmu_format_attrs[] = {
  168. XGENE_PMU_FORMAT_ATTR(iob_eventid, "config:0-7"),
  169. XGENE_PMU_FORMAT_ATTR(iob_agentid, "config1:0-63"),
  170. NULL,
  171. };
  172. static struct attribute *mcb_pmu_format_attrs[] = {
  173. XGENE_PMU_FORMAT_ATTR(mcb_eventid, "config:0-5"),
  174. XGENE_PMU_FORMAT_ATTR(mcb_agentid, "config1:0-9"),
  175. NULL,
  176. };
  177. static struct attribute *mc_pmu_format_attrs[] = {
  178. XGENE_PMU_FORMAT_ATTR(mc_eventid, "config:0-28"),
  179. NULL,
  180. };
  181. static const struct attribute_group l3c_pmu_format_attr_group = {
  182. .name = "format",
  183. .attrs = l3c_pmu_format_attrs,
  184. };
  185. static const struct attribute_group iob_pmu_format_attr_group = {
  186. .name = "format",
  187. .attrs = iob_pmu_format_attrs,
  188. };
  189. static const struct attribute_group mcb_pmu_format_attr_group = {
  190. .name = "format",
  191. .attrs = mcb_pmu_format_attrs,
  192. };
  193. static const struct attribute_group mc_pmu_format_attr_group = {
  194. .name = "format",
  195. .attrs = mc_pmu_format_attrs,
  196. };
  197. static struct attribute *l3c_pmu_v3_format_attrs[] = {
  198. XGENE_PMU_FORMAT_ATTR(l3c_eventid, "config:0-39"),
  199. NULL,
  200. };
  201. static struct attribute *iob_pmu_v3_format_attrs[] = {
  202. XGENE_PMU_FORMAT_ATTR(iob_eventid, "config:0-47"),
  203. NULL,
  204. };
  205. static struct attribute *iob_slow_pmu_v3_format_attrs[] = {
  206. XGENE_PMU_FORMAT_ATTR(iob_slow_eventid, "config:0-16"),
  207. NULL,
  208. };
  209. static struct attribute *mcb_pmu_v3_format_attrs[] = {
  210. XGENE_PMU_FORMAT_ATTR(mcb_eventid, "config:0-35"),
  211. NULL,
  212. };
  213. static struct attribute *mc_pmu_v3_format_attrs[] = {
  214. XGENE_PMU_FORMAT_ATTR(mc_eventid, "config:0-44"),
  215. NULL,
  216. };
  217. static const struct attribute_group l3c_pmu_v3_format_attr_group = {
  218. .name = "format",
  219. .attrs = l3c_pmu_v3_format_attrs,
  220. };
  221. static const struct attribute_group iob_pmu_v3_format_attr_group = {
  222. .name = "format",
  223. .attrs = iob_pmu_v3_format_attrs,
  224. };
  225. static const struct attribute_group iob_slow_pmu_v3_format_attr_group = {
  226. .name = "format",
  227. .attrs = iob_slow_pmu_v3_format_attrs,
  228. };
  229. static const struct attribute_group mcb_pmu_v3_format_attr_group = {
  230. .name = "format",
  231. .attrs = mcb_pmu_v3_format_attrs,
  232. };
  233. static const struct attribute_group mc_pmu_v3_format_attr_group = {
  234. .name = "format",
  235. .attrs = mc_pmu_v3_format_attrs,
  236. };
  237. /*
  238. * sysfs event attributes
  239. */
  240. static ssize_t xgene_pmu_event_show(struct device *dev,
  241. struct device_attribute *attr, char *buf)
  242. {
  243. struct dev_ext_attribute *eattr;
  244. eattr = container_of(attr, struct dev_ext_attribute, attr);
  245. return sprintf(buf, "config=0x%lx\n", (unsigned long) eattr->var);
  246. }
  247. #define XGENE_PMU_EVENT_ATTR(_name, _config) \
  248. (&((struct dev_ext_attribute[]) { \
  249. { .attr = __ATTR(_name, S_IRUGO, xgene_pmu_event_show, NULL), \
  250. .var = (void *) _config, } \
  251. })[0].attr.attr)
  252. static struct attribute *l3c_pmu_events_attrs[] = {
  253. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  254. XGENE_PMU_EVENT_ATTR(cycle-count-div-64, 0x01),
  255. XGENE_PMU_EVENT_ATTR(read-hit, 0x02),
  256. XGENE_PMU_EVENT_ATTR(read-miss, 0x03),
  257. XGENE_PMU_EVENT_ATTR(write-need-replacement, 0x06),
  258. XGENE_PMU_EVENT_ATTR(write-not-need-replacement, 0x07),
  259. XGENE_PMU_EVENT_ATTR(tq-full, 0x08),
  260. XGENE_PMU_EVENT_ATTR(ackq-full, 0x09),
  261. XGENE_PMU_EVENT_ATTR(wdb-full, 0x0a),
  262. XGENE_PMU_EVENT_ATTR(bank-fifo-full, 0x0b),
  263. XGENE_PMU_EVENT_ATTR(odb-full, 0x0c),
  264. XGENE_PMU_EVENT_ATTR(wbq-full, 0x0d),
  265. XGENE_PMU_EVENT_ATTR(bank-conflict-fifo-issue, 0x0e),
  266. XGENE_PMU_EVENT_ATTR(bank-fifo-issue, 0x0f),
  267. NULL,
  268. };
  269. static struct attribute *iob_pmu_events_attrs[] = {
  270. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  271. XGENE_PMU_EVENT_ATTR(cycle-count-div-64, 0x01),
  272. XGENE_PMU_EVENT_ATTR(axi0-read, 0x02),
  273. XGENE_PMU_EVENT_ATTR(axi0-read-partial, 0x03),
  274. XGENE_PMU_EVENT_ATTR(axi1-read, 0x04),
  275. XGENE_PMU_EVENT_ATTR(axi1-read-partial, 0x05),
  276. XGENE_PMU_EVENT_ATTR(csw-read-block, 0x06),
  277. XGENE_PMU_EVENT_ATTR(csw-read-partial, 0x07),
  278. XGENE_PMU_EVENT_ATTR(axi0-write, 0x10),
  279. XGENE_PMU_EVENT_ATTR(axi0-write-partial, 0x11),
  280. XGENE_PMU_EVENT_ATTR(axi1-write, 0x13),
  281. XGENE_PMU_EVENT_ATTR(axi1-write-partial, 0x14),
  282. XGENE_PMU_EVENT_ATTR(csw-inbound-dirty, 0x16),
  283. NULL,
  284. };
  285. static struct attribute *mcb_pmu_events_attrs[] = {
  286. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  287. XGENE_PMU_EVENT_ATTR(cycle-count-div-64, 0x01),
  288. XGENE_PMU_EVENT_ATTR(csw-read, 0x02),
  289. XGENE_PMU_EVENT_ATTR(csw-write-request, 0x03),
  290. XGENE_PMU_EVENT_ATTR(mcb-csw-stall, 0x04),
  291. XGENE_PMU_EVENT_ATTR(cancel-read-gack, 0x05),
  292. NULL,
  293. };
  294. static struct attribute *mc_pmu_events_attrs[] = {
  295. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  296. XGENE_PMU_EVENT_ATTR(cycle-count-div-64, 0x01),
  297. XGENE_PMU_EVENT_ATTR(act-cmd-sent, 0x02),
  298. XGENE_PMU_EVENT_ATTR(pre-cmd-sent, 0x03),
  299. XGENE_PMU_EVENT_ATTR(rd-cmd-sent, 0x04),
  300. XGENE_PMU_EVENT_ATTR(rda-cmd-sent, 0x05),
  301. XGENE_PMU_EVENT_ATTR(wr-cmd-sent, 0x06),
  302. XGENE_PMU_EVENT_ATTR(wra-cmd-sent, 0x07),
  303. XGENE_PMU_EVENT_ATTR(pde-cmd-sent, 0x08),
  304. XGENE_PMU_EVENT_ATTR(sre-cmd-sent, 0x09),
  305. XGENE_PMU_EVENT_ATTR(prea-cmd-sent, 0x0a),
  306. XGENE_PMU_EVENT_ATTR(ref-cmd-sent, 0x0b),
  307. XGENE_PMU_EVENT_ATTR(rd-rda-cmd-sent, 0x0c),
  308. XGENE_PMU_EVENT_ATTR(wr-wra-cmd-sent, 0x0d),
  309. XGENE_PMU_EVENT_ATTR(in-rd-collision, 0x0e),
  310. XGENE_PMU_EVENT_ATTR(in-wr-collision, 0x0f),
  311. XGENE_PMU_EVENT_ATTR(collision-queue-not-empty, 0x10),
  312. XGENE_PMU_EVENT_ATTR(collision-queue-full, 0x11),
  313. XGENE_PMU_EVENT_ATTR(mcu-request, 0x12),
  314. XGENE_PMU_EVENT_ATTR(mcu-rd-request, 0x13),
  315. XGENE_PMU_EVENT_ATTR(mcu-hp-rd-request, 0x14),
  316. XGENE_PMU_EVENT_ATTR(mcu-wr-request, 0x15),
  317. XGENE_PMU_EVENT_ATTR(mcu-rd-proceed-all, 0x16),
  318. XGENE_PMU_EVENT_ATTR(mcu-rd-proceed-cancel, 0x17),
  319. XGENE_PMU_EVENT_ATTR(mcu-rd-response, 0x18),
  320. XGENE_PMU_EVENT_ATTR(mcu-rd-proceed-speculative-all, 0x19),
  321. XGENE_PMU_EVENT_ATTR(mcu-rd-proceed-speculative-cancel, 0x1a),
  322. XGENE_PMU_EVENT_ATTR(mcu-wr-proceed-all, 0x1b),
  323. XGENE_PMU_EVENT_ATTR(mcu-wr-proceed-cancel, 0x1c),
  324. NULL,
  325. };
  326. static const struct attribute_group l3c_pmu_events_attr_group = {
  327. .name = "events",
  328. .attrs = l3c_pmu_events_attrs,
  329. };
  330. static const struct attribute_group iob_pmu_events_attr_group = {
  331. .name = "events",
  332. .attrs = iob_pmu_events_attrs,
  333. };
  334. static const struct attribute_group mcb_pmu_events_attr_group = {
  335. .name = "events",
  336. .attrs = mcb_pmu_events_attrs,
  337. };
  338. static const struct attribute_group mc_pmu_events_attr_group = {
  339. .name = "events",
  340. .attrs = mc_pmu_events_attrs,
  341. };
  342. static struct attribute *l3c_pmu_v3_events_attrs[] = {
  343. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  344. XGENE_PMU_EVENT_ATTR(read-hit, 0x01),
  345. XGENE_PMU_EVENT_ATTR(read-miss, 0x02),
  346. XGENE_PMU_EVENT_ATTR(index-flush-eviction, 0x03),
  347. XGENE_PMU_EVENT_ATTR(write-caused-replacement, 0x04),
  348. XGENE_PMU_EVENT_ATTR(write-not-caused-replacement, 0x05),
  349. XGENE_PMU_EVENT_ATTR(clean-eviction, 0x06),
  350. XGENE_PMU_EVENT_ATTR(dirty-eviction, 0x07),
  351. XGENE_PMU_EVENT_ATTR(read, 0x08),
  352. XGENE_PMU_EVENT_ATTR(write, 0x09),
  353. XGENE_PMU_EVENT_ATTR(request, 0x0a),
  354. XGENE_PMU_EVENT_ATTR(tq-bank-conflict-issue-stall, 0x0b),
  355. XGENE_PMU_EVENT_ATTR(tq-full, 0x0c),
  356. XGENE_PMU_EVENT_ATTR(ackq-full, 0x0d),
  357. XGENE_PMU_EVENT_ATTR(wdb-full, 0x0e),
  358. XGENE_PMU_EVENT_ATTR(odb-full, 0x10),
  359. XGENE_PMU_EVENT_ATTR(wbq-full, 0x11),
  360. XGENE_PMU_EVENT_ATTR(input-req-async-fifo-stall, 0x12),
  361. XGENE_PMU_EVENT_ATTR(output-req-async-fifo-stall, 0x13),
  362. XGENE_PMU_EVENT_ATTR(output-data-async-fifo-stall, 0x14),
  363. XGENE_PMU_EVENT_ATTR(total-insertion, 0x15),
  364. XGENE_PMU_EVENT_ATTR(sip-insertions-r-set, 0x16),
  365. XGENE_PMU_EVENT_ATTR(sip-insertions-r-clear, 0x17),
  366. XGENE_PMU_EVENT_ATTR(dip-insertions-r-set, 0x18),
  367. XGENE_PMU_EVENT_ATTR(dip-insertions-r-clear, 0x19),
  368. XGENE_PMU_EVENT_ATTR(dip-insertions-force-r-set, 0x1a),
  369. XGENE_PMU_EVENT_ATTR(egression, 0x1b),
  370. XGENE_PMU_EVENT_ATTR(replacement, 0x1c),
  371. XGENE_PMU_EVENT_ATTR(old-replacement, 0x1d),
  372. XGENE_PMU_EVENT_ATTR(young-replacement, 0x1e),
  373. XGENE_PMU_EVENT_ATTR(r-set-replacement, 0x1f),
  374. XGENE_PMU_EVENT_ATTR(r-clear-replacement, 0x20),
  375. XGENE_PMU_EVENT_ATTR(old-r-replacement, 0x21),
  376. XGENE_PMU_EVENT_ATTR(old-nr-replacement, 0x22),
  377. XGENE_PMU_EVENT_ATTR(young-r-replacement, 0x23),
  378. XGENE_PMU_EVENT_ATTR(young-nr-replacement, 0x24),
  379. XGENE_PMU_EVENT_ATTR(bloomfilter-clearing, 0x25),
  380. XGENE_PMU_EVENT_ATTR(generation-flip, 0x26),
  381. XGENE_PMU_EVENT_ATTR(vcc-droop-detected, 0x27),
  382. NULL,
  383. };
  384. static struct attribute *iob_fast_pmu_v3_events_attrs[] = {
  385. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  386. XGENE_PMU_EVENT_ATTR(pa-req-buf-alloc-all, 0x01),
  387. XGENE_PMU_EVENT_ATTR(pa-req-buf-alloc-rd, 0x02),
  388. XGENE_PMU_EVENT_ATTR(pa-req-buf-alloc-wr, 0x03),
  389. XGENE_PMU_EVENT_ATTR(pa-all-cp-req, 0x04),
  390. XGENE_PMU_EVENT_ATTR(pa-cp-blk-req, 0x05),
  391. XGENE_PMU_EVENT_ATTR(pa-cp-ptl-req, 0x06),
  392. XGENE_PMU_EVENT_ATTR(pa-cp-rd-req, 0x07),
  393. XGENE_PMU_EVENT_ATTR(pa-cp-wr-req, 0x08),
  394. XGENE_PMU_EVENT_ATTR(ba-all-req, 0x09),
  395. XGENE_PMU_EVENT_ATTR(ba-rd-req, 0x0a),
  396. XGENE_PMU_EVENT_ATTR(ba-wr-req, 0x0b),
  397. XGENE_PMU_EVENT_ATTR(pa-rd-shared-req-issued, 0x10),
  398. XGENE_PMU_EVENT_ATTR(pa-rd-exclusive-req-issued, 0x11),
  399. XGENE_PMU_EVENT_ATTR(pa-wr-invalidate-req-issued-stashable, 0x12),
  400. XGENE_PMU_EVENT_ATTR(pa-wr-invalidate-req-issued-nonstashable, 0x13),
  401. XGENE_PMU_EVENT_ATTR(pa-wr-back-req-issued-stashable, 0x14),
  402. XGENE_PMU_EVENT_ATTR(pa-wr-back-req-issued-nonstashable, 0x15),
  403. XGENE_PMU_EVENT_ATTR(pa-ptl-wr-req, 0x16),
  404. XGENE_PMU_EVENT_ATTR(pa-ptl-rd-req, 0x17),
  405. XGENE_PMU_EVENT_ATTR(pa-wr-back-clean-data, 0x18),
  406. XGENE_PMU_EVENT_ATTR(pa-wr-back-cancelled-on-SS, 0x1b),
  407. XGENE_PMU_EVENT_ATTR(pa-barrier-occurrence, 0x1c),
  408. XGENE_PMU_EVENT_ATTR(pa-barrier-cycles, 0x1d),
  409. XGENE_PMU_EVENT_ATTR(pa-total-cp-snoops, 0x20),
  410. XGENE_PMU_EVENT_ATTR(pa-rd-shared-snoop, 0x21),
  411. XGENE_PMU_EVENT_ATTR(pa-rd-shared-snoop-hit, 0x22),
  412. XGENE_PMU_EVENT_ATTR(pa-rd-exclusive-snoop, 0x23),
  413. XGENE_PMU_EVENT_ATTR(pa-rd-exclusive-snoop-hit, 0x24),
  414. XGENE_PMU_EVENT_ATTR(pa-rd-wr-invalid-snoop, 0x25),
  415. XGENE_PMU_EVENT_ATTR(pa-rd-wr-invalid-snoop-hit, 0x26),
  416. XGENE_PMU_EVENT_ATTR(pa-req-buffer-full, 0x28),
  417. XGENE_PMU_EVENT_ATTR(cswlf-outbound-req-fifo-full, 0x29),
  418. XGENE_PMU_EVENT_ATTR(cswlf-inbound-snoop-fifo-backpressure, 0x2a),
  419. XGENE_PMU_EVENT_ATTR(cswlf-outbound-lack-fifo-full, 0x2b),
  420. XGENE_PMU_EVENT_ATTR(cswlf-inbound-gack-fifo-backpressure, 0x2c),
  421. XGENE_PMU_EVENT_ATTR(cswlf-outbound-data-fifo-full, 0x2d),
  422. XGENE_PMU_EVENT_ATTR(cswlf-inbound-data-fifo-backpressure, 0x2e),
  423. XGENE_PMU_EVENT_ATTR(cswlf-inbound-req-backpressure, 0x2f),
  424. NULL,
  425. };
  426. static struct attribute *iob_slow_pmu_v3_events_attrs[] = {
  427. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  428. XGENE_PMU_EVENT_ATTR(pa-axi0-rd-req, 0x01),
  429. XGENE_PMU_EVENT_ATTR(pa-axi0-wr-req, 0x02),
  430. XGENE_PMU_EVENT_ATTR(pa-axi1-rd-req, 0x03),
  431. XGENE_PMU_EVENT_ATTR(pa-axi1-wr-req, 0x04),
  432. XGENE_PMU_EVENT_ATTR(ba-all-axi-req, 0x07),
  433. XGENE_PMU_EVENT_ATTR(ba-axi-rd-req, 0x08),
  434. XGENE_PMU_EVENT_ATTR(ba-axi-wr-req, 0x09),
  435. XGENE_PMU_EVENT_ATTR(ba-free-list-empty, 0x10),
  436. NULL,
  437. };
  438. static struct attribute *mcb_pmu_v3_events_attrs[] = {
  439. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  440. XGENE_PMU_EVENT_ATTR(req-receive, 0x01),
  441. XGENE_PMU_EVENT_ATTR(rd-req-recv, 0x02),
  442. XGENE_PMU_EVENT_ATTR(rd-req-recv-2, 0x03),
  443. XGENE_PMU_EVENT_ATTR(wr-req-recv, 0x04),
  444. XGENE_PMU_EVENT_ATTR(wr-req-recv-2, 0x05),
  445. XGENE_PMU_EVENT_ATTR(rd-req-sent-to-mcu, 0x06),
  446. XGENE_PMU_EVENT_ATTR(rd-req-sent-to-mcu-2, 0x07),
  447. XGENE_PMU_EVENT_ATTR(rd-req-sent-to-spec-mcu, 0x08),
  448. XGENE_PMU_EVENT_ATTR(rd-req-sent-to-spec-mcu-2, 0x09),
  449. XGENE_PMU_EVENT_ATTR(glbl-ack-recv-for-rd-sent-to-spec-mcu, 0x0a),
  450. XGENE_PMU_EVENT_ATTR(glbl-ack-go-recv-for-rd-sent-to-spec-mcu, 0x0b),
  451. XGENE_PMU_EVENT_ATTR(glbl-ack-nogo-recv-for-rd-sent-to-spec-mcu, 0x0c),
  452. XGENE_PMU_EVENT_ATTR(glbl-ack-go-recv-any-rd-req, 0x0d),
  453. XGENE_PMU_EVENT_ATTR(glbl-ack-go-recv-any-rd-req-2, 0x0e),
  454. XGENE_PMU_EVENT_ATTR(wr-req-sent-to-mcu, 0x0f),
  455. XGENE_PMU_EVENT_ATTR(gack-recv, 0x10),
  456. XGENE_PMU_EVENT_ATTR(rd-gack-recv, 0x11),
  457. XGENE_PMU_EVENT_ATTR(wr-gack-recv, 0x12),
  458. XGENE_PMU_EVENT_ATTR(cancel-rd-gack, 0x13),
  459. XGENE_PMU_EVENT_ATTR(cancel-wr-gack, 0x14),
  460. XGENE_PMU_EVENT_ATTR(mcb-csw-req-stall, 0x15),
  461. XGENE_PMU_EVENT_ATTR(mcu-req-intf-blocked, 0x16),
  462. XGENE_PMU_EVENT_ATTR(mcb-mcu-rd-intf-stall, 0x17),
  463. XGENE_PMU_EVENT_ATTR(csw-rd-intf-blocked, 0x18),
  464. XGENE_PMU_EVENT_ATTR(csw-local-ack-intf-blocked, 0x19),
  465. XGENE_PMU_EVENT_ATTR(mcu-req-table-full, 0x1a),
  466. XGENE_PMU_EVENT_ATTR(mcu-stat-table-full, 0x1b),
  467. XGENE_PMU_EVENT_ATTR(mcu-wr-table-full, 0x1c),
  468. XGENE_PMU_EVENT_ATTR(mcu-rdreceipt-resp, 0x1d),
  469. XGENE_PMU_EVENT_ATTR(mcu-wrcomplete-resp, 0x1e),
  470. XGENE_PMU_EVENT_ATTR(mcu-retryack-resp, 0x1f),
  471. XGENE_PMU_EVENT_ATTR(mcu-pcrdgrant-resp, 0x20),
  472. XGENE_PMU_EVENT_ATTR(mcu-req-from-lastload, 0x21),
  473. XGENE_PMU_EVENT_ATTR(mcu-req-from-bypass, 0x22),
  474. XGENE_PMU_EVENT_ATTR(volt-droop-detect, 0x23),
  475. NULL,
  476. };
  477. static struct attribute *mc_pmu_v3_events_attrs[] = {
  478. XGENE_PMU_EVENT_ATTR(cycle-count, 0x00),
  479. XGENE_PMU_EVENT_ATTR(act-sent, 0x01),
  480. XGENE_PMU_EVENT_ATTR(pre-sent, 0x02),
  481. XGENE_PMU_EVENT_ATTR(rd-sent, 0x03),
  482. XGENE_PMU_EVENT_ATTR(rda-sent, 0x04),
  483. XGENE_PMU_EVENT_ATTR(wr-sent, 0x05),
  484. XGENE_PMU_EVENT_ATTR(wra-sent, 0x06),
  485. XGENE_PMU_EVENT_ATTR(pd-entry-vld, 0x07),
  486. XGENE_PMU_EVENT_ATTR(sref-entry-vld, 0x08),
  487. XGENE_PMU_EVENT_ATTR(prea-sent, 0x09),
  488. XGENE_PMU_EVENT_ATTR(ref-sent, 0x0a),
  489. XGENE_PMU_EVENT_ATTR(rd-rda-sent, 0x0b),
  490. XGENE_PMU_EVENT_ATTR(wr-wra-sent, 0x0c),
  491. XGENE_PMU_EVENT_ATTR(raw-hazard, 0x0d),
  492. XGENE_PMU_EVENT_ATTR(war-hazard, 0x0e),
  493. XGENE_PMU_EVENT_ATTR(waw-hazard, 0x0f),
  494. XGENE_PMU_EVENT_ATTR(rar-hazard, 0x10),
  495. XGENE_PMU_EVENT_ATTR(raw-war-waw-hazard, 0x11),
  496. XGENE_PMU_EVENT_ATTR(hprd-lprd-wr-req-vld, 0x12),
  497. XGENE_PMU_EVENT_ATTR(lprd-req-vld, 0x13),
  498. XGENE_PMU_EVENT_ATTR(hprd-req-vld, 0x14),
  499. XGENE_PMU_EVENT_ATTR(hprd-lprd-req-vld, 0x15),
  500. XGENE_PMU_EVENT_ATTR(wr-req-vld, 0x16),
  501. XGENE_PMU_EVENT_ATTR(partial-wr-req-vld, 0x17),
  502. XGENE_PMU_EVENT_ATTR(rd-retry, 0x18),
  503. XGENE_PMU_EVENT_ATTR(wr-retry, 0x19),
  504. XGENE_PMU_EVENT_ATTR(retry-gnt, 0x1a),
  505. XGENE_PMU_EVENT_ATTR(rank-change, 0x1b),
  506. XGENE_PMU_EVENT_ATTR(dir-change, 0x1c),
  507. XGENE_PMU_EVENT_ATTR(rank-dir-change, 0x1d),
  508. XGENE_PMU_EVENT_ATTR(rank-active, 0x1e),
  509. XGENE_PMU_EVENT_ATTR(rank-idle, 0x1f),
  510. XGENE_PMU_EVENT_ATTR(rank-pd, 0x20),
  511. XGENE_PMU_EVENT_ATTR(rank-sref, 0x21),
  512. XGENE_PMU_EVENT_ATTR(queue-fill-gt-thresh, 0x22),
  513. XGENE_PMU_EVENT_ATTR(queue-rds-gt-thresh, 0x23),
  514. XGENE_PMU_EVENT_ATTR(queue-wrs-gt-thresh, 0x24),
  515. XGENE_PMU_EVENT_ATTR(phy-updt-complt, 0x25),
  516. XGENE_PMU_EVENT_ATTR(tz-fail, 0x26),
  517. XGENE_PMU_EVENT_ATTR(dram-errc, 0x27),
  518. XGENE_PMU_EVENT_ATTR(dram-errd, 0x28),
  519. XGENE_PMU_EVENT_ATTR(rd-enq, 0x29),
  520. XGENE_PMU_EVENT_ATTR(wr-enq, 0x2a),
  521. XGENE_PMU_EVENT_ATTR(tmac-limit-reached, 0x2b),
  522. XGENE_PMU_EVENT_ATTR(tmaw-tracker-full, 0x2c),
  523. NULL,
  524. };
  525. static const struct attribute_group l3c_pmu_v3_events_attr_group = {
  526. .name = "events",
  527. .attrs = l3c_pmu_v3_events_attrs,
  528. };
  529. static const struct attribute_group iob_fast_pmu_v3_events_attr_group = {
  530. .name = "events",
  531. .attrs = iob_fast_pmu_v3_events_attrs,
  532. };
  533. static const struct attribute_group iob_slow_pmu_v3_events_attr_group = {
  534. .name = "events",
  535. .attrs = iob_slow_pmu_v3_events_attrs,
  536. };
  537. static const struct attribute_group mcb_pmu_v3_events_attr_group = {
  538. .name = "events",
  539. .attrs = mcb_pmu_v3_events_attrs,
  540. };
  541. static const struct attribute_group mc_pmu_v3_events_attr_group = {
  542. .name = "events",
  543. .attrs = mc_pmu_v3_events_attrs,
  544. };
  545. /*
  546. * sysfs cpumask attributes
  547. */
  548. static ssize_t xgene_pmu_cpumask_show(struct device *dev,
  549. struct device_attribute *attr, char *buf)
  550. {
  551. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(dev_get_drvdata(dev));
  552. return cpumap_print_to_pagebuf(true, buf, &pmu_dev->parent->cpu);
  553. }
  554. static DEVICE_ATTR(cpumask, S_IRUGO, xgene_pmu_cpumask_show, NULL);
  555. static struct attribute *xgene_pmu_cpumask_attrs[] = {
  556. &dev_attr_cpumask.attr,
  557. NULL,
  558. };
  559. static const struct attribute_group pmu_cpumask_attr_group = {
  560. .attrs = xgene_pmu_cpumask_attrs,
  561. };
  562. /*
  563. * Per PMU device attribute groups of PMU v1 and v2
  564. */
  565. static const struct attribute_group *l3c_pmu_attr_groups[] = {
  566. &l3c_pmu_format_attr_group,
  567. &pmu_cpumask_attr_group,
  568. &l3c_pmu_events_attr_group,
  569. NULL
  570. };
  571. static const struct attribute_group *iob_pmu_attr_groups[] = {
  572. &iob_pmu_format_attr_group,
  573. &pmu_cpumask_attr_group,
  574. &iob_pmu_events_attr_group,
  575. NULL
  576. };
  577. static const struct attribute_group *mcb_pmu_attr_groups[] = {
  578. &mcb_pmu_format_attr_group,
  579. &pmu_cpumask_attr_group,
  580. &mcb_pmu_events_attr_group,
  581. NULL
  582. };
  583. static const struct attribute_group *mc_pmu_attr_groups[] = {
  584. &mc_pmu_format_attr_group,
  585. &pmu_cpumask_attr_group,
  586. &mc_pmu_events_attr_group,
  587. NULL
  588. };
  589. /*
  590. * Per PMU device attribute groups of PMU v3
  591. */
  592. static const struct attribute_group *l3c_pmu_v3_attr_groups[] = {
  593. &l3c_pmu_v3_format_attr_group,
  594. &pmu_cpumask_attr_group,
  595. &l3c_pmu_v3_events_attr_group,
  596. NULL
  597. };
  598. static const struct attribute_group *iob_fast_pmu_v3_attr_groups[] = {
  599. &iob_pmu_v3_format_attr_group,
  600. &pmu_cpumask_attr_group,
  601. &iob_fast_pmu_v3_events_attr_group,
  602. NULL
  603. };
  604. static const struct attribute_group *iob_slow_pmu_v3_attr_groups[] = {
  605. &iob_slow_pmu_v3_format_attr_group,
  606. &pmu_cpumask_attr_group,
  607. &iob_slow_pmu_v3_events_attr_group,
  608. NULL
  609. };
  610. static const struct attribute_group *mcb_pmu_v3_attr_groups[] = {
  611. &mcb_pmu_v3_format_attr_group,
  612. &pmu_cpumask_attr_group,
  613. &mcb_pmu_v3_events_attr_group,
  614. NULL
  615. };
  616. static const struct attribute_group *mc_pmu_v3_attr_groups[] = {
  617. &mc_pmu_v3_format_attr_group,
  618. &pmu_cpumask_attr_group,
  619. &mc_pmu_v3_events_attr_group,
  620. NULL
  621. };
  622. static int get_next_avail_cntr(struct xgene_pmu_dev *pmu_dev)
  623. {
  624. int cntr;
  625. cntr = find_first_zero_bit(pmu_dev->cntr_assign_mask,
  626. pmu_dev->max_counters);
  627. if (cntr == pmu_dev->max_counters)
  628. return -ENOSPC;
  629. set_bit(cntr, pmu_dev->cntr_assign_mask);
  630. return cntr;
  631. }
  632. static void clear_avail_cntr(struct xgene_pmu_dev *pmu_dev, int cntr)
  633. {
  634. clear_bit(cntr, pmu_dev->cntr_assign_mask);
  635. }
  636. static inline void xgene_pmu_mask_int(struct xgene_pmu *xgene_pmu)
  637. {
  638. writel(PCPPMU_INTENMASK, xgene_pmu->pcppmu_csr + PCPPMU_INTMASK_REG);
  639. }
  640. static inline void xgene_pmu_v3_mask_int(struct xgene_pmu *xgene_pmu)
  641. {
  642. writel(PCPPMU_V3_INTENMASK, xgene_pmu->pcppmu_csr + PCPPMU_INTMASK_REG);
  643. }
  644. static inline void xgene_pmu_unmask_int(struct xgene_pmu *xgene_pmu)
  645. {
  646. writel(PCPPMU_INTCLRMASK, xgene_pmu->pcppmu_csr + PCPPMU_INTMASK_REG);
  647. }
  648. static inline void xgene_pmu_v3_unmask_int(struct xgene_pmu *xgene_pmu)
  649. {
  650. writel(PCPPMU_V3_INTCLRMASK,
  651. xgene_pmu->pcppmu_csr + PCPPMU_INTMASK_REG);
  652. }
  653. static inline u64 xgene_pmu_read_counter32(struct xgene_pmu_dev *pmu_dev,
  654. int idx)
  655. {
  656. return readl(pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
  657. }
  658. static inline u64 xgene_pmu_read_counter64(struct xgene_pmu_dev *pmu_dev,
  659. int idx)
  660. {
  661. u32 lo, hi;
  662. /*
  663. * v3 has 64-bit counter registers composed by 2 32-bit registers
  664. * This can be a problem if the counter increases and carries
  665. * out of bit [31] between 2 reads. The extra reads would help
  666. * to prevent this issue.
  667. */
  668. do {
  669. hi = xgene_pmu_read_counter32(pmu_dev, 2 * idx + 1);
  670. lo = xgene_pmu_read_counter32(pmu_dev, 2 * idx);
  671. } while (hi != xgene_pmu_read_counter32(pmu_dev, 2 * idx + 1));
  672. return (((u64)hi << 32) | lo);
  673. }
  674. static inline void
  675. xgene_pmu_write_counter32(struct xgene_pmu_dev *pmu_dev, int idx, u64 val)
  676. {
  677. writel(val, pmu_dev->inf->csr + PMU_PMEVCNTR0 + (4 * idx));
  678. }
  679. static inline void
  680. xgene_pmu_write_counter64(struct xgene_pmu_dev *pmu_dev, int idx, u64 val)
  681. {
  682. u32 cnt_lo, cnt_hi;
  683. cnt_hi = upper_32_bits(val);
  684. cnt_lo = lower_32_bits(val);
  685. /* v3 has 64-bit counter registers composed by 2 32-bit registers */
  686. xgene_pmu_write_counter32(pmu_dev, 2 * idx, cnt_lo);
  687. xgene_pmu_write_counter32(pmu_dev, 2 * idx + 1, cnt_hi);
  688. }
  689. static inline void
  690. xgene_pmu_write_evttype(struct xgene_pmu_dev *pmu_dev, int idx, u32 val)
  691. {
  692. writel(val, pmu_dev->inf->csr + PMU_PMEVTYPER0 + (4 * idx));
  693. }
  694. static inline void
  695. xgene_pmu_write_agentmsk(struct xgene_pmu_dev *pmu_dev, u32 val)
  696. {
  697. writel(val, pmu_dev->inf->csr + PMU_PMAMR0);
  698. }
  699. static inline void
  700. xgene_pmu_v3_write_agentmsk(struct xgene_pmu_dev *pmu_dev, u32 val) { }
  701. static inline void
  702. xgene_pmu_write_agent1msk(struct xgene_pmu_dev *pmu_dev, u32 val)
  703. {
  704. writel(val, pmu_dev->inf->csr + PMU_PMAMR1);
  705. }
  706. static inline void
  707. xgene_pmu_v3_write_agent1msk(struct xgene_pmu_dev *pmu_dev, u32 val) { }
  708. static inline void
  709. xgene_pmu_enable_counter(struct xgene_pmu_dev *pmu_dev, int idx)
  710. {
  711. u32 val;
  712. val = readl(pmu_dev->inf->csr + PMU_PMCNTENSET);
  713. val |= 1 << idx;
  714. writel(val, pmu_dev->inf->csr + PMU_PMCNTENSET);
  715. }
  716. static inline void
  717. xgene_pmu_disable_counter(struct xgene_pmu_dev *pmu_dev, int idx)
  718. {
  719. u32 val;
  720. val = readl(pmu_dev->inf->csr + PMU_PMCNTENCLR);
  721. val |= 1 << idx;
  722. writel(val, pmu_dev->inf->csr + PMU_PMCNTENCLR);
  723. }
  724. static inline void
  725. xgene_pmu_enable_counter_int(struct xgene_pmu_dev *pmu_dev, int idx)
  726. {
  727. u32 val;
  728. val = readl(pmu_dev->inf->csr + PMU_PMINTENSET);
  729. val |= 1 << idx;
  730. writel(val, pmu_dev->inf->csr + PMU_PMINTENSET);
  731. }
  732. static inline void
  733. xgene_pmu_disable_counter_int(struct xgene_pmu_dev *pmu_dev, int idx)
  734. {
  735. u32 val;
  736. val = readl(pmu_dev->inf->csr + PMU_PMINTENCLR);
  737. val |= 1 << idx;
  738. writel(val, pmu_dev->inf->csr + PMU_PMINTENCLR);
  739. }
  740. static inline void xgene_pmu_reset_counters(struct xgene_pmu_dev *pmu_dev)
  741. {
  742. u32 val;
  743. val = readl(pmu_dev->inf->csr + PMU_PMCR);
  744. val |= PMU_PMCR_P;
  745. writel(val, pmu_dev->inf->csr + PMU_PMCR);
  746. }
  747. static inline void xgene_pmu_start_counters(struct xgene_pmu_dev *pmu_dev)
  748. {
  749. u32 val;
  750. val = readl(pmu_dev->inf->csr + PMU_PMCR);
  751. val |= PMU_PMCR_E;
  752. writel(val, pmu_dev->inf->csr + PMU_PMCR);
  753. }
  754. static inline void xgene_pmu_stop_counters(struct xgene_pmu_dev *pmu_dev)
  755. {
  756. u32 val;
  757. val = readl(pmu_dev->inf->csr + PMU_PMCR);
  758. val &= ~PMU_PMCR_E;
  759. writel(val, pmu_dev->inf->csr + PMU_PMCR);
  760. }
  761. static void xgene_perf_pmu_enable(struct pmu *pmu)
  762. {
  763. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(pmu);
  764. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  765. int enabled = bitmap_weight(pmu_dev->cntr_assign_mask,
  766. pmu_dev->max_counters);
  767. if (!enabled)
  768. return;
  769. xgene_pmu->ops->start_counters(pmu_dev);
  770. }
  771. static void xgene_perf_pmu_disable(struct pmu *pmu)
  772. {
  773. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(pmu);
  774. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  775. xgene_pmu->ops->stop_counters(pmu_dev);
  776. }
  777. static int xgene_perf_event_init(struct perf_event *event)
  778. {
  779. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  780. struct hw_perf_event *hw = &event->hw;
  781. struct perf_event *sibling;
  782. /* Test the event attr type check for PMU enumeration */
  783. if (event->attr.type != event->pmu->type)
  784. return -ENOENT;
  785. /*
  786. * SOC PMU counters are shared across all cores.
  787. * Therefore, it does not support per-process mode.
  788. * Also, it does not support event sampling mode.
  789. */
  790. if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK)
  791. return -EINVAL;
  792. if (event->cpu < 0)
  793. return -EINVAL;
  794. /*
  795. * Many perf core operations (eg. events rotation) operate on a
  796. * single CPU context. This is obvious for CPU PMUs, where one
  797. * expects the same sets of events being observed on all CPUs,
  798. * but can lead to issues for off-core PMUs, where each
  799. * event could be theoretically assigned to a different CPU. To
  800. * mitigate this, we enforce CPU assignment to one, selected
  801. * processor (the one described in the "cpumask" attribute).
  802. */
  803. event->cpu = cpumask_first(&pmu_dev->parent->cpu);
  804. hw->config = event->attr.config;
  805. /*
  806. * Each bit of the config1 field represents an agent from which the
  807. * request of the event come. The event is counted only if it's caused
  808. * by a request of an agent has the bit cleared.
  809. * By default, the event is counted for all agents.
  810. */
  811. hw->config_base = event->attr.config1;
  812. /*
  813. * We must NOT create groups containing mixed PMUs, although software
  814. * events are acceptable
  815. */
  816. if (event->group_leader->pmu != event->pmu &&
  817. !is_software_event(event->group_leader))
  818. return -EINVAL;
  819. for_each_sibling_event(sibling, event->group_leader) {
  820. if (sibling->pmu != event->pmu &&
  821. !is_software_event(sibling))
  822. return -EINVAL;
  823. }
  824. return 0;
  825. }
  826. static void xgene_perf_enable_event(struct perf_event *event)
  827. {
  828. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  829. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  830. xgene_pmu->ops->write_evttype(pmu_dev, GET_CNTR(event),
  831. GET_EVENTID(event));
  832. xgene_pmu->ops->write_agentmsk(pmu_dev, ~((u32)GET_AGENTID(event)));
  833. if (pmu_dev->inf->type == PMU_TYPE_IOB)
  834. xgene_pmu->ops->write_agent1msk(pmu_dev,
  835. ~((u32)GET_AGENT1ID(event)));
  836. xgene_pmu->ops->enable_counter(pmu_dev, GET_CNTR(event));
  837. xgene_pmu->ops->enable_counter_int(pmu_dev, GET_CNTR(event));
  838. }
  839. static void xgene_perf_disable_event(struct perf_event *event)
  840. {
  841. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  842. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  843. xgene_pmu->ops->disable_counter(pmu_dev, GET_CNTR(event));
  844. xgene_pmu->ops->disable_counter_int(pmu_dev, GET_CNTR(event));
  845. }
  846. static void xgene_perf_event_set_period(struct perf_event *event)
  847. {
  848. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  849. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  850. struct hw_perf_event *hw = &event->hw;
  851. /*
  852. * For 32 bit counter, it has a period of 2^32. To account for the
  853. * possibility of extreme interrupt latency we program for a period of
  854. * half that. Hopefully, we can handle the interrupt before another 2^31
  855. * events occur and the counter overtakes its previous value.
  856. * For 64 bit counter, we don't expect it overflow.
  857. */
  858. u64 val = 1ULL << 31;
  859. local64_set(&hw->prev_count, val);
  860. xgene_pmu->ops->write_counter(pmu_dev, hw->idx, val);
  861. }
  862. static void xgene_perf_event_update(struct perf_event *event)
  863. {
  864. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  865. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  866. struct hw_perf_event *hw = &event->hw;
  867. u64 delta, prev_raw_count, new_raw_count;
  868. again:
  869. prev_raw_count = local64_read(&hw->prev_count);
  870. new_raw_count = xgene_pmu->ops->read_counter(pmu_dev, GET_CNTR(event));
  871. if (local64_cmpxchg(&hw->prev_count, prev_raw_count,
  872. new_raw_count) != prev_raw_count)
  873. goto again;
  874. delta = (new_raw_count - prev_raw_count) & pmu_dev->max_period;
  875. local64_add(delta, &event->count);
  876. }
  877. static void xgene_perf_read(struct perf_event *event)
  878. {
  879. xgene_perf_event_update(event);
  880. }
  881. static void xgene_perf_start(struct perf_event *event, int flags)
  882. {
  883. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  884. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  885. struct hw_perf_event *hw = &event->hw;
  886. if (WARN_ON_ONCE(!(hw->state & PERF_HES_STOPPED)))
  887. return;
  888. WARN_ON_ONCE(!(hw->state & PERF_HES_UPTODATE));
  889. hw->state = 0;
  890. xgene_perf_event_set_period(event);
  891. if (flags & PERF_EF_RELOAD) {
  892. u64 prev_raw_count = local64_read(&hw->prev_count);
  893. xgene_pmu->ops->write_counter(pmu_dev, GET_CNTR(event),
  894. prev_raw_count);
  895. }
  896. xgene_perf_enable_event(event);
  897. perf_event_update_userpage(event);
  898. }
  899. static void xgene_perf_stop(struct perf_event *event, int flags)
  900. {
  901. struct hw_perf_event *hw = &event->hw;
  902. if (hw->state & PERF_HES_UPTODATE)
  903. return;
  904. xgene_perf_disable_event(event);
  905. WARN_ON_ONCE(hw->state & PERF_HES_STOPPED);
  906. hw->state |= PERF_HES_STOPPED;
  907. if (hw->state & PERF_HES_UPTODATE)
  908. return;
  909. xgene_perf_read(event);
  910. hw->state |= PERF_HES_UPTODATE;
  911. }
  912. static int xgene_perf_add(struct perf_event *event, int flags)
  913. {
  914. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  915. struct hw_perf_event *hw = &event->hw;
  916. hw->state = PERF_HES_UPTODATE | PERF_HES_STOPPED;
  917. /* Allocate an event counter */
  918. hw->idx = get_next_avail_cntr(pmu_dev);
  919. if (hw->idx < 0)
  920. return -EAGAIN;
  921. /* Update counter event pointer for Interrupt handler */
  922. pmu_dev->pmu_counter_event[hw->idx] = event;
  923. if (flags & PERF_EF_START)
  924. xgene_perf_start(event, PERF_EF_RELOAD);
  925. return 0;
  926. }
  927. static void xgene_perf_del(struct perf_event *event, int flags)
  928. {
  929. struct xgene_pmu_dev *pmu_dev = to_pmu_dev(event->pmu);
  930. struct hw_perf_event *hw = &event->hw;
  931. xgene_perf_stop(event, PERF_EF_UPDATE);
  932. /* clear the assigned counter */
  933. clear_avail_cntr(pmu_dev, GET_CNTR(event));
  934. perf_event_update_userpage(event);
  935. pmu_dev->pmu_counter_event[hw->idx] = NULL;
  936. }
  937. static int xgene_init_perf(struct xgene_pmu_dev *pmu_dev, char *name)
  938. {
  939. struct xgene_pmu *xgene_pmu;
  940. if (pmu_dev->parent->version == PCP_PMU_V3)
  941. pmu_dev->max_period = PMU_V3_CNT_MAX_PERIOD;
  942. else
  943. pmu_dev->max_period = PMU_CNT_MAX_PERIOD;
  944. /* First version PMU supports only single event counter */
  945. xgene_pmu = pmu_dev->parent;
  946. if (xgene_pmu->version == PCP_PMU_V1)
  947. pmu_dev->max_counters = 1;
  948. else
  949. pmu_dev->max_counters = PMU_MAX_COUNTERS;
  950. /* Perf driver registration */
  951. pmu_dev->pmu = (struct pmu) {
  952. .attr_groups = pmu_dev->attr_groups,
  953. .task_ctx_nr = perf_invalid_context,
  954. .pmu_enable = xgene_perf_pmu_enable,
  955. .pmu_disable = xgene_perf_pmu_disable,
  956. .event_init = xgene_perf_event_init,
  957. .add = xgene_perf_add,
  958. .del = xgene_perf_del,
  959. .start = xgene_perf_start,
  960. .stop = xgene_perf_stop,
  961. .read = xgene_perf_read,
  962. .capabilities = PERF_PMU_CAP_NO_EXCLUDE,
  963. };
  964. /* Hardware counter init */
  965. xgene_pmu->ops->stop_counters(pmu_dev);
  966. xgene_pmu->ops->reset_counters(pmu_dev);
  967. return perf_pmu_register(&pmu_dev->pmu, name, -1);
  968. }
  969. static int
  970. xgene_pmu_dev_add(struct xgene_pmu *xgene_pmu, struct xgene_pmu_dev_ctx *ctx)
  971. {
  972. struct device *dev = xgene_pmu->dev;
  973. struct xgene_pmu_dev *pmu;
  974. pmu = devm_kzalloc(dev, sizeof(*pmu), GFP_KERNEL);
  975. if (!pmu)
  976. return -ENOMEM;
  977. pmu->parent = xgene_pmu;
  978. pmu->inf = &ctx->inf;
  979. ctx->pmu_dev = pmu;
  980. switch (pmu->inf->type) {
  981. case PMU_TYPE_L3C:
  982. if (!(xgene_pmu->l3c_active_mask & pmu->inf->enable_mask))
  983. return -ENODEV;
  984. if (xgene_pmu->version == PCP_PMU_V3)
  985. pmu->attr_groups = l3c_pmu_v3_attr_groups;
  986. else
  987. pmu->attr_groups = l3c_pmu_attr_groups;
  988. break;
  989. case PMU_TYPE_IOB:
  990. if (xgene_pmu->version == PCP_PMU_V3)
  991. pmu->attr_groups = iob_fast_pmu_v3_attr_groups;
  992. else
  993. pmu->attr_groups = iob_pmu_attr_groups;
  994. break;
  995. case PMU_TYPE_IOB_SLOW:
  996. if (xgene_pmu->version == PCP_PMU_V3)
  997. pmu->attr_groups = iob_slow_pmu_v3_attr_groups;
  998. break;
  999. case PMU_TYPE_MCB:
  1000. if (!(xgene_pmu->mcb_active_mask & pmu->inf->enable_mask))
  1001. return -ENODEV;
  1002. if (xgene_pmu->version == PCP_PMU_V3)
  1003. pmu->attr_groups = mcb_pmu_v3_attr_groups;
  1004. else
  1005. pmu->attr_groups = mcb_pmu_attr_groups;
  1006. break;
  1007. case PMU_TYPE_MC:
  1008. if (!(xgene_pmu->mc_active_mask & pmu->inf->enable_mask))
  1009. return -ENODEV;
  1010. if (xgene_pmu->version == PCP_PMU_V3)
  1011. pmu->attr_groups = mc_pmu_v3_attr_groups;
  1012. else
  1013. pmu->attr_groups = mc_pmu_attr_groups;
  1014. break;
  1015. default:
  1016. return -EINVAL;
  1017. }
  1018. if (xgene_init_perf(pmu, ctx->name)) {
  1019. dev_err(dev, "%s PMU: Failed to init perf driver\n", ctx->name);
  1020. return -ENODEV;
  1021. }
  1022. dev_info(dev, "%s PMU registered\n", ctx->name);
  1023. return 0;
  1024. }
  1025. static void _xgene_pmu_isr(int irq, struct xgene_pmu_dev *pmu_dev)
  1026. {
  1027. struct xgene_pmu *xgene_pmu = pmu_dev->parent;
  1028. void __iomem *csr = pmu_dev->inf->csr;
  1029. u32 pmovsr;
  1030. int idx;
  1031. xgene_pmu->ops->stop_counters(pmu_dev);
  1032. if (xgene_pmu->version == PCP_PMU_V3)
  1033. pmovsr = readl(csr + PMU_PMOVSSET) & PMU_OVERFLOW_MASK;
  1034. else
  1035. pmovsr = readl(csr + PMU_PMOVSR) & PMU_OVERFLOW_MASK;
  1036. if (!pmovsr)
  1037. goto out;
  1038. /* Clear interrupt flag */
  1039. if (xgene_pmu->version == PCP_PMU_V1)
  1040. writel(0x0, csr + PMU_PMOVSR);
  1041. else if (xgene_pmu->version == PCP_PMU_V2)
  1042. writel(pmovsr, csr + PMU_PMOVSR);
  1043. else
  1044. writel(pmovsr, csr + PMU_PMOVSCLR);
  1045. for (idx = 0; idx < PMU_MAX_COUNTERS; idx++) {
  1046. struct perf_event *event = pmu_dev->pmu_counter_event[idx];
  1047. int overflowed = pmovsr & BIT(idx);
  1048. /* Ignore if we don't have an event. */
  1049. if (!event || !overflowed)
  1050. continue;
  1051. xgene_perf_event_update(event);
  1052. xgene_perf_event_set_period(event);
  1053. }
  1054. out:
  1055. xgene_pmu->ops->start_counters(pmu_dev);
  1056. }
  1057. static irqreturn_t xgene_pmu_isr(int irq, void *dev_id)
  1058. {
  1059. u32 intr_mcu, intr_mcb, intr_l3c, intr_iob;
  1060. struct xgene_pmu_dev_ctx *ctx;
  1061. struct xgene_pmu *xgene_pmu = dev_id;
  1062. unsigned long flags;
  1063. u32 val;
  1064. raw_spin_lock_irqsave(&xgene_pmu->lock, flags);
  1065. /* Get Interrupt PMU source */
  1066. val = readl(xgene_pmu->pcppmu_csr + PCPPMU_INTSTATUS_REG);
  1067. if (xgene_pmu->version == PCP_PMU_V3) {
  1068. intr_mcu = PCPPMU_V3_INT_MCU;
  1069. intr_mcb = PCPPMU_V3_INT_MCB;
  1070. intr_l3c = PCPPMU_V3_INT_L3C;
  1071. intr_iob = PCPPMU_V3_INT_IOB;
  1072. } else {
  1073. intr_mcu = PCPPMU_INT_MCU;
  1074. intr_mcb = PCPPMU_INT_MCB;
  1075. intr_l3c = PCPPMU_INT_L3C;
  1076. intr_iob = PCPPMU_INT_IOB;
  1077. }
  1078. if (val & intr_mcu) {
  1079. list_for_each_entry(ctx, &xgene_pmu->mcpmus, next) {
  1080. _xgene_pmu_isr(irq, ctx->pmu_dev);
  1081. }
  1082. }
  1083. if (val & intr_mcb) {
  1084. list_for_each_entry(ctx, &xgene_pmu->mcbpmus, next) {
  1085. _xgene_pmu_isr(irq, ctx->pmu_dev);
  1086. }
  1087. }
  1088. if (val & intr_l3c) {
  1089. list_for_each_entry(ctx, &xgene_pmu->l3cpmus, next) {
  1090. _xgene_pmu_isr(irq, ctx->pmu_dev);
  1091. }
  1092. }
  1093. if (val & intr_iob) {
  1094. list_for_each_entry(ctx, &xgene_pmu->iobpmus, next) {
  1095. _xgene_pmu_isr(irq, ctx->pmu_dev);
  1096. }
  1097. }
  1098. raw_spin_unlock_irqrestore(&xgene_pmu->lock, flags);
  1099. return IRQ_HANDLED;
  1100. }
  1101. static int acpi_pmu_probe_active_mcb_mcu_l3c(struct xgene_pmu *xgene_pmu,
  1102. struct platform_device *pdev)
  1103. {
  1104. void __iomem *csw_csr, *mcba_csr, *mcbb_csr;
  1105. struct resource *res;
  1106. unsigned int reg;
  1107. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1108. csw_csr = devm_ioremap_resource(&pdev->dev, res);
  1109. if (IS_ERR(csw_csr)) {
  1110. dev_err(&pdev->dev, "ioremap failed for CSW CSR resource\n");
  1111. return PTR_ERR(csw_csr);
  1112. }
  1113. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  1114. mcba_csr = devm_ioremap_resource(&pdev->dev, res);
  1115. if (IS_ERR(mcba_csr)) {
  1116. dev_err(&pdev->dev, "ioremap failed for MCBA CSR resource\n");
  1117. return PTR_ERR(mcba_csr);
  1118. }
  1119. res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
  1120. mcbb_csr = devm_ioremap_resource(&pdev->dev, res);
  1121. if (IS_ERR(mcbb_csr)) {
  1122. dev_err(&pdev->dev, "ioremap failed for MCBB CSR resource\n");
  1123. return PTR_ERR(mcbb_csr);
  1124. }
  1125. xgene_pmu->l3c_active_mask = 0x1;
  1126. reg = readl(csw_csr + CSW_CSWCR);
  1127. if (reg & CSW_CSWCR_DUALMCB_MASK) {
  1128. /* Dual MCB active */
  1129. xgene_pmu->mcb_active_mask = 0x3;
  1130. /* Probe all active MC(s) */
  1131. reg = readl(mcbb_csr + CSW_CSWCR);
  1132. xgene_pmu->mc_active_mask =
  1133. (reg & MCBADDRMR_DUALMCU_MODE_MASK) ? 0xF : 0x5;
  1134. } else {
  1135. /* Single MCB active */
  1136. xgene_pmu->mcb_active_mask = 0x1;
  1137. /* Probe all active MC(s) */
  1138. reg = readl(mcba_csr + CSW_CSWCR);
  1139. xgene_pmu->mc_active_mask =
  1140. (reg & MCBADDRMR_DUALMCU_MODE_MASK) ? 0x3 : 0x1;
  1141. }
  1142. return 0;
  1143. }
  1144. static int acpi_pmu_v3_probe_active_mcb_mcu_l3c(struct xgene_pmu *xgene_pmu,
  1145. struct platform_device *pdev)
  1146. {
  1147. void __iomem *csw_csr;
  1148. struct resource *res;
  1149. unsigned int reg;
  1150. u32 mcb0routing;
  1151. u32 mcb1routing;
  1152. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1153. csw_csr = devm_ioremap_resource(&pdev->dev, res);
  1154. if (IS_ERR(csw_csr)) {
  1155. dev_err(&pdev->dev, "ioremap failed for CSW CSR resource\n");
  1156. return PTR_ERR(csw_csr);
  1157. }
  1158. reg = readl(csw_csr + CSW_CSWCR);
  1159. mcb0routing = CSW_CSWCR_MCB0_ROUTING(reg);
  1160. mcb1routing = CSW_CSWCR_MCB1_ROUTING(reg);
  1161. if (reg & CSW_CSWCR_DUALMCB_MASK) {
  1162. /* Dual MCB active */
  1163. xgene_pmu->mcb_active_mask = 0x3;
  1164. /* Probe all active L3C(s), maximum is 8 */
  1165. xgene_pmu->l3c_active_mask = 0xFF;
  1166. /* Probe all active MC(s), maximum is 8 */
  1167. if ((mcb0routing == 0x2) && (mcb1routing == 0x2))
  1168. xgene_pmu->mc_active_mask = 0xFF;
  1169. else if ((mcb0routing == 0x1) && (mcb1routing == 0x1))
  1170. xgene_pmu->mc_active_mask = 0x33;
  1171. else
  1172. xgene_pmu->mc_active_mask = 0x11;
  1173. } else {
  1174. /* Single MCB active */
  1175. xgene_pmu->mcb_active_mask = 0x1;
  1176. /* Probe all active L3C(s), maximum is 4 */
  1177. xgene_pmu->l3c_active_mask = 0x0F;
  1178. /* Probe all active MC(s), maximum is 4 */
  1179. if (mcb0routing == 0x2)
  1180. xgene_pmu->mc_active_mask = 0x0F;
  1181. else if (mcb0routing == 0x1)
  1182. xgene_pmu->mc_active_mask = 0x03;
  1183. else
  1184. xgene_pmu->mc_active_mask = 0x01;
  1185. }
  1186. return 0;
  1187. }
  1188. static int fdt_pmu_probe_active_mcb_mcu_l3c(struct xgene_pmu *xgene_pmu,
  1189. struct platform_device *pdev)
  1190. {
  1191. struct regmap *csw_map, *mcba_map, *mcbb_map;
  1192. struct device_node *np = pdev->dev.of_node;
  1193. unsigned int reg;
  1194. csw_map = syscon_regmap_lookup_by_phandle(np, "regmap-csw");
  1195. if (IS_ERR(csw_map)) {
  1196. dev_err(&pdev->dev, "unable to get syscon regmap csw\n");
  1197. return PTR_ERR(csw_map);
  1198. }
  1199. mcba_map = syscon_regmap_lookup_by_phandle(np, "regmap-mcba");
  1200. if (IS_ERR(mcba_map)) {
  1201. dev_err(&pdev->dev, "unable to get syscon regmap mcba\n");
  1202. return PTR_ERR(mcba_map);
  1203. }
  1204. mcbb_map = syscon_regmap_lookup_by_phandle(np, "regmap-mcbb");
  1205. if (IS_ERR(mcbb_map)) {
  1206. dev_err(&pdev->dev, "unable to get syscon regmap mcbb\n");
  1207. return PTR_ERR(mcbb_map);
  1208. }
  1209. xgene_pmu->l3c_active_mask = 0x1;
  1210. if (regmap_read(csw_map, CSW_CSWCR, &reg))
  1211. return -EINVAL;
  1212. if (reg & CSW_CSWCR_DUALMCB_MASK) {
  1213. /* Dual MCB active */
  1214. xgene_pmu->mcb_active_mask = 0x3;
  1215. /* Probe all active MC(s) */
  1216. if (regmap_read(mcbb_map, MCBADDRMR, &reg))
  1217. return 0;
  1218. xgene_pmu->mc_active_mask =
  1219. (reg & MCBADDRMR_DUALMCU_MODE_MASK) ? 0xF : 0x5;
  1220. } else {
  1221. /* Single MCB active */
  1222. xgene_pmu->mcb_active_mask = 0x1;
  1223. /* Probe all active MC(s) */
  1224. if (regmap_read(mcba_map, MCBADDRMR, &reg))
  1225. return 0;
  1226. xgene_pmu->mc_active_mask =
  1227. (reg & MCBADDRMR_DUALMCU_MODE_MASK) ? 0x3 : 0x1;
  1228. }
  1229. return 0;
  1230. }
  1231. static int xgene_pmu_probe_active_mcb_mcu_l3c(struct xgene_pmu *xgene_pmu,
  1232. struct platform_device *pdev)
  1233. {
  1234. if (has_acpi_companion(&pdev->dev)) {
  1235. if (xgene_pmu->version == PCP_PMU_V3)
  1236. return acpi_pmu_v3_probe_active_mcb_mcu_l3c(xgene_pmu,
  1237. pdev);
  1238. else
  1239. return acpi_pmu_probe_active_mcb_mcu_l3c(xgene_pmu,
  1240. pdev);
  1241. }
  1242. return fdt_pmu_probe_active_mcb_mcu_l3c(xgene_pmu, pdev);
  1243. }
  1244. static char *xgene_pmu_dev_name(struct device *dev, u32 type, int id)
  1245. {
  1246. switch (type) {
  1247. case PMU_TYPE_L3C:
  1248. return devm_kasprintf(dev, GFP_KERNEL, "l3c%d", id);
  1249. case PMU_TYPE_IOB:
  1250. return devm_kasprintf(dev, GFP_KERNEL, "iob%d", id);
  1251. case PMU_TYPE_IOB_SLOW:
  1252. return devm_kasprintf(dev, GFP_KERNEL, "iob_slow%d", id);
  1253. case PMU_TYPE_MCB:
  1254. return devm_kasprintf(dev, GFP_KERNEL, "mcb%d", id);
  1255. case PMU_TYPE_MC:
  1256. return devm_kasprintf(dev, GFP_KERNEL, "mc%d", id);
  1257. default:
  1258. return devm_kasprintf(dev, GFP_KERNEL, "unknown");
  1259. }
  1260. }
  1261. #if defined(CONFIG_ACPI)
  1262. static struct
  1263. xgene_pmu_dev_ctx *acpi_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu,
  1264. struct acpi_device *adev, u32 type)
  1265. {
  1266. struct device *dev = xgene_pmu->dev;
  1267. struct list_head resource_list;
  1268. struct xgene_pmu_dev_ctx *ctx;
  1269. const union acpi_object *obj;
  1270. struct hw_pmu_info *inf;
  1271. void __iomem *dev_csr;
  1272. struct resource res;
  1273. struct resource_entry *rentry;
  1274. int enable_bit;
  1275. int rc;
  1276. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1277. if (!ctx)
  1278. return NULL;
  1279. INIT_LIST_HEAD(&resource_list);
  1280. rc = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
  1281. if (rc <= 0) {
  1282. dev_err(dev, "PMU type %d: No resources found\n", type);
  1283. return NULL;
  1284. }
  1285. list_for_each_entry(rentry, &resource_list, node) {
  1286. if (resource_type(rentry->res) == IORESOURCE_MEM) {
  1287. res = *rentry->res;
  1288. rentry = NULL;
  1289. break;
  1290. }
  1291. }
  1292. acpi_dev_free_resource_list(&resource_list);
  1293. if (rentry) {
  1294. dev_err(dev, "PMU type %d: No memory resource found\n", type);
  1295. return NULL;
  1296. }
  1297. dev_csr = devm_ioremap_resource(dev, &res);
  1298. if (IS_ERR(dev_csr)) {
  1299. dev_err(dev, "PMU type %d: Fail to map resource\n", type);
  1300. return NULL;
  1301. }
  1302. /* A PMU device node without enable-bit-index is always enabled */
  1303. rc = acpi_dev_get_property(adev, "enable-bit-index",
  1304. ACPI_TYPE_INTEGER, &obj);
  1305. if (rc < 0)
  1306. enable_bit = 0;
  1307. else
  1308. enable_bit = (int) obj->integer.value;
  1309. ctx->name = xgene_pmu_dev_name(dev, type, enable_bit);
  1310. if (!ctx->name) {
  1311. dev_err(dev, "PMU type %d: Fail to get device name\n", type);
  1312. return NULL;
  1313. }
  1314. inf = &ctx->inf;
  1315. inf->type = type;
  1316. inf->csr = dev_csr;
  1317. inf->enable_mask = 1 << enable_bit;
  1318. return ctx;
  1319. }
  1320. static const struct acpi_device_id xgene_pmu_acpi_type_match[] = {
  1321. {"APMC0D5D", PMU_TYPE_L3C},
  1322. {"APMC0D5E", PMU_TYPE_IOB},
  1323. {"APMC0D5F", PMU_TYPE_MCB},
  1324. {"APMC0D60", PMU_TYPE_MC},
  1325. {"APMC0D84", PMU_TYPE_L3C},
  1326. {"APMC0D85", PMU_TYPE_IOB},
  1327. {"APMC0D86", PMU_TYPE_IOB_SLOW},
  1328. {"APMC0D87", PMU_TYPE_MCB},
  1329. {"APMC0D88", PMU_TYPE_MC},
  1330. {},
  1331. };
  1332. static const struct acpi_device_id *xgene_pmu_acpi_match_type(
  1333. const struct acpi_device_id *ids,
  1334. struct acpi_device *adev)
  1335. {
  1336. const struct acpi_device_id *match_id = NULL;
  1337. const struct acpi_device_id *id;
  1338. for (id = ids; id->id[0] || id->cls; id++) {
  1339. if (!acpi_match_device_ids(adev, id))
  1340. match_id = id;
  1341. else if (match_id)
  1342. break;
  1343. }
  1344. return match_id;
  1345. }
  1346. static acpi_status acpi_pmu_dev_add(acpi_handle handle, u32 level,
  1347. void *data, void **return_value)
  1348. {
  1349. const struct acpi_device_id *acpi_id;
  1350. struct xgene_pmu *xgene_pmu = data;
  1351. struct xgene_pmu_dev_ctx *ctx;
  1352. struct acpi_device *adev;
  1353. if (acpi_bus_get_device(handle, &adev))
  1354. return AE_OK;
  1355. if (acpi_bus_get_status(adev) || !adev->status.present)
  1356. return AE_OK;
  1357. acpi_id = xgene_pmu_acpi_match_type(xgene_pmu_acpi_type_match, adev);
  1358. if (!acpi_id)
  1359. return AE_OK;
  1360. ctx = acpi_get_pmu_hw_inf(xgene_pmu, adev, (u32)acpi_id->driver_data);
  1361. if (!ctx)
  1362. return AE_OK;
  1363. if (xgene_pmu_dev_add(xgene_pmu, ctx)) {
  1364. /* Can't add the PMU device, skip it */
  1365. devm_kfree(xgene_pmu->dev, ctx);
  1366. return AE_OK;
  1367. }
  1368. switch (ctx->inf.type) {
  1369. case PMU_TYPE_L3C:
  1370. list_add(&ctx->next, &xgene_pmu->l3cpmus);
  1371. break;
  1372. case PMU_TYPE_IOB:
  1373. list_add(&ctx->next, &xgene_pmu->iobpmus);
  1374. break;
  1375. case PMU_TYPE_IOB_SLOW:
  1376. list_add(&ctx->next, &xgene_pmu->iobpmus);
  1377. break;
  1378. case PMU_TYPE_MCB:
  1379. list_add(&ctx->next, &xgene_pmu->mcbpmus);
  1380. break;
  1381. case PMU_TYPE_MC:
  1382. list_add(&ctx->next, &xgene_pmu->mcpmus);
  1383. break;
  1384. }
  1385. return AE_OK;
  1386. }
  1387. static int acpi_pmu_probe_pmu_dev(struct xgene_pmu *xgene_pmu,
  1388. struct platform_device *pdev)
  1389. {
  1390. struct device *dev = xgene_pmu->dev;
  1391. acpi_handle handle;
  1392. acpi_status status;
  1393. handle = ACPI_HANDLE(dev);
  1394. if (!handle)
  1395. return -EINVAL;
  1396. status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
  1397. acpi_pmu_dev_add, NULL, xgene_pmu, NULL);
  1398. if (ACPI_FAILURE(status)) {
  1399. dev_err(dev, "failed to probe PMU devices\n");
  1400. return -ENODEV;
  1401. }
  1402. return 0;
  1403. }
  1404. #else
  1405. static int acpi_pmu_probe_pmu_dev(struct xgene_pmu *xgene_pmu,
  1406. struct platform_device *pdev)
  1407. {
  1408. return 0;
  1409. }
  1410. #endif
  1411. static struct
  1412. xgene_pmu_dev_ctx *fdt_get_pmu_hw_inf(struct xgene_pmu *xgene_pmu,
  1413. struct device_node *np, u32 type)
  1414. {
  1415. struct device *dev = xgene_pmu->dev;
  1416. struct xgene_pmu_dev_ctx *ctx;
  1417. struct hw_pmu_info *inf;
  1418. void __iomem *dev_csr;
  1419. struct resource res;
  1420. int enable_bit;
  1421. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  1422. if (!ctx)
  1423. return NULL;
  1424. if (of_address_to_resource(np, 0, &res) < 0) {
  1425. dev_err(dev, "PMU type %d: No resource address found\n", type);
  1426. return NULL;
  1427. }
  1428. dev_csr = devm_ioremap_resource(dev, &res);
  1429. if (IS_ERR(dev_csr)) {
  1430. dev_err(dev, "PMU type %d: Fail to map resource\n", type);
  1431. return NULL;
  1432. }
  1433. /* A PMU device node without enable-bit-index is always enabled */
  1434. if (of_property_read_u32(np, "enable-bit-index", &enable_bit))
  1435. enable_bit = 0;
  1436. ctx->name = xgene_pmu_dev_name(dev, type, enable_bit);
  1437. if (!ctx->name) {
  1438. dev_err(dev, "PMU type %d: Fail to get device name\n", type);
  1439. return NULL;
  1440. }
  1441. inf = &ctx->inf;
  1442. inf->type = type;
  1443. inf->csr = dev_csr;
  1444. inf->enable_mask = 1 << enable_bit;
  1445. return ctx;
  1446. }
  1447. static int fdt_pmu_probe_pmu_dev(struct xgene_pmu *xgene_pmu,
  1448. struct platform_device *pdev)
  1449. {
  1450. struct xgene_pmu_dev_ctx *ctx;
  1451. struct device_node *np;
  1452. for_each_child_of_node(pdev->dev.of_node, np) {
  1453. if (!of_device_is_available(np))
  1454. continue;
  1455. if (of_device_is_compatible(np, "apm,xgene-pmu-l3c"))
  1456. ctx = fdt_get_pmu_hw_inf(xgene_pmu, np, PMU_TYPE_L3C);
  1457. else if (of_device_is_compatible(np, "apm,xgene-pmu-iob"))
  1458. ctx = fdt_get_pmu_hw_inf(xgene_pmu, np, PMU_TYPE_IOB);
  1459. else if (of_device_is_compatible(np, "apm,xgene-pmu-mcb"))
  1460. ctx = fdt_get_pmu_hw_inf(xgene_pmu, np, PMU_TYPE_MCB);
  1461. else if (of_device_is_compatible(np, "apm,xgene-pmu-mc"))
  1462. ctx = fdt_get_pmu_hw_inf(xgene_pmu, np, PMU_TYPE_MC);
  1463. else
  1464. ctx = NULL;
  1465. if (!ctx)
  1466. continue;
  1467. if (xgene_pmu_dev_add(xgene_pmu, ctx)) {
  1468. /* Can't add the PMU device, skip it */
  1469. devm_kfree(xgene_pmu->dev, ctx);
  1470. continue;
  1471. }
  1472. switch (ctx->inf.type) {
  1473. case PMU_TYPE_L3C:
  1474. list_add(&ctx->next, &xgene_pmu->l3cpmus);
  1475. break;
  1476. case PMU_TYPE_IOB:
  1477. list_add(&ctx->next, &xgene_pmu->iobpmus);
  1478. break;
  1479. case PMU_TYPE_IOB_SLOW:
  1480. list_add(&ctx->next, &xgene_pmu->iobpmus);
  1481. break;
  1482. case PMU_TYPE_MCB:
  1483. list_add(&ctx->next, &xgene_pmu->mcbpmus);
  1484. break;
  1485. case PMU_TYPE_MC:
  1486. list_add(&ctx->next, &xgene_pmu->mcpmus);
  1487. break;
  1488. }
  1489. }
  1490. return 0;
  1491. }
  1492. static int xgene_pmu_probe_pmu_dev(struct xgene_pmu *xgene_pmu,
  1493. struct platform_device *pdev)
  1494. {
  1495. if (has_acpi_companion(&pdev->dev))
  1496. return acpi_pmu_probe_pmu_dev(xgene_pmu, pdev);
  1497. return fdt_pmu_probe_pmu_dev(xgene_pmu, pdev);
  1498. }
  1499. static const struct xgene_pmu_data xgene_pmu_data = {
  1500. .id = PCP_PMU_V1,
  1501. };
  1502. static const struct xgene_pmu_data xgene_pmu_v2_data = {
  1503. .id = PCP_PMU_V2,
  1504. };
  1505. static const struct xgene_pmu_ops xgene_pmu_ops = {
  1506. .mask_int = xgene_pmu_mask_int,
  1507. .unmask_int = xgene_pmu_unmask_int,
  1508. .read_counter = xgene_pmu_read_counter32,
  1509. .write_counter = xgene_pmu_write_counter32,
  1510. .write_evttype = xgene_pmu_write_evttype,
  1511. .write_agentmsk = xgene_pmu_write_agentmsk,
  1512. .write_agent1msk = xgene_pmu_write_agent1msk,
  1513. .enable_counter = xgene_pmu_enable_counter,
  1514. .disable_counter = xgene_pmu_disable_counter,
  1515. .enable_counter_int = xgene_pmu_enable_counter_int,
  1516. .disable_counter_int = xgene_pmu_disable_counter_int,
  1517. .reset_counters = xgene_pmu_reset_counters,
  1518. .start_counters = xgene_pmu_start_counters,
  1519. .stop_counters = xgene_pmu_stop_counters,
  1520. };
  1521. static const struct xgene_pmu_ops xgene_pmu_v3_ops = {
  1522. .mask_int = xgene_pmu_v3_mask_int,
  1523. .unmask_int = xgene_pmu_v3_unmask_int,
  1524. .read_counter = xgene_pmu_read_counter64,
  1525. .write_counter = xgene_pmu_write_counter64,
  1526. .write_evttype = xgene_pmu_write_evttype,
  1527. .write_agentmsk = xgene_pmu_v3_write_agentmsk,
  1528. .write_agent1msk = xgene_pmu_v3_write_agent1msk,
  1529. .enable_counter = xgene_pmu_enable_counter,
  1530. .disable_counter = xgene_pmu_disable_counter,
  1531. .enable_counter_int = xgene_pmu_enable_counter_int,
  1532. .disable_counter_int = xgene_pmu_disable_counter_int,
  1533. .reset_counters = xgene_pmu_reset_counters,
  1534. .start_counters = xgene_pmu_start_counters,
  1535. .stop_counters = xgene_pmu_stop_counters,
  1536. };
  1537. static const struct of_device_id xgene_pmu_of_match[] = {
  1538. { .compatible = "apm,xgene-pmu", .data = &xgene_pmu_data },
  1539. { .compatible = "apm,xgene-pmu-v2", .data = &xgene_pmu_v2_data },
  1540. {},
  1541. };
  1542. MODULE_DEVICE_TABLE(of, xgene_pmu_of_match);
  1543. #ifdef CONFIG_ACPI
  1544. static const struct acpi_device_id xgene_pmu_acpi_match[] = {
  1545. {"APMC0D5B", PCP_PMU_V1},
  1546. {"APMC0D5C", PCP_PMU_V2},
  1547. {"APMC0D83", PCP_PMU_V3},
  1548. {},
  1549. };
  1550. MODULE_DEVICE_TABLE(acpi, xgene_pmu_acpi_match);
  1551. #endif
  1552. static int xgene_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
  1553. {
  1554. struct xgene_pmu *xgene_pmu = hlist_entry_safe(node, struct xgene_pmu,
  1555. node);
  1556. if (cpumask_empty(&xgene_pmu->cpu))
  1557. cpumask_set_cpu(cpu, &xgene_pmu->cpu);
  1558. /* Overflow interrupt also should use the same CPU */
  1559. WARN_ON(irq_set_affinity(xgene_pmu->irq, &xgene_pmu->cpu));
  1560. return 0;
  1561. }
  1562. static int xgene_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
  1563. {
  1564. struct xgene_pmu *xgene_pmu = hlist_entry_safe(node, struct xgene_pmu,
  1565. node);
  1566. struct xgene_pmu_dev_ctx *ctx;
  1567. unsigned int target;
  1568. if (!cpumask_test_and_clear_cpu(cpu, &xgene_pmu->cpu))
  1569. return 0;
  1570. target = cpumask_any_but(cpu_online_mask, cpu);
  1571. if (target >= nr_cpu_ids)
  1572. return 0;
  1573. list_for_each_entry(ctx, &xgene_pmu->mcpmus, next) {
  1574. perf_pmu_migrate_context(&ctx->pmu_dev->pmu, cpu, target);
  1575. }
  1576. list_for_each_entry(ctx, &xgene_pmu->mcbpmus, next) {
  1577. perf_pmu_migrate_context(&ctx->pmu_dev->pmu, cpu, target);
  1578. }
  1579. list_for_each_entry(ctx, &xgene_pmu->l3cpmus, next) {
  1580. perf_pmu_migrate_context(&ctx->pmu_dev->pmu, cpu, target);
  1581. }
  1582. list_for_each_entry(ctx, &xgene_pmu->iobpmus, next) {
  1583. perf_pmu_migrate_context(&ctx->pmu_dev->pmu, cpu, target);
  1584. }
  1585. cpumask_set_cpu(target, &xgene_pmu->cpu);
  1586. /* Overflow interrupt also should use the same CPU */
  1587. WARN_ON(irq_set_affinity(xgene_pmu->irq, &xgene_pmu->cpu));
  1588. return 0;
  1589. }
  1590. static int xgene_pmu_probe(struct platform_device *pdev)
  1591. {
  1592. const struct xgene_pmu_data *dev_data;
  1593. const struct of_device_id *of_id;
  1594. struct xgene_pmu *xgene_pmu;
  1595. struct resource *res;
  1596. int irq, rc;
  1597. int version;
  1598. /* Install a hook to update the reader CPU in case it goes offline */
  1599. rc = cpuhp_setup_state_multi(CPUHP_AP_PERF_ARM_APM_XGENE_ONLINE,
  1600. "CPUHP_AP_PERF_ARM_APM_XGENE_ONLINE",
  1601. xgene_pmu_online_cpu,
  1602. xgene_pmu_offline_cpu);
  1603. if (rc)
  1604. return rc;
  1605. xgene_pmu = devm_kzalloc(&pdev->dev, sizeof(*xgene_pmu), GFP_KERNEL);
  1606. if (!xgene_pmu)
  1607. return -ENOMEM;
  1608. xgene_pmu->dev = &pdev->dev;
  1609. platform_set_drvdata(pdev, xgene_pmu);
  1610. version = -EINVAL;
  1611. of_id = of_match_device(xgene_pmu_of_match, &pdev->dev);
  1612. if (of_id) {
  1613. dev_data = (const struct xgene_pmu_data *) of_id->data;
  1614. version = dev_data->id;
  1615. }
  1616. #ifdef CONFIG_ACPI
  1617. if (ACPI_COMPANION(&pdev->dev)) {
  1618. const struct acpi_device_id *acpi_id;
  1619. acpi_id = acpi_match_device(xgene_pmu_acpi_match, &pdev->dev);
  1620. if (acpi_id)
  1621. version = (int) acpi_id->driver_data;
  1622. }
  1623. #endif
  1624. if (version < 0)
  1625. return -ENODEV;
  1626. if (version == PCP_PMU_V3)
  1627. xgene_pmu->ops = &xgene_pmu_v3_ops;
  1628. else
  1629. xgene_pmu->ops = &xgene_pmu_ops;
  1630. INIT_LIST_HEAD(&xgene_pmu->l3cpmus);
  1631. INIT_LIST_HEAD(&xgene_pmu->iobpmus);
  1632. INIT_LIST_HEAD(&xgene_pmu->mcbpmus);
  1633. INIT_LIST_HEAD(&xgene_pmu->mcpmus);
  1634. xgene_pmu->version = version;
  1635. dev_info(&pdev->dev, "X-Gene PMU version %d\n", xgene_pmu->version);
  1636. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1637. xgene_pmu->pcppmu_csr = devm_ioremap_resource(&pdev->dev, res);
  1638. if (IS_ERR(xgene_pmu->pcppmu_csr)) {
  1639. dev_err(&pdev->dev, "ioremap failed for PCP PMU resource\n");
  1640. return PTR_ERR(xgene_pmu->pcppmu_csr);
  1641. }
  1642. irq = platform_get_irq(pdev, 0);
  1643. if (irq < 0)
  1644. return -EINVAL;
  1645. rc = devm_request_irq(&pdev->dev, irq, xgene_pmu_isr,
  1646. IRQF_NOBALANCING | IRQF_NO_THREAD,
  1647. dev_name(&pdev->dev), xgene_pmu);
  1648. if (rc) {
  1649. dev_err(&pdev->dev, "Could not request IRQ %d\n", irq);
  1650. return rc;
  1651. }
  1652. xgene_pmu->irq = irq;
  1653. raw_spin_lock_init(&xgene_pmu->lock);
  1654. /* Check for active MCBs and MCUs */
  1655. rc = xgene_pmu_probe_active_mcb_mcu_l3c(xgene_pmu, pdev);
  1656. if (rc) {
  1657. dev_warn(&pdev->dev, "Unknown MCB/MCU active status\n");
  1658. xgene_pmu->mcb_active_mask = 0x1;
  1659. xgene_pmu->mc_active_mask = 0x1;
  1660. }
  1661. /* Add this instance to the list used by the hotplug callback */
  1662. rc = cpuhp_state_add_instance(CPUHP_AP_PERF_ARM_APM_XGENE_ONLINE,
  1663. &xgene_pmu->node);
  1664. if (rc) {
  1665. dev_err(&pdev->dev, "Error %d registering hotplug", rc);
  1666. return rc;
  1667. }
  1668. /* Walk through the tree for all PMU perf devices */
  1669. rc = xgene_pmu_probe_pmu_dev(xgene_pmu, pdev);
  1670. if (rc) {
  1671. dev_err(&pdev->dev, "No PMU perf devices found!\n");
  1672. goto out_unregister;
  1673. }
  1674. /* Enable interrupt */
  1675. xgene_pmu->ops->unmask_int(xgene_pmu);
  1676. return 0;
  1677. out_unregister:
  1678. cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_APM_XGENE_ONLINE,
  1679. &xgene_pmu->node);
  1680. return rc;
  1681. }
  1682. static void
  1683. xgene_pmu_dev_cleanup(struct xgene_pmu *xgene_pmu, struct list_head *pmus)
  1684. {
  1685. struct xgene_pmu_dev_ctx *ctx;
  1686. list_for_each_entry(ctx, pmus, next) {
  1687. perf_pmu_unregister(&ctx->pmu_dev->pmu);
  1688. }
  1689. }
  1690. static int xgene_pmu_remove(struct platform_device *pdev)
  1691. {
  1692. struct xgene_pmu *xgene_pmu = dev_get_drvdata(&pdev->dev);
  1693. xgene_pmu_dev_cleanup(xgene_pmu, &xgene_pmu->l3cpmus);
  1694. xgene_pmu_dev_cleanup(xgene_pmu, &xgene_pmu->iobpmus);
  1695. xgene_pmu_dev_cleanup(xgene_pmu, &xgene_pmu->mcbpmus);
  1696. xgene_pmu_dev_cleanup(xgene_pmu, &xgene_pmu->mcpmus);
  1697. cpuhp_state_remove_instance(CPUHP_AP_PERF_ARM_APM_XGENE_ONLINE,
  1698. &xgene_pmu->node);
  1699. return 0;
  1700. }
  1701. static struct platform_driver xgene_pmu_driver = {
  1702. .probe = xgene_pmu_probe,
  1703. .remove = xgene_pmu_remove,
  1704. .driver = {
  1705. .name = "xgene-pmu",
  1706. .of_match_table = xgene_pmu_of_match,
  1707. .acpi_match_table = ACPI_PTR(xgene_pmu_acpi_match),
  1708. .suppress_bind_attrs = true,
  1709. },
  1710. };
  1711. builtin_platform_driver(xgene_pmu_driver);