2525#include <linux/export.h>
2626#include <linux/delay.h>
2727#include <linux/seq_file.h>
28+ #include <linux/jump_label.h>
2829#include <linux/pci.h>
2930
3031#include <asm/isc.h>
@@ -50,6 +51,8 @@ static unsigned long *zpci_iomap_bitmap;
5051struct zpci_iomap_entry * zpci_iomap_start ;
5152EXPORT_SYMBOL_GPL (zpci_iomap_start );
5253
54+ DEFINE_STATIC_KEY_FALSE (have_mio );
55+
5356static struct kmem_cache * zdev_fmb_cache ;
5457
5558struct zpci_dev * get_zdev_by_fid (u32 fid )
@@ -223,18 +226,48 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
223226 zpci_memcpy_toio (to , from , count );
224227}
225228
229+ void __iomem * ioremap (unsigned long ioaddr , unsigned long size )
230+ {
231+ struct vm_struct * area ;
232+ unsigned long offset ;
233+
234+ if (!size )
235+ return NULL ;
236+
237+ if (!static_branch_unlikely (& have_mio ))
238+ return (void __iomem * ) ioaddr ;
239+
240+ offset = ioaddr & ~PAGE_MASK ;
241+ ioaddr &= PAGE_MASK ;
242+ size = PAGE_ALIGN (size + offset );
243+ area = get_vm_area (size , VM_IOREMAP );
244+ if (!area )
245+ return NULL ;
246+
247+ if (ioremap_page_range ((unsigned long ) area -> addr ,
248+ (unsigned long ) area -> addr + size ,
249+ ioaddr , PAGE_KERNEL )) {
250+ vunmap (area -> addr );
251+ return NULL ;
252+ }
253+ return (void __iomem * ) ((unsigned long ) area -> addr + offset );
254+ }
255+ EXPORT_SYMBOL (ioremap );
256+
257+ void iounmap (volatile void __iomem * addr )
258+ {
259+ if (static_branch_likely (& have_mio ))
260+ vunmap ((__force void * ) ((unsigned long ) addr & PAGE_MASK ));
261+ }
262+ EXPORT_SYMBOL (iounmap );
263+
226264/* Create a virtual mapping cookie for a PCI BAR */
227- void __iomem * pci_iomap_range (struct pci_dev * pdev ,
228- int bar ,
229- unsigned long offset ,
230- unsigned long max )
265+ static void __iomem * pci_iomap_range_fh (struct pci_dev * pdev , int bar ,
266+ unsigned long offset , unsigned long max )
231267{
232268 struct zpci_dev * zdev = to_zpci (pdev );
233269 int idx ;
234270
235- if (!pci_resource_len (pdev , bar ) || bar >= PCI_BAR_COUNT )
236- return NULL ;
237-
238271 idx = zdev -> bars [bar ].map_idx ;
239272 spin_lock (& zpci_iomap_lock );
240273 /* Detect overrun */
@@ -245,6 +278,30 @@ void __iomem *pci_iomap_range(struct pci_dev *pdev,
245278
246279 return (void __iomem * ) ZPCI_ADDR (idx ) + offset ;
247280}
281+
282+ static void __iomem * pci_iomap_range_mio (struct pci_dev * pdev , int bar ,
283+ unsigned long offset ,
284+ unsigned long max )
285+ {
286+ unsigned long barsize = pci_resource_len (pdev , bar );
287+ struct zpci_dev * zdev = to_zpci (pdev );
288+ void __iomem * iova ;
289+
290+ iova = ioremap ((unsigned long ) zdev -> bars [bar ].mio_wt , barsize );
291+ return iova ? iova + offset : iova ;
292+ }
293+
294+ void __iomem * pci_iomap_range (struct pci_dev * pdev , int bar ,
295+ unsigned long offset , unsigned long max )
296+ {
297+ if (!pci_resource_len (pdev , bar ) || bar >= PCI_BAR_COUNT )
298+ return NULL ;
299+
300+ if (static_branch_likely (& have_mio ))
301+ return pci_iomap_range_mio (pdev , bar , offset , max );
302+ else
303+ return pci_iomap_range_fh (pdev , bar , offset , max );
304+ }
248305EXPORT_SYMBOL (pci_iomap_range );
249306
250307void __iomem * pci_iomap (struct pci_dev * dev , int bar , unsigned long maxlen )
@@ -253,7 +310,37 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
253310}
254311EXPORT_SYMBOL (pci_iomap );
255312
256- void pci_iounmap (struct pci_dev * pdev , void __iomem * addr )
313+ static void __iomem * pci_iomap_wc_range_mio (struct pci_dev * pdev , int bar ,
314+ unsigned long offset , unsigned long max )
315+ {
316+ unsigned long barsize = pci_resource_len (pdev , bar );
317+ struct zpci_dev * zdev = to_zpci (pdev );
318+ void __iomem * iova ;
319+
320+ iova = ioremap ((unsigned long ) zdev -> bars [bar ].mio_wb , barsize );
321+ return iova ? iova + offset : iova ;
322+ }
323+
324+ void __iomem * pci_iomap_wc_range (struct pci_dev * pdev , int bar ,
325+ unsigned long offset , unsigned long max )
326+ {
327+ if (!pci_resource_len (pdev , bar ) || bar >= PCI_BAR_COUNT )
328+ return NULL ;
329+
330+ if (static_branch_likely (& have_mio ))
331+ return pci_iomap_wc_range_mio (pdev , bar , offset , max );
332+ else
333+ return pci_iomap_range_fh (pdev , bar , offset , max );
334+ }
335+ EXPORT_SYMBOL (pci_iomap_wc_range );
336+
337+ void __iomem * pci_iomap_wc (struct pci_dev * dev , int bar , unsigned long maxlen )
338+ {
339+ return pci_iomap_wc_range (dev , bar , 0 , maxlen );
340+ }
341+ EXPORT_SYMBOL (pci_iomap_wc );
342+
343+ static void pci_iounmap_fh (struct pci_dev * pdev , void __iomem * addr )
257344{
258345 unsigned int idx = ZPCI_IDX (addr );
259346
@@ -266,6 +353,19 @@ void pci_iounmap(struct pci_dev *pdev, void __iomem *addr)
266353 }
267354 spin_unlock (& zpci_iomap_lock );
268355}
356+
357+ static void pci_iounmap_mio (struct pci_dev * pdev , void __iomem * addr )
358+ {
359+ iounmap (addr );
360+ }
361+
362+ void pci_iounmap (struct pci_dev * pdev , void __iomem * addr )
363+ {
364+ if (static_branch_likely (& have_mio ))
365+ pci_iounmap_mio (pdev , addr );
366+ else
367+ pci_iounmap_fh (pdev , addr );
368+ }
269369EXPORT_SYMBOL (pci_iounmap );
270370
271371static int pci_read (struct pci_bus * bus , unsigned int devfn , int where ,
@@ -312,15 +412,21 @@ static struct resource iov_res = {
312412
313413static void zpci_map_resources (struct pci_dev * pdev )
314414{
415+ struct zpci_dev * zdev = to_zpci (pdev );
315416 resource_size_t len ;
316417 int i ;
317418
318419 for (i = 0 ; i < PCI_BAR_COUNT ; i ++ ) {
319420 len = pci_resource_len (pdev , i );
320421 if (!len )
321422 continue ;
322- pdev -> resource [i ].start =
323- (resource_size_t __force ) pci_iomap (pdev , i , 0 );
423+
424+ if (static_branch_likely (& have_mio ))
425+ pdev -> resource [i ].start =
426+ (resource_size_t __force ) zdev -> bars [i ].mio_wb ;
427+ else
428+ pdev -> resource [i ].start =
429+ (resource_size_t __force ) pci_iomap (pdev , i , 0 );
324430 pdev -> resource [i ].end = pdev -> resource [i ].start + len - 1 ;
325431 }
326432
@@ -341,6 +447,9 @@ static void zpci_unmap_resources(struct pci_dev *pdev)
341447 resource_size_t len ;
342448 int i ;
343449
450+ if (static_branch_likely (& have_mio ))
451+ return ;
452+
344453 for (i = 0 ; i < PCI_BAR_COUNT ; i ++ ) {
345454 len = pci_resource_len (pdev , i );
346455 if (!len )
@@ -772,6 +881,9 @@ static int __init pci_base_init(void)
772881 if (!test_facility (69 ) || !test_facility (71 ))
773882 return 0 ;
774883
884+ if (test_facility (153 ))
885+ static_branch_enable (& have_mio );
886+
775887 rc = zpci_debug_init ();
776888 if (rc )
777889 goto out ;
0 commit comments