Skip to contentSkip to conversation

lib: devres: add a helper function for ioremap_uc

PATCH In review Tuowen Zhao 5 participants 8 messages Oct 14, 2019 – Dec 4, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 lib: devres: add a helper function for ioremap_uc

Implement a resource managed strongly uncachable ioremap function.

---
Changes from previous version:

* Add Cc stable

 .../driver-api/driver-model/devres.rst        |  1 +
 include/linux/io.h                            |  2 ++
 lib/devres.c                                  | 19 +++++++++++++++++++
 3 files changed, 22 insertions(+)
Documentation/driver-api/driver-model/devres.rst +1 -0
index a100bef54952..92628fdc2f11 100644
@@ -314,6 +314,7 @@ IOMAP
   devm_ioport_unmap()
   devm_ioremap()
   devm_ioremap_nocache()
+  devm_ioremap_uc()
   devm_ioremap_wc()
   devm_ioremap_resource() : checks resource, requests memory region, ioremaps
   devm_iounmap()
include/linux/io.h +2 -0
index accac822336a..a59834bc0a11 100644
@@ -64,6 +64,8 @@ static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
 
 void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
 			   resource_size_t size);
+void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
+				   resource_size_t size);
 void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
 				   resource_size_t size);
 void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
lib/devres.c +19 -0
index 6a0e9bd6524a..17624d35e82d 100644
@@ -9,6 +9,7 @@
 enum devm_ioremap_type {
 	DEVM_IOREMAP = 0,
 	DEVM_IOREMAP_NC,
+	DEVM_IOREMAP_UC,
 	DEVM_IOREMAP_WC,
 };
 
@@ -39,6 +40,9 @@ static void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset,
 	case DEVM_IOREMAP_NC:
 		addr = ioremap_nocache(offset, size);
 		break;
+	case DEVM_IOREMAP_UC:
+		addr = ioremap_uc(offset, size);
+		break;
 	case DEVM_IOREMAP_WC:
 		addr = ioremap_wc(offset, size);
 		break;
@@ -68,6 +72,21 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
 }
 EXPORT_SYMBOL(devm_ioremap);
 
