intr_remapping.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. #include <linux/interrupt.h>
  2. #include <linux/dmar.h>
  3. #include <linux/spinlock.h>
  4. #include <linux/jiffies.h>
  5. #include <linux/pci.h>
  6. #include <linux/irq.h>
  7. #include <asm/io_apic.h>
  8. #include <asm/smp.h>
  9. #include <asm/cpu.h>
  10. #include <linux/intel-iommu.h>
  11. #include "intr_remapping.h"
  12. #include <acpi/acpi.h>
  13. static struct ioapic_scope ir_ioapic[MAX_IO_APICS];
  14. static int ir_ioapic_num;
  15. int intr_remapping_enabled;
  16. static int disable_intremap;
  17. static __init int setup_nointremap(char *str)
  18. {
  19. disable_intremap = 1;
  20. return 0;
  21. }
  22. early_param("nointremap", setup_nointremap);
  23. struct irq_2_iommu {
  24. struct intel_iommu *iommu;
  25. u16 irte_index;
  26. u16 sub_handle;
  27. u8 irte_mask;
  28. };
  29. #ifdef CONFIG_GENERIC_HARDIRQS
  30. static struct irq_2_iommu *get_one_free_irq_2_iommu(int node)
  31. {
  32. struct irq_2_iommu *iommu;
  33. iommu = kzalloc_node(sizeof(*iommu), GFP_ATOMIC, node);
  34. printk(KERN_DEBUG "alloc irq_2_iommu on node %d\n", node);
  35. return iommu;
  36. }
  37. static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
  38. {
  39. struct irq_desc *desc;
  40. desc = irq_to_desc(irq);
  41. if (WARN_ON_ONCE(!desc))
  42. return NULL;
  43. return desc->irq_2_iommu;
  44. }
  45. static struct irq_2_iommu *irq_2_iommu_alloc_node(unsigned int irq, int node)
  46. {
  47. struct irq_desc *desc;
  48. struct irq_2_iommu *irq_iommu;
  49. /*
  50. * alloc irq desc if not allocated already.
  51. */
  52. desc = irq_to_desc_alloc_node(irq, node);
  53. if (!desc) {
  54. printk(KERN_INFO "can not get irq_desc for %d\n", irq);
  55. return NULL;
  56. }
  57. irq_iommu = desc->irq_2_iommu;
  58. if (!irq_iommu)
  59. desc->irq_2_iommu = get_one_free_irq_2_iommu(node);
  60. return desc->irq_2_iommu;
  61. }
  62. static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq)
  63. {
  64. return irq_2_iommu_alloc_node(irq, cpu_to_node(boot_cpu_id));
  65. }
  66. #else /* !CONFIG_SPARSE_IRQ */
  67. static struct irq_2_iommu irq_2_iommuX[NR_IRQS];
  68. static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
  69. {
  70. if (irq < nr_irqs)
  71. return &irq_2_iommuX[irq];
  72. return NULL;
  73. }
  74. static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq)
  75. {
  76. return irq_2_iommu(irq);
  77. }
  78. #endif
  79. static DEFINE_SPINLOCK(irq_2_ir_lock);
  80. static struct irq_2_iommu *valid_irq_2_iommu(unsigned int irq)
  81. {
  82. struct irq_2_iommu *irq_iommu;
  83. irq_iommu = irq_2_iommu(irq);
  84. if (!irq_iommu)
  85. return NULL;
  86. if (!irq_iommu->iommu)
  87. return NULL;
  88. return irq_iommu;
  89. }
  90. int irq_remapped(int irq)
  91. {
  92. return valid_irq_2_iommu(irq) != NULL;
  93. }
  94. int get_irte(int irq, struct irte *entry)
  95. {
  96. int index;
  97. struct irq_2_iommu *irq_iommu;
  98. unsigned long flags;
  99. if (!entry)
  100. return -1;
  101. spin_lock_irqsave(&irq_2_ir_lock, flags);
  102. irq_iommu = valid_irq_2_iommu(irq);
  103. if (!irq_iommu) {
  104. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  105. return -1;
  106. }
  107. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  108. *entry = *(irq_iommu->iommu->ir_table->base + index);
  109. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  110. return 0;
  111. }
  112. int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
  113. {
  114. struct ir_table *table = iommu->ir_table;
  115. struct irq_2_iommu *irq_iommu;
  116. u16 index, start_index;
  117. unsigned int mask = 0;
  118. unsigned long flags;
  119. int i;
  120. if (!count)
  121. return -1;
  122. #ifndef CONFIG_SPARSE_IRQ
  123. /* protect irq_2_iommu_alloc later */
  124. if (irq >= nr_irqs)
  125. return -1;
  126. #endif
  127. /*
  128. * start the IRTE search from index 0.
  129. */
  130. index = start_index = 0;
  131. if (count > 1) {
  132. count = __roundup_pow_of_two(count);
  133. mask = ilog2(count);
  134. }
  135. if (mask > ecap_max_handle_mask(iommu->ecap)) {
  136. printk(KERN_ERR
  137. "Requested mask %x exceeds the max invalidation handle"
  138. " mask value %Lx\n", mask,
  139. ecap_max_handle_mask(iommu->ecap));
  140. return -1;
  141. }
  142. spin_lock_irqsave(&irq_2_ir_lock, flags);
  143. do {
  144. for (i = index; i < index + count; i++)
  145. if (table->base[i].present)
  146. break;
  147. /* empty index found */
  148. if (i == index + count)
  149. break;
  150. index = (index + count) % INTR_REMAP_TABLE_ENTRIES;
  151. if (index == start_index) {
  152. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  153. printk(KERN_ERR "can't allocate an IRTE\n");
  154. return -1;
  155. }
  156. } while (1);
  157. for (i = index; i < index + count; i++)
  158. table->base[i].present = 1;
  159. irq_iommu = irq_2_iommu_alloc(irq);
  160. if (!irq_iommu) {
  161. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  162. printk(KERN_ERR "can't allocate irq_2_iommu\n");
  163. return -1;
  164. }
  165. irq_iommu->iommu = iommu;
  166. irq_iommu->irte_index = index;
  167. irq_iommu->sub_handle = 0;
  168. irq_iommu->irte_mask = mask;
  169. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  170. return index;
  171. }
  172. static int qi_flush_iec(struct intel_iommu *iommu, int index, int mask)
  173. {
  174. struct qi_desc desc;
  175. desc.low = QI_IEC_IIDEX(index) | QI_IEC_TYPE | QI_IEC_IM(mask)
  176. | QI_IEC_SELECTIVE;
  177. desc.high = 0;
  178. return qi_submit_sync(&desc, iommu);
  179. }
  180. int map_irq_to_irte_handle(int irq, u16 *sub_handle)
  181. {
  182. int index;
  183. struct irq_2_iommu *irq_iommu;
  184. unsigned long flags;
  185. spin_lock_irqsave(&irq_2_ir_lock, flags);
  186. irq_iommu = valid_irq_2_iommu(irq);
  187. if (!irq_iommu) {
  188. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  189. return -1;
  190. }
  191. *sub_handle = irq_iommu->sub_handle;
  192. index = irq_iommu->irte_index;
  193. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  194. return index;
  195. }
  196. int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
  197. {
  198. struct irq_2_iommu *irq_iommu;
  199. unsigned long flags;
  200. spin_lock_irqsave(&irq_2_ir_lock, flags);
  201. irq_iommu = irq_2_iommu_alloc(irq);
  202. if (!irq_iommu) {
  203. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  204. printk(KERN_ERR "can't allocate irq_2_iommu\n");
  205. return -1;
  206. }
  207. irq_iommu->iommu = iommu;
  208. irq_iommu->irte_index = index;
  209. irq_iommu->sub_handle = subhandle;
  210. irq_iommu->irte_mask = 0;
  211. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  212. return 0;
  213. }
  214. int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index)
  215. {
  216. struct irq_2_iommu *irq_iommu;
  217. unsigned long flags;
  218. spin_lock_irqsave(&irq_2_ir_lock, flags);
  219. irq_iommu = valid_irq_2_iommu(irq);
  220. if (!irq_iommu) {
  221. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  222. return -1;
  223. }
  224. irq_iommu->iommu = NULL;
  225. irq_iommu->irte_index = 0;
  226. irq_iommu->sub_handle = 0;
  227. irq_2_iommu(irq)->irte_mask = 0;
  228. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  229. return 0;
  230. }
  231. int modify_irte(int irq, struct irte *irte_modified)
  232. {
  233. int rc;
  234. int index;
  235. struct irte *irte;
  236. struct intel_iommu *iommu;
  237. struct irq_2_iommu *irq_iommu;
  238. unsigned long flags;
  239. spin_lock_irqsave(&irq_2_ir_lock, flags);
  240. irq_iommu = valid_irq_2_iommu(irq);
  241. if (!irq_iommu) {
  242. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  243. return -1;
  244. }
  245. iommu = irq_iommu->iommu;
  246. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  247. irte = &iommu->ir_table->base[index];
  248. set_64bit((unsigned long *)&irte->low, irte_modified->low);
  249. set_64bit((unsigned long *)&irte->high, irte_modified->high);
  250. __iommu_flush_cache(iommu, irte, sizeof(*irte));
  251. rc = qi_flush_iec(iommu, index, 0);
  252. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  253. return rc;
  254. }
  255. int flush_irte(int irq)
  256. {
  257. int rc;
  258. int index;
  259. struct intel_iommu *iommu;
  260. struct irq_2_iommu *irq_iommu;
  261. unsigned long flags;
  262. spin_lock_irqsave(&irq_2_ir_lock, flags);
  263. irq_iommu = valid_irq_2_iommu(irq);
  264. if (!irq_iommu) {
  265. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  266. return -1;
  267. }
  268. iommu = irq_iommu->iommu;
  269. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  270. rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask);
  271. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  272. return rc;
  273. }
  274. struct intel_iommu *map_ioapic_to_ir(int apic)
  275. {
  276. int i;
  277. for (i = 0; i < MAX_IO_APICS; i++)
  278. if (ir_ioapic[i].id == apic)
  279. return ir_ioapic[i].iommu;
  280. return NULL;
  281. }
  282. struct intel_iommu *map_dev_to_ir(struct pci_dev *dev)
  283. {
  284. struct dmar_drhd_unit *drhd;
  285. drhd = dmar_find_matched_drhd_unit(dev);
  286. if (!drhd)
  287. return NULL;
  288. return drhd->iommu;
  289. }
  290. static int clear_entries(struct irq_2_iommu *irq_iommu)
  291. {
  292. struct irte *start, *entry, *end;
  293. struct intel_iommu *iommu;
  294. int index;
  295. if (irq_iommu->sub_handle)
  296. return 0;
  297. iommu = irq_iommu->iommu;
  298. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  299. start = iommu->ir_table->base + index;
  300. end = start + (1 << irq_iommu->irte_mask);
  301. for (entry = start; entry < end; entry++) {
  302. set_64bit((unsigned long *)&entry->low, 0);
  303. set_64bit((unsigned long *)&entry->high, 0);
  304. }
  305. return qi_flush_iec(iommu, index, irq_iommu->irte_mask);
  306. }
  307. int free_irte(int irq)
  308. {
  309. int rc = 0;
  310. struct irq_2_iommu *irq_iommu;
  311. unsigned long flags;
  312. spin_lock_irqsave(&irq_2_ir_lock, flags);
  313. irq_iommu = valid_irq_2_iommu(irq);
  314. if (!irq_iommu) {
  315. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  316. return -1;
  317. }
  318. rc = clear_entries(irq_iommu);
  319. irq_iommu->iommu = NULL;
  320. irq_iommu->irte_index = 0;
  321. irq_iommu->sub_handle = 0;
  322. irq_iommu->irte_mask = 0;
  323. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  324. return rc;
  325. }
  326. static void iommu_set_intr_remapping(struct intel_iommu *iommu, int mode)
  327. {
  328. u64 addr;
  329. u32 sts;
  330. unsigned long flags;
  331. addr = virt_to_phys((void *)iommu->ir_table->base);
  332. spin_lock_irqsave(&iommu->register_lock, flags);
  333. dmar_writeq(iommu->reg + DMAR_IRTA_REG,
  334. (addr) | IR_X2APIC_MODE(mode) | INTR_REMAP_TABLE_REG_SIZE);
  335. /* Set interrupt-remapping table pointer */
  336. iommu->gcmd |= DMA_GCMD_SIRTP;
  337. writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
  338. IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
  339. readl, (sts & DMA_GSTS_IRTPS), sts);
  340. spin_unlock_irqrestore(&iommu->register_lock, flags);
  341. /*
  342. * global invalidation of interrupt entry cache before enabling
  343. * interrupt-remapping.
  344. */
  345. qi_global_iec(iommu);
  346. spin_lock_irqsave(&iommu->register_lock, flags);
  347. /* Enable interrupt-remapping */
  348. iommu->gcmd |= DMA_GCMD_IRE;
  349. writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
  350. IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
  351. readl, (sts & DMA_GSTS_IRES), sts);
  352. spin_unlock_irqrestore(&iommu->register_lock, flags);
  353. }
  354. static int setup_intr_remapping(struct intel_iommu *iommu, int mode)
  355. {
  356. struct ir_table *ir_table;
  357. struct page *pages;
  358. ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table),
  359. GFP_ATOMIC);
  360. if (!iommu->ir_table)
  361. return -ENOMEM;
  362. pages = alloc_pages(GFP_ATOMIC | __GFP_ZERO, INTR_REMAP_PAGE_ORDER);
  363. if (!pages) {
  364. printk(KERN_ERR "failed to allocate pages of order %d\n",
  365. INTR_REMAP_PAGE_ORDER);
  366. kfree(iommu->ir_table);
  367. return -ENOMEM;
  368. }
  369. ir_table->base = page_address(pages);
  370. iommu_set_intr_remapping(iommu, mode);
  371. return 0;
  372. }
  373. /*
  374. * Disable Interrupt Remapping.
  375. */
  376. static void iommu_disable_intr_remapping(struct intel_iommu *iommu)
  377. {
  378. unsigned long flags;
  379. u32 sts;
  380. if (!ecap_ir_support(iommu->ecap))
  381. return;
  382. /*
  383. * global invalidation of interrupt entry cache before disabling
  384. * interrupt-remapping.
  385. */
  386. qi_global_iec(iommu);
  387. spin_lock_irqsave(&iommu->register_lock, flags);
  388. sts = dmar_readq(iommu->reg + DMAR_GSTS_REG);
  389. if (!(sts & DMA_GSTS_IRES))
  390. goto end;
  391. iommu->gcmd &= ~DMA_GCMD_IRE;
  392. writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
  393. IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
  394. readl, !(sts & DMA_GSTS_IRES), sts);
  395. end:
  396. spin_unlock_irqrestore(&iommu->register_lock, flags);
  397. }
  398. int __init intr_remapping_supported(void)
  399. {
  400. struct dmar_drhd_unit *drhd;
  401. if (disable_intremap)
  402. return 0;
  403. for_each_drhd_unit(drhd) {
  404. struct intel_iommu *iommu = drhd->iommu;
  405. if (!ecap_ir_support(iommu->ecap))
  406. return 0;
  407. }
  408. return 1;
  409. }
  410. int __init enable_intr_remapping(int eim)
  411. {
  412. struct dmar_drhd_unit *drhd;
  413. int setup = 0;
  414. for_each_drhd_unit(drhd) {
  415. struct intel_iommu *iommu = drhd->iommu;
  416. /*
  417. * If the queued invalidation is already initialized,
  418. * shouldn't disable it.
  419. */
  420. if (iommu->qi)
  421. continue;
  422. /*
  423. * Clear previous faults.
  424. */
  425. dmar_fault(-1, iommu);
  426. /*
  427. * Disable intr remapping and queued invalidation, if already
  428. * enabled prior to OS handover.
  429. */
  430. iommu_disable_intr_remapping(iommu);
  431. dmar_disable_qi(iommu);
  432. }
  433. /*
  434. * check for the Interrupt-remapping support
  435. */
  436. for_each_drhd_unit(drhd) {
  437. struct intel_iommu *iommu = drhd->iommu;
  438. if (!ecap_ir_support(iommu->ecap))
  439. continue;
  440. if (eim && !ecap_eim_support(iommu->ecap)) {
  441. printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, "
  442. " ecap %Lx\n", drhd->reg_base_addr, iommu->ecap);
  443. return -1;
  444. }
  445. }
  446. /*
  447. * Enable queued invalidation for all the DRHD's.
  448. */
  449. for_each_drhd_unit(drhd) {
  450. int ret;
  451. struct intel_iommu *iommu = drhd->iommu;
  452. ret = dmar_enable_qi(iommu);
  453. if (ret) {
  454. printk(KERN_ERR "DRHD %Lx: failed to enable queued, "
  455. " invalidation, ecap %Lx, ret %d\n",
  456. drhd->reg_base_addr, iommu->ecap, ret);
  457. return -1;
  458. }
  459. }
  460. /*
  461. * Setup Interrupt-remapping for all the DRHD's now.
  462. */
  463. for_each_drhd_unit(drhd) {
  464. struct intel_iommu *iommu = drhd->iommu;
  465. if (!ecap_ir_support(iommu->ecap))
  466. continue;
  467. if (setup_intr_remapping(iommu, eim))
  468. goto error;
  469. setup = 1;
  470. }
  471. if (!setup)
  472. goto error;
  473. intr_remapping_enabled = 1;
  474. return 0;
  475. error:
  476. /*
  477. * handle error condition gracefully here!
  478. */
  479. return -1;
  480. }
  481. static int ir_parse_ioapic_scope(struct acpi_dmar_header *header,
  482. struct intel_iommu *iommu)
  483. {
  484. struct acpi_dmar_hardware_unit *drhd;
  485. struct acpi_dmar_device_scope *scope;
  486. void *start, *end;
  487. drhd = (struct acpi_dmar_hardware_unit *)header;
  488. start = (void *)(drhd + 1);
  489. end = ((void *)drhd) + header->length;
  490. while (start < end) {
  491. scope = start;
  492. if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC) {
  493. if (ir_ioapic_num == MAX_IO_APICS) {
  494. printk(KERN_WARNING "Exceeded Max IO APICS\n");
  495. return -1;
  496. }
  497. printk(KERN_INFO "IOAPIC id %d under DRHD base"
  498. " 0x%Lx\n", scope->enumeration_id,
  499. drhd->address);
  500. ir_ioapic[ir_ioapic_num].iommu = iommu;
  501. ir_ioapic[ir_ioapic_num].id = scope->enumeration_id;
  502. ir_ioapic_num++;
  503. }
  504. start += scope->length;
  505. }
  506. return 0;
  507. }
  508. /*
  509. * Finds the assocaition between IOAPIC's and its Interrupt-remapping
  510. * hardware unit.
  511. */
  512. int __init parse_ioapics_under_ir(void)
  513. {
  514. struct dmar_drhd_unit *drhd;
  515. int ir_supported = 0;
  516. for_each_drhd_unit(drhd) {
  517. struct intel_iommu *iommu = drhd->iommu;
  518. if (ecap_ir_support(iommu->ecap)) {
  519. if (ir_parse_ioapic_scope(drhd->hdr, iommu))
  520. return -1;
  521. ir_supported = 1;
  522. }
  523. }
  524. if (ir_supported && ir_ioapic_num != nr_ioapics) {
  525. printk(KERN_WARNING
  526. "Not all IO-APIC's listed under remapping hardware\n");
  527. return -1;
  528. }
  529. return ir_supported;
  530. }
  531. void disable_intr_remapping(void)
  532. {
  533. struct dmar_drhd_unit *drhd;
  534. struct intel_iommu *iommu = NULL;
  535. /*
  536. * Disable Interrupt-remapping for all the DRHD's now.
  537. */
  538. for_each_iommu(iommu, drhd) {
  539. if (!ecap_ir_support(iommu->ecap))
  540. continue;
  541. iommu_disable_intr_remapping(iommu);
  542. }
  543. }
  544. int reenable_intr_remapping(int eim)
  545. {
  546. struct dmar_drhd_unit *drhd;
  547. int setup = 0;
  548. struct intel_iommu *iommu = NULL;
  549. for_each_iommu(iommu, drhd)
  550. if (iommu->qi)
  551. dmar_reenable_qi(iommu);
  552. /*
  553. * Setup Interrupt-remapping for all the DRHD's now.
  554. */
  555. for_each_iommu(iommu, drhd) {
  556. if (!ecap_ir_support(iommu->ecap))
  557. continue;
  558. /* Set up interrupt remapping for iommu.*/
  559. iommu_set_intr_remapping(iommu, eim);
  560. setup = 1;
  561. }
  562. if (!setup)
  563. goto error;
  564. return 0;
  565. error:
  566. /*
  567. * handle error condition gracefully here!
  568. */
  569. return -1;
  570. }