xgene_pmu.c 56 KB

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