+/**
+ * devm_ioremap_uc - Managed ioremap_uc()
+ * @dev: Generic device to remap IO address for
+ * @offset: Resource address to map
+ * @size: Size of map
+ *
+ * Managed ioremap_uc().  Map is automatically unmapped on driver detach.
+ */
+void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
+			      resource_size_t size)
+{
+	return __devm_ioremap(dev, offset, size, DEVM_IOREMAP_UC);
+}
+EXPORT_SYMBOL_GPL(devm_ioremap_uc);
+
 /**
  * devm_ioremap_nocache - Managed ioremap_nocache()
  * @dev: Generic device to remap IO address for
Signature · 1 line
2.23.0
#1 lore raw

PATCH v4 2/2 mfd: intel-lpss: use devm_ioremap_uc for MMIO

Some BIOS erroneously specifies write-combining BAR for intel-lpss-pci in MTRR. This will cause the system to hang during boot. If possible, this bug could be corrected with a firmware update.

This patch use devm_ioremap_uc to overwrite/ignore the MTRR settings by forcing the use of strongly uncachable pages for intel-lpss.

The BIOS bug is present on Dell XPS 13 7390 2-in-1:

[    0.001734]   5 base 4000000000 mask 6000000000 write-combining

4000000000-7fffffffff : PCI Bus 0000:00
4000000000-400fffffff : 0000:00:02.0 (i915) 4010000000-4010000fff : 0000:00:15.0 (intel-lpss-pci)

---
 drivers/mfd/intel-lpss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/intel-lpss.c +1 -1
index bfe4ff337581..b0f0781a6b9c 100644
@@ -384,7 +384,7 @@ int intel_lpss_probe(struct device *dev,
 	if (!lpss)
 		return -ENOMEM;
 
-	lpss->priv = devm_ioremap(dev, info->mem->start + LPSS_PRIV_OFFSET,
+	lpss->priv = devm_ioremap_uc(dev, info->mem->start + LPSS_PRIV_OFFSET,
 				  LPSS_PRIV_SIZE);
 	if (!lpss->priv)
 		return -ENOMEM;
Signature · 1 line
2.23.0
#2 lore raw
In reply to Tuowen Zhao
Thank you for the patch! Yet something to improve:

Hi Tuowen,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.4-rc3 next-20191014]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url: https://github.com/0day-ci/linux/commits/Tuowen-Zhao/lib-devres-add-a-helper-function-for-ioremap_uc/20191015-000416
config: sparc64-allmodconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=sparc64

If you fix the issue, kindly add following tag

All error/warnings (new ones prefixed by >>):

lib/devres.c: In function '__devm_ioremap':

>> lib/devres.c:44:10: error: implicit declaration of function 'ioremap_uc'; did you mean 'ioremap_wc'? [-Werror=implicit-function-declaration]
      addr = ioremap_uc(offset, size);
             ^~~~~~~~~~
             ioremap_wc
>> lib/devres.c:44:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
      addr = ioremap_uc(offset, size);
           ^

cc1: some warnings being treated as errors

vim +44 lib/devres.c

    25	
    26	static void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset,
    27					    resource_size_t size,
    28					    enum devm_ioremap_type type)
    29	{
    30		void __iomem **ptr, *addr = NULL;
    31	
    32		ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
    33		if (!ptr)
    34			return NULL;
    35	
    36		switch (type) {
    37		case DEVM_IOREMAP:
    38			addr = ioremap(offset, size);
    39			break;
    40		case DEVM_IOREMAP_NC:
    41			addr = ioremap_nocache(offset, size);
    42			break;
    43		case DEVM_IOREMAP_UC:
  > 44			addr = ioremap_uc(offset, size);
    45			break;
    46		case DEVM_IOREMAP_WC:
    47			addr = ioremap_wc(offset, size);
    48			break;
    49		}
    50	
    51		if (addr) {
    52			*ptr = addr;
    53			devres_add(dev, ptr);
    54		} else
    55			devres_free(ptr);
    56	
    57		return addr;
    58	}
    59	

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw
Quoted 4 lines · kbuild test robot

-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree GCC_VERSION=7.4.0 make.cross ARCH=sparc64

Oops, I'm not sure how would we best fix this. Clearly the patch is not intended for sparc64. Maybe adding devm_ioremap_uc is rather not safe right now.

Although, We could declare dummies for these architectures like it has been for powerpc.

I just noticed another driver having this issue, and fixed with direct calls to ioremap_uc().

3cc2dac5be3f2: drivers/video/fbdev/atyfb: Replace MTRR UC hole with strong UC

Tuowen

#4 lore raw
Quoted 9 lines · Tuowen Zhao
Quoted 4 lines · kbuild test robot

-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree GCC_VERSION=7.4.0 make.cross ARCH=sparc64

Oops, I'm not sure how would we best fix this. Clearly the patch is not intended for sparc64. Maybe adding devm_ioremap_uc is rather not safe right now.

It seems you need a preparatory patch to satisfy sparc64.

Quoted 8 lines

Although, We could declare dummies for these architectures like it has been for powerpc.

I just noticed another driver having this issue, and fixed with direct calls to ioremap_uc().

3cc2dac5be3f2: drivers/video/fbdev/atyfb: Replace MTRR UC hole with strong UC

That's why I asked Luis to have a look at this :)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Tuowen Zhao
Quoted 4 lines · kbuild test robot

-O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree GCC_VERSION=7.4.0 make.cross ARCH=sparc64

Quoted 5 lines
Quoted 3 lines

Oops, I'm not sure how would we best fix this. Clearly the patch is not intended for sparc64. Maybe adding devm_ioremap_uc is rather not safe right now.

It seems you need a preparatory patch to satisfy sparc64.

Indeed, can you add that? If you are not comfortable the way to leave behind lazy architectures is the HAS_FOO feature and then have your driver require that or depend on the archs that support this. This allows non-lazy architecturess to move forward with life.

Luis

#6 lore raw
Quoted 6 lines · Luis Chamberlain

Indeed, can you add that? If you are not comfortable the way to leave behind lazy architectures is the HAS_FOO feature and then have your driver require that or depend on the archs that support this. This allows non-lazy architecturess to move forward with life.

Luis

Upon close examination, the issue seems easy to fix. Going to submit a new set shortly.

sparc64 and hexagon don't have ioremap_uc defined. Hexagon also doesn't have ioremap_wc but didn't report an issue before so devm_ioremap won't have an problem.

Interestingly tho, majority of the archs include <asm-generic/io.h>, thus having prototypes. These two archs and a few others don't. I'm wondering if including the prototypes is actually the recommended practice.

Tuowen

#7 lore raw
In reply to Tuowen Zhao
Quoted 3 lines · Tuowen Zhao

Implement a resource managed strongly uncachable ioremap function.

Really ?

Quoted 6 lines

This patch results in hard build failures when building hexagon images.

lib/devres.c:44:3: error: implicit declaration of function 'ioremap_uc'

Guenter