irq-gic-v3-its.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  1. /*
  2. * Copyright (C) 2013, 2014 ARM Limited, All Rights Reserved.
  3. * Author: Marc Zyngier <marc.zyngier@arm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <linux/acpi.h>
  18. #include <linux/bitmap.h>
  19. #include <linux/cpu.h>
  20. #include <linux/delay.h>
  21. #include <linux/dma-iommu.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irqdomain.h>
  24. #include <linux/acpi_iort.h>
  25. #include <linux/log2.h>
  26. #include <linux/mm.h>
  27. #include <linux/msi.h>
  28. #include <linux/of.h>
  29. #include <linux/of_address.h>
  30. #include <linux/of_irq.h>
  31. #include <linux/of_pci.h>
  32. #include <linux/of_platform.h>
  33. #include <linux/percpu.h>
  34. #include <linux/slab.h>
  35. #include <linux/irqchip.h>
  36. #include <linux/irqchip/arm-gic-v3.h>
  37. #include <asm/cputype.h>
  38. #include <asm/exception.h>
  39. #include "irq-gic-common.h"
  40. #define ITS_FLAGS_CMDQ_NEEDS_FLUSHING (1ULL << 0)
  41. #define ITS_FLAGS_WORKAROUND_CAVIUM_22375 (1ULL << 1)
  42. #define ITS_FLAGS_WORKAROUND_CAVIUM_23144 (1ULL << 2)
  43. #define RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING (1 << 0)
  44. /*
  45. * Collection structure - just an ID, and a redistributor address to
  46. * ping. We use one per CPU as a bag of interrupts assigned to this
  47. * CPU.
  48. */
  49. struct its_collection {
  50. u64 target_address;
  51. u16 col_id;
  52. };
  53. /*
  54. * The ITS_BASER structure - contains memory information, cached
  55. * value of BASER register configuration and ITS page size.
  56. */
  57. struct its_baser {
  58. void *base;
  59. u64 val;
  60. u32 order;
  61. u32 psz;
  62. };
  63. /*
  64. * The ITS structure - contains most of the infrastructure, with the
  65. * top-level MSI domain, the command queue, the collections, and the
  66. * list of devices writing to it.
  67. */
  68. struct its_node {
  69. raw_spinlock_t lock;
  70. struct list_head entry;
  71. void __iomem *base;
  72. phys_addr_t phys_base;
  73. struct its_cmd_block *cmd_base;
  74. struct its_cmd_block *cmd_write;
  75. struct its_baser tables[GITS_BASER_NR_REGS];
  76. struct its_collection *collections;
  77. struct list_head its_device_list;
  78. u64 flags;
  79. u32 ite_size;
  80. u32 device_ids;
  81. int numa_node;
  82. };
  83. #define ITS_ITT_ALIGN SZ_256
  84. /* Convert page order to size in bytes */
  85. #define PAGE_ORDER_TO_SIZE(o) (PAGE_SIZE << (o))
  86. struct event_lpi_map {
  87. unsigned long *lpi_map;
  88. u16 *col_map;
  89. irq_hw_number_t lpi_base;
  90. int nr_lpis;
  91. };
  92. /*
  93. * The ITS view of a device - belongs to an ITS, a collection, owns an
  94. * interrupt translation table, and a list of interrupts.
  95. */
  96. struct its_device {
  97. struct list_head entry;
  98. struct its_node *its;
  99. struct event_lpi_map event_map;
  100. void *itt;
  101. u32 nr_ites;
  102. u32 device_id;
  103. };
  104. static LIST_HEAD(its_nodes);
  105. static DEFINE_SPINLOCK(its_lock);
  106. static struct rdists *gic_rdists;
  107. static struct irq_domain *its_parent;
  108. #define gic_data_rdist() (raw_cpu_ptr(gic_rdists->rdist))
  109. #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base)
  110. static struct its_collection *dev_event_to_col(struct its_device *its_dev,
  111. u32 event)
  112. {
  113. struct its_node *its = its_dev->its;
  114. return its->collections + its_dev->event_map.col_map[event];
  115. }
  116. /*
  117. * ITS command descriptors - parameters to be encoded in a command
  118. * block.
  119. */
  120. struct its_cmd_desc {
  121. union {
  122. struct {
  123. struct its_device *dev;
  124. u32 event_id;
  125. } its_inv_cmd;
  126. struct {
  127. struct its_device *dev;
  128. u32 event_id;
  129. } its_int_cmd;
  130. struct {
  131. struct its_device *dev;
  132. int valid;
  133. } its_mapd_cmd;
  134. struct {
  135. struct its_collection *col;
  136. int valid;
  137. } its_mapc_cmd;
  138. struct {
  139. struct its_device *dev;
  140. u32 phys_id;
  141. u32 event_id;
  142. } its_mapvi_cmd;
  143. struct {
  144. struct its_device *dev;
  145. struct its_collection *col;
  146. u32 event_id;
  147. } its_movi_cmd;
  148. struct {
  149. struct its_device *dev;
  150. u32 event_id;
  151. } its_discard_cmd;
  152. struct {
  153. struct its_collection *col;
  154. } its_invall_cmd;
  155. };
  156. };
  157. /*
  158. * The ITS command block, which is what the ITS actually parses.
  159. */
  160. struct its_cmd_block {
  161. u64 raw_cmd[4];
  162. };
  163. #define ITS_CMD_QUEUE_SZ SZ_64K
  164. #define ITS_CMD_QUEUE_NR_ENTRIES (ITS_CMD_QUEUE_SZ / sizeof(struct its_cmd_block))
  165. typedef struct its_collection *(*its_cmd_builder_t)(struct its_cmd_block *,
  166. struct its_cmd_desc *);
  167. static void its_encode_cmd(struct its_cmd_block *cmd, u8 cmd_nr)
  168. {
  169. cmd->raw_cmd[0] &= ~0xffULL;
  170. cmd->raw_cmd[0] |= cmd_nr;
  171. }
  172. static void its_encode_devid(struct its_cmd_block *cmd, u32 devid)
  173. {
  174. cmd->raw_cmd[0] &= BIT_ULL(32) - 1;
  175. cmd->raw_cmd[0] |= ((u64)devid) << 32;
  176. }
  177. static void its_encode_event_id(struct its_cmd_block *cmd, u32 id)
  178. {
  179. cmd->raw_cmd[1] &= ~0xffffffffULL;
  180. cmd->raw_cmd[1] |= id;
  181. }
  182. static void its_encode_phys_id(struct its_cmd_block *cmd, u32 phys_id)
  183. {
  184. cmd->raw_cmd[1] &= 0xffffffffULL;
  185. cmd->raw_cmd[1] |= ((u64)phys_id) << 32;
  186. }
  187. static void its_encode_size(struct its_cmd_block *cmd, u8 size)
  188. {
  189. cmd->raw_cmd[1] &= ~0x1fULL;
  190. cmd->raw_cmd[1] |= size & 0x1f;
  191. }
  192. static void its_encode_itt(struct its_cmd_block *cmd, u64 itt_addr)
  193. {
  194. cmd->raw_cmd[2] &= ~0xffffffffffffULL;
  195. cmd->raw_cmd[2] |= itt_addr & 0xffffffffff00ULL;
  196. }
  197. static void its_encode_valid(struct its_cmd_block *cmd, int valid)
  198. {
  199. cmd->raw_cmd[2] &= ~(1ULL << 63);
  200. cmd->raw_cmd[2] |= ((u64)!!valid) << 63;
  201. }
  202. static void its_encode_target(struct its_cmd_block *cmd, u64 target_addr)
  203. {
  204. cmd->raw_cmd[2] &= ~(0xffffffffULL << 16);
  205. cmd->raw_cmd[2] |= (target_addr & (0xffffffffULL << 16));
  206. }
  207. static void its_encode_collection(struct its_cmd_block *cmd, u16 col)
  208. {
  209. cmd->raw_cmd[2] &= ~0xffffULL;
  210. cmd->raw_cmd[2] |= col;
  211. }
  212. static inline void its_fixup_cmd(struct its_cmd_block *cmd)
  213. {
  214. /* Let's fixup BE commands */
  215. cmd->raw_cmd[0] = cpu_to_le64(cmd->raw_cmd[0]);
  216. cmd->raw_cmd[1] = cpu_to_le64(cmd->raw_cmd[1]);
  217. cmd->raw_cmd[2] = cpu_to_le64(cmd->raw_cmd[2]);
  218. cmd->raw_cmd[3] = cpu_to_le64(cmd->raw_cmd[3]);
  219. }
  220. static struct its_collection *its_build_mapd_cmd(struct its_cmd_block *cmd,
  221. struct its_cmd_desc *desc)
  222. {
  223. unsigned long itt_addr;
  224. u8 size = ilog2(desc->its_mapd_cmd.dev->nr_ites);
  225. itt_addr = virt_to_phys(desc->its_mapd_cmd.dev->itt);
  226. itt_addr = ALIGN(itt_addr, ITS_ITT_ALIGN);
  227. its_encode_cmd(cmd, GITS_CMD_MAPD);
  228. its_encode_devid(cmd, desc->its_mapd_cmd.dev->device_id);
  229. its_encode_size(cmd, size - 1);
  230. its_encode_itt(cmd, itt_addr);
  231. its_encode_valid(cmd, desc->its_mapd_cmd.valid);
  232. its_fixup_cmd(cmd);
  233. return NULL;
  234. }
  235. static struct its_collection *its_build_mapc_cmd(struct its_cmd_block *cmd,
  236. struct its_cmd_desc *desc)
  237. {
  238. its_encode_cmd(cmd, GITS_CMD_MAPC);
  239. its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id);
  240. its_encode_target(cmd, desc->its_mapc_cmd.col->target_address);
  241. its_encode_valid(cmd, desc->its_mapc_cmd.valid);
  242. its_fixup_cmd(cmd);
  243. return desc->its_mapc_cmd.col;
  244. }
  245. static struct its_collection *its_build_mapvi_cmd(struct its_cmd_block *cmd,
  246. struct its_cmd_desc *desc)
  247. {
  248. struct its_collection *col;
  249. col = dev_event_to_col(desc->its_mapvi_cmd.dev,
  250. desc->its_mapvi_cmd.event_id);
  251. its_encode_cmd(cmd, GITS_CMD_MAPVI);
  252. its_encode_devid(cmd, desc->its_mapvi_cmd.dev->device_id);
  253. its_encode_event_id(cmd, desc->its_mapvi_cmd.event_id);
  254. its_encode_phys_id(cmd, desc->its_mapvi_cmd.phys_id);
  255. its_encode_collection(cmd, col->col_id);
  256. its_fixup_cmd(cmd);
  257. return col;
  258. }
  259. static struct its_collection *its_build_movi_cmd(struct its_cmd_block *cmd,
  260. struct its_cmd_desc *desc)
  261. {
  262. struct its_collection *col;
  263. col = dev_event_to_col(desc->its_movi_cmd.dev,
  264. desc->its_movi_cmd.event_id);
  265. its_encode_cmd(cmd, GITS_CMD_MOVI);
  266. its_encode_devid(cmd, desc->its_movi_cmd.dev->device_id);
  267. its_encode_event_id(cmd, desc->its_movi_cmd.event_id);
  268. its_encode_collection(cmd, desc->its_movi_cmd.col->col_id);
  269. its_fixup_cmd(cmd);
  270. return col;
  271. }
  272. static struct its_collection *its_build_discard_cmd(struct its_cmd_block *cmd,
  273. struct its_cmd_desc *desc)
  274. {
  275. struct its_collection *col;
  276. col = dev_event_to_col(desc->its_discard_cmd.dev,
  277. desc->its_discard_cmd.event_id);
  278. its_encode_cmd(cmd, GITS_CMD_DISCARD);
  279. its_encode_devid(cmd, desc->its_discard_cmd.dev->device_id);
  280. its_encode_event_id(cmd, desc->its_discard_cmd.event_id);
  281. its_fixup_cmd(cmd);
  282. return col;
  283. }
  284. static struct its_collection *its_build_inv_cmd(struct its_cmd_block *cmd,
  285. struct its_cmd_desc *desc)
  286. {
  287. struct its_collection *col;
  288. col = dev_event_to_col(desc->its_inv_cmd.dev,
  289. desc->its_inv_cmd.event_id);
  290. its_encode_cmd(cmd, GITS_CMD_INV);
  291. its_encode_devid(cmd, desc->its_inv_cmd.dev->device_id);
  292. its_encode_event_id(cmd, desc->its_inv_cmd.event_id);
  293. its_fixup_cmd(cmd);
  294. return col;
  295. }
  296. static struct its_collection *its_build_invall_cmd(struct its_cmd_block *cmd,
  297. struct its_cmd_desc *desc)
  298. {
  299. its_encode_cmd(cmd, GITS_CMD_INVALL);
  300. its_encode_collection(cmd, desc->its_mapc_cmd.col->col_id);
  301. its_fixup_cmd(cmd);
  302. return NULL;
  303. }
  304. static u64 its_cmd_ptr_to_offset(struct its_node *its,
  305. struct its_cmd_block *ptr)
  306. {
  307. return (ptr - its->cmd_base) * sizeof(*ptr);
  308. }
  309. static int its_queue_full(struct its_node *its)
  310. {
  311. int widx;
  312. int ridx;
  313. widx = its->cmd_write - its->cmd_base;
  314. ridx = readl_relaxed(its->base + GITS_CREADR) / sizeof(struct its_cmd_block);
  315. /* This is incredibly unlikely to happen, unless the ITS locks up. */
  316. if (((widx + 1) % ITS_CMD_QUEUE_NR_ENTRIES) == ridx)
  317. return 1;
  318. return 0;
  319. }
  320. static struct its_cmd_block *its_allocate_entry(struct its_node *its)
  321. {
  322. struct its_cmd_block *cmd;
  323. u32 count = 1000000; /* 1s! */
  324. while (its_queue_full(its)) {
  325. count--;
  326. if (!count) {
  327. pr_err_ratelimited("ITS queue not draining\n");
  328. return NULL;
  329. }
  330. cpu_relax();
  331. udelay(1);
  332. }
  333. cmd = its->cmd_write++;
  334. /* Handle queue wrapping */
  335. if (its->cmd_write == (its->cmd_base + ITS_CMD_QUEUE_NR_ENTRIES))
  336. its->cmd_write = its->cmd_base;
  337. return cmd;
  338. }
  339. static struct its_cmd_block *its_post_commands(struct its_node *its)
  340. {
  341. u64 wr = its_cmd_ptr_to_offset(its, its->cmd_write);
  342. writel_relaxed(wr, its->base + GITS_CWRITER);
  343. return its->cmd_write;
  344. }
  345. static void its_flush_cmd(struct its_node *its, struct its_cmd_block *cmd)
  346. {
  347. /*
  348. * Make sure the commands written to memory are observable by
  349. * the ITS.
  350. */
  351. if (its->flags & ITS_FLAGS_CMDQ_NEEDS_FLUSHING)
  352. gic_flush_dcache_to_poc(cmd, sizeof(*cmd));
  353. else
  354. dsb(ishst);
  355. }
  356. static void its_wait_for_range_completion(struct its_node *its,
  357. struct its_cmd_block *from,
  358. struct its_cmd_block *to)
  359. {
  360. u64 rd_idx, from_idx, to_idx;
  361. u32 count = 1000000; /* 1s! */
  362. from_idx = its_cmd_ptr_to_offset(its, from);
  363. to_idx = its_cmd_ptr_to_offset(its, to);
  364. while (1) {
  365. rd_idx = readl_relaxed(its->base + GITS_CREADR);
  366. if (rd_idx >= to_idx || rd_idx < from_idx)
  367. break;
  368. count--;
  369. if (!count) {
  370. pr_err_ratelimited("ITS queue timeout\n");
  371. return;
  372. }
  373. cpu_relax();
  374. udelay(1);
  375. }
  376. }
  377. static void its_send_single_command(struct its_node *its,
  378. its_cmd_builder_t builder,
  379. struct its_cmd_desc *desc)
  380. {
  381. struct its_cmd_block *cmd, *sync_cmd, *next_cmd;
  382. struct its_collection *sync_col;
  383. unsigned long flags;
  384. raw_spin_lock_irqsave(&its->lock, flags);
  385. cmd = its_allocate_entry(its);
  386. if (!cmd) { /* We're soooooo screewed... */
  387. pr_err_ratelimited("ITS can't allocate, dropping command\n");
  388. raw_spin_unlock_irqrestore(&its->lock, flags);
  389. return;
  390. }
  391. sync_col = builder(cmd, desc);
  392. its_flush_cmd(its, cmd);
  393. if (sync_col) {
  394. sync_cmd = its_allocate_entry(its);
  395. if (!sync_cmd) {
  396. pr_err_ratelimited("ITS can't SYNC, skipping\n");
  397. goto post;
  398. }
  399. its_encode_cmd(sync_cmd, GITS_CMD_SYNC);
  400. its_encode_target(sync_cmd, sync_col->target_address);
  401. its_fixup_cmd(sync_cmd);
  402. its_flush_cmd(its, sync_cmd);
  403. }
  404. post:
  405. next_cmd = its_post_commands(its);
  406. raw_spin_unlock_irqrestore(&its->lock, flags);
  407. its_wait_for_range_completion(its, cmd, next_cmd);
  408. }
  409. static void its_send_inv(struct its_device *dev, u32 event_id)
  410. {
  411. struct its_cmd_desc desc;
  412. desc.its_inv_cmd.dev = dev;
  413. desc.its_inv_cmd.event_id = event_id;
  414. its_send_single_command(dev->its, its_build_inv_cmd, &desc);
  415. }
  416. static void its_send_mapd(struct its_device *dev, int valid)
  417. {
  418. struct its_cmd_desc desc;
  419. desc.its_mapd_cmd.dev = dev;
  420. desc.its_mapd_cmd.valid = !!valid;
  421. its_send_single_command(dev->its, its_build_mapd_cmd, &desc);
  422. }
  423. static void its_send_mapc(struct its_node *its, struct its_collection *col,
  424. int valid)
  425. {
  426. struct its_cmd_desc desc;
  427. desc.its_mapc_cmd.col = col;
  428. desc.its_mapc_cmd.valid = !!valid;
  429. its_send_single_command(its, its_build_mapc_cmd, &desc);
  430. }
  431. static void its_send_mapvi(struct its_device *dev, u32 irq_id, u32 id)
  432. {
  433. struct its_cmd_desc desc;
  434. desc.its_mapvi_cmd.dev = dev;
  435. desc.its_mapvi_cmd.phys_id = irq_id;
  436. desc.its_mapvi_cmd.event_id = id;
  437. its_send_single_command(dev->its, its_build_mapvi_cmd, &desc);
  438. }
  439. static void its_send_movi(struct its_device *dev,
  440. struct its_collection *col, u32 id)
  441. {
  442. struct its_cmd_desc desc;
  443. desc.its_movi_cmd.dev = dev;
  444. desc.its_movi_cmd.col = col;
  445. desc.its_movi_cmd.event_id = id;
  446. its_send_single_command(dev->its, its_build_movi_cmd, &desc);
  447. }
  448. static void its_send_discard(struct its_device *dev, u32 id)
  449. {
  450. struct its_cmd_desc desc;
  451. desc.its_discard_cmd.dev = dev;
  452. desc.its_discard_cmd.event_id = id;
  453. its_send_single_command(dev->its, its_build_discard_cmd, &desc);
  454. }
  455. static void its_send_invall(struct its_node *its, struct its_collection *col)
  456. {
  457. struct its_cmd_desc desc;
  458. desc.its_invall_cmd.col = col;
  459. its_send_single_command(its, its_build_invall_cmd, &desc);
  460. }
  461. /*
  462. * irqchip functions - assumes MSI, mostly.
  463. */
  464. static inline u32 its_get_event_id(struct irq_data *d)
  465. {
  466. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  467. return d->hwirq - its_dev->event_map.lpi_base;
  468. }
  469. static void lpi_set_config(struct irq_data *d, bool enable)
  470. {
  471. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  472. irq_hw_number_t hwirq = d->hwirq;
  473. u32 id = its_get_event_id(d);
  474. u8 *cfg = page_address(gic_rdists->prop_page) + hwirq - 8192;
  475. if (enable)
  476. *cfg |= LPI_PROP_ENABLED;
  477. else
  478. *cfg &= ~LPI_PROP_ENABLED;
  479. /*
  480. * Make the above write visible to the redistributors.
  481. * And yes, we're flushing exactly: One. Single. Byte.
  482. * Humpf...
  483. */
  484. if (gic_rdists->flags & RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING)
  485. gic_flush_dcache_to_poc(cfg, sizeof(*cfg));
  486. else
  487. dsb(ishst);
  488. its_send_inv(its_dev, id);
  489. }
  490. static void its_mask_irq(struct irq_data *d)
  491. {
  492. lpi_set_config(d, false);
  493. }
  494. static void its_unmask_irq(struct irq_data *d)
  495. {
  496. lpi_set_config(d, true);
  497. }
  498. static int its_set_affinity(struct irq_data *d, const struct cpumask *mask_val,
  499. bool force)
  500. {
  501. unsigned int cpu;
  502. const struct cpumask *cpu_mask = cpu_online_mask;
  503. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  504. struct its_collection *target_col;
  505. u32 id = its_get_event_id(d);
  506. /* lpi cannot be routed to a redistributor that is on a foreign node */
  507. if (its_dev->its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {
  508. if (its_dev->its->numa_node >= 0) {
  509. cpu_mask = cpumask_of_node(its_dev->its->numa_node);
  510. if (!cpumask_intersects(mask_val, cpu_mask))
  511. return -EINVAL;
  512. }
  513. }
  514. cpu = cpumask_any_and(mask_val, cpu_mask);
  515. if (cpu >= nr_cpu_ids)
  516. return -EINVAL;
  517. target_col = &its_dev->its->collections[cpu];
  518. its_send_movi(its_dev, target_col, id);
  519. its_dev->event_map.col_map[id] = cpu;
  520. return IRQ_SET_MASK_OK_DONE;
  521. }
  522. static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg)
  523. {
  524. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  525. struct its_node *its;
  526. u64 addr;
  527. its = its_dev->its;
  528. addr = its->phys_base + GITS_TRANSLATER;
  529. msg->address_lo = lower_32_bits(addr);
  530. msg->address_hi = upper_32_bits(addr);
  531. msg->data = its_get_event_id(d);
  532. iommu_dma_map_msi_msg(d->irq, msg);
  533. }
  534. static struct irq_chip its_irq_chip = {
  535. .name = "ITS",
  536. .irq_mask = its_mask_irq,
  537. .irq_unmask = its_unmask_irq,
  538. .irq_eoi = irq_chip_eoi_parent,
  539. .irq_set_affinity = its_set_affinity,
  540. .irq_compose_msi_msg = its_irq_compose_msi_msg,
  541. };
  542. /*
  543. * How we allocate LPIs:
  544. *
  545. * The GIC has id_bits bits for interrupt identifiers. From there, we
  546. * must subtract 8192 which are reserved for SGIs/PPIs/SPIs. Then, as
  547. * we allocate LPIs by chunks of 32, we can shift the whole thing by 5
  548. * bits to the right.
  549. *
  550. * This gives us (((1UL << id_bits) - 8192) >> 5) possible allocations.
  551. */
  552. #define IRQS_PER_CHUNK_SHIFT 5
  553. #define IRQS_PER_CHUNK (1 << IRQS_PER_CHUNK_SHIFT)
  554. static unsigned long *lpi_bitmap;
  555. static u32 lpi_chunks;
  556. static DEFINE_SPINLOCK(lpi_lock);
  557. static int its_lpi_to_chunk(int lpi)
  558. {
  559. return (lpi - 8192) >> IRQS_PER_CHUNK_SHIFT;
  560. }
  561. static int its_chunk_to_lpi(int chunk)
  562. {
  563. return (chunk << IRQS_PER_CHUNK_SHIFT) + 8192;
  564. }
  565. static int __init its_lpi_init(u32 id_bits)
  566. {
  567. lpi_chunks = its_lpi_to_chunk(1UL << id_bits);
  568. lpi_bitmap = kzalloc(BITS_TO_LONGS(lpi_chunks) * sizeof(long),
  569. GFP_KERNEL);
  570. if (!lpi_bitmap) {
  571. lpi_chunks = 0;
  572. return -ENOMEM;
  573. }
  574. pr_info("ITS: Allocated %d chunks for LPIs\n", (int)lpi_chunks);
  575. return 0;
  576. }
  577. static unsigned long *its_lpi_alloc_chunks(int nr_irqs, int *base, int *nr_ids)
  578. {
  579. unsigned long *bitmap = NULL;
  580. int chunk_id;
  581. int nr_chunks;
  582. int i;
  583. nr_chunks = DIV_ROUND_UP(nr_irqs, IRQS_PER_CHUNK);
  584. spin_lock(&lpi_lock);
  585. do {
  586. chunk_id = bitmap_find_next_zero_area(lpi_bitmap, lpi_chunks,
  587. 0, nr_chunks, 0);
  588. if (chunk_id < lpi_chunks)
  589. break;
  590. nr_chunks--;
  591. } while (nr_chunks > 0);
  592. if (!nr_chunks)
  593. goto out;
  594. bitmap = kzalloc(BITS_TO_LONGS(nr_chunks * IRQS_PER_CHUNK) * sizeof (long),
  595. GFP_ATOMIC);
  596. if (!bitmap)
  597. goto out;
  598. for (i = 0; i < nr_chunks; i++)
  599. set_bit(chunk_id + i, lpi_bitmap);
  600. *base = its_chunk_to_lpi(chunk_id);
  601. *nr_ids = nr_chunks * IRQS_PER_CHUNK;
  602. out:
  603. spin_unlock(&lpi_lock);
  604. if (!bitmap)
  605. *base = *nr_ids = 0;
  606. return bitmap;
  607. }
  608. static void its_lpi_free(struct event_lpi_map *map)
  609. {
  610. int base = map->lpi_base;
  611. int nr_ids = map->nr_lpis;
  612. int lpi;
  613. spin_lock(&lpi_lock);
  614. for (lpi = base; lpi < (base + nr_ids); lpi += IRQS_PER_CHUNK) {
  615. int chunk = its_lpi_to_chunk(lpi);
  616. BUG_ON(chunk > lpi_chunks);
  617. if (test_bit(chunk, lpi_bitmap)) {
  618. clear_bit(chunk, lpi_bitmap);
  619. } else {
  620. pr_err("Bad LPI chunk %d\n", chunk);
  621. }
  622. }
  623. spin_unlock(&lpi_lock);
  624. kfree(map->lpi_map);
  625. kfree(map->col_map);
  626. }
  627. /*
  628. * We allocate 64kB for PROPBASE. That gives us at most 64K LPIs to
  629. * deal with (one configuration byte per interrupt). PENDBASE has to
  630. * be 64kB aligned (one bit per LPI, plus 8192 bits for SPI/PPI/SGI).
  631. */
  632. #define LPI_PROPBASE_SZ SZ_64K
  633. #define LPI_PENDBASE_SZ (LPI_PROPBASE_SZ / 8 + SZ_1K)
  634. /*
  635. * This is how many bits of ID we need, including the useless ones.
  636. */
  637. #define LPI_NRBITS ilog2(LPI_PROPBASE_SZ + SZ_8K)
  638. #define LPI_PROP_DEFAULT_PRIO 0xa0
  639. static int __init its_alloc_lpi_tables(void)
  640. {
  641. phys_addr_t paddr;
  642. gic_rdists->prop_page = alloc_pages(GFP_NOWAIT,
  643. get_order(LPI_PROPBASE_SZ));
  644. if (!gic_rdists->prop_page) {
  645. pr_err("Failed to allocate PROPBASE\n");
  646. return -ENOMEM;
  647. }
  648. paddr = page_to_phys(gic_rdists->prop_page);
  649. pr_info("GIC: using LPI property table @%pa\n", &paddr);
  650. /* Priority 0xa0, Group-1, disabled */
  651. memset(page_address(gic_rdists->prop_page),
  652. LPI_PROP_DEFAULT_PRIO | LPI_PROP_GROUP1,
  653. LPI_PROPBASE_SZ);
  654. /* Make sure the GIC will observe the written configuration */
  655. gic_flush_dcache_to_poc(page_address(gic_rdists->prop_page), LPI_PROPBASE_SZ);
  656. return 0;
  657. }
  658. static const char *its_base_type_string[] = {
  659. [GITS_BASER_TYPE_DEVICE] = "Devices",
  660. [GITS_BASER_TYPE_VCPU] = "Virtual CPUs",
  661. [GITS_BASER_TYPE_CPU] = "Physical CPUs",
  662. [GITS_BASER_TYPE_COLLECTION] = "Interrupt Collections",
  663. [GITS_BASER_TYPE_RESERVED5] = "Reserved (5)",
  664. [GITS_BASER_TYPE_RESERVED6] = "Reserved (6)",
  665. [GITS_BASER_TYPE_RESERVED7] = "Reserved (7)",
  666. };
  667. static u64 its_read_baser(struct its_node *its, struct its_baser *baser)
  668. {
  669. u32 idx = baser - its->tables;
  670. return gits_read_baser(its->base + GITS_BASER + (idx << 3));
  671. }
  672. static void its_write_baser(struct its_node *its, struct its_baser *baser,
  673. u64 val)
  674. {
  675. u32 idx = baser - its->tables;
  676. gits_write_baser(val, its->base + GITS_BASER + (idx << 3));
  677. baser->val = its_read_baser(its, baser);
  678. }
  679. static int its_setup_baser(struct its_node *its, struct its_baser *baser,
  680. u64 cache, u64 shr, u32 psz, u32 order,
  681. bool indirect)
  682. {
  683. u64 val = its_read_baser(its, baser);
  684. u64 esz = GITS_BASER_ENTRY_SIZE(val);
  685. u64 type = GITS_BASER_TYPE(val);
  686. u32 alloc_pages;
  687. void *base;
  688. u64 tmp;
  689. retry_alloc_baser:
  690. alloc_pages = (PAGE_ORDER_TO_SIZE(order) / psz);
  691. if (alloc_pages > GITS_BASER_PAGES_MAX) {
  692. pr_warn("ITS@%pa: %s too large, reduce ITS pages %u->%u\n",
  693. &its->phys_base, its_base_type_string[type],
  694. alloc_pages, GITS_BASER_PAGES_MAX);
  695. alloc_pages = GITS_BASER_PAGES_MAX;
  696. order = get_order(GITS_BASER_PAGES_MAX * psz);
  697. }
  698. base = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
  699. if (!base)
  700. return -ENOMEM;
  701. retry_baser:
  702. val = (virt_to_phys(base) |
  703. (type << GITS_BASER_TYPE_SHIFT) |
  704. ((esz - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) |
  705. ((alloc_pages - 1) << GITS_BASER_PAGES_SHIFT) |
  706. cache |
  707. shr |
  708. GITS_BASER_VALID);
  709. val |= indirect ? GITS_BASER_INDIRECT : 0x0;
  710. switch (psz) {
  711. case SZ_4K:
  712. val |= GITS_BASER_PAGE_SIZE_4K;
  713. break;
  714. case SZ_16K:
  715. val |= GITS_BASER_PAGE_SIZE_16K;
  716. break;
  717. case SZ_64K:
  718. val |= GITS_BASER_PAGE_SIZE_64K;
  719. break;
  720. }
  721. its_write_baser(its, baser, val);
  722. tmp = baser->val;
  723. if ((val ^ tmp) & GITS_BASER_SHAREABILITY_MASK) {
  724. /*
  725. * Shareability didn't stick. Just use
  726. * whatever the read reported, which is likely
  727. * to be the only thing this redistributor
  728. * supports. If that's zero, make it
  729. * non-cacheable as well.
  730. */
  731. shr = tmp & GITS_BASER_SHAREABILITY_MASK;
  732. if (!shr) {
  733. cache = GITS_BASER_nC;
  734. gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order));
  735. }
  736. goto retry_baser;
  737. }
  738. if ((val ^ tmp) & GITS_BASER_PAGE_SIZE_MASK) {
  739. /*
  740. * Page size didn't stick. Let's try a smaller
  741. * size and retry. If we reach 4K, then
  742. * something is horribly wrong...
  743. */
  744. free_pages((unsigned long)base, order);
  745. baser->base = NULL;
  746. switch (psz) {
  747. case SZ_16K:
  748. psz = SZ_4K;
  749. goto retry_alloc_baser;
  750. case SZ_64K:
  751. psz = SZ_16K;
  752. goto retry_alloc_baser;
  753. }
  754. }
  755. if (val != tmp) {
  756. pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n",
  757. &its->phys_base, its_base_type_string[type],
  758. val, tmp);
  759. free_pages((unsigned long)base, order);
  760. return -ENXIO;
  761. }
  762. baser->order = order;
  763. baser->base = base;
  764. baser->psz = psz;
  765. tmp = indirect ? GITS_LVL1_ENTRY_SIZE : esz;
  766. pr_info("ITS@%pa: allocated %d %s @%lx (%s, esz %d, psz %dK, shr %d)\n",
  767. &its->phys_base, (int)(PAGE_ORDER_TO_SIZE(order) / (int)tmp),
  768. its_base_type_string[type],
  769. (unsigned long)virt_to_phys(base),
  770. indirect ? "indirect" : "flat", (int)esz,
  771. psz / SZ_1K, (int)shr >> GITS_BASER_SHAREABILITY_SHIFT);
  772. return 0;
  773. }
  774. static bool its_parse_baser_device(struct its_node *its, struct its_baser *baser,
  775. u32 psz, u32 *order)
  776. {
  777. u64 esz = GITS_BASER_ENTRY_SIZE(its_read_baser(its, baser));
  778. u64 val = GITS_BASER_InnerShareable | GITS_BASER_WaWb;
  779. u32 ids = its->device_ids;
  780. u32 new_order = *order;
  781. bool indirect = false;
  782. /* No need to enable Indirection if memory requirement < (psz*2)bytes */
  783. if ((esz << ids) > (psz * 2)) {
  784. /*
  785. * Find out whether hw supports a single or two-level table by
  786. * table by reading bit at offset '62' after writing '1' to it.
  787. */
  788. its_write_baser(its, baser, val | GITS_BASER_INDIRECT);
  789. indirect = !!(baser->val & GITS_BASER_INDIRECT);
  790. if (indirect) {
  791. /*
  792. * The size of the lvl2 table is equal to ITS page size
  793. * which is 'psz'. For computing lvl1 table size,
  794. * subtract ID bits that sparse lvl2 table from 'ids'
  795. * which is reported by ITS hardware times lvl1 table
  796. * entry size.
  797. */
  798. ids -= ilog2(psz / (int)esz);
  799. esz = GITS_LVL1_ENTRY_SIZE;
  800. }
  801. }
  802. /*
  803. * Allocate as many entries as required to fit the
  804. * range of device IDs that the ITS can grok... The ID
  805. * space being incredibly sparse, this results in a
  806. * massive waste of memory if two-level device table
  807. * feature is not supported by hardware.
  808. */
  809. new_order = max_t(u32, get_order(esz << ids), new_order);
  810. if (new_order >= MAX_ORDER) {
  811. new_order = MAX_ORDER - 1;
  812. ids = ilog2(PAGE_ORDER_TO_SIZE(new_order) / (int)esz);
  813. pr_warn("ITS@%pa: Device Table too large, reduce ids %u->%u\n",
  814. &its->phys_base, its->device_ids, ids);
  815. }
  816. *order = new_order;
  817. return indirect;
  818. }
  819. static void its_free_tables(struct its_node *its)
  820. {
  821. int i;
  822. for (i = 0; i < GITS_BASER_NR_REGS; i++) {
  823. if (its->tables[i].base) {
  824. free_pages((unsigned long)its->tables[i].base,
  825. its->tables[i].order);
  826. its->tables[i].base = NULL;
  827. }
  828. }
  829. }
  830. static int its_alloc_tables(struct its_node *its)
  831. {
  832. u64 typer = gic_read_typer(its->base + GITS_TYPER);
  833. u32 ids = GITS_TYPER_DEVBITS(typer);
  834. u64 shr = GITS_BASER_InnerShareable;
  835. u64 cache = GITS_BASER_WaWb;
  836. u32 psz = SZ_64K;
  837. int err, i;
  838. if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_22375) {
  839. /*
  840. * erratum 22375: only alloc 8MB table size
  841. * erratum 24313: ignore memory access type
  842. */
  843. cache = GITS_BASER_nCnB;
  844. ids = 0x14; /* 20 bits, 8MB */
  845. }
  846. its->device_ids = ids;
  847. for (i = 0; i < GITS_BASER_NR_REGS; i++) {
  848. struct its_baser *baser = its->tables + i;
  849. u64 val = its_read_baser(its, baser);
  850. u64 type = GITS_BASER_TYPE(val);
  851. u32 order = get_order(psz);
  852. bool indirect = false;
  853. if (type == GITS_BASER_TYPE_NONE)
  854. continue;
  855. if (type == GITS_BASER_TYPE_DEVICE)
  856. indirect = its_parse_baser_device(its, baser, psz, &order);
  857. err = its_setup_baser(its, baser, cache, shr, psz, order, indirect);
  858. if (err < 0) {
  859. its_free_tables(its);
  860. return err;
  861. }
  862. /* Update settings which will be used for next BASERn */
  863. psz = baser->psz;
  864. cache = baser->val & GITS_BASER_CACHEABILITY_MASK;
  865. shr = baser->val & GITS_BASER_SHAREABILITY_MASK;
  866. }
  867. return 0;
  868. }
  869. static int its_alloc_collections(struct its_node *its)
  870. {
  871. its->collections = kzalloc(nr_cpu_ids * sizeof(*its->collections),
  872. GFP_KERNEL);
  873. if (!its->collections)
  874. return -ENOMEM;
  875. return 0;
  876. }
  877. static void its_cpu_init_lpis(void)
  878. {
  879. void __iomem *rbase = gic_data_rdist_rd_base();
  880. struct page *pend_page;
  881. u64 val, tmp;
  882. /* If we didn't allocate the pending table yet, do it now */
  883. pend_page = gic_data_rdist()->pend_page;
  884. if (!pend_page) {
  885. phys_addr_t paddr;
  886. /*
  887. * The pending pages have to be at least 64kB aligned,
  888. * hence the 'max(LPI_PENDBASE_SZ, SZ_64K)' below.
  889. */
  890. pend_page = alloc_pages(GFP_NOWAIT | __GFP_ZERO,
  891. get_order(max(LPI_PENDBASE_SZ, SZ_64K)));
  892. if (!pend_page) {
  893. pr_err("Failed to allocate PENDBASE for CPU%d\n",
  894. smp_processor_id());
  895. return;
  896. }
  897. /* Make sure the GIC will observe the zero-ed page */
  898. gic_flush_dcache_to_poc(page_address(pend_page), LPI_PENDBASE_SZ);
  899. paddr = page_to_phys(pend_page);
  900. pr_info("CPU%d: using LPI pending table @%pa\n",
  901. smp_processor_id(), &paddr);
  902. gic_data_rdist()->pend_page = pend_page;
  903. }
  904. /* Disable LPIs */
  905. val = readl_relaxed(rbase + GICR_CTLR);
  906. val &= ~GICR_CTLR_ENABLE_LPIS;
  907. writel_relaxed(val, rbase + GICR_CTLR);
  908. /*
  909. * Make sure any change to the table is observable by the GIC.
  910. */
  911. dsb(sy);
  912. /* set PROPBASE */
  913. val = (page_to_phys(gic_rdists->prop_page) |
  914. GICR_PROPBASER_InnerShareable |
  915. GICR_PROPBASER_WaWb |
  916. ((LPI_NRBITS - 1) & GICR_PROPBASER_IDBITS_MASK));
  917. gicr_write_propbaser(val, rbase + GICR_PROPBASER);
  918. tmp = gicr_read_propbaser(rbase + GICR_PROPBASER);
  919. if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) {
  920. if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) {
  921. /*
  922. * The HW reports non-shareable, we must
  923. * remove the cacheability attributes as
  924. * well.
  925. */
  926. val &= ~(GICR_PROPBASER_SHAREABILITY_MASK |
  927. GICR_PROPBASER_CACHEABILITY_MASK);
  928. val |= GICR_PROPBASER_nC;
  929. gicr_write_propbaser(val, rbase + GICR_PROPBASER);
  930. }
  931. pr_info_once("GIC: using cache flushing for LPI property table\n");
  932. gic_rdists->flags |= RDIST_FLAGS_PROPBASE_NEEDS_FLUSHING;
  933. }
  934. /* set PENDBASE */
  935. val = (page_to_phys(pend_page) |
  936. GICR_PENDBASER_InnerShareable |
  937. GICR_PENDBASER_WaWb);
  938. gicr_write_pendbaser(val, rbase + GICR_PENDBASER);
  939. tmp = gicr_read_pendbaser(rbase + GICR_PENDBASER);
  940. if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) {
  941. /*
  942. * The HW reports non-shareable, we must remove the
  943. * cacheability attributes as well.
  944. */
  945. val &= ~(GICR_PENDBASER_SHAREABILITY_MASK |
  946. GICR_PENDBASER_CACHEABILITY_MASK);
  947. val |= GICR_PENDBASER_nC;
  948. gicr_write_pendbaser(val, rbase + GICR_PENDBASER);
  949. }
  950. /* Enable LPIs */
  951. val = readl_relaxed(rbase + GICR_CTLR);
  952. val |= GICR_CTLR_ENABLE_LPIS;
  953. writel_relaxed(val, rbase + GICR_CTLR);
  954. /* Make sure the GIC has seen the above */
  955. dsb(sy);
  956. }
  957. static void its_cpu_init_collection(void)
  958. {
  959. struct its_node *its;
  960. int cpu;
  961. spin_lock(&its_lock);
  962. cpu = smp_processor_id();
  963. list_for_each_entry(its, &its_nodes, entry) {
  964. u64 target;
  965. /* avoid cross node collections and its mapping */
  966. if (its->flags & ITS_FLAGS_WORKAROUND_CAVIUM_23144) {
  967. struct device_node *cpu_node;
  968. cpu_node = of_get_cpu_node(cpu, NULL);
  969. if (its->numa_node != NUMA_NO_NODE &&
  970. its->numa_node != of_node_to_nid(cpu_node))
  971. continue;
  972. }
  973. /*
  974. * We now have to bind each collection to its target
  975. * redistributor.
  976. */
  977. if (gic_read_typer(its->base + GITS_TYPER) & GITS_TYPER_PTA) {
  978. /*
  979. * This ITS wants the physical address of the
  980. * redistributor.
  981. */
  982. target = gic_data_rdist()->phys_base;
  983. } else {
  984. /*
  985. * This ITS wants a linear CPU number.
  986. */
  987. target = gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER);
  988. target = GICR_TYPER_CPU_NUMBER(target) << 16;
  989. }
  990. /* Perform collection mapping */
  991. its->collections[cpu].target_address = target;
  992. its->collections[cpu].col_id = cpu;
  993. its_send_mapc(its, &its->collections[cpu], 1);
  994. its_send_invall(its, &its->collections[cpu]);
  995. }
  996. spin_unlock(&its_lock);
  997. }
  998. static struct its_device *its_find_device(struct its_node *its, u32 dev_id)
  999. {
  1000. struct its_device *its_dev = NULL, *tmp;
  1001. unsigned long flags;
  1002. raw_spin_lock_irqsave(&its->lock, flags);
  1003. list_for_each_entry(tmp, &its->its_device_list, entry) {
  1004. if (tmp->device_id == dev_id) {
  1005. its_dev = tmp;
  1006. break;
  1007. }
  1008. }
  1009. raw_spin_unlock_irqrestore(&its->lock, flags);
  1010. return its_dev;
  1011. }
  1012. static struct its_baser *its_get_baser(struct its_node *its, u32 type)
  1013. {
  1014. int i;
  1015. for (i = 0; i < GITS_BASER_NR_REGS; i++) {
  1016. if (GITS_BASER_TYPE(its->tables[i].val) == type)
  1017. return &its->tables[i];
  1018. }
  1019. return NULL;
  1020. }
  1021. static bool its_alloc_device_table(struct its_node *its, u32 dev_id)
  1022. {
  1023. struct its_baser *baser;
  1024. struct page *page;
  1025. u32 esz, idx;
  1026. __le64 *table;
  1027. baser = its_get_baser(its, GITS_BASER_TYPE_DEVICE);
  1028. /* Don't allow device id that exceeds ITS hardware limit */
  1029. if (!baser)
  1030. return (ilog2(dev_id) < its->device_ids);
  1031. /* Don't allow device id that exceeds single, flat table limit */
  1032. esz = GITS_BASER_ENTRY_SIZE(baser->val);
  1033. if (!(baser->val & GITS_BASER_INDIRECT))
  1034. return (dev_id < (PAGE_ORDER_TO_SIZE(baser->order) / esz));
  1035. /* Compute 1st level table index & check if that exceeds table limit */
  1036. idx = dev_id >> ilog2(baser->psz / esz);
  1037. if (idx >= (PAGE_ORDER_TO_SIZE(baser->order) / GITS_LVL1_ENTRY_SIZE))
  1038. return false;
  1039. table = baser->base;
  1040. /* Allocate memory for 2nd level table */
  1041. if (!table[idx]) {
  1042. page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(baser->psz));
  1043. if (!page)
  1044. return false;
  1045. /* Flush Lvl2 table to PoC if hw doesn't support coherency */
  1046. if (!(baser->val & GITS_BASER_SHAREABILITY_MASK))
  1047. gic_flush_dcache_to_poc(page_address(page), baser->psz);
  1048. table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID);
  1049. /* Flush Lvl1 entry to PoC if hw doesn't support coherency */
  1050. if (!(baser->val & GITS_BASER_SHAREABILITY_MASK))
  1051. gic_flush_dcache_to_poc(table + idx, GITS_LVL1_ENTRY_SIZE);
  1052. /* Ensure updated table contents are visible to ITS hardware */
  1053. dsb(sy);
  1054. }
  1055. return true;
  1056. }
  1057. static struct its_device *its_create_device(struct its_node *its, u32 dev_id,
  1058. int nvecs)
  1059. {
  1060. struct its_device *dev;
  1061. unsigned long *lpi_map;
  1062. unsigned long flags;
  1063. u16 *col_map = NULL;
  1064. void *itt;
  1065. int lpi_base;
  1066. int nr_lpis;
  1067. int nr_ites;
  1068. int sz;
  1069. if (!its_alloc_device_table(its, dev_id))
  1070. return NULL;
  1071. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1072. /*
  1073. * At least one bit of EventID is being used, hence a minimum
  1074. * of two entries. No, the architecture doesn't let you
  1075. * express an ITT with a single entry.
  1076. */
  1077. nr_ites = max(2UL, roundup_pow_of_two(nvecs));
  1078. sz = nr_ites * its->ite_size;
  1079. sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1;
  1080. itt = kzalloc(sz, GFP_KERNEL);
  1081. lpi_map = its_lpi_alloc_chunks(nvecs, &lpi_base, &nr_lpis);
  1082. if (lpi_map)
  1083. col_map = kzalloc(sizeof(*col_map) * nr_lpis, GFP_KERNEL);
  1084. if (!dev || !itt || !lpi_map || !col_map) {
  1085. kfree(dev);
  1086. kfree(itt);
  1087. kfree(lpi_map);
  1088. kfree(col_map);
  1089. return NULL;
  1090. }
  1091. gic_flush_dcache_to_poc(itt, sz);
  1092. dev->its = its;
  1093. dev->itt = itt;
  1094. dev->nr_ites = nr_ites;
  1095. dev->event_map.lpi_map = lpi_map;
  1096. dev->event_map.col_map = col_map;
  1097. dev->event_map.lpi_base = lpi_base;
  1098. dev->event_map.nr_lpis = nr_lpis;
  1099. dev->device_id = dev_id;
  1100. INIT_LIST_HEAD(&dev->entry);
  1101. raw_spin_lock_irqsave(&its->lock, flags);
  1102. list_add(&dev->entry, &its->its_device_list);
  1103. raw_spin_unlock_irqrestore(&its->lock, flags);
  1104. /* Map device to its ITT */
  1105. its_send_mapd(dev, 1);
  1106. return dev;
  1107. }
  1108. static void its_free_device(struct its_device *its_dev)
  1109. {
  1110. unsigned long flags;
  1111. raw_spin_lock_irqsave(&its_dev->its->lock, flags);
  1112. list_del(&its_dev->entry);
  1113. raw_spin_unlock_irqrestore(&its_dev->its->lock, flags);
  1114. kfree(its_dev->itt);
  1115. kfree(its_dev);
  1116. }
  1117. static int its_alloc_device_irq(struct its_device *dev, irq_hw_number_t *hwirq)
  1118. {
  1119. int idx;
  1120. idx = find_first_zero_bit(dev->event_map.lpi_map,
  1121. dev->event_map.nr_lpis);
  1122. if (idx == dev->event_map.nr_lpis)
  1123. return -ENOSPC;
  1124. *hwirq = dev->event_map.lpi_base + idx;
  1125. set_bit(idx, dev->event_map.lpi_map);
  1126. return 0;
  1127. }
  1128. static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
  1129. int nvec, msi_alloc_info_t *info)
  1130. {
  1131. struct its_node *its;
  1132. struct its_device *its_dev;
  1133. struct msi_domain_info *msi_info;
  1134. u32 dev_id;
  1135. /*
  1136. * We ignore "dev" entierely, and rely on the dev_id that has
  1137. * been passed via the scratchpad. This limits this domain's
  1138. * usefulness to upper layers that definitely know that they
  1139. * are built on top of the ITS.
  1140. */
  1141. dev_id = info->scratchpad[0].ul;
  1142. msi_info = msi_get_domain_info(domain);
  1143. its = msi_info->data;
  1144. its_dev = its_find_device(its, dev_id);
  1145. if (its_dev) {
  1146. /*
  1147. * We already have seen this ID, probably through
  1148. * another alias (PCI bridge of some sort). No need to
  1149. * create the device.
  1150. */
  1151. pr_debug("Reusing ITT for devID %x\n", dev_id);
  1152. goto out;
  1153. }
  1154. its_dev = its_create_device(its, dev_id, nvec);
  1155. if (!its_dev)
  1156. return -ENOMEM;
  1157. pr_debug("ITT %d entries, %d bits\n", nvec, ilog2(nvec));
  1158. out:
  1159. info->scratchpad[0].ptr = its_dev;
  1160. return 0;
  1161. }
  1162. static struct msi_domain_ops its_msi_domain_ops = {
  1163. .msi_prepare = its_msi_prepare,
  1164. };
  1165. static int its_irq_gic_domain_alloc(struct irq_domain *domain,
  1166. unsigned int virq,
  1167. irq_hw_number_t hwirq)
  1168. {
  1169. struct irq_fwspec fwspec;
  1170. if (irq_domain_get_of_node(domain->parent)) {
  1171. fwspec.fwnode = domain->parent->fwnode;
  1172. fwspec.param_count = 3;
  1173. fwspec.param[0] = GIC_IRQ_TYPE_LPI;
  1174. fwspec.param[1] = hwirq;
  1175. fwspec.param[2] = IRQ_TYPE_EDGE_RISING;
  1176. } else if (is_fwnode_irqchip(domain->parent->fwnode)) {
  1177. fwspec.fwnode = domain->parent->fwnode;
  1178. fwspec.param_count = 2;
  1179. fwspec.param[0] = hwirq;
  1180. fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
  1181. } else {
  1182. return -EINVAL;
  1183. }
  1184. return irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
  1185. }
  1186. static int its_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
  1187. unsigned int nr_irqs, void *args)
  1188. {
  1189. msi_alloc_info_t *info = args;
  1190. struct its_device *its_dev = info->scratchpad[0].ptr;
  1191. irq_hw_number_t hwirq;
  1192. int err;
  1193. int i;
  1194. for (i = 0; i < nr_irqs; i++) {
  1195. err = its_alloc_device_irq(its_dev, &hwirq);
  1196. if (err)
  1197. return err;
  1198. err = its_irq_gic_domain_alloc(domain, virq + i, hwirq);
  1199. if (err)
  1200. return err;
  1201. irq_domain_set_hwirq_and_chip(domain, virq + i,
  1202. hwirq, &its_irq_chip, its_dev);
  1203. pr_debug("ID:%d pID:%d vID:%d\n",
  1204. (int)(hwirq - its_dev->event_map.lpi_base),
  1205. (int) hwirq, virq + i);
  1206. }
  1207. return 0;
  1208. }
  1209. static void its_irq_domain_activate(struct irq_domain *domain,
  1210. struct irq_data *d)
  1211. {
  1212. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  1213. u32 event = its_get_event_id(d);
  1214. const struct cpumask *cpu_mask = cpu_online_mask;
  1215. /* get the cpu_mask of local node */
  1216. if (its_dev->its->numa_node >= 0)
  1217. cpu_mask = cpumask_of_node(its_dev->its->numa_node);
  1218. /* Bind the LPI to the first possible CPU */
  1219. its_dev->event_map.col_map[event] = cpumask_first(cpu_mask);
  1220. /* Map the GIC IRQ and event to the device */
  1221. its_send_mapvi(its_dev, d->hwirq, event);
  1222. }
  1223. static void its_irq_domain_deactivate(struct irq_domain *domain,
  1224. struct irq_data *d)
  1225. {
  1226. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  1227. u32 event = its_get_event_id(d);
  1228. /* Stop the delivery of interrupts */
  1229. its_send_discard(its_dev, event);
  1230. }
  1231. static void its_irq_domain_free(struct irq_domain *domain, unsigned int virq,
  1232. unsigned int nr_irqs)
  1233. {
  1234. struct irq_data *d = irq_domain_get_irq_data(domain, virq);
  1235. struct its_device *its_dev = irq_data_get_irq_chip_data(d);
  1236. int i;
  1237. for (i = 0; i < nr_irqs; i++) {
  1238. struct irq_data *data = irq_domain_get_irq_data(domain,
  1239. virq + i);
  1240. u32 event = its_get_event_id(data);
  1241. /* Mark interrupt index as unused */
  1242. clear_bit(event, its_dev->event_map.lpi_map);
  1243. /* Nuke the entry in the domain */
  1244. irq_domain_reset_irq_data(data);
  1245. }
  1246. /* If all interrupts have been freed, start mopping the floor */
  1247. if (bitmap_empty(its_dev->event_map.lpi_map,
  1248. its_dev->event_map.nr_lpis)) {
  1249. its_lpi_free(&its_dev->event_map);
  1250. /* Unmap device/itt */
  1251. its_send_mapd(its_dev, 0);
  1252. its_free_device(its_dev);
  1253. }
  1254. irq_domain_free_irqs_parent(domain, virq, nr_irqs);
  1255. }
  1256. static const struct irq_domain_ops its_domain_ops = {
  1257. .alloc = its_irq_domain_alloc,
  1258. .free = its_irq_domain_free,
  1259. .activate = its_irq_domain_activate,
  1260. .deactivate = its_irq_domain_deactivate,
  1261. };
  1262. static int its_force_quiescent(void __iomem *base)
  1263. {
  1264. u32 count = 1000000; /* 1s */
  1265. u32 val;
  1266. val = readl_relaxed(base + GITS_CTLR);
  1267. /*
  1268. * GIC architecture specification requires the ITS to be both
  1269. * disabled and quiescent for writes to GITS_BASER<n> or
  1270. * GITS_CBASER to not have UNPREDICTABLE results.
  1271. */
  1272. if ((val & GITS_CTLR_QUIESCENT) && !(val & GITS_CTLR_ENABLE))
  1273. return 0;
  1274. /* Disable the generation of all interrupts to this ITS */
  1275. val &= ~GITS_CTLR_ENABLE;
  1276. writel_relaxed(val, base + GITS_CTLR);
  1277. /* Poll GITS_CTLR and wait until ITS becomes quiescent */
  1278. while (1) {
  1279. val = readl_relaxed(base + GITS_CTLR);
  1280. if (val & GITS_CTLR_QUIESCENT)
  1281. return 0;
  1282. count--;
  1283. if (!count)
  1284. return -EBUSY;
  1285. cpu_relax();
  1286. udelay(1);
  1287. }
  1288. }
  1289. static void __maybe_unused its_enable_quirk_cavium_22375(void *data)
  1290. {
  1291. struct its_node *its = data;
  1292. its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_22375;
  1293. }
  1294. static void __maybe_unused its_enable_quirk_cavium_23144(void *data)
  1295. {
  1296. struct its_node *its = data;
  1297. its->flags |= ITS_FLAGS_WORKAROUND_CAVIUM_23144;
  1298. }
  1299. static const struct gic_quirk its_quirks[] = {
  1300. #ifdef CONFIG_CAVIUM_ERRATUM_22375
  1301. {
  1302. .desc = "ITS: Cavium errata 22375, 24313",
  1303. .iidr = 0xa100034c, /* ThunderX pass 1.x */
  1304. .mask = 0xffff0fff,
  1305. .init = its_enable_quirk_cavium_22375,
  1306. },
  1307. #endif
  1308. #ifdef CONFIG_CAVIUM_ERRATUM_23144
  1309. {
  1310. .desc = "ITS: Cavium erratum 23144",
  1311. .iidr = 0xa100034c, /* ThunderX pass 1.x */
  1312. .mask = 0xffff0fff,
  1313. .init = its_enable_quirk_cavium_23144,
  1314. },
  1315. #endif
  1316. {
  1317. }
  1318. };
  1319. static void its_enable_quirks(struct its_node *its)
  1320. {
  1321. u32 iidr = readl_relaxed(its->base + GITS_IIDR);
  1322. gic_enable_quirks(iidr, its_quirks, its);
  1323. }
  1324. static int its_init_domain(struct fwnode_handle *handle, struct its_node *its)
  1325. {
  1326. struct irq_domain *inner_domain;
  1327. struct msi_domain_info *info;
  1328. info = kzalloc(sizeof(*info), GFP_KERNEL);
  1329. if (!info)
  1330. return -ENOMEM;
  1331. inner_domain = irq_domain_create_tree(handle, &its_domain_ops, its);
  1332. if (!inner_domain) {
  1333. kfree(info);
  1334. return -ENOMEM;
  1335. }
  1336. inner_domain->parent = its_parent;
  1337. inner_domain->bus_token = DOMAIN_BUS_NEXUS;
  1338. info->ops = &its_msi_domain_ops;
  1339. info->data = its;
  1340. inner_domain->host_data = info;
  1341. return 0;
  1342. }
  1343. static int __init its_probe_one(struct resource *res,
  1344. struct fwnode_handle *handle, int numa_node)
  1345. {
  1346. struct its_node *its;
  1347. void __iomem *its_base;
  1348. u32 val;
  1349. u64 baser, tmp;
  1350. int err;
  1351. its_base = ioremap(res->start, resource_size(res));
  1352. if (!its_base) {
  1353. pr_warn("ITS@%pa: Unable to map ITS registers\n", &res->start);
  1354. return -ENOMEM;
  1355. }
  1356. val = readl_relaxed(its_base + GITS_PIDR2) & GIC_PIDR2_ARCH_MASK;
  1357. if (val != 0x30 && val != 0x40) {
  1358. pr_warn("ITS@%pa: No ITS detected, giving up\n", &res->start);
  1359. err = -ENODEV;
  1360. goto out_unmap;
  1361. }
  1362. err = its_force_quiescent(its_base);
  1363. if (err) {
  1364. pr_warn("ITS@%pa: Failed to quiesce, giving up\n", &res->start);
  1365. goto out_unmap;
  1366. }
  1367. pr_info("ITS %pR\n", res);
  1368. its = kzalloc(sizeof(*its), GFP_KERNEL);
  1369. if (!its) {
  1370. err = -ENOMEM;
  1371. goto out_unmap;
  1372. }
  1373. raw_spin_lock_init(&its->lock);
  1374. INIT_LIST_HEAD(&its->entry);
  1375. INIT_LIST_HEAD(&its->its_device_list);
  1376. its->base = its_base;
  1377. its->phys_base = res->start;
  1378. its->ite_size = ((gic_read_typer(its_base + GITS_TYPER) >> 4) & 0xf) + 1;
  1379. its->numa_node = numa_node;
  1380. its->cmd_base = kzalloc(ITS_CMD_QUEUE_SZ, GFP_KERNEL);
  1381. if (!its->cmd_base) {
  1382. err = -ENOMEM;
  1383. goto out_free_its;
  1384. }
  1385. its->cmd_write = its->cmd_base;
  1386. its_enable_quirks(its);
  1387. err = its_alloc_tables(its);
  1388. if (err)
  1389. goto out_free_cmd;
  1390. err = its_alloc_collections(its);
  1391. if (err)
  1392. goto out_free_tables;
  1393. baser = (virt_to_phys(its->cmd_base) |
  1394. GITS_CBASER_WaWb |
  1395. GITS_CBASER_InnerShareable |
  1396. (ITS_CMD_QUEUE_SZ / SZ_4K - 1) |
  1397. GITS_CBASER_VALID);
  1398. gits_write_cbaser(baser, its->base + GITS_CBASER);
  1399. tmp = gits_read_cbaser(its->base + GITS_CBASER);
  1400. if ((tmp ^ baser) & GITS_CBASER_SHAREABILITY_MASK) {
  1401. if (!(tmp & GITS_CBASER_SHAREABILITY_MASK)) {
  1402. /*
  1403. * The HW reports non-shareable, we must
  1404. * remove the cacheability attributes as
  1405. * well.
  1406. */
  1407. baser &= ~(GITS_CBASER_SHAREABILITY_MASK |
  1408. GITS_CBASER_CACHEABILITY_MASK);
  1409. baser |= GITS_CBASER_nC;
  1410. gits_write_cbaser(baser, its->base + GITS_CBASER);
  1411. }
  1412. pr_info("ITS: using cache flushing for cmd queue\n");
  1413. its->flags |= ITS_FLAGS_CMDQ_NEEDS_FLUSHING;
  1414. }
  1415. gits_write_cwriter(0, its->base + GITS_CWRITER);
  1416. writel_relaxed(GITS_CTLR_ENABLE, its->base + GITS_CTLR);
  1417. err = its_init_domain(handle, its);
  1418. if (err)
  1419. goto out_free_tables;
  1420. spin_lock(&its_lock);
  1421. list_add(&its->entry, &its_nodes);
  1422. spin_unlock(&its_lock);
  1423. return 0;
  1424. out_free_tables:
  1425. its_free_tables(its);
  1426. out_free_cmd:
  1427. kfree(its->cmd_base);
  1428. out_free_its:
  1429. kfree(its);
  1430. out_unmap:
  1431. iounmap(its_base);
  1432. pr_err("ITS@%pa: failed probing (%d)\n", &res->start, err);
  1433. return err;
  1434. }
  1435. static bool gic_rdists_supports_plpis(void)
  1436. {
  1437. return !!(gic_read_typer(gic_data_rdist_rd_base() + GICR_TYPER) & GICR_TYPER_PLPIS);
  1438. }
  1439. int its_cpu_init(void)
  1440. {
  1441. if (!list_empty(&its_nodes)) {
  1442. if (!gic_rdists_supports_plpis()) {
  1443. pr_info("CPU%d: LPIs not supported\n", smp_processor_id());
  1444. return -ENXIO;
  1445. }
  1446. its_cpu_init_lpis();
  1447. its_cpu_init_collection();
  1448. }
  1449. return 0;
  1450. }
  1451. static struct of_device_id its_device_id[] = {
  1452. { .compatible = "arm,gic-v3-its", },
  1453. {},
  1454. };
  1455. static int __init its_of_probe(struct device_node *node)
  1456. {
  1457. struct device_node *np;
  1458. struct resource res;
  1459. for (np = of_find_matching_node(node, its_device_id); np;
  1460. np = of_find_matching_node(np, its_device_id)) {
  1461. if (!of_property_read_bool(np, "msi-controller")) {
  1462. pr_warn("%s: no msi-controller property, ITS ignored\n",
  1463. np->full_name);
  1464. continue;
  1465. }
  1466. if (of_address_to_resource(np, 0, &res)) {
  1467. pr_warn("%s: no regs?\n", np->full_name);
  1468. continue;
  1469. }
  1470. its_probe_one(&res, &np->fwnode, of_node_to_nid(np));
  1471. }
  1472. return 0;
  1473. }
  1474. #ifdef CONFIG_ACPI
  1475. #define ACPI_GICV3_ITS_MEM_SIZE (SZ_128K)
  1476. static int __init gic_acpi_parse_madt_its(struct acpi_subtable_header *header,
  1477. const unsigned long end)
  1478. {
  1479. struct acpi_madt_generic_translator *its_entry;
  1480. struct fwnode_handle *dom_handle;
  1481. struct resource res;
  1482. int err;
  1483. its_entry = (struct acpi_madt_generic_translator *)header;
  1484. memset(&res, 0, sizeof(res));
  1485. res.start = its_entry->base_address;
  1486. res.end = its_entry->base_address + ACPI_GICV3_ITS_MEM_SIZE - 1;
  1487. res.flags = IORESOURCE_MEM;
  1488. dom_handle = irq_domain_alloc_fwnode((void *)its_entry->base_address);
  1489. if (!dom_handle) {
  1490. pr_err("ITS@%pa: Unable to allocate GICv3 ITS domain token\n",
  1491. &res.start);
  1492. return -ENOMEM;
  1493. }
  1494. err = iort_register_domain_token(its_entry->translation_id, dom_handle);
  1495. if (err) {
  1496. pr_err("ITS@%pa: Unable to register GICv3 ITS domain token (ITS ID %d) to IORT\n",
  1497. &res.start, its_entry->translation_id);
  1498. goto dom_err;
  1499. }
  1500. err = its_probe_one(&res, dom_handle, NUMA_NO_NODE);
  1501. if (!err)
  1502. return 0;
  1503. iort_deregister_domain_token(its_entry->translation_id);
  1504. dom_err:
  1505. irq_domain_free_fwnode(dom_handle);
  1506. return err;
  1507. }
  1508. static void __init its_acpi_probe(void)
  1509. {
  1510. acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_TRANSLATOR,
  1511. gic_acpi_parse_madt_its, 0);
  1512. }
  1513. #else
  1514. static void __init its_acpi_probe(void) { }
  1515. #endif
  1516. int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
  1517. struct irq_domain *parent_domain)
  1518. {
  1519. struct device_node *of_node;
  1520. its_parent = parent_domain;
  1521. of_node = to_of_node(handle);
  1522. if (of_node)
  1523. its_of_probe(of_node);
  1524. else
  1525. its_acpi_probe();
  1526. if (list_empty(&its_nodes)) {
  1527. pr_warn("ITS: No ITS available, not enabling LPIs\n");
  1528. return -ENXIO;
  1529. }
  1530. gic_rdists = rdists;
  1531. its_alloc_lpi_tables();
  1532. its_lpi_init(rdists->id_bits);
  1533. return 0;
  1534. }