2 * This file implements the DMA operations for NVLink devices. The NPU
3 * devices all point to the same iommu table as the parent PCI device.
5 * Copyright Alistair Popple, IBM Corporation 2015.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2 of the GNU General Public
9 * License as published by the Free Software Foundation.
12 #include <linux/slab.h>
13 #include <linux/mmu_notifier.h>
14 #include <linux/mmu_context.h>
16 #include <linux/export.h>
17 #include <linux/pci.h>
18 #include <linux/memblock.h>
19 #include <linux/iommu.h>
22 #include <asm/powernv.h>
26 #include <asm/iommu.h>
27 #include <asm/pnv-pci.h>
28 #include <asm/msi_bitmap.h>
34 #define npu_to_phb(x) container_of(x, struct pnv_phb, npu)
37 * When an address shootdown range exceeds this threshold we invalidate the
38 * entire TLB on the GPU for the given PID rather than each specific address in
41 #define ATSD_THRESHOLD (2*1024*1024)
44 * Other types of TCE cache invalidation are not functional in the
47 static struct pci_dev *get_pci_dev(struct device_node *dn)
49 return PCI_DN(dn)->pcidev;
52 /* Given a NPU device get the associated PCI device. */
53 struct pci_dev *pnv_pci_get_gpu_dev(struct pci_dev *npdev)
55 struct device_node *dn;
56 struct pci_dev *gpdev;
61 if (WARN_ON(!npdev->dev.of_node))
64 /* Get assoicated PCI device */
65 dn = of_parse_phandle(npdev->dev.of_node, "ibm,gpu", 0);
69 gpdev = get_pci_dev(dn);
74 EXPORT_SYMBOL(pnv_pci_get_gpu_dev);
76 /* Given the real PCI device get a linked NPU device. */
77 struct pci_dev *pnv_pci_get_npu_dev(struct pci_dev *gpdev, int index)
79 struct device_node *dn;
80 struct pci_dev *npdev;
85 /* Not all PCI devices have device-tree nodes */
86 if (!gpdev->dev.of_node)
89 /* Get assoicated PCI device */
90 dn = of_parse_phandle(gpdev->dev.of_node, "ibm,npu", index);
94 npdev = get_pci_dev(dn);
99 EXPORT_SYMBOL(pnv_pci_get_npu_dev);
101 #define NPU_DMA_OP_UNSUPPORTED() \
102 dev_err_once(dev, "%s operation unsupported for NVLink devices\n", \
105 static void *dma_npu_alloc(struct device *dev, size_t size,
106 dma_addr_t *dma_handle, gfp_t flag,
109 NPU_DMA_OP_UNSUPPORTED();
113 static void dma_npu_free(struct device *dev, size_t size,
114 void *vaddr, dma_addr_t dma_handle,
117 NPU_DMA_OP_UNSUPPORTED();
120 static dma_addr_t dma_npu_map_page(struct device *dev, struct page *page,
121 unsigned long offset, size_t size,
122 enum dma_data_direction direction,
125 NPU_DMA_OP_UNSUPPORTED();
129 static int dma_npu_map_sg(struct device *dev, struct scatterlist *sglist,
130 int nelems, enum dma_data_direction direction,
133 NPU_DMA_OP_UNSUPPORTED();
137 static int dma_npu_dma_supported(struct device *dev, u64 mask)
139 NPU_DMA_OP_UNSUPPORTED();
143 static u64 dma_npu_get_required_mask(struct device *dev)
145 NPU_DMA_OP_UNSUPPORTED();
149 static const struct dma_map_ops dma_npu_ops = {
150 .map_page = dma_npu_map_page,
151 .map_sg = dma_npu_map_sg,
152 .alloc = dma_npu_alloc,
153 .free = dma_npu_free,
154 .dma_supported = dma_npu_dma_supported,
155 .get_required_mask = dma_npu_get_required_mask,
159 * Returns the PE assoicated with the PCI device of the given
160 * NPU. Returns the linked pci device if pci_dev != NULL.
162 static struct pnv_ioda_pe *get_gpu_pci_dev_and_pe(struct pnv_ioda_pe *npe,
163 struct pci_dev **gpdev)
166 struct pci_controller *hose;
167 struct pci_dev *pdev;
168 struct pnv_ioda_pe *pe;
171 pdev = pnv_pci_get_gpu_dev(npe->pdev);
175 pdn = pci_get_pdn(pdev);
176 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
179 hose = pci_bus_to_host(pdev->bus);
180 phb = hose->private_data;
181 pe = &phb->ioda.pe_array[pdn->pe_number];
189 long pnv_npu_set_window(struct pnv_ioda_pe *npe, int num,
190 struct iommu_table *tbl)
192 struct pnv_phb *phb = npe->phb;
194 const unsigned long size = tbl->it_indirect_levels ?
195 tbl->it_level_size : tbl->it_size;
196 const __u64 start_addr = tbl->it_offset << tbl->it_page_shift;
197 const __u64 win_size = tbl->it_size << tbl->it_page_shift;
199 pe_info(npe, "Setting up window %llx..%llx pg=%lx\n",
200 start_addr, start_addr + win_size - 1,
201 IOMMU_PAGE_SIZE(tbl));
203 rc = opal_pci_map_pe_dma_window(phb->opal_id,
206 tbl->it_indirect_levels + 1,
209 IOMMU_PAGE_SIZE(tbl));
211 pe_err(npe, "Failed to configure TCE table, err %lld\n", rc);
214 pnv_pci_ioda2_tce_invalidate_entire(phb, false);
216 /* Add the table to the list so its TCE cache will get invalidated */
217 pnv_pci_link_table_and_group(phb->hose->node, num,
218 tbl, &npe->table_group);
223 long pnv_npu_unset_window(struct pnv_ioda_pe *npe, int num)
225 struct pnv_phb *phb = npe->phb;
228 pe_info(npe, "Removing DMA window\n");
230 rc = opal_pci_map_pe_dma_window(phb->opal_id, npe->pe_number,
232 0/* levels */, 0/* table address */,
233 0/* table size */, 0/* page size */);
235 pe_err(npe, "Unmapping failed, ret = %lld\n", rc);
238 pnv_pci_ioda2_tce_invalidate_entire(phb, false);
240 pnv_pci_unlink_table_and_group(npe->table_group.tables[num],
247 * Enables 32 bit DMA on NPU.
249 static void pnv_npu_dma_set_32(struct pnv_ioda_pe *npe)
251 struct pci_dev *gpdev;
252 struct pnv_ioda_pe *gpe;
256 * Find the assoicated PCI devices and get the dma window
257 * information from there.
259 if (!npe->pdev || !(npe->flags & PNV_IODA_PE_DEV))
262 gpe = get_gpu_pci_dev_and_pe(npe, &gpdev);
266 rc = pnv_npu_set_window(npe, 0, gpe->table_group.tables[0]);
269 * We don't initialise npu_pe->tce32_table as we always use
270 * dma_npu_ops which are nops.
272 set_dma_ops(&npe->pdev->dev, &dma_npu_ops);
276 * Enables bypass mode on the NPU. The NPU only supports one
277 * window per link, so bypass needs to be explicitly enabled or
278 * disabled. Unlike for a PHB3 bypass and non-bypass modes can't be
279 * active at the same time.
281 static int pnv_npu_dma_set_bypass(struct pnv_ioda_pe *npe)
283 struct pnv_phb *phb = npe->phb;
285 phys_addr_t top = memblock_end_of_DRAM();
287 if (phb->type != PNV_PHB_NPU || !npe->pdev)
290 rc = pnv_npu_unset_window(npe, 0);
291 if (rc != OPAL_SUCCESS)
294 /* Enable the bypass window */
296 top = roundup_pow_of_two(top);
297 dev_info(&npe->pdev->dev, "Enabling bypass for PE %x\n",
299 rc = opal_pci_map_pe_dma_window_real(phb->opal_id,
300 npe->pe_number, npe->pe_number,
301 0 /* bypass base */, top);
303 if (rc == OPAL_SUCCESS)
304 pnv_pci_ioda2_tce_invalidate_entire(phb, false);
309 void pnv_npu_try_dma_set_bypass(struct pci_dev *gpdev, bool bypass)
314 struct pnv_ioda_pe *npe;
315 struct pci_dev *npdev;
318 npdev = pnv_pci_get_npu_dev(gpdev, i);
323 pdn = pci_get_pdn(npdev);
324 if (WARN_ON(!pdn || pdn->pe_number == IODA_INVALID_PE))
327 phb = pci_bus_to_host(npdev->bus)->private_data;
329 /* We only do bypass if it's enabled on the linked device */
330 npe = &phb->ioda.pe_array[pdn->pe_number];
333 dev_info(&npdev->dev,
334 "Using 64-bit DMA iommu bypass\n");
335 pnv_npu_dma_set_bypass(npe);
337 dev_info(&npdev->dev, "Using 32-bit DMA via iommu\n");
338 pnv_npu_dma_set_32(npe);
343 /* Switch ownership from platform code to external user (e.g. VFIO) */
344 void pnv_npu_take_ownership(struct pnv_ioda_pe *npe)
346 struct pnv_phb *phb = npe->phb;
350 * Note: NPU has just a single TVE in the hardware which means that
351 * while used by the kernel, it can have either 32bit window or
352 * DMA bypass but never both. So we deconfigure 32bit window only
353 * if it was enabled at the moment of ownership change.
355 if (npe->table_group.tables[0]) {
356 pnv_npu_unset_window(npe, 0);
361 rc = opal_pci_map_pe_dma_window_real(phb->opal_id,
362 npe->pe_number, npe->pe_number,
363 0 /* bypass base */, 0);
365 pe_err(npe, "Failed to disable bypass, err %lld\n", rc);
368 pnv_pci_ioda2_tce_invalidate_entire(npe->phb, false);
371 struct pnv_ioda_pe *pnv_pci_npu_setup_iommu(struct pnv_ioda_pe *npe)
373 struct pnv_phb *phb = npe->phb;
374 struct pci_bus *pbus = phb->hose->bus;
375 struct pci_dev *npdev, *gpdev = NULL, *gptmp;
376 struct pnv_ioda_pe *gpe = get_gpu_pci_dev_and_pe(npe, &gpdev);
381 list_for_each_entry(npdev, &pbus->devices, bus_list) {
382 gptmp = pnv_pci_get_gpu_dev(npdev);
387 pe_info(gpe, "Attached NPU %s\n", dev_name(&npdev->dev));
388 iommu_group_add_device(gpe->table_group.group, &npdev->dev);
394 /* Maximum number of nvlinks per npu */
395 #define NV_MAX_LINKS 6
397 /* Maximum index of npu2 hosts in the system. Always < NV_MAX_NPUS */
398 static int max_npu2_index;
401 struct mm_struct *mm;
402 struct pci_dev *npdev[NV_MAX_NPUS][NV_MAX_LINKS];
403 struct mmu_notifier mn;
406 /* Callback to stop translation requests on a given GPU */
407 struct npu_context *(*release_cb)(struct npu_context *, void *);
410 * Private pointer passed to the above callback for usage by
416 struct mmio_atsd_reg {
422 * Find a free MMIO ATSD register and mark it in use. Return -ENOSPC
423 * if none are available.
425 static int get_mmio_atsd_reg(struct npu *npu)
429 for (i = 0; i < npu->mmio_atsd_count; i++) {
430 if (!test_bit(i, &npu->mmio_atsd_usage))
431 if (!test_and_set_bit_lock(i, &npu->mmio_atsd_usage))
438 static void put_mmio_atsd_reg(struct npu *npu, int reg)
440 clear_bit_unlock(reg, &npu->mmio_atsd_usage);
443 /* MMIO ATSD register offsets */
444 #define XTS_ATSD_AVA 1
445 #define XTS_ATSD_STAT 2
447 static void mmio_launch_invalidate(struct mmio_atsd_reg *mmio_atsd_reg,
448 unsigned long launch, unsigned long va)
450 struct npu *npu = mmio_atsd_reg->npu;
451 int reg = mmio_atsd_reg->reg;
453 __raw_writeq(cpu_to_be64(va),
454 npu->mmio_atsd_regs[reg] + XTS_ATSD_AVA);
456 __raw_writeq(cpu_to_be64(launch), npu->mmio_atsd_regs[reg]);
459 static void mmio_invalidate_pid(struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS],
460 unsigned long pid, bool flush)
463 unsigned long launch;
465 for (i = 0; i <= max_npu2_index; i++) {
466 if (mmio_atsd_reg[i].reg < 0)
469 /* IS set to invalidate matching PID */
470 launch = PPC_BIT(12);
472 /* PRS set to process-scoped */
473 launch |= PPC_BIT(13);
477 mmu_get_ap(mmu_virtual_psize) << PPC_BITLSHIFT(17);
480 launch |= pid << PPC_BITLSHIFT(38);
483 launch |= !flush << PPC_BITLSHIFT(39);
485 /* Invalidating the entire process doesn't use a va */
486 mmio_launch_invalidate(&mmio_atsd_reg[i], launch, 0);
490 static void mmio_invalidate_va(struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS],
491 unsigned long va, unsigned long pid, bool flush)
494 unsigned long launch;
496 for (i = 0; i <= max_npu2_index; i++) {
497 if (mmio_atsd_reg[i].reg < 0)
500 /* IS set to invalidate target VA */
503 /* PRS set to process scoped */
504 launch |= PPC_BIT(13);
508 mmu_get_ap(mmu_virtual_psize) << PPC_BITLSHIFT(17);
511 launch |= pid << PPC_BITLSHIFT(38);
514 launch |= !flush << PPC_BITLSHIFT(39);
516 mmio_launch_invalidate(&mmio_atsd_reg[i], launch, va);
520 #define mn_to_npu_context(x) container_of(x, struct npu_context, mn)
522 static void mmio_invalidate_wait(
523 struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS])
528 /* Wait for all invalidations to complete */
529 for (i = 0; i <= max_npu2_index; i++) {
530 if (mmio_atsd_reg[i].reg < 0)
533 /* Wait for completion */
534 npu = mmio_atsd_reg[i].npu;
535 reg = mmio_atsd_reg[i].reg;
536 while (__raw_readq(npu->mmio_atsd_regs[reg] + XTS_ATSD_STAT))
542 * Acquires all the address translation shootdown (ATSD) registers required to
543 * launch an ATSD on all links this npu_context is active on.
545 static void acquire_atsd_reg(struct npu_context *npu_context,
546 struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS])
550 struct pci_dev *npdev;
551 struct pnv_phb *nphb;
553 for (i = 0; i <= max_npu2_index; i++) {
554 mmio_atsd_reg[i].reg = -1;
555 for (j = 0; j < NV_MAX_LINKS; j++) {
557 * There are no ordering requirements with respect to
558 * the setup of struct npu_context, but to ensure
559 * consistent behaviour we need to ensure npdev[][] is
562 npdev = READ_ONCE(npu_context->npdev[i][j]);
566 nphb = pci_bus_to_host(npdev->bus)->private_data;
568 mmio_atsd_reg[i].npu = npu;
569 mmio_atsd_reg[i].reg = get_mmio_atsd_reg(npu);
570 while (mmio_atsd_reg[i].reg < 0) {
571 mmio_atsd_reg[i].reg = get_mmio_atsd_reg(npu);
580 * Release previously acquired ATSD registers. To avoid deadlocks the registers
581 * must be released in the same order they were acquired above in
584 static void release_atsd_reg(struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS])
588 for (i = 0; i <= max_npu2_index; i++) {
590 * We can't rely on npu_context->npdev[][] being the same here
591 * as when acquire_atsd_reg() was called, hence we use the
592 * values stored in mmio_atsd_reg during the acquire phase
593 * rather than re-reading npdev[][].
595 if (mmio_atsd_reg[i].reg < 0)
598 put_mmio_atsd_reg(mmio_atsd_reg[i].npu, mmio_atsd_reg[i].reg);
603 * Invalidate either a single address or an entire PID depending on
606 static void mmio_invalidate(struct npu_context *npu_context, int va,
607 unsigned long address, bool flush)
609 struct mmio_atsd_reg mmio_atsd_reg[NV_MAX_NPUS];
610 unsigned long pid = npu_context->mm->context.id;
613 * Unfortunately the nest mmu does not support flushing specific
614 * addresses so we have to flush the whole mm.
616 flush_tlb_mm(npu_context->mm);
619 * Loop over all the NPUs this process is active on and launch
622 acquire_atsd_reg(npu_context, mmio_atsd_reg);
624 mmio_invalidate_va(mmio_atsd_reg, address, pid, flush);
626 mmio_invalidate_pid(mmio_atsd_reg, pid, flush);
628 mmio_invalidate_wait(mmio_atsd_reg);
631 * The GPU requires two flush ATSDs to ensure all entries have
632 * been flushed. We use PID 0 as it will never be used for a
633 * process on the GPU.
635 mmio_invalidate_pid(mmio_atsd_reg, 0, true);
636 mmio_invalidate_wait(mmio_atsd_reg);
637 mmio_invalidate_pid(mmio_atsd_reg, 0, true);
638 mmio_invalidate_wait(mmio_atsd_reg);
640 release_atsd_reg(mmio_atsd_reg);
643 static void pnv_npu2_mn_release(struct mmu_notifier *mn,
644 struct mm_struct *mm)
646 struct npu_context *npu_context = mn_to_npu_context(mn);
648 /* Call into device driver to stop requests to the NMMU */
649 if (npu_context->release_cb)
650 npu_context->release_cb(npu_context, npu_context->priv);
653 * There should be no more translation requests for this PID, but we
654 * need to ensure any entries for it are removed from the TLB.
656 mmio_invalidate(npu_context, 0, 0, true);
659 static void pnv_npu2_mn_change_pte(struct mmu_notifier *mn,
660 struct mm_struct *mm,
661 unsigned long address,
664 struct npu_context *npu_context = mn_to_npu_context(mn);
666 mmio_invalidate(npu_context, 1, address, true);
669 static void pnv_npu2_mn_invalidate_range(struct mmu_notifier *mn,
670 struct mm_struct *mm,
671 unsigned long start, unsigned long end)
673 struct npu_context *npu_context = mn_to_npu_context(mn);
674 unsigned long address;
676 if (end - start > ATSD_THRESHOLD) {
678 * Just invalidate the entire PID if the address range is too
681 mmio_invalidate(npu_context, 0, 0, true);
683 for (address = start; address < end; address += PAGE_SIZE)
684 mmio_invalidate(npu_context, 1, address, false);
686 /* Do the flush only on the final addess == end */
687 mmio_invalidate(npu_context, 1, address, true);
691 static const struct mmu_notifier_ops nv_nmmu_notifier_ops = {
692 .release = pnv_npu2_mn_release,
693 .change_pte = pnv_npu2_mn_change_pte,
694 .invalidate_range = pnv_npu2_mn_invalidate_range,
698 * Call into OPAL to setup the nmmu context for the current task in
699 * the NPU. This must be called to setup the context tables before the
700 * GPU issues ATRs. pdev should be a pointed to PCIe GPU device.
702 * A release callback should be registered to allow a device driver to
703 * be notified that it should not launch any new translation requests
704 * as the final TLB invalidate is about to occur.
706 * Returns an error if there no contexts are currently available or a
707 * npu_context which should be passed to pnv_npu2_handle_fault().
709 * mmap_sem must be held in write mode.
711 struct npu_context *pnv_npu2_init_context(struct pci_dev *gpdev,
713 struct npu_context *(*cb)(struct npu_context *, void *),
718 struct device_node *nvlink_dn;
719 struct mm_struct *mm = current->mm;
720 struct pnv_phb *nphb;
722 struct npu_context *npu_context;
725 * At present we don't support GPUs connected to multiple NPUs and I'm
726 * not sure the hardware does either.
728 struct pci_dev *npdev = pnv_pci_get_npu_dev(gpdev, 0);
730 if (!firmware_has_feature(FW_FEATURE_OPAL))
731 return ERR_PTR(-ENODEV);
734 /* No nvlink associated with this GPU device */
735 return ERR_PTR(-ENODEV);
737 if (!mm || mm->context.id == 0) {
739 * Kernel thread contexts are not supported and context id 0 is
740 * reserved on the GPU.
742 return ERR_PTR(-EINVAL);
745 nphb = pci_bus_to_host(npdev->bus)->private_data;
749 * Setup the NPU context table for a particular GPU. These need to be
750 * per-GPU as we need the tables to filter ATSDs when there are no
751 * active contexts on a particular GPU.
753 rc = opal_npu_init_context(nphb->opal_id, mm->context.id, flags,
754 PCI_DEVID(gpdev->bus->number, gpdev->devfn));
756 return ERR_PTR(-ENOSPC);
759 * We store the npu pci device so we can more easily get at the
762 npu_context = mm->context.npu_context;
764 npu_context = kzalloc(sizeof(struct npu_context), GFP_KERNEL);
766 return ERR_PTR(-ENOMEM);
768 mm->context.npu_context = npu_context;
769 npu_context->mm = mm;
770 npu_context->mn.ops = &nv_nmmu_notifier_ops;
771 __mmu_notifier_register(&npu_context->mn, mm);
772 kref_init(&npu_context->kref);
774 kref_get(&npu_context->kref);
777 npu_context->release_cb = cb;
778 npu_context->priv = priv;
779 nvlink_dn = of_parse_phandle(npdev->dev.of_node, "ibm,nvlink", 0);
780 if (WARN_ON(of_property_read_u32(nvlink_dn, "ibm,npu-link-index",
782 return ERR_PTR(-ENODEV);
785 * npdev is a pci_dev pointer setup by the PCI code. We assign it to
786 * npdev[][] to indicate to the mmu notifiers that an invalidation
787 * should also be sent over this nvlink. The notifiers don't use any
788 * other fields in npu_context, so we just need to ensure that when they
789 * deference npu_context->npdev[][] it is either a valid pointer or
792 WRITE_ONCE(npu_context->npdev[npu->index][nvlink_index], npdev);
796 EXPORT_SYMBOL(pnv_npu2_init_context);
798 static void pnv_npu2_release_context(struct kref *kref)
800 struct npu_context *npu_context =
801 container_of(kref, struct npu_context, kref);
803 npu_context->mm->context.npu_context = NULL;
804 mmu_notifier_unregister(&npu_context->mn,
810 void pnv_npu2_destroy_context(struct npu_context *npu_context,
811 struct pci_dev *gpdev)
813 struct pnv_phb *nphb;
815 struct pci_dev *npdev = pnv_pci_get_npu_dev(gpdev, 0);
816 struct device_node *nvlink_dn;
822 if (!firmware_has_feature(FW_FEATURE_OPAL))
825 nphb = pci_bus_to_host(npdev->bus)->private_data;
827 nvlink_dn = of_parse_phandle(npdev->dev.of_node, "ibm,nvlink", 0);
828 if (WARN_ON(of_property_read_u32(nvlink_dn, "ibm,npu-link-index",
831 WRITE_ONCE(npu_context->npdev[npu->index][nvlink_index], NULL);
832 opal_npu_destroy_context(nphb->opal_id, npu_context->mm->context.id,
833 PCI_DEVID(gpdev->bus->number, gpdev->devfn));
834 kref_put(&npu_context->kref, pnv_npu2_release_context);
836 EXPORT_SYMBOL(pnv_npu2_destroy_context);
839 * Assumes mmap_sem is held for the contexts associated mm.
841 int pnv_npu2_handle_fault(struct npu_context *context, uintptr_t *ea,
842 unsigned long *flags, unsigned long *status, int count)
844 u64 rc = 0, result = 0;
846 struct page *page[1];
848 /* mmap_sem should be held so the struct_mm must be present */
849 struct mm_struct *mm = context->mm;
851 if (!firmware_has_feature(FW_FEATURE_OPAL))
854 WARN_ON(!rwsem_is_locked(&mm->mmap_sem));
856 for (i = 0; i < count; i++) {
857 is_write = flags[i] & NPU2_WRITE;
858 rc = get_user_pages_remote(NULL, mm, ea[i], 1,
859 is_write ? FOLL_WRITE : 0,
863 * To support virtualised environments we will have to do an
864 * access to the page to ensure it gets faulted into the
865 * hypervisor. For the moment virtualisation is not supported in
866 * other areas so leave the access out.
880 EXPORT_SYMBOL(pnv_npu2_handle_fault);
882 int pnv_npu2_init(struct pnv_phb *phb)
886 struct device_node *dn;
887 struct pci_dev *gpdev;
888 static int npu_index;
891 for_each_child_of_node(phb->hose->dn, dn) {
892 gpdev = pnv_pci_get_gpu_dev(get_pci_dev(dn));
894 rc = opal_npu_map_lpar(phb->opal_id,
895 PCI_DEVID(gpdev->bus->number, gpdev->devfn),
899 "Error %lld mapping device to LPAR\n",
904 for (i = 0; !of_property_read_u64_index(phb->hose->dn, "ibm,mmio-atsd",
906 phb->npu.mmio_atsd_regs[i] = ioremap(mmio_atsd, 32);
908 pr_info("NPU%lld: Found %d MMIO ATSD registers", phb->opal_id, i);
909 phb->npu.mmio_atsd_count = i;
910 phb->npu.mmio_atsd_usage = 0;
912 if (WARN_ON(npu_index >= NV_MAX_NPUS))
914 max_npu2_index = npu_index;
915 phb->npu.index = npu_index;