dm: core: Create a new header file for 'compat' features

At present dm/device.h includes the linux-compatible features. This
requires including linux/compat.h which in turn includes a lot of headers.
One of these is malloc.h which we thus end up including in every file in
U-Boot. Apart from the inefficiency of this, it is problematic for sandbox
which needs to use the system malloc() in some files.

Move the compatibility features into a separate header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/net/bcm6348-eth.c b/drivers/net/bcm6348-eth.c
index 7100e68..fe35329 100644
--- a/drivers/net/bcm6348-eth.c
+++ b/drivers/net/bcm6348-eth.c
@@ -10,6 +10,7 @@
 #include <clk.h>
 #include <dm.h>
 #include <dma.h>
+#include <malloc.h>
 #include <miiphy.h>
 #include <net.h>
 #include <phy.h>
diff --git a/drivers/net/bcm6368-eth.c b/drivers/net/bcm6368-eth.c
index 110985e..1200049 100644
--- a/drivers/net/bcm6368-eth.c
+++ b/drivers/net/bcm6368-eth.c
@@ -10,11 +10,13 @@
 #include <clk.h>
 #include <dm.h>
 #include <dma.h>
+#include <malloc.h>
 #include <miiphy.h>
 #include <net.h>
 #include <reset.h>
 #include <wait_bit.h>
 #include <asm/io.h>
+#include <dm/device_compat.h>
 
 #define ETH_PORT_STR			"brcm,enetsw-port"
 
diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index aa33fd5..baac277 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -17,6 +17,7 @@
 #include <malloc.h>
 #include <pci.h>
 #include <reset.h>
+#include <dm/device_compat.h>
 #include <dm/devres.h>
 #include <linux/compiler.h>
 #include <linux/err.h>
diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 4632111..0564beb 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -31,6 +31,7 @@
 #include <cpu_func.h>
 #include <dm.h>
 #include <errno.h>
+#include <malloc.h>
 #include <memalign.h>
 #include <miiphy.h>
 #include <net.h>
diff --git a/drivers/net/dwmac_socfpga.c b/drivers/net/dwmac_socfpga.c
index 66a5f95..e93561d 100644
--- a/drivers/net/dwmac_socfpga.c
+++ b/drivers/net/dwmac_socfpga.c
@@ -14,6 +14,7 @@
 #include <reset.h>
 #include <syscon.h>
 #include "designware.h"
+#include <dm/device_compat.h>
 #include <linux/err.h>
 
 #include <asm/arch/system_manager.h>
diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c
index 0946011..9212920 100644
--- a/drivers/net/e1000.c
+++ b/drivers/net/e1000.c
@@ -33,6 +33,7 @@
 #include <cpu_func.h>
 #include <dm.h>
 #include <errno.h>
+#include <malloc.h>
 #include <memalign.h>
 #include <pci.h>
 #include "e1000.h"
diff --git a/drivers/net/e1000_spi.c b/drivers/net/e1000_spi.c
index aecd290..52b3c79 100644
--- a/drivers/net/e1000_spi.c
+++ b/drivers/net/e1000_spi.c
@@ -1,6 +1,7 @@
 #include <common.h>
 #include <console.h>
 #include "e1000.h"
+#include <malloc.h>
 #include <linux/compiler.h>
 
 /*-----------------------------------------------------------------------
diff --git a/drivers/net/fsl-mc/dpio/qbman_portal.c b/drivers/net/fsl-mc/dpio/qbman_portal.c
index c51354c..e161b4e 100644
--- a/drivers/net/fsl-mc/dpio/qbman_portal.c
+++ b/drivers/net/fsl-mc/dpio/qbman_portal.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2014 Freescale Semiconductor
  */
 
+#include <malloc.h>
 #include <asm/arch/clock.h>
 #include "qbman_portal.h"
 
diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c
index 8ff43a9..07bbcc9 100644
--- a/drivers/net/fsl-mc/mc.c
+++ b/drivers/net/fsl-mc/mc.c
@@ -8,6 +8,7 @@
 #include <cpu_func.h>
 #include <env.h>
 #include <errno.h>
+#include <malloc.h>
 #include <linux/bug.h>
 #include <asm/io.h>
 #include <linux/libfdt.h>
diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c
index f0d15fe..bee7315 100644
--- a/drivers/net/fsl_enetc.c
+++ b/drivers/net/fsl_enetc.c
@@ -7,6 +7,7 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <malloc.h>
 #include <memalign.h>
 #include <asm/io.h>
 #include <pci.h>
diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index ebb7433..40e6b3b 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -14,9 +14,11 @@
 #include <clk.h>
 #include <cpu_func.h>
 #include <dm.h>
+#include <malloc.h>
 #include <miiphy.h>
 #include <net.h>
 #include <wait_bit.h>
+#include <dm/device_compat.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
 
diff --git a/drivers/net/higmacv300.c b/drivers/net/higmacv300.c
index 897741a..0c1dd68 100644
--- a/drivers/net/higmacv300.c
+++ b/drivers/net/higmacv300.c
@@ -4,6 +4,7 @@
  */
 
 #include <cpu_func.h>
