David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 1 | /* |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 2 | * |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 3 | * Description: Defines the platform resources for Gaia-based settops. |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2005-2009 Scientific-Atlanta, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | * |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 21 | * NOTE: The bootloader allocates persistent memory at an address which is |
| 22 | * 16 MiB below the end of the highest address in KSEG0. All fixed |
| 23 | * address memory reservations must avoid this region. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/device.h> |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/resource.h> |
| 30 | #include <linux/serial_reg.h> |
| 31 | #include <linux/io.h> |
| 32 | #include <linux/bootmem.h> |
| 33 | #include <linux/mm.h> |
| 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/module.h> |
| 36 | #include <asm/page.h> |
| 37 | #include <linux/swap.h> |
| 38 | #include <linux/highmem.h> |
| 39 | #include <linux/dma-mapping.h> |
| 40 | |
| 41 | #include <asm/mach-powertv/asic.h> |
| 42 | #include <asm/mach-powertv/asic_regs.h> |
| 43 | #include <asm/mach-powertv/interrupts.h> |
| 44 | |
| 45 | #ifdef CONFIG_BOOTLOADER_DRIVER |
| 46 | #include <asm/mach-powertv/kbldr.h> |
| 47 | #endif |
| 48 | #include <asm/bootinfo.h> |
| 49 | |
| 50 | #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0)) |
| 51 | |
| 52 | /* |
| 53 | * Forward Prototypes |
| 54 | */ |
| 55 | static void pmem_setup_resource(void); |
| 56 | |
| 57 | /* |
| 58 | * Global Variables |
| 59 | */ |
| 60 | enum asic_type asic; |
| 61 | |
| 62 | unsigned int platform_features; |
| 63 | unsigned int platform_family; |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 64 | struct register_map _asic_register_map; |
| 65 | EXPORT_SYMBOL(_asic_register_map); /* Exported for testing */ |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 66 | unsigned long asic_phy_base; |
| 67 | unsigned long asic_base; |
| 68 | EXPORT_SYMBOL(asic_base); /* Exported for testing */ |
| 69 | struct resource *gp_resources; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Don't recommend to use it directly, it is usually used by kernel internally. |
| 73 | * Portable code should be using interfaces such as ioremp, dma_map_single, etc. |
| 74 | */ |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 75 | unsigned long phys_to_dma_offset; |
| 76 | EXPORT_SYMBOL(phys_to_dma_offset); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * |
| 80 | * IO Resource Definition |
| 81 | * |
| 82 | */ |
| 83 | |
| 84 | struct resource asic_resource = { |
| 85 | .name = "ASIC Resource", |
| 86 | .start = 0, |
| 87 | .end = ASIC_IO_SIZE, |
| 88 | .flags = IORESOURCE_MEM, |
| 89 | }; |
| 90 | |
| 91 | /* |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 92 | * Allow override of bootloader-specified model |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 93 | * Returns zero on success, a negative errno value on failure. This parameter |
David VomLehn | 0d36575 | 2010-08-02 18:40:58 -0700 | [diff] [blame] | 94 | * allows overriding of the bootloader-specified model. |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 95 | */ |
| 96 | static char __initdata cmdline[COMMAND_LINE_SIZE]; |
| 97 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 98 | #define FORCEFAMILY_PARAM "forcefamily" |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 99 | |
David VomLehn | 0d36575 | 2010-08-02 18:40:58 -0700 | [diff] [blame] | 100 | /* |
| 101 | * check_forcefamily - check for, and parse, forcefamily command line parameter |
| 102 | * @forced_family: Pointer to two-character array in which to store the |
| 103 | * value of the forcedfamily parameter, if any. |
| 104 | */ |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 105 | static __init int check_forcefamily(unsigned char forced_family[2]) |
| 106 | { |
| 107 | const char *p; |
| 108 | |
| 109 | forced_family[0] = '\0'; |
| 110 | forced_family[1] = '\0'; |
| 111 | |
| 112 | /* Check the command line for a forcefamily directive */ |
| 113 | strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1); |
| 114 | p = strstr(cmdline, FORCEFAMILY_PARAM); |
| 115 | if (p && (p != cmdline) && (*(p - 1) != ' ')) |
| 116 | p = strstr(p, " " FORCEFAMILY_PARAM "="); |
| 117 | |
| 118 | if (p) { |
| 119 | p += strlen(FORCEFAMILY_PARAM "="); |
| 120 | |
| 121 | if (*p == '\0' || *(p + 1) == '\0' || |
| 122 | (*(p + 2) != '\0' && *(p + 2) != ' ')) |
| 123 | pr_err(FORCEFAMILY_PARAM " must be exactly two " |
| 124 | "characters long, ignoring value\n"); |
| 125 | |
| 126 | else { |
| 127 | forced_family[0] = *p; |
| 128 | forced_family[1] = *(p + 1); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * platform_set_family - determine major platform family type. |
| 137 | * |
| 138 | * Returns family type; -1 if none |
| 139 | * Returns the family type; -1 if none |
| 140 | * |
| 141 | */ |
| 142 | static __init noinline void platform_set_family(void) |
| 143 | { |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 144 | unsigned char forced_family[2]; |
| 145 | unsigned short bootldr_family; |
| 146 | |
David VomLehn | 0d36575 | 2010-08-02 18:40:58 -0700 | [diff] [blame] | 147 | if (check_forcefamily(forced_family) == 0) |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 148 | bootldr_family = BOOTLDRFAMILY(forced_family[0], |
| 149 | forced_family[1]); |
Markos Chandras | f7c1285 | 2013-09-03 15:21:59 +0100 | [diff] [blame] | 150 | else |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 151 | bootldr_family = (unsigned short) BOOTLDRFAMILY( |
| 152 | CONFIG_BOOTLOADER_FAMILY[0], |
| 153 | CONFIG_BOOTLOADER_FAMILY[1]); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 154 | |
| 155 | pr_info("Bootloader Family = 0x%04X\n", bootldr_family); |
| 156 | |
| 157 | switch (bootldr_family) { |
| 158 | case BOOTLDRFAMILY('R', '1'): |
| 159 | platform_family = FAMILY_1500; |
| 160 | break; |
| 161 | case BOOTLDRFAMILY('4', '4'): |
| 162 | platform_family = FAMILY_4500; |
| 163 | break; |
| 164 | case BOOTLDRFAMILY('4', '6'): |
| 165 | platform_family = FAMILY_4600; |
| 166 | break; |
| 167 | case BOOTLDRFAMILY('A', '1'): |
| 168 | platform_family = FAMILY_4600VZA; |
| 169 | break; |
| 170 | case BOOTLDRFAMILY('8', '5'): |
| 171 | platform_family = FAMILY_8500; |
| 172 | break; |
| 173 | case BOOTLDRFAMILY('R', '2'): |
| 174 | platform_family = FAMILY_8500RNG; |
| 175 | break; |
| 176 | case BOOTLDRFAMILY('8', '6'): |
| 177 | platform_family = FAMILY_8600; |
| 178 | break; |
| 179 | case BOOTLDRFAMILY('B', '1'): |
| 180 | platform_family = FAMILY_8600VZB; |
| 181 | break; |
| 182 | case BOOTLDRFAMILY('E', '1'): |
| 183 | platform_family = FAMILY_1500VZE; |
| 184 | break; |
| 185 | case BOOTLDRFAMILY('F', '1'): |
| 186 | platform_family = FAMILY_1500VZF; |
| 187 | break; |
David VomLehn | 51f1336 | 2010-08-02 11:44:00 -0700 | [diff] [blame] | 188 | case BOOTLDRFAMILY('8', '7'): |
| 189 | platform_family = FAMILY_8700; |
| 190 | break; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 191 | default: |
| 192 | platform_family = -1; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | unsigned int platform_get_family(void) |
| 197 | { |
| 198 | return platform_family; |
| 199 | } |
| 200 | EXPORT_SYMBOL(platform_get_family); |
| 201 | |
| 202 | /* |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 203 | * platform_get_asic - determine the ASIC type. |
| 204 | * |
David VomLehn | 0d36575 | 2010-08-02 18:40:58 -0700 | [diff] [blame] | 205 | * Returns the ASIC type, or ASIC_UNKNOWN if unknown |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 206 | * |
| 207 | */ |
| 208 | enum asic_type platform_get_asic(void) |
| 209 | { |
| 210 | return asic; |
| 211 | } |
| 212 | EXPORT_SYMBOL(platform_get_asic); |
| 213 | |
| 214 | /* |
David VomLehn | 0d36575 | 2010-08-02 18:40:58 -0700 | [diff] [blame] | 215 | * set_register_map - set ASIC register configuration |
| 216 | * @phys_base: Physical address of the base of the ASIC registers |
| 217 | * @map: Description of key ASIC registers |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 218 | */ |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 219 | static void __init set_register_map(unsigned long phys_base, |
| 220 | const struct register_map *map) |
| 221 | { |
| 222 | asic_phy_base = phys_base; |
| 223 | _asic_register_map = *map; |
| 224 | register_map_virtualize(&_asic_register_map); |
| 225 | asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE); |
| 226 | } |
| 227 | |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 228 | /** |
| 229 | * configure_platform - configuration based on platform type. |
| 230 | */ |
| 231 | void __init configure_platform(void) |
| 232 | { |
| 233 | platform_set_family(); |
| 234 | |
| 235 | switch (platform_family) { |
| 236 | case FAMILY_1500: |
| 237 | case FAMILY_1500VZE: |
| 238 | case FAMILY_1500VZF: |
| 239 | platform_features = FFS_CAPABLE; |
| 240 | asic = ASIC_CALLIOPE; |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 241 | set_register_map(CALLIOPE_IO_BASE, &calliope_register_map); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 242 | |
| 243 | if (platform_family == FAMILY_1500VZE) { |
| 244 | gp_resources = non_dvr_vze_calliope_resources; |
| 245 | pr_info("Platform: 1500/Vz Class E - " |
| 246 | "CALLIOPE, NON_DVR_CAPABLE\n"); |
| 247 | } else if (platform_family == FAMILY_1500VZF) { |
| 248 | gp_resources = non_dvr_vzf_calliope_resources; |
| 249 | pr_info("Platform: 1500/Vz Class F - " |
| 250 | "CALLIOPE, NON_DVR_CAPABLE\n"); |
| 251 | } else { |
| 252 | gp_resources = non_dvr_calliope_resources; |
| 253 | pr_info("Platform: 1500/RNG100 - CALLIOPE, " |
| 254 | "NON_DVR_CAPABLE\n"); |
| 255 | } |
| 256 | break; |
| 257 | |
| 258 | case FAMILY_4500: |
| 259 | platform_features = FFS_CAPABLE | PCIE_CAPABLE | |
| 260 | DISPLAY_CAPABLE; |
| 261 | asic = ASIC_ZEUS; |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 262 | set_register_map(ZEUS_IO_BASE, &zeus_register_map); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 263 | gp_resources = non_dvr_zeus_resources; |
| 264 | |
| 265 | pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n"); |
| 266 | break; |
| 267 | |
| 268 | case FAMILY_4600: |
| 269 | { |
| 270 | unsigned int chipversion = 0; |
| 271 | |
| 272 | /* The settop has PCIE but it isn't used, so don't advertise |
| 273 | * it*/ |
| 274 | platform_features = FFS_CAPABLE | DISPLAY_CAPABLE; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 275 | |
David VomLehn | 28d7d21 | 2010-06-18 16:51:49 -0700 | [diff] [blame] | 276 | /* Cronus and Cronus Lite have the same register map */ |
| 277 | set_register_map(CRONUS_IO_BASE, &cronus_register_map); |
| 278 | |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 279 | /* ASIC version will determine if this is a real CronusLite or |
| 280 | * Castrati(Cronus) */ |
| 281 | chipversion = asic_read(chipver3) << 24; |
| 282 | chipversion |= asic_read(chipver2) << 16; |
| 283 | chipversion |= asic_read(chipver1) << 8; |
| 284 | chipversion |= asic_read(chipver0); |
| 285 | |
| 286 | if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11)) |
| 287 | asic = ASIC_CRONUS; |
| 288 | else |
| 289 | asic = ASIC_CRONUSLITE; |
| 290 | |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 291 | gp_resources = non_dvr_cronuslite_resources; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 292 | pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, " |
| 293 | "chipversion=0x%08X\n", |
| 294 | (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE", |
| 295 | chipversion); |
| 296 | break; |
| 297 | } |
| 298 | case FAMILY_4600VZA: |
| 299 | platform_features = FFS_CAPABLE | DISPLAY_CAPABLE; |
| 300 | asic = ASIC_CRONUS; |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 301 | set_register_map(CRONUS_IO_BASE, &cronus_register_map); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 302 | gp_resources = non_dvr_cronus_resources; |
| 303 | |
| 304 | pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n"); |
| 305 | break; |
| 306 | |
| 307 | case FAMILY_8500: |
| 308 | case FAMILY_8500RNG: |
| 309 | platform_features = DVR_CAPABLE | PCIE_CAPABLE | |
| 310 | DISPLAY_CAPABLE; |
| 311 | asic = ASIC_ZEUS; |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 312 | set_register_map(ZEUS_IO_BASE, &zeus_register_map); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 313 | gp_resources = dvr_zeus_resources; |
| 314 | |
| 315 | pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n"); |
| 316 | break; |
| 317 | |
| 318 | case FAMILY_8600: |
| 319 | case FAMILY_8600VZB: |
| 320 | platform_features = DVR_CAPABLE | PCIE_CAPABLE | |
| 321 | DISPLAY_CAPABLE; |
| 322 | asic = ASIC_CRONUS; |
David VomLehn | 59dfa2f | 2009-12-23 17:34:46 -0800 | [diff] [blame] | 323 | set_register_map(CRONUS_IO_BASE, &cronus_register_map); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 324 | gp_resources = dvr_cronus_resources; |
| 325 | |
| 326 | pr_info("Platform: 8600/Vz Class B - CRONUS, " |
| 327 | "DVR_CAPABLE\n"); |
| 328 | break; |
| 329 | |
David VomLehn | 51f1336 | 2010-08-02 11:44:00 -0700 | [diff] [blame] | 330 | case FAMILY_8700: |
| 331 | platform_features = FFS_CAPABLE | PCIE_CAPABLE; |
| 332 | asic = ASIC_GAIA; |
| 333 | set_register_map(GAIA_IO_BASE, &gaia_register_map); |
| 334 | gp_resources = dvr_gaia_resources; |
| 335 | |
| 336 | pr_info("Platform: 8700 - GAIA, DVR_CAPABLE\n"); |
| 337 | break; |
| 338 | |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 339 | default: |
| 340 | pr_crit("Platform: UNKNOWN PLATFORM\n"); |
| 341 | break; |
| 342 | } |
| 343 | |
| 344 | switch (asic) { |
| 345 | case ASIC_ZEUS: |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 346 | phys_to_dma_offset = 0x30000000; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 347 | break; |
| 348 | case ASIC_CALLIOPE: |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 349 | phys_to_dma_offset = 0x10000000; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 350 | break; |
| 351 | case ASIC_CRONUSLITE: |
| 352 | /* Fall through */ |
| 353 | case ASIC_CRONUS: |
| 354 | /* |
| 355 | * TODO: We suppose 0x10000000 aliases into 0x20000000- |
| 356 | * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000- |
| 357 | * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000. |
| 358 | */ |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 359 | phys_to_dma_offset = 0x10000000; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 360 | break; |
| 361 | default: |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 362 | phys_to_dma_offset = 0x00000000; |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 363 | break; |
| 364 | } |
| 365 | } |
| 366 | |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 367 | /* |
David VomLehn | 0d36575 | 2010-08-02 18:40:58 -0700 | [diff] [blame] | 368 | * RESOURCE ALLOCATION |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 369 | * |
| 370 | */ |
| 371 | /* |
| 372 | * Allocates/reserves the Platform memory resources early in the boot process. |
| 373 | * This ignores any resources that are designated IORESOURCE_IO |
| 374 | */ |
| 375 | void __init platform_alloc_bootmem(void) |
| 376 | { |
| 377 | int i; |
| 378 | int total = 0; |
| 379 | |
| 380 | /* Get persistent memory data from command line before allocating |
| 381 | * resources. This need to happen before normal command line parsing |
| 382 | * has been done */ |
| 383 | pmem_setup_resource(); |
| 384 | |
| 385 | /* Loop through looking for resources that want a particular address */ |
| 386 | for (i = 0; gp_resources[i].flags != 0; i++) { |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 387 | int size = resource_size(&gp_resources[i]); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 388 | if ((gp_resources[i].start != 0) && |
| 389 | ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) { |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 390 | reserve_bootmem(dma_to_phys(gp_resources[i].start), |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 391 | size, 0); |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 392 | total += resource_size(&gp_resources[i]); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 393 | pr_info("reserve resource %s at %08x (%u bytes)\n", |
| 394 | gp_resources[i].name, gp_resources[i].start, |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 395 | resource_size(&gp_resources[i])); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |
| 399 | /* Loop through assigning addresses for those that are left */ |
| 400 | for (i = 0; gp_resources[i].flags != 0; i++) { |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 401 | int size = resource_size(&gp_resources[i]); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 402 | if ((gp_resources[i].start == 0) && |
| 403 | ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) { |
| 404 | void *mem = alloc_bootmem_pages(size); |
| 405 | |
| 406 | if (mem == NULL) |
| 407 | pr_err("Unable to allocate bootmem pages " |
| 408 | "for %s\n", gp_resources[i].name); |
| 409 | |
| 410 | else { |
| 411 | gp_resources[i].start = |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 412 | phys_to_dma(virt_to_phys(mem)); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 413 | gp_resources[i].end = |
| 414 | gp_resources[i].start + size - 1; |
| 415 | total += size; |
| 416 | pr_info("allocate resource %s at %08x " |
| 417 | "(%u bytes)\n", |
| 418 | gp_resources[i].name, |
| 419 | gp_resources[i].start, size); |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | pr_info("Total Platform driver memory allocation: 0x%08x\n", total); |
| 425 | |
| 426 | /* indicate resources that are platform I/O related */ |
| 427 | for (i = 0; gp_resources[i].flags != 0; i++) { |
| 428 | if ((gp_resources[i].start != 0) && |
| 429 | ((gp_resources[i].flags & IORESOURCE_IO) != 0)) { |
| 430 | pr_info("reserved platform resource %s at %08x\n", |
| 431 | gp_resources[i].name, gp_resources[i].start); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * |
| 438 | * PERSISTENT MEMORY (PMEM) CONFIGURATION |
| 439 | * |
| 440 | */ |
| 441 | static unsigned long pmemaddr __initdata; |
| 442 | |
| 443 | static int __init early_param_pmemaddr(char *p) |
| 444 | { |
| 445 | pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0); |
| 446 | return 0; |
| 447 | } |
| 448 | early_param("pmemaddr", early_param_pmemaddr); |
| 449 | |
| 450 | static long pmemlen __initdata; |
| 451 | |
| 452 | static int __init early_param_pmemlen(char *p) |
| 453 | { |
| 454 | /* TODO: we can use this code when and if the bootloader ever changes this */ |
| 455 | #if 0 |
| 456 | pmemlen = (unsigned long)simple_strtoul(p, NULL, 0); |
| 457 | #else |
| 458 | pmemlen = 0x20000; |
| 459 | #endif |
| 460 | return 0; |
| 461 | } |
| 462 | early_param("pmemlen", early_param_pmemlen); |
| 463 | |
| 464 | /* |
| 465 | * Set up persistent memory. If we were given values, we patch the array of |
| 466 | * resources. Otherwise, persistent memory may be allocated anywhere at all. |
| 467 | */ |
| 468 | static void __init pmem_setup_resource(void) |
| 469 | { |
| 470 | struct resource *resource; |
| 471 | resource = asic_resource_get("DiagPersistentMemory"); |
| 472 | |
| 473 | if (resource && pmemaddr && pmemlen) { |
| 474 | /* The address provided by bootloader is in kseg0. Convert to |
| 475 | * a bus address. */ |
David VomLehn | ca36c36 | 2010-05-21 11:25:36 -0700 | [diff] [blame] | 476 | resource->start = phys_to_dma(pmemaddr - 0x80000000); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 477 | resource->end = resource->start + pmemlen - 1; |
| 478 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 479 | pr_info("persistent memory: start=0x%x end=0x%x\n", |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 480 | resource->start, resource->end); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * |
| 486 | * RESOURCE ACCESS FUNCTIONS |
| 487 | * |
| 488 | */ |
| 489 | |
| 490 | /** |
| 491 | * asic_resource_get - retrieves parameters for a platform resource. |
| 492 | * @name: string to match resource |
| 493 | * |
| 494 | * Returns a pointer to a struct resource corresponding to the given name. |
| 495 | * |
| 496 | * CANNOT BE NAMED platform_resource_get, which would be the obvious choice, |
| 497 | * as this function name is already declared |
| 498 | */ |
| 499 | struct resource *asic_resource_get(const char *name) |
| 500 | { |
| 501 | int i; |
| 502 | |
| 503 | for (i = 0; gp_resources[i].flags != 0; i++) { |
| 504 | if (strcmp(gp_resources[i].name, name) == 0) |
| 505 | return &gp_resources[i]; |
| 506 | } |
| 507 | |
| 508 | return NULL; |
| 509 | } |
| 510 | EXPORT_SYMBOL(asic_resource_get); |
| 511 | |
| 512 | /** |
| 513 | * platform_release_memory - release pre-allocated memory |
| 514 | * @ptr: pointer to memory to release |
| 515 | * @size: size of resource |
| 516 | * |
| 517 | * This must only be called for memory allocated or reserved via the boot |
| 518 | * memory allocator. |
| 519 | */ |
| 520 | void platform_release_memory(void *ptr, int size) |
| 521 | { |
Markos Chandras | c055629 | 2013-07-25 16:11:28 +0100 | [diff] [blame] | 522 | free_reserved_area(ptr, ptr + size, -1, NULL); |
David VomLehn | a3a0f8c | 2009-08-30 17:15:11 -0700 | [diff] [blame] | 523 | } |
| 524 | EXPORT_SYMBOL(platform_release_memory); |
| 525 | |
| 526 | /* |
| 527 | * |
| 528 | * FEATURE AVAILABILITY FUNCTIONS |
| 529 | * |
| 530 | */ |
| 531 | int platform_supports_dvr(void) |
| 532 | { |
| 533 | return (platform_features & DVR_CAPABLE) != 0; |
| 534 | } |
| 535 | |
| 536 | int platform_supports_ffs(void) |
| 537 | { |
| 538 | return (platform_features & FFS_CAPABLE) != 0; |
| 539 | } |
| 540 | |
| 541 | int platform_supports_pcie(void) |
| 542 | { |
| 543 | return (platform_features & PCIE_CAPABLE) != 0; |
| 544 | } |
| 545 | |
| 546 | int platform_supports_display(void) |
| 547 | { |
| 548 | return (platform_features & DISPLAY_CAPABLE) != 0; |
| 549 | } |