Skip to content

Commit 1ab66d1

Browse files
apopplempe
authored andcommitted
powerpc/powernv: Introduce address translation services for Nvlink2
Nvlink2 supports address translation services (ATS) allowing devices to request address translations from an mmu known as the nest MMU which is setup to walk the CPU page tables. To access this functionality certain firmware calls are required to setup and manage hardware context tables in the nvlink processing unit (NPU). The NPU also manages forwarding of TLB invalidates (known as address translation shootdowns/ATSDs) to attached devices. This patch exports several methods to allow device drivers to register a process id (PASID/PID) in the hardware tables and to receive notification of when a device should stop issuing address translation requests (ATRs). It also adds a fault handler to allow device drivers to demand fault pages in. Signed-off-by: Alistair Popple <[email protected]> [mpe: Fix up comment formatting, use flush_tlb_mm()] Signed-off-by: Michael Ellerman <[email protected]>
1 parent 4c3b89e commit 1ab66d1

File tree

9 files changed

+508
-2
lines changed

9 files changed

+508
-2
lines changed

arch/powerpc/include/asm/book3s/64/mmu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,16 @@ extern struct patb_entry *partition_tb;
7575
typedef unsigned long mm_context_id_t;
7676
struct spinlock;
7777

78+
/* Maximum possible number of NPUs in a system. */
79+
#define NV_MAX_NPUS 8
80+
7881
typedef struct {
7982
mm_context_id_t id;
8083
u16 user_psize; /* page size index */
8184

85+
/* NPU NMMU context */
86+
struct npu_context *npu_context;
87+
8288
#ifdef CONFIG_PPC_MM_SLICES
8389
u64 low_slices_psize; /* SLB page size encodings */
8490
unsigned char high_slices_psize[SLICE_ARRAY_SIZE];

arch/powerpc/include/asm/opal-api.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@
168168
#define OPAL_INT_SET_MFRR 125
169169
#define OPAL_PCI_TCE_KILL 126
170170
#define OPAL_NMMU_SET_PTCR 127
171-
#define OPAL_LAST 127
171+
#define OPAL_NPU_INIT_CONTEXT 146
172+
#define OPAL_NPU_DESTROY_CONTEXT 147
173+
#define OPAL_NPU_MAP_LPAR 148
174+
#define OPAL_LAST 148
172175

173176
/* Device tree flags */
174177

arch/powerpc/include/asm/opal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ extern struct device_node *opal_node;
2929

3030
/* API functions */
3131
int64_t opal_invalid_call(void);
32+
int64_t opal_npu_destroy_context(uint64_t phb_id, uint64_t pid, uint64_t bdf);
33+
int64_t opal_npu_init_context(uint64_t phb_id, int pasid, uint64_t msr,
34+
uint64_t bdf);
35+
int64_t opal_npu_map_lpar(uint64_t phb_id, uint64_t bdf, uint64_t lparid,
36+
uint64_t lpcr);
3237
int64_t opal_console_write(int64_t term_number, __be64 *length,
3338
const uint8_t *buffer);
3439
int64_t opal_console_read(int64_t term_number, __be64 *length,

arch/powerpc/include/asm/powernv.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,31 @@
1111
#define _ASM_POWERNV_H
1212

1313
#ifdef CONFIG_PPC_POWERNV
14+
#define NPU2_WRITE 1
1415
extern void powernv_set_nmmu_ptcr(unsigned long ptcr);
16+
extern struct npu_context *pnv_npu2_init_context(struct pci_dev *gpdev,
17+
unsigned long flags,
18+
struct npu_context *(*cb)(struct npu_context *, void *),
19+
void *priv);
20+
extern void pnv_npu2_destroy_context(struct npu_context *context,
21+
struct pci_dev *gpdev);
22+
extern int pnv_npu2_handle_fault(struct npu_context *context, uintptr_t *ea,
23+
unsigned long *flags, unsigned long *status,
24+
int count);
1525
#else
1626
static inline void powernv_set_nmmu_ptcr(unsigned long ptcr) { }
27+
static inline struct npu_context *pnv_npu2_init_context(struct pci_dev *gpdev,
28+
unsigned long flags,
29+
struct npu_context *(*cb)(struct npu_context *, void *),
30+
void *priv) { return ERR_PTR(-ENODEV); }
31+
static inline void pnv_npu2_destroy_context(struct npu_context *context,
32+
struct pci_dev *gpdev) { }
33+
34+
static inline int pnv_npu2_handle_fault(struct npu_context *context,
35+
uintptr_t *ea, unsigned long *flags,
36+
unsigned long *status, int count) {
37+
return -ENODEV;
38+
}
1739
#endif
1840

1941
#endif /* _ASM_POWERNV_H */

arch/powerpc/mm/mmu_context_book3s64.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ static int radix__init_new_context(struct mm_struct *mm)
138138
rts_field = radix__get_tree_size();
139139
process_tb[index].prtb0 = cpu_to_be64(rts_field | __pa(mm->pgd) | RADIX_PGD_INDEX_SIZE);
140140

141+
mm->context.npu_context = NULL;
142+
141143
return index;
142144
}
143145

0 commit comments

Comments
 (0)