+#include <malloc.h>
 #include <asm/io.h>
 #include <common.h>
 #include <console.h>
diff --git a/drivers/net/mscc_eswitch/jr2_switch.c b/drivers/net/mscc_eswitch/jr2_switch.c
index 6655177..33dd002 100644
--- a/drivers/net/mscc_eswitch/jr2_switch.c
+++ b/drivers/net/mscc_eswitch/jr2_switch.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <config.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/of_access.h>
 #include <dm/of_addr.h>
 #include <fdt_support.h>
diff --git a/drivers/net/mscc_eswitch/luton_switch.c b/drivers/net/mscc_eswitch/luton_switch.c
index dffe81d..9d24c00 100644
--- a/drivers/net/mscc_eswitch/luton_switch.c
+++ b/drivers/net/mscc_eswitch/luton_switch.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <config.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/of_access.h>
 #include <dm/of_addr.h>
 #include <fdt_support.h>
diff --git a/drivers/net/mscc_eswitch/ocelot_switch.c b/drivers/net/mscc_eswitch/ocelot_switch.c
index 0ba84ab..fe48f37 100644
--- a/drivers/net/mscc_eswitch/ocelot_switch.c
+++ b/drivers/net/mscc_eswitch/ocelot_switch.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <config.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/of_access.h>
 #include <dm/of_addr.h>
 #include <fdt_support.h>
diff --git a/drivers/net/mscc_eswitch/serval_switch.c b/drivers/net/mscc_eswitch/serval_switch.c
index 1a21360..f05fa42 100644
--- a/drivers/net/mscc_eswitch/serval_switch.c
+++ b/drivers/net/mscc_eswitch/serval_switch.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <config.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/of_access.h>
 #include <dm/of_addr.h>
 #include <fdt_support.h>
diff --git a/drivers/net/mscc_eswitch/servalt_switch.c b/drivers/net/mscc_eswitch/servalt_switch.c
index d20ec49..bf95a38 100644
--- a/drivers/net/mscc_eswitch/servalt_switch.c
+++ b/drivers/net/mscc_eswitch/servalt_switch.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <config.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/of_access.h>
 #include <dm/of_addr.h>
 #include <fdt_support.h>
diff --git a/drivers/net/mtk_eth.c b/drivers/net/mtk_eth.c
index c22e590..77589b2 100644
--- a/drivers/net/mtk_eth.c
+++ b/drivers/net/mtk_eth.c
@@ -17,6 +17,7 @@
 #include <wait_bit.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <dm/device_compat.h>
 #include <linux/err.h>
 #include <linux/ioport.h>
 #include <linux/mdio.h>
diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c
index 505fabd..d737400 100644
--- a/drivers/net/mvneta.c
+++ b/drivers/net/mvneta.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <malloc.h>
 #include <asm/io.h>
+#include <dm/device_compat.h>
 #include <dm/devres.h>
 #include <linux/errno.h>
 #include <phy.h>
diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 105fdc9..fcd2486 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -17,6 +17,7 @@
 #include <cpu_func.h>
 #include <dm.h>
 #include <dm/device-internal.h>
+#include <dm/device_compat.h>
 #include <dm/devres.h>
 #include <dm/lists.h>
 #include <net.h>
diff --git a/drivers/net/pch_gbe.c b/drivers/net/pch_gbe.c
index e4507bf..b282370 100644
--- a/drivers/net/pch_gbe.c
+++ b/drivers/net/pch_gbe.c
@@ -9,6 +9,7 @@
 #include <cpu_func.h>
 #include <dm.h>
 #include <errno.h>
+#include <malloc.h>
 #include <asm/io.h>
 #include <pci.h>
 #include <miiphy.h>
diff --git a/drivers/net/pfe_eth/pfe_driver.c b/drivers/net/pfe_eth/pfe_driver.c
index 14a8c68..f70a235 100644
--- a/drivers/net/pfe_eth/pfe_driver.c
+++ b/drivers/net/pfe_eth/pfe_driver.c
@@ -4,6 +4,7 @@
  * Copyright 2017 NXP
  */
 
+#include <malloc.h>
 #include <net/pfe_eth/pfe_eth.h>
 #include <net/pfe_eth/pfe_firmware.h>
 
diff --git a/drivers/net/pfe_eth/pfe_eth.c b/drivers/net/pfe_eth/pfe_eth.c
index c525674..1b5d11e 100644
--- a/drivers/net/pfe_eth/pfe_eth.c
+++ b/drivers/net/pfe_eth/pfe_eth.c
@@ -6,6 +6,7 @@
 
 #include <common.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/platform_data/pfe_dm_eth.h>
 #include <net.h>
 #include <net/pfe_eth/pfe_eth.h>
diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c
index e4563f1..13112d9 100644
--- a/drivers/net/pfe_eth/pfe_firmware.c
+++ b/drivers/net/pfe_eth/pfe_firmware.c
@@ -10,6 +10,7 @@
  * files.
  */
 
