Skip to content

Commit b02002c

Browse files
niklas88Vasily Gorbik
authored andcommitted
s390/pci: Implement ioremap_wc/prot() with MIO
With our current support for the new MIO PCI instructions, write combining/write back MMIO memory can be obtained via the pci_iomap_wc() and pci_iomap_wc_range() functions. This is achieved by using the write back address for a specific bar as provided in clp_store_query_pci_fn() These functions are however not widely used and instead drivers often rely on ioremap_wc() and ioremap_prot(), which on other platforms enable write combining using a PTE flag set through the pgrprot value. While we do not have a write combining flag in the low order flag bits of the PTE like x86_64 does, with MIO support, there is a write back bit in the physical address (bit 1 on z15) and thus also the PTE. Which bit is used to toggle write back and whether it is available at all, is however not fixed in the architecture. Instead we get this information from the CLP Store Logical Processor Characteristics for PCI command. When the write back bit is not provided we fall back to the existing behavior. Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Reviewed-by: Pierre Morel <pmorel@linux.ibm.com> Reviewed-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 4d4a3ca commit b02002c

11 files changed

Lines changed: 132 additions & 5 deletions

File tree

‎Documentation/features/vm/ioremap_prot/arch-support.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
| parisc: | TODO |
2525
| powerpc: | ok |
2626
| riscv: | TODO |
27-
| s390: | TODO |
27+
| s390: | ok |
2828
| sh: | ok |
2929
| sparc: | TODO |
3030
| um: | TODO |

‎arch/s390/include/asm/clp.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/* CLP common request & response block size */
66
#define CLP_BLK_SIZE PAGE_SIZE
77

8+
/* Call Logical Processor - Command Code */
9+
#define CLP_SLPC 0x0001
10+
811
#define CLP_LPS_BASE 0
912
#define CLP_LPS_PCI 2
1013

‎arch/s390/include/asm/io.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <linux/kernel.h>
1414
#include <asm/page.h>
15+
#include <asm/pgtable.h>
1516
#include <asm/pci_io.h>
1617

1718
#define xlate_dev_mem_ptr xlate_dev_mem_ptr
@@ -26,7 +27,10 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
2627

2728
#define IO_SPACE_LIMIT 0
2829

30+
void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot);
2931
void __iomem *ioremap(phys_addr_t addr, size_t size);
32+
void __iomem *ioremap_wc(phys_addr_t addr, size_t size);
33+
void __iomem *ioremap_wt(phys_addr_t addr, size_t size);
3034
void iounmap(volatile void __iomem *addr);
3135

3236
static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
@@ -52,6 +56,10 @@ static inline void ioport_unmap(void __iomem *p)
5256
#define pci_iomap_wc pci_iomap_wc
5357
#define pci_iomap_wc_range pci_iomap_wc_range
5458

59+
#define ioremap ioremap
60+
#define ioremap_wt ioremap_wt
61+
#define ioremap_wc ioremap_wc
62+
5563
#define memcpy_fromio(dst, src, count) zpci_memcpy_fromio(dst, src, count)
5664
#define memcpy_toio(dst, src, count) zpci_memcpy_toio(dst, src, count)
5765
#define memset_io(dst, val, count) zpci_memset_io(dst, val, count)

‎arch/s390/include/asm/pci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ int zpci_unregister_ioat(struct zpci_dev *, u8);
208208
void zpci_remove_reserved_devices(void);
209209

210210
/* CLP */
211+
int clp_setup_writeback_mio(void);
211212
int clp_scan_pci_devices(void);
212213
int clp_rescan_pci_devices(void);
213214
int clp_rescan_pci_devices_simple(u32 *fid);

