Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: address: Reshuffle to remove forward declarations

Reshuffle the code to get rid of the forward declarations, which
improves readability.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/b8701c04d27e51618444a747c4f4be5cc889ce28.1680248888.git.geert+renesas@glider.be
Signed-off-by: Rob Herring <robh@kernel.org>

authored by

Geert Uytterhoeven and committed by
Rob Herring
5eac0bdc 65b6b046

+133 -138
+133 -138
drivers/of/address.c
··· 22 22 #define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS) 23 23 #define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && (ns) > 0) 24 24 25 - static struct of_bus *of_match_bus(struct device_node *np); 26 - static int __of_address_to_resource(struct device_node *dev, int index, 27 - int bar_no, struct resource *r); 28 - static bool of_mmio_is_nonposted(struct device_node *np); 29 - 30 25 /* Debug utility */ 31 26 #ifdef DEBUG 32 27 static void of_dump_addr(const char *s, const __be32 *addr, int na) ··· 189 194 return of_bus_default_translate(addr + 1, offset, na - 1); 190 195 } 191 196 #endif /* CONFIG_PCI */ 192 - 193 - int of_pci_address_to_resource(struct device_node *dev, int bar, 194 - struct resource *r) 195 - { 196 - 197 - if (!IS_ENABLED(CONFIG_PCI)) 198 - return -ENOSYS; 199 - 200 - return __of_address_to_resource(dev, -1, bar, r); 201 - } 202 - EXPORT_SYMBOL_GPL(of_pci_address_to_resource); 203 197 204 198 /* 205 199 * of_pci_range_to_resource - Create a resource from an of_pci_range ··· 818 834 return port; 819 835 } 820 836 821 - static int __of_address_to_resource(struct device_node *dev, int index, int bar_no, 822 - struct resource *r) 823 - { 824 - u64 taddr; 825 - const __be32 *addrp; 826 - u64 size; 827 - unsigned int flags; 828 - const char *name = NULL; 829 - 830 - addrp = __of_get_address(dev, index, bar_no, &size, &flags); 831 - if (addrp == NULL) 832 - return -EINVAL; 833 - 834 - /* Get optional "reg-names" property to add a name to a resource */ 835 - if (index >= 0) 836 - of_property_read_string_index(dev, "reg-names", index, &name); 837 - 838 - if (flags & IORESOURCE_MEM) 839 - taddr = of_translate_address(dev, addrp); 840 - else if (flags & IORESOURCE_IO) 841 - taddr = of_translate_ioport(dev, addrp, size); 842 - else 843 - return -EINVAL; 844 - 845 - if (taddr == OF_BAD_ADDR) 846 - return -EINVAL; 847 - memset(r, 0, sizeof(struct resource)); 848 - 849 - if (of_mmio_is_nonposted(dev)) 850 - flags |= IORESOURCE_MEM_NONPOSTED; 851 - 852 - r->start = taddr; 853 - r->end = taddr + size - 1; 854 - r->flags = flags; 855 - r->name = name ? name : dev->full_name; 856 - 857 - return 0; 858 - } 859 - 860 - /** 861 - * of_address_to_resource - Translate device tree address and return as resource 862 - * @dev: Caller's Device Node 863 - * @index: Index into the array 864 - * @r: Pointer to resource array 865 - * 866 - * Returns -EINVAL if the range cannot be converted to resource. 867 - * 868 - * Note that if your address is a PIO address, the conversion will fail if 869 - * the physical address can't be internally converted to an IO token with 870 - * pci_address_to_pio(), that is because it's either called too early or it 871 - * can't be matched to any host bridge IO space 872 - */ 873 - int of_address_to_resource(struct device_node *dev, int index, 874 - struct resource *r) 875 - { 876 - return __of_address_to_resource(dev, index, -1, r); 877 - } 878 - EXPORT_SYMBOL_GPL(of_address_to_resource); 879 - 880 - /** 881 - * of_iomap - Maps the memory mapped IO for a given device_node 882 - * @np: the device whose io range will be mapped 883 - * @index: index of the io range 884 - * 885 - * Returns a pointer to the mapped memory 886 - */ 887 - void __iomem *of_iomap(struct device_node *np, int index) 888 - { 889 - struct resource res; 890 - 891 - if (of_address_to_resource(np, index, &res)) 892 - return NULL; 893 - 894 - if (res.flags & IORESOURCE_MEM_NONPOSTED) 895 - return ioremap_np(res.start, resource_size(&res)); 896 - else 897 - return ioremap(res.start, resource_size(&res)); 898 - } 899 - EXPORT_SYMBOL(of_iomap); 900 - 901 - /* 902 - * of_io_request_and_map - Requests a resource and maps the memory mapped IO 903 - * for a given device_node 904 - * @device: the device whose io range will be mapped 905 - * @index: index of the io range 906 - * @name: name "override" for the memory region request or NULL 907 - * 908 - * Returns a pointer to the requested and mapped memory or an ERR_PTR() encoded 909 - * error code on failure. Usage example: 910 - * 911 - * base = of_io_request_and_map(node, 0, "foo"); 912 - * if (IS_ERR(base)) 913 - * return PTR_ERR(base); 914 - */ 915 - void __iomem *of_io_request_and_map(struct device_node *np, int index, 916 - const char *name) 917 - { 918 - struct resource res; 919 - void __iomem *mem; 920 - 921 - if (of_address_to_resource(np, index, &res)) 922 - return IOMEM_ERR_PTR(-EINVAL); 923 - 924 - if (!name) 925 - name = res.name; 926 - if (!request_mem_region(res.start, resource_size(&res), name)) 927 - return IOMEM_ERR_PTR(-EBUSY); 928 - 929 - if (res.flags & IORESOURCE_MEM_NONPOSTED) 930 - mem = ioremap_np(res.start, resource_size(&res)); 931 - else 932 - mem = ioremap(res.start, resource_size(&res)); 933 - 934 - if (!mem) { 935 - release_mem_region(res.start, resource_size(&res)); 936 - return IOMEM_ERR_PTR(-ENOMEM); 937 - } 938 - 939 - return mem; 940 - } 941 - EXPORT_SYMBOL(of_io_request_and_map); 942 - 943 837 #ifdef CONFIG_HAS_DMA 944 838 /** 945 839 * of_dma_get_range - Get DMA range info and put it into a map array ··· 1014 1152 of_node_put(parent); 1015 1153 return nonposted; 1016 1154 } 1155 + 1156 + static int __of_address_to_resource(struct device_node *dev, int index, int bar_no, 1157 + struct resource *r) 1158 + { 1159 + u64 taddr; 1160 + const __be32 *addrp; 1161 + u64 size; 1162 + unsigned int flags; 1163 + const char *name = NULL; 1164 + 1165 + addrp = __of_get_address(dev, index, bar_no, &size, &flags); 1166 + if (addrp == NULL) 1167 + return -EINVAL; 1168 + 1169 + /* Get optional "reg-names" property to add a name to a resource */ 1170 + if (index >= 0) 1171 + of_property_read_string_index(dev, "reg-names", index, &name); 1172 + 1173 + if (flags & IORESOURCE_MEM) 1174 + taddr = of_translate_address(dev, addrp); 1175 + else if (flags & IORESOURCE_IO) 1176 + taddr = of_translate_ioport(dev, addrp, size); 1177 + else 1178 + return -EINVAL; 1179 + 1180 + if (taddr == OF_BAD_ADDR) 1181 + return -EINVAL; 1182 + memset(r, 0, sizeof(struct resource)); 1183 + 1184 + if (of_mmio_is_nonposted(dev)) 1185 + flags |= IORESOURCE_MEM_NONPOSTED; 1186 + 1187 + r->start = taddr; 1188 + r->end = taddr + size - 1; 1189 + r->flags = flags; 1190 + r->name = name ? name : dev->full_name; 1191 + 1192 + return 0; 1193 + } 1194 + 1195 + /** 1196 + * of_address_to_resource - Translate device tree address and return as resource 1197 + * @dev: Caller's Device Node 1198 + * @index: Index into the array 1199 + * @r: Pointer to resource array 1200 + * 1201 + * Returns -EINVAL if the range cannot be converted to resource. 1202 + * 1203 + * Note that if your address is a PIO address, the conversion will fail if 1204 + * the physical address can't be internally converted to an IO token with 1205 + * pci_address_to_pio(), that is because it's either called too early or it 1206 + * can't be matched to any host bridge IO space 1207 + */ 1208 + int of_address_to_resource(struct device_node *dev, int index, 1209 + struct resource *r) 1210 + { 1211 + return __of_address_to_resource(dev, index, -1, r); 1212 + } 1213 + EXPORT_SYMBOL_GPL(of_address_to_resource); 1214 + 1215 + int of_pci_address_to_resource(struct device_node *dev, int bar, 1216 + struct resource *r) 1217 + { 1218 + 1219 + if (!IS_ENABLED(CONFIG_PCI)) 1220 + return -ENOSYS; 1221 + 1222 + return __of_address_to_resource(dev, -1, bar, r); 1223 + } 1224 + EXPORT_SYMBOL_GPL(of_pci_address_to_resource); 1225 + 1226 + /** 1227 + * of_iomap - Maps the memory mapped IO for a given device_node 1228 + * @np: the device whose io range will be mapped 1229 + * @index: index of the io range 1230 + * 1231 + * Returns a pointer to the mapped memory 1232 + */ 1233 + void __iomem *of_iomap(struct device_node *np, int index) 1234 + { 1235 + struct resource res; 1236 + 1237 + if (of_address_to_resource(np, index, &res)) 1238 + return NULL; 1239 + 1240 + if (res.flags & IORESOURCE_MEM_NONPOSTED) 1241 + return ioremap_np(res.start, resource_size(&res)); 1242 + else 1243 + return ioremap(res.start, resource_size(&res)); 1244 + } 1245 + EXPORT_SYMBOL(of_iomap); 1246 + 1247 + /* 1248 + * of_io_request_and_map - Requests a resource and maps the memory mapped IO 1249 + * for a given device_node 1250 + * @device: the device whose io range will be mapped 1251 + * @index: index of the io range 1252 + * @name: name "override" for the memory region request or NULL 1253 + * 1254 + * Returns a pointer to the requested and mapped memory or an ERR_PTR() encoded 1255 + * error code on failure. Usage example: 1256 + * 1257 + * base = of_io_request_and_map(node, 0, "foo"); 1258 + * if (IS_ERR(base)) 1259 + * return PTR_ERR(base); 1260 + */ 1261 + void __iomem *of_io_request_and_map(struct device_node *np, int index, 1262 + const char *name) 1263 + { 1264 + struct resource res; 1265 + void __iomem *mem; 1266 + 1267 + if (of_address_to_resource(np, index, &res)) 1268 + return IOMEM_ERR_PTR(-EINVAL); 1269 + 1270 + if (!name) 1271 + name = res.name; 1272 + if (!request_mem_region(res.start, resource_size(&res), name)) 1273 + return IOMEM_ERR_PTR(-EBUSY); 1274 + 1275 + if (res.flags & IORESOURCE_MEM_NONPOSTED) 1276 + mem = ioremap_np(res.start, resource_size(&res)); 1277 + else 1278 + mem = ioremap(res.start, resource_size(&res)); 1279 + 1280 + if (!mem) { 1281 + release_mem_region(res.start, resource_size(&res)); 1282 + return IOMEM_ERR_PTR(-ENOMEM); 1283 + } 1284 + 1285 + return mem; 1286 + } 1287 + EXPORT_SYMBOL(of_io_request_and_map);