+#include <malloc.h>
 #include <net/pfe_eth/pfe_eth.h>
 #include <net/pfe_eth/pfe_firmware.h>
 #ifdef CONFIG_CHAIN_OF_TRUST
diff --git a/drivers/net/pfe_eth/pfe_mdio.c b/drivers/net/pfe_eth/pfe_mdio.c
index 6230967..b990e7f 100644
--- a/drivers/net/pfe_eth/pfe_mdio.c
+++ b/drivers/net/pfe_eth/pfe_mdio.c
@@ -5,6 +5,7 @@
  */
 #include <common.h>
 #include <dm.h>
+#include <malloc.h>
 #include <dm/platform_data/pfe_dm_eth.h>
 #include <net.h>
 #include <net/pfe_eth/pfe_eth.h>
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 0ae0edd..9d9f746 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -7,6 +7,7 @@
 
 #include <config.h>
 #include <common.h>
+#include <malloc.h>
 #include <phy.h>
 #include <dm.h>
 #include <fdt_support.h>
diff --git a/drivers/net/pic32_eth.c b/drivers/net/pic32_eth.c
index 3458440..e966be0 100644
--- a/drivers/net/pic32_eth.c
+++ b/drivers/net/pic32_eth.c
@@ -7,6 +7,7 @@
 #include <cpu_func.h>
 #include <errno.h>
 #include <dm.h>
+#include <malloc.h>
 #include <net.h>
 #include <miiphy.h>
 #include <console.h>
diff --git a/drivers/net/sandbox-raw-bus.c b/drivers/net/sandbox-raw-bus.c
index 0086f25..fb1ba5a 100644
--- a/drivers/net/sandbox-raw-bus.c
+++ b/drivers/net/sandbox-raw-bus.c
@@ -8,6 +8,7 @@
 #include <asm/eth-raw-os.h>
 #include <dm.h>
 #include <errno.h>
+#include <malloc.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
 
diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c
index 64e92ab..5d66a63 100644
--- a/drivers/net/sni_ave.c
+++ b/drivers/net/sni_ave.c
@@ -8,14 +8,16 @@
 #include <cpu_func.h>
 #include <dm.h>
 #include <fdt_support.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/iopoll.h>
+#include <malloc.h>
 #include <miiphy.h>
 #include <net.h>
 #include <regmap.h>
 #include <reset.h>
 #include <syscon.h>
+#include <dm/device_compat.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
 
 #define AVE_GRST_DELAY_MSEC	40
 #define AVE_MIN_XMITSIZE	60
diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
index 6f10578..1ae776b 100644
--- a/drivers/net/sun8i_emac.c
+++ b/drivers/net/sun8i_emac.c
@@ -18,6 +18,7 @@
 #include <clk.h>
 #include <dm.h>
 #include <fdt_support.h>
+#include <dm/device_compat.h>
 #include <linux/err.h>
 #include <malloc.h>
 #include <miiphy.h>
diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c
index 9a5f7fd..a9874e4 100644
--- a/drivers/net/sunxi_emac.c
+++ b/drivers/net/sunxi_emac.c
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <clk.h>
 #include <dm.h>
+#include <dm/device_compat.h>
 #include <linux/err.h>
 #include <malloc.h>
 #include <miiphy.h>
diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
index 2590486..2b77213 100644
--- a/drivers/net/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -7,10 +7,12 @@
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 #include <clk.h>
 #include <dm.h>
+#include <dm/device_compat.h>
 #include <dm/lists.h>
 #include <dma-uclass.h>
 #include <dm/of_access.h>
diff --git a/drivers/net/ti/cpsw-common.c b/drivers/net/ti/cpsw-common.c
index 21b8bbd..ca93edb 100644
--- a/drivers/net/ti/cpsw-common.c
+++ b/drivers/net/ti/cpsw-common.c
@@ -10,6 +10,7 @@
 #include <fdt_support.h>
 #include <asm/io.h>
 #include <cpsw.h>
+#include <dm/device_compat.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
diff --git a/drivers/net/ti/cpsw.c b/drivers/net/ti/cpsw.c
index 5762562..04b01a8 100644
--- a/drivers/net/ti/cpsw.c
+++ b/drivers/net/ti/cpsw.c
@@ -14,6 +14,7 @@
 #include <net.h>
 #include <netdev.h>
 #include <cpsw.h>
+#include <dm/device_compat.h>
 #include <linux/errno.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
diff --git a/drivers/net/ti/cpsw_mdio.c b/drivers/net/ti/cpsw_mdio.c
index 6e8f652..1fa520b 100644
--- a/drivers/net/ti/cpsw_mdio.c
+++ b/drivers/net/ti/cpsw_mdio.c
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <asm/io.h>
 #include <miiphy.h>
 #include <wait_bit.h>
diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
index 3d9d520..288037e 100644
--- a/drivers/net/zynq_gem.c
+++ b/drivers/net/zynq_gem.c
@@ -25,6 +25,7 @@
 #include <asm/system.h>
 #include <asm/arch/hardware.h>
 #include <asm/arch/sys_proto.h>
+#include <dm/device_compat.h>
 #include <linux/err.h>
 #include <linux/errno.h>