‎arch/s390/include/asm/pci_clp.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/*
88
* Call Logical Processor - Command Codes
99
*/
10+
#define CLP_SLPC 0x0001
1011
#define CLP_LIST_PCI 0x0002
1112
#define CLP_QUERY_PCI_FN 0x0003
1213
#define CLP_QUERY_PCI_FNGRP 0x0004
@@ -51,6 +52,19 @@ struct clp_fh_list_entry {
5152

5253
extern bool zpci_unique_uid;
5354

55+
struct clp_rsp_slpc_pci {
56+
struct clp_rsp_hdr hdr;
57+
u32 reserved2[4];
58+
u32 lpif[8];
59+
u32 reserved3[4];
60+
u32 vwb : 1;
61+
u32 : 1;
62+
u32 mio_wb : 6;
63+
u32 : 24;
64+
u32 reserved5[3];
65+
u32 lpic[8];
66+
} __packed;
67+
5468
/* List PCI functions request */
5569
struct clp_req_list_pci {
5670
struct clp_req_hdr hdr;
@@ -172,6 +186,11 @@ struct clp_rsp_set_pci {
172186
} __packed;
173187

174188
/* Combined request/response block structures used by clp insn */
189+
struct clp_req_rsp_slpc_pci {
190+
struct clp_req_slpc request;
191+
struct clp_rsp_slpc_pci response;
192+
} __packed;
193+
175194
struct clp_req_rsp_list_pci {
176195
struct clp_req_list_pci request;
177196
struct clp_rsp_list_pci response;

‎arch/s390/include/asm/pgtable.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,12 @@ void gmap_pmdp_invalidate(struct mm_struct *mm, unsigned long vmaddr);
11861186
void gmap_pmdp_idte_local(struct mm_struct *mm, unsigned long vmaddr);
11871187
void gmap_pmdp_idte_global(struct mm_struct *mm, unsigned long vmaddr);
11881188

1189+
#define pgprot_writecombine pgprot_writecombine
1190+
pgprot_t pgprot_writecombine(pgprot_t prot);
1191+
1192+
#define pgprot_writethrough pgprot_writethrough
1193+
pgprot_t pgprot_writethrough(pgprot_t prot);
1194+
11891195
/*
11901196
* Certain architectures need to do special things when PTEs
11911197
* within a page table are directly modified. Thus, the following
@@ -1209,7 +1215,8 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
12091215
static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
12101216
{
12111217
pte_t __pte;
1212-
pte_val(__pte) = physpage + pgprot_val(pgprot);
1218+
1219+
pte_val(__pte) = physpage | pgprot_val(pgprot);
12131220
if (!MACHINE_HAS_NX)
12141221
pte_val(__pte) &= ~_PAGE_NOEXEC;
12151222
return pte_mkyoung(__pte);

‎arch/s390/include/asm/setup.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ extern unsigned long vmalloc_size;
9494
extern unsigned long max_physmem_end;
9595
extern unsigned long __swsusp_reset_dma;
9696

97+
/* The Write Back bit position in the physaddr is given by the SLPC PCI */
98+
extern unsigned long mio_wb_bit_mask;
99+
97100
#define MACHINE_IS_VM (S390_lowcore.machine_flags & MACHINE_FLAG_VM)
98101
#define MACHINE_IS_KVM (S390_lowcore.machine_flags & MACHINE_FLAG_KVM)
99102
#define MACHINE_IS_LPAR (S390_lowcore.machine_flags & MACHINE_FLAG_LPAR)

‎arch/s390/kernel/setup.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ unsigned long MODULES_END;
127127
struct lowcore *lowcore_ptr[NR_CPUS];
128128
EXPORT_SYMBOL(lowcore_ptr);
129129

130+
/*
131+
* The Write Back bit position in the physaddr is given by the SLPC PCI.
132+
* Leaving the mask zero always uses write through which is safe
133+
*/
134+
unsigned long mio_wb_bit_mask __ro_after_init;
135+
130136
/*
131137
* This is set up by the setup-routine at boot-time
132138
* for S390 need to find out, what we have to setup

‎arch/s390/mm/pgtable.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
#include <asm/mmu_context.h>
2525
#include <asm/page-states.h>
2626

27+
pgprot_t pgprot_writecombine(pgprot_t prot)
28+
{
29+
/*
30+
* mio_wb_bit_mask may be set on a different CPU, but it is only set
31+
* once at init and only read afterwards.
32+
*/
33+
return __pgprot(pgprot_val(prot) | mio_wb_bit_mask);
34+
}
35+
EXPORT_SYMBOL_GPL(pgprot_writecombine);
36+
37+
pgprot_t pgprot_writethrough(pgprot_t prot)
38+
{
39+
/*
40+
* mio_wb_bit_mask may be set on a different CPU, but it is only set
41+
* once at init and only read afterwards.
42+
*/
43+
return __pgprot(pgprot_val(prot) & ~mio_wb_bit_mask);
44+
}
45+
EXPORT_SYMBOL_GPL(pgprot_writethrough);
46+
2747
static inline void ptep_ipte_local(struct mm_struct *mm, unsigned long addr,
2848
pte_t *ptep, int nodat)
2949
{

‎arch/s390/pci/pci.c‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
226226
zpci_memcpy_toio(to, from, count);
227227
}
228228

229-
void __iomem *ioremap(phys_addr_t addr, size_t size)
229+
static void __iomem *__ioremap(phys_addr_t addr, size_t size, pgprot_t prot)
230230
{
231231
unsigned long offset, vaddr;
232232
struct vm_struct *area;
@@ -247,14 +247,37 @@ void __iomem *ioremap(phys_addr_t addr, size_t size)
247247
return NULL;
248248

249249
vaddr = (unsigned long) area->addr;
250-
if (ioremap_page_range(vaddr, vaddr + size, addr, PAGE_KERNEL)) {
250+
if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) {
251251
free_vm_area(area);
252252
return NULL;
253253
}
254254
return (void __iomem *) ((unsigned long) area->addr + offset);
255255
}
256+
257+
void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot)
258+
{
259+
return __ioremap(addr, size, __pgprot(prot));
260+
}
261+
EXPORT_SYMBOL(ioremap_prot);
262+
263+
void __iomem *ioremap(phys_addr_t addr, size_t size)
264+
{
265+
return __ioremap(addr, size, PAGE_KERNEL);
266+
}
256267
EXPORT_SYMBOL(ioremap);
257268

269+
void __iomem *ioremap_wc(phys_addr_t addr, size_t size)
270+
{
271+
return __ioremap(addr, size, pgprot_writecombine(PAGE_KERNEL));
272+
}
273+
EXPORT_SYMBOL(ioremap_wc);
274+
275+
void __iomem *ioremap_wt(phys_addr_t addr, size_t size)
276+
{
277+
return __ioremap(addr, size, pgprot_writethrough(PAGE_KERNEL));
278+
}
279+
EXPORT_SYMBOL(ioremap_wt);
280+
258281
void iounmap(volatile void __iomem *addr)
259282
{
260283
if (static_branch_likely(&have_mio))
@@ -784,6 +807,9 @@ static int zpci_mem_init(void)
784807
if (!zpci_iomap_bitmap)
785808
goto error_iomap_bitmap;
786809

810+
if (static_branch_likely(&have_mio))
811+
clp_setup_writeback_mio();
812+
787813
return 0;
788814
error_iomap_bitmap:
789815
kfree(zpci_iomap_start);

0 commit comments

Comments
 (0)