pci/devres: add and use pci_iomap_wc() and pcim_iomap_wc()
Subsystems (4)
v4 cover pci/devres: add and use pci_iomap_wc() and pcim_iomap_wc()
From: "Luis R. Rodriguez" <[email protected]>
This series adds pci_iomap_wc() and the respective devm helper pcim_iomap_wc().
Luis R. Rodriguez (5):
pci: add pci_iomap_wc() variants
lib: devres: add pcim_iomap_wc() variants
video: fbdev: arkfb: use arch_phys_wc_add() and pci_iomap_wc()
video: fbdev: s3fb: use arch_phys_wc_add() and pci_iomap_wc()
video: fbdev: vt8623fb: use arch_phys_wc_add() and pci_iomap_wc()
drivers/video/fbdev/arkfb.c | 36 +++---------------- drivers/video/fbdev/s3fb.c | 35 ++++-------------- drivers/video/fbdev/vt8623fb.c | 31 ++++------------ include/asm-generic/pci_iomap.h | 14 ++++++++ include/linux/pci.h | 2 ++ lib/devres.c | 78 +++++++++++++++++++++++++++++++++++++++++ lib/pci_iomap.c | 61 ++++++++++++++++++++++++++++++++ 7 files changed, 172 insertions(+), 85 deletions(-)
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 1/5 pci: add pci_iomap_wc() variants
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have pci_read_bases() just peg an IORESOURCE_WC flag for us but where exactly video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.
Although there is also arch_phys_wc_add() that makes use of architecture specific write-combining alternatives (MTRR on x86 when a system does not have PAT) we void polluting pci_iomap() space with it and force drivers and subsystems that want to use it to be explicit.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (see commit de33c442e titled "x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()")
--- include/asm-generic/pci_iomap.h | 14 ++++++++++ lib/pci_iomap.c | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
include/asm-generic/pci_iomap.h +14 -0
@@ -15,9 +15,13 @@ struct pci_dev;#ifdef CONFIG_PCI /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */ extern void __iomem *pci_iomap (struct pci_dev *dev,int bar,unsigned long max); +extern void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long max);extern void __iomem *pci_iomap_range (struct pci_dev *dev,int bar,unsigned long offset,unsigned long maxlen); +extern void __iomem *pci_iomap_wc_range (struct pci_dev *dev,int bar, +unsigned long offset, +unsigned long maxlen);/* Create a virtual mapping cookie for a port on a given PCI device. * Do not call this directly, it exists to make it easier for architectures * to override */
@@ -34,12 +38,22 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lonreturn NULL ; } +static inline void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long max) +{ +return NULL ; +}static inline void __iomem *pci_iomap_range (struct pci_dev *dev,int bar,unsigned long offset,unsigned long maxlen) {return NULL ; } +static inline void __iomem *pci_iomap_wc_range (struct pci_dev *dev,int bar, +unsigned long offset, +unsigned long maxlen) +{ +return NULL ; +}#endif #endif /* __ASM_GENERIC_IO_H */
lib/pci_iomap.c +61 -0
71 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Bjorn Helgaas
maintainerRe: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
[+cc linux-pci]
Hi Luis,
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for us
This makes it sound like pci_read_bases() could do a better job if we just tried harder, but I don't think that's the case. All pci_read_bases() can do is look at the bits in the BAR. For memory BARs, there's a "prefetchable" bit and a "64-bit" bit.
If you just want to complain that the PCI spec didn't define a way for software to discover whether a BAR can be mapped with WC, that's fine, but it's misleading to suggest that pci_read_bases() could figure out WC without some help from the spec.
Quoted 11 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combining alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.
I'm not quite sure I understand the point you're making here about not polluting pci_iomap_wc() with arch_phys_wc_add(). I think the choice is for a driver to do either this:
info->screen_base = pci_iomap_wc(dev, 0, 0);
or this:
info->screen_base = pci_iomap_wc(dev, 0, 0); par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0),
pci_resource_len(dev, 0));
The driver is *already* being explicit because it calls pci_iomap_wc() instead of pci_iomap().
It seems like it would be ideal if ioremap_wc() could call arch_phys_wc_add() internally. Doesn't any caller of arch_phys_wc_add() have to also do some sort of ioremap() beforehand? I assume there's some reason for separating them, and I see that the current arch_phys_wc_add() requires the caller to store a handle, but doing both seems confusing.
Quoted 4 lines
There are a few motivations for this:
a) Take advantage of PAT when available
Quoted 8 lines
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(see commitde33c442etitled "x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()")
I think these are now _PAGE_CACHE_MODE_UC and_PAGE_CACHE_MODE_UC_MINUS, right?
Quoted 9 lines
...
lib/pci_iomap.c +7
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar);
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 86
Quoted 10 lines
lib/pci_iomap.c +10
-0+unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen; +if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len);
Is there any point in checking for IORESOURCE_IO? If a driver calls pci_iomap_wc_range(), I assume it already knows this is an IORESOURCE_MEM BAR, so if we see IORESOURCE_IO here we should just return an error, i.e., NULL.
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 92
Quoted 6 lines
lib/pci_iomap.c +6
-0+if (flags &IORESOURCE_MEM ) +return ioremap_wc (start, len); +/* What? */ +return NULL ; +} +EXPORT_SYMBOL_GPL (pci_iomap_wc_range);
Bjorn
Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
Quoted 16 lines · Bjorn Helgaas
[+cc linux-pci]
Hi Luis,
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usThis makes it sound like
pci_read_bases()could do a better job if we just tried harder, but I don't think that's the case. Allpci_read_bases()can do is look at the bits in the BAR. For memory BARs, there's a "prefetchable" bit and a "64-bit" bit.
Quoted 4 lines
If you just want to complain that the PCI spec didn't define a way for software to discover whether a BAR can be mapped with WC, that's fine, but it's misleading to suggest that
pci_read_bases()could figure out WC without some help from the spec.
You're right sorry about that, in my original patch this was more of a question and I did not have a full answer for but mst had clarified before the spec doesn't allow for this [0] and you are confirming this now as well.
[0] https://lkml.org/lkml/2015/4/21/714
I'll update the patch and at least document we did think about this and that its a shortcoming of the spec.
Quoted 22 lines
Quoted 11 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combining alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.I'm not quite sure I understand the point you're making here about not polluting
pci_iomap_wc()witharch_phys_wc_add(). I think the choice is for a driver to do either this:info->screen_base = pci_iomap_wc(dev, 0, 0);or this:
info->screen_base=pci_iomap_wc(dev, 0, 0);par->wc_cookie= arch_phys_wc_add(pci_resource_start(dev, 0),
Quoted 7 lines
pci_resource_len(dev, 0));The driver is *already* being explicit because it calls
pci_iomap_wc()instead ofpci_iomap().It seems like it would be ideal if
ioremap_wc()could callarch_phys_wc_add()internally.
Indeed, that's what I was alluding to.
Quoted 3 lines
Doesn't any caller of
arch_phys_wc_add()have to also do some sort ofioremap()beforehand?
This is not a requirement as the physical address is used, not the virtual address.
Quoted 1 line
I assume there's some reason for separating them,
Well a full sweep to change to arch_phys_wc_add() was never done, consider this part of the last effort to do so. In retrospect now that I've covered all other drivers in 12 different series of patches I think its perhaps best to not mesh them together as we're phasing out MTRR and the only reason to have arch_phys_wc_add() is for MTRR which is legacy.
I'll update the commit log to mention that.
Quoted 2 lines
and I see that the current
arch_phys_wc_add()requires the caller to store a handle, but doing both seems confusing.
That's just a cookie so that later when we undo the driver we can tell the backend to remove it.
Quoted 7 lines
Quoted 7 lines
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
Quoted 8 lines
Quoted 5 lines
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(see commitde33c442etitled "x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()")I think these are now
_PAGE_CACHE_MODE_UCand_PAGE_CACHE_MODE_UC_MINUS, right?
Indeed, thanks, I'll fix that in the commit log.
Quoted 16 lines
Quoted 16 lines
...
lib/pci_iomap.c +14
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen)
Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 86
Quoted 3 lines
lib/pci_iomap.c +3
-0+ len = maxlen; +if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len);Is there any point in checking for
IORESOURCE_IO? If a driver callspci_iomap_wc_range(), I assume it already knows this is anIORESOURCE_MEMBAR, so if we seeIORESOURCE_IOhere we should just return an error, i.e., NULL.
Agreed, will fix with all the other changes on the commit log and repost. I won't repost the full series but just this one patch as a v5.
Thanks for the review.
Luis
Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
Quoted 71 lines · Luis R. Rodriguez
Quoted 16 lines · Bjorn Helgaas
[+cc linux-pci]
Hi Luis,
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usThis makes it sound like
pci_read_bases()could do a better job if we just tried harder, but I don't think that's the case. Allpci_read_bases()can do is look at the bits in the BAR. For memory BARs, there's a "prefetchable" bit and a "64-bit" bit.Quoted 4 lines
If you just want to complain that the PCI spec didn't define a way for software to discover whether a BAR can be mapped with WC, that's fine, but it's misleading to suggest that
pci_read_bases()could figure out WC without some help from the spec.You're right sorry about that, in my original patch this was more of a question and I did not have a full answer for but mst had clarified before the spec doesn't allow for this [0] and you are confirming this now as well.
[0] https://lkml.org/lkml/2015/4/21/714
I'll update the patch and at least document we did think about this and that its a shortcoming of the spec.
Quoted 24 lines
Quoted 11 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combining alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.I'm not quite sure I understand the point you're making here about not polluting
pci_iomap_wc()witharch_phys_wc_add(). I think the choice is for a driver to do either this:info->screen_base = pci_iomap_wc(dev, 0, 0);or this:
info->screen_base = pci_iomap_wc(dev, 0, 0); par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0), pci_resource_len(dev, 0));Quoted 5 lines
The driver is *already* being explicit because it calls
pci_iomap_wc()instead ofpci_iomap().It seems like it would be ideal if
ioremap_wc()could callarch_phys_wc_add()internally.Indeed, that's what I was alluding to.
Quoted 3 lines
Doesn't any caller of
arch_phys_wc_add()have to also do some sort ofioremap()beforehand?This is not a requirement as the physical address is used, not the virtual address.
Quoted 8 lines
Quoted 1 line
I assume there's some reason for separating them,
Well a full sweep to change to
arch_phys_wc_add()was never done, consider this part of the last effort to do so. In retrospect now that I've covered all other drivers in 12 different series of patches I think its perhaps best to not mesh them together as we're phasing out MTRR and the only reason to havearch_phys_wc_add()is for MTRR which is legacy.
I would say it much more strongly.
Drivers for new hardware SHOULD NOT call arch_phys_wc_add, directly or otherwise. MTRRs are crap. They have nasty alignment requirements, they are a very limited and unpredictable resource, and the interact poorly with BIOS. They should really only be used for old video framebuffers and such.
Anything new should use PAT (it's been available for a long time) and possibly streaming memory writes. Even fancy server gear (myri10ge, for example) should stay far away from MTRRs and such: it's very easy to put enough devices in a server board that you simply run out of MTRRs and arch_phys_wc_add will stop working.
If we make ioremap_wc and similar start automatically adding MTRRs, then performance will vary wildly with the order of driver loading, because we'll run out of MTRRs part-way through bootup.
ioremap_wc via PAT, on the other hand, is 100% reliable on newer hardware.
Maybe I should have called it arch_phys_wc_add_awful_legacy_hack.
--Andy
Re: [PATCH v4 1/5] pci: add pci_iomap_wc() variants
Quoted 95 lines · Andy Lutomirski
Quoted 71 lines · Luis R. Rodriguez
Quoted 16 lines · Bjorn Helgaas
[+cc linux-pci]
Hi Luis,
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usThis makes it sound like
pci_read_bases()could do a better job if we just tried harder, but I don't think that's the case. Allpci_read_bases()can do is look at the bits in the BAR. For memory BARs, there's a "prefetchable" bit and a "64-bit" bit.Quoted 4 lines
If you just want to complain that the PCI spec didn't define a way for software to discover whether a BAR can be mapped with WC, that's fine, but it's misleading to suggest that
pci_read_bases()could figure out WC without some help from the spec.You're right sorry about that, in my original patch this was more of a question and I did not have a full answer for but mst had clarified before the spec doesn't allow for this [0] and you are confirming this now as well.
[0] https://lkml.org/lkml/2015/4/21/714
I'll update the patch and at least document we did think about this and that its a shortcoming of the spec.
Quoted 24 lines
Quoted 11 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combining alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.I'm not quite sure I understand the point you're making here about not polluting
pci_iomap_wc()witharch_phys_wc_add(). I think the choice is for a driver to do either this:info->screen_base = pci_iomap_wc(dev, 0, 0);or this:
info->screen_base = pci_iomap_wc(dev, 0, 0); par->wc_cookie = arch_phys_wc_add(pci_resource_start(dev, 0), pci_resource_len(dev, 0));Quoted 5 lines
The driver is *already* being explicit because it calls
pci_iomap_wc()instead ofpci_iomap().It seems like it would be ideal if
ioremap_wc()could callarch_phys_wc_add()internally.Indeed, that's what I was alluding to.
Quoted 3 lines
Doesn't any caller of
arch_phys_wc_add()have to also do some sort ofioremap()beforehand?This is not a requirement as the physical address is used, not the virtual address.
Quoted 8 lines
Quoted 1 line
I assume there's some reason for separating them,
Well a full sweep to change to
arch_phys_wc_add()was never done, consider this part of the last effort to do so. In retrospect now that I've covered all other drivers in 12 different series of patches I think its perhaps best to not mesh them together as we're phasing out MTRR and the only reason to havearch_phys_wc_add()is for MTRR which is legacy.I would say it much more strongly.
Drivers for new hardware SHOULD NOT call
arch_phys_wc_add, directly or otherwise. MTRRs are crap. They have nasty alignment requirements, they are a very limited and unpredictable resource, and the interact poorly with BIOS. They should really only be used for old video framebuffers and such.Anything new should use PAT (it's been available for a long time) and possibly streaming memory writes. Even fancy server gear (myri10ge, for example) should stay far away from MTRRs and such: it's very easy to put enough devices in a server board that you simply run out of MTRRs and
arch_phys_wc_addwill stop working.
Quoted 7 lines
If we make
ioremap_wcand similar start automatically adding MTRRs, then performance will vary wildly with the order of driver loading, because we'll run out of MTRRs part-way through bootup.
ioremap_wcvia PAT, on the other hand, is 100% reliable on newer hardware.Maybe I should have called it
arch_phys_wc_add_awful_legacy_hack.
Thanks, I'll document such technicalities as well ;)
Luis
PATCH v4 2/5 lib: devres: add pcim_iomap_wc() variants
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Now that we have pci_iomap_wc() add the respective devres helpers.
--- include/linux/pci.h | 2 ++ lib/devres.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+)
include/linux/pci.h +2 -0
@@ -1619,9 +1619,11 @@ static inline void pci_dev_specific_enable_acs(struct pci_dev *dev) { }#endif void __iomem *pcim_iomap (struct pci_dev *pdev,int bar,unsigned long maxlen); +void __iomem *pcim_iomap_wc (struct pci_dev *pdev,int bar,unsigned long maxlen);void pcim_iounmap (struct pci_dev *pdev,void __iomem *addr);void __iomem *const *pcim_iomap_table (struct pci_dev *pdev);int pcim_iomap_regions (struct pci_dev *pdev,int mask,const char *name); +int pcim_iomap_wc_regions (struct pci_dev *pdev,int mask,const char *name);int pcim_iomap_regions_request_all (struct pci_dev *pdev,int mask,const char *name);void pcim_iounmap_regions (struct pci_dev *pdev,int mask);
lib/devres.c +78 -0
90 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Bjorn Helgaas
maintainerRe: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
[+cc linux-pci]
Hi Luis,
Quoted 3 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Now that we have
pci_iomap_wc()add the respective devres helpers.
I guess I'm still confused about the relationship between pci_iomap_wc() and arch_phys_wc_add().
Do you expect every caller of pcim_iomap_wc() to also call arch_phys_wc_add()?
If so, I'm not sure how pcim_iomap_wc() fits into the picture. A driver can call both pcim_iomap_wc() and arch_phys_wc_add(), but the driver doesn't explicitly do the unmap, so where would the arch_phys_wc_del() happen?
If not, how does a driver know whether it should call arch_phys_wc_add()?
Quoted 27 lines
...
/**
+ *pcim_iomap_wc_regions- Request and iomap PCI BARs with write-combining
+ * @pdev: PCI device to map IO resources for
+ * @mask: Mask of BARs to request and iomap
+ * @name: Name used when requesting regions
+ *
+ * Request and iomap regions specified by @mask with a preference for
+ * write-combining.
+ */lib/devres.c +17
-0+int pcim_iomap_wc_regions (struct pci_dev *pdev,int mask,const char *name) +{ +void __iomem *const *iomap; +int i, rc; + + iomap =pcim_iomap_table (pdev); +if (!iomap) +return -ENOMEM ; + +for (i =0 ; i <DEVICE_COUNT_RESOURCE ; i++) { +unsigned long len; + +if (!(mask & (1 << i))) +continue ; + + rc = -EINVAL ; + len =pci_resource_len (pdev, i);
lib/devres.c int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) · line 444
Quoted 10 lines
lib/devres.c +10
-0+if (!len) + goto err_inval; + + rc =pci_request_region (pdev, i, name); +if (rc) + goto err_inval; + + rc = -ENOMEM ; +if (!pcim_iomap_wc (pdev, i,0 )) + goto err_region;
Is there a user for this? Are there really devices where *all* the BARs can be mapped with WC? Are there enough of them to make it worth adding this?
I don't see users of either pcim_iomap_wc() or pcim_iomap_wc_regions() so far. Did I miss them, or do you just expect them in the near future?
Bjorn
Re: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
Quoted 7 lines · Bjorn Helgaas
[+cc linux-pci]
Hi Luis,
Quoted 2 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Quoted 7 lines
Quoted 1 line
Now that we have
pci_iomap_wc()add the respective devres helpers.I guess I'm still confused about the relationship between
pci_iomap_wc()andarch_phys_wc_add().Do you expect every caller of
pcim_iomap_wc()to also callarch_phys_wc_add()?
Yeap.
Quoted 4 lines
If so, I'm not sure how
pcim_iomap_wc()fits into the picture. A driver can call bothpcim_iomap_wc()andarch_phys_wc_add(), but the driver doesn't explicitly do the unmap, so where would thearch_phys_wc_del()happen?
As with other current drivers not using devres, upon exit or where they would otherwise typically iounmap().
Quoted 1 line
If not, how does a driver know whether it should call
arch_phys_wc_add()?
Sadly they'd have to figure it out, as Andy notes arch_phys_wc_add() is a hack so I think we need to leave it as such and hope to see arch_phys_wc_add() use phased as it won't be needed anymore really. arch_phys_wc_add() really should only be used by device drivers that know that are working with non-PAT systems. The code already takes care of this but since its an x86 write-combining hack we should not consider meshing it with devres.
Quoted 33 lines
Quoted 33 lines
...
/**
+ *pcim_iomap_wc_regions- Request and iomap PCI BARs with write-combining
+ * @pdev: PCI device to map IO resources for
+ * @mask: Mask of BARs to request and iomap
+ * @name: Name used when requesting regions
+ *
+ * Request and iomap regions specified by @mask with a preference for
+ * write-combining.
+ */lib/devres.c +23
-0+int pcim_iomap_wc_regions (struct pci_dev *pdev,int mask,const char *name) +{ +void __iomem *const *iomap; +int i, rc; + + iomap =pcim_iomap_table (pdev); +if (!iomap) +return -ENOMEM ; + +for (i =0 ; i <DEVICE_COUNT_RESOURCE ; i++) { +unsigned long len; + +if (!(mask & (1 << i))) +continue ; + + rc = -EINVAL ; + len =pci_resource_len (pdev, i); +if (!len) + goto err_inval; + + rc =pci_request_region (pdev, i, name); +if (rc) + goto err_inval;
Quoted 8 lines
lib/devres.c int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name) · line 444
Quoted 4 lines
lib/devres.c +4
-0+ + rc = -ENOMEM ; +if (!pcim_iomap_wc (pdev, i,0 )) + goto err_region;Is there a user for this? Are there really devices where *all* the BARs can be mapped with WC? Are there enough of them to make it worth adding this?
Not right now, I did this more to help with a friend who is testing one driver for a feature. The driver is upstream but a way to make the feature take effect only under certain conditions still would need to be done.
Quoted 2 lines
I don't see users of either
pcim_iomap_wc()orpcim_iomap_wc_regions()so far. Did I miss them, or do you just expect them in the near future?
The later, and also I hate seeing folks later add code under EXPORT_SYMBOL() rather than EXPORT_SYMBOL_GPL() so I figure I'd rather do it first. It happened recently in my v1 series, someone beat me to a write-combining export symbol and changed it to EXPORT_SYMBOL(). Feel free to drop this though but I hope no one out there then tries to just add an EXPORT_SYMBOL() later for this...
Luis
Bjorn Helgaas
maintainerRe: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
Quoted 10 lines · Luis R. Rodriguez
Quoted 2 lines · Bjorn Helgaas
I don't see users of either
pcim_iomap_wc()orpcim_iomap_wc_regions()so far. Did I miss them, or do you just expect them in the near future?The later, and also I hate seeing folks later add code under
EXPORT_SYMBOL()rather thanEXPORT_SYMBOL_GPL()so I figure I'd rather do it first. It happened recently in my v1 series, someone beat me to a write-combining export symbol and changed it toEXPORT_SYMBOL(). Feel free to drop this though but I hope no one out there then tries to just add anEXPORT_SYMBOL()later for this...
Why do you want them to be EXPORT_SYMBOL_GPL? I would expect them to be exported the same way pcim_iomap(), pcim_iomap_regions(), and ioremap_wc() are exported, i.e., with EXPORT_SYMBOL.
Per Documentation/DocBook/kernel-hacking.tmpl, EXPORT_SYMBOL_GPL "implies that the function is considered an internal implementation issue, and not really an interface." I don't think these are internal implementation issues.
Bjorn
Re: [PATCH v4 2/5] lib: devres: add pcim_iomap_wc() variants
Quoted 12 lines · Bjorn Helgaas
Quoted 10 lines · Luis R. Rodriguez
Quoted 2 lines · Bjorn Helgaas
I don't see users of either
pcim_iomap_wc()orpcim_iomap_wc_regions()so far. Did I miss them, or do you just expect them in the near future?The later, and also I hate seeing folks later add code under
EXPORT_SYMBOL()rather thanEXPORT_SYMBOL_GPL()so I figure I'd rather do it first. It happened recently in my v1 series, someone beat me to a write-combining export symbol and changed it toEXPORT_SYMBOL(). Feel free to drop this though but I hope no one out there then tries to just add anEXPORT_SYMBOL()later for this...
Quoted 8 lines
Why do you want them to be
EXPORT_SYMBOL_GPL? I would expect them to be exported the same waypcim_iomap(),pcim_iomap_regions(), andioremap_wc()are exported, i.e., withEXPORT_SYMBOL.Quoted 1 line
Per
Documentation/DocBook/kernel-hacking.tmpl,EXPORT_SYMBOL_GPL"implies that the function is considered an internal implementation issue, and not really an interface." I don't think these are internal implementation issues.
What Documentation/DocBook/kernel-hacking.tmpl states over EXPORT_SYMBOL_GPL() is old and in no way reflects current trends and reality. For instance, some folks believe that if some code has EXPORT_SYMBOL() declared that they can use it on proprietary modules. This is terribly incorrect, quite a few developers do not in any way stand by this as a "needed" clarification on their code [0]. I'm one of them, but to be even more clear on this I simply *always* use EXPORT_SYMBOL_GPL() to remove any possible doubt over this on any symbols that I export. Heck, even tons of driver library code uses EXPORT_SYMBOL_GPL().
[0] https://lkml.org/lkml/2012/4/20/402
Luis
PATCH v4 3/5 video: fbdev: arkfb: use arch_phys_wc_add() and pci_iomap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Convert the driver from using the x86 specific MTRR code to the architecture agnostic arch_phys_wc_add(). arch_phys_wc_add() will avoid MTRR if write-combining is available, in order to take advantage of that also ensure the ioremap'd area is requested as write-combining.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (see commit de33c442e titled "x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()")
The conversion done is expressed by the following Coccinelle SmPL patch, it additionally required manual intervention to address all the #ifdery and removal of redundant things which arch_phys_wc_add() already addresses such as verbose message about when MTRR fails and doing nothing when we didn't get an MTRR.
@ mtrr_found @
expression index, base, size;
@@
-index = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); +index = arch_phys_wc_add(base, size);
@ mtrr_rm depends on mtrr_found @
expression mtrr_found.index, mtrr_found.base, mtrr_found.size; @@
-mtrr_del(index, base, size);
+arch_phys_wc_del(index);
@ mtrr_rm_zero_arg depends on mtrr_found @
expression mtrr_found.index;
@@
-mtrr_del(index, 0, 0);
+arch_phys_wc_del(index);
@ mtrr_rm_fb_info depends on mtrr_found @
struct fb_info *info;
expression mtrr_found.index;
@@
-mtrr_del(index, info->fix.smem_start, info->fix.smem_len); +arch_phys_wc_del(index);
@ ioremap_replace_nocache depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap_nocache(base, size);
+info->screen_base = ioremap_wc(base, size);
@ ioremap_replace_default depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap(base, size);
+info->screen_base = ioremap_wc(base, size);
--- drivers/video/fbdev/arkfb.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-)
drivers/video/fbdev/arkfb.c +5 -31
@@ -26,13 +26,9 @@#include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */ #include <video/vga.h> -#ifdef CONFIG_MTRR -#include <asm/mtrr.h> -#endif -struct arkfb_info {int mclk_freq; -int mtrr_reg; +int wc_cookie;struct dac_info *dac;struct vgastate state;
@@ -102,10 +98,6 @@ static const struct svga_timing_regs ark_timing_regs = {static char *mode_option ="640x480-8@60" ; -#ifdef CONFIG_MTRR -static int mtrr =1 ; -#endif -MODULE_AUTHOR ("(c) 2007 Ondrej Zajicek <[email protected]>" );MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("fbdev driver for ARK 2000PV" );
@@ -115,11 +107,6 @@ MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");module_param_named (mode, mode_option, charp,0444 );MODULE_PARM_DESC (mode,"Default video mode ('640x480-8@60', etc) (deprecated)" ); -#ifdef CONFIG_MTRR -module_param (mtrr, int,0444 ); -MODULE_PARM_DESC (mtrr,"Enable write-combining with MTRR (1=enable, 0=disable, default=1)" ); -#endif -static int threshold =4 ;module_param (threshold, int,0644 );
@@ -1002,7 +989,7 @@ static int ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) info->fix.smem_len =pci_resource_len (dev,0 );/* Map physical IO memory address into kernel space */ - info->screen_base =pci_iomap (dev,0 ,0 ); + info->screen_base =pci_iomap_wc (dev,0 ,0 );if (! info->screen_base) { rc = -ENOMEM ;dev_err (info->device,"iomap for framebuffer failed\n" );
@@ -1057,14 +1044,8 @@ static int ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)/* Record a reference to the driver data */ pci_set_drvdata (dev, info); - -#ifdef CONFIG_MTRR -if (mtrr) { - par->mtrr_reg =-1 ; - par->mtrr_reg =mtrr_add (info->fix.smem_start, info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); - } -#endif - + par->wc_cookie =arch_phys_wc_add (info->fix.smem_start, + info->fix.smem_len);return 0 ;/* Error handling */
@@ -1092,14 +1073,7 @@ static void ark_pci_remove(struct pci_dev *dev)if (info) {struct arkfb_info *par = info->par; - -#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - } -#endif - +arch_phys_wc_del (par->wc_cookie);dac_release (par->dac);unregister_framebuffer (info);fb_dealloc_cmap (&info->cmap);
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 4/5 video: fbdev: s3fb: use arch_phys_wc_add() and pci_iomap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This driver uses the same area for MTRR as for the ioremap(). Convert the driver from using the x86 specific MTRR code to the architecture agnostic arch_phys_wc_add(). arch_phys_wc_add() will avoid MTRR if write-combining is available, in order to take advantage of that also ensure the ioremap'd area is requested as write-combining.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (see commit de33c442e titled "x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()")
The conversion done is expressed by the following Coccinelle SmPL patch, it additionally required manual intervention to address all the #ifdery and removal of redundant things which arch_phys_wc_add() already addresses such as verbose message about when MTRR fails and doing nothing when we didn't get an MTRR.
@ mtrr_found @
expression index, base, size;
@@
-index = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); +index = arch_phys_wc_add(base, size);
@ mtrr_rm depends on mtrr_found @
expression mtrr_found.index, mtrr_found.base, mtrr_found.size; @@
-mtrr_del(index, base, size);
+arch_phys_wc_del(index);
@ mtrr_rm_zero_arg depends on mtrr_found @
expression mtrr_found.index;
@@
-mtrr_del(index, 0, 0);
+arch_phys_wc_del(index);
@ mtrr_rm_fb_info depends on mtrr_found @
struct fb_info *info;
expression mtrr_found.index;
@@
-mtrr_del(index, info->fix.smem_start, info->fix.smem_len); +arch_phys_wc_del(index);
@ ioremap_replace_nocache depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap_nocache(base, size);
+info->screen_base = ioremap_wc(base, size);
@ ioremap_replace_default depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap(base, size);
+info->screen_base = ioremap_wc(base, size);
--- drivers/video/fbdev/s3fb.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-)
drivers/video/fbdev/s3fb.c +6 -29
@@ -28,13 +28,9 @@#include <linux/i2c.h> #include <linux/i2c-algo-bit.h> -#ifdef CONFIG_MTRR -#include <asm/mtrr.h> -#endif -struct s3fb_info {int chip, rev, mclk_freq; -int mtrr_reg; +int wc_cookie;struct vgastate state;struct mutex open_lock;unsigned int ref_count;
@@ -154,11 +150,7 @@ static const struct svga_timing_regs s3_timing_regs = {static char *mode_option; - -#ifdef CONFIG_MTRR static int mtrr =1 ; -#endif -static int fasttext =1 ;
@@ -170,11 +162,8 @@ module_param(mode_option, charp, 0444);MODULE_PARM_DESC (mode_option,"Default video mode ('640x480-8@60', etc)" );module_param_named (mode, mode_option, charp,0444 );MODULE_PARM_DESC (mode,"Default video mode ('640x480-8@60', etc) (deprecated)" ); - -#ifdef CONFIG_MTRR module_param (mtrr, int,0444 );MODULE_PARM_DESC (mtrr,"Enable write-combining with MTRR (1=enable, 0=disable, default=1)" ); -#endif module_param (fasttext, int,0644 );MODULE_PARM_DESC (fasttext,"Enable S3 fast text mode (1=enable, 0=disable, default=1)" );
@@ -1168,7 +1157,7 @@ static int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) info->fix.smem_len =pci_resource_len (dev,0 );/* Map physical IO memory address into kernel space */ - info->screen_base =pci_iomap (dev,0 ,0 ); + info->screen_base =pci_iomap_wc (dev,0 ,0 );if (! info->screen_base) { rc = -ENOMEM ;dev_err (info->device,"iomap for framebuffer failed\n" );
@@ -1365,12 +1354,9 @@ static int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)/* Record a reference to the driver data */ pci_set_drvdata (dev, info); -#ifdef CONFIG_MTRR -if (mtrr) { - par->mtrr_reg =-1 ; - par->mtrr_reg =mtrr_add (info->fix.smem_start, info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); - } -#endif +if (mtrr) + par->wc_cookie =arch_phys_wc_add (info->fix.smem_start, + info->fix.smem_len);return 0 ;
@@ -1405,14 +1391,7 @@ static void s3_pci_remove(struct pci_dev *dev)if (info) { par = info->par; - -#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - } -#endif - +arch_phys_wc_del (par->wc_cookie);unregister_framebuffer (info);fb_dealloc_cmap (&info->cmap);
@@ -1551,10 +1530,8 @@ static int __init s3fb_setup(char *options)if (!*opt)continue ; -#ifdef CONFIG_MTRR else if (!strncmp (opt,"mtrr:" ,5 )) mtrr =simple_strtoul (opt +5 ,NULL ,0 ); -#endif else if (!strncmp (opt,"fasttext:" ,9 )) fasttext =simple_strtoul (opt +9 ,NULL ,0 );else
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH v4 5/5 video: fbdev: vt8623fb: use arch_phys_wc_add() and pci_iomap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This driver uses the same area for MTRR as for the ioremap(). Convert the driver from using the x86 specific MTRR code to the architecture agnostic arch_phys_wc_add(). arch_phys_wc_add() will avoid MTRR if write-combining is available, in order to take advantage of that also ensure the ioremap'd area is requested as write-combining.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (see commit de33c442e titled "x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()")
The conversion done is expressed by the following Coccinelle SmPL patch, it additionally required manual intervention to address all the #ifdery and removal of redundant things which arch_phys_wc_add() already addresses such as verbose message about when MTRR fails and doing nothing when we didn't get an MTRR.
@ mtrr_found @
expression index, base, size;
@@
-index = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); +index = arch_phys_wc_add(base, size);
@ mtrr_rm depends on mtrr_found @
expression mtrr_found.index, mtrr_found.base, mtrr_found.size; @@
-mtrr_del(index, base, size);
+arch_phys_wc_del(index);
@ mtrr_rm_zero_arg depends on mtrr_found @
expression mtrr_found.index;
@@
-mtrr_del(index, 0, 0);
+arch_phys_wc_del(index);
@ mtrr_rm_fb_info depends on mtrr_found @
struct fb_info *info;
expression mtrr_found.index;
@@
-mtrr_del(index, info->fix.smem_start, info->fix.smem_len); +arch_phys_wc_del(index);
@ ioremap_replace_nocache depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap_nocache(base, size);
+info->screen_base = ioremap_wc(base, size);
@ ioremap_replace_default depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap(base, size);
+info->screen_base = ioremap_wc(base, size);
--- drivers/video/fbdev/vt8623fb.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-)
drivers/video/fbdev/vt8623fb.c +6 -25
@@ -26,13 +26,9 @@#include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */ #include <video/vga.h> -#ifdef CONFIG_MTRR -#include <asm/mtrr.h> -#endif -struct vt8623fb_info {char __iomem *mmio_base; -int mtrr_reg; +int wc_cookie;struct vgastate state;struct mutex open_lock;unsigned int ref_count;
@@ -99,10 +95,7 @@ static struct svga_timing_regs vt8623_timing_regs = {/* Module parameters */ static char *mode_option ="640x480-8@60" ; - -#ifdef CONFIG_MTRR static int mtrr =1 ; -#endif MODULE_AUTHOR ("(c) 2006 Ondrej Zajicek <[email protected]>" );MODULE_LICENSE ("GPL" );
@@ -112,11 +105,8 @@ module_param(mode_option, charp, 0644);MODULE_PARM_DESC (mode_option,"Default video mode ('640x480-8@60', etc)" );module_param_named (mode, mode_option, charp,0 );MODULE_PARM_DESC (mode,"Default video mode e.g. '648x480-8@60' (deprecated)" ); - -#ifdef CONFIG_MTRR module_param (mtrr, int,0444 );MODULE_PARM_DESC (mtrr,"Enable write-combining with MTRR (1=enable, 0=disable, default=1)" ); -#endif /* ------------------------------------------------------------------------- */
@@ -710,7 +700,7 @@ static int vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) info->fix.mmio_len =pci_resource_len (dev,1 );/* Map physical IO memory address into kernel space */ - info->screen_base =pci_iomap (dev,0 ,0 ); + info->screen_base =pci_iomap_wc (dev,0 ,0 );if (! info->screen_base) { rc = -ENOMEM ;dev_err (info->device,"iomap for framebuffer failed\n" );
@@ -781,12 +771,9 @@ static int vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)/* Record a reference to the driver data */ pci_set_drvdata (dev, info); -#ifdef CONFIG_MTRR -if (mtrr) { - par->mtrr_reg =-1 ; - par->mtrr_reg =mtrr_add (info->fix.smem_start, info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); - } -#endif +if (mtrr) + par->wc_cookie =arch_phys_wc_add (info->fix.smem_start, + info->fix.smem_len);return 0 ;
@@ -816,13 +803,7 @@ static void vt8623_pci_remove(struct pci_dev *dev)if (info) {struct vt8623fb_info *par = info->par; -#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - } -#endif - +arch_phys_wc_del (par->wc_cookie);unregister_framebuffer (info);fb_dealloc_cmap (&info->cmap);
Signature · 1 line
2.3.2.209.gd67f9d5.dirty