Blame view

arch/powerpc/boot/of.c 2.28 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
  /*
   * Copyright (C) Paul Mackerras 1997.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version
   * 2 of the License, or (at your option) any later version.
   */
  #include <stdarg.h>
decd300b3   Olaf Hering   [PATCH] ppc64: ma...
10
  #include <stddef.h>
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
11
12
  #include "types.h"
  #include "elf.h"
decd300b3   Olaf Hering   [PATCH] ppc64: ma...
13
14
  #include "string.h"
  #include "stdio.h"
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
15
16
  #include "page.h"
  #include "ops.h"
7840e5e95   Olaf Hering   [PATCH] ppc64: pr...
17

2e6016133   David Gibson   [POWERPC] Split l...
18
  #include "of.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19

b2c5f6192   Mark A. Greer   [POWERPC] Start a...
20
21
22
23
  /* Value picked to match that used by yaboot */
  #define PROG_START	0x01400000	/* only used on 64-bit systems */
  #define RAM_END		(512<<20)	/* Fixme: use OF */
  #define	ONE_MB		0x100000
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
24
25
26
  
  
  static unsigned long claim_base;
0c9fa2914   Benjamin Herrenschmidt   powerpc/zImage: m...
27
28
  void epapr_platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  			 unsigned long r6, unsigned long r7);
4ca478e60   Geert Uytterhoeven   [POWERPC] bootwra...
29
  static void *of_try_claim(unsigned long size)
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
30
31
  {
  	unsigned long addr = 0;
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
32

c998de146   Benjamin Herrenschmidt   [POWERPC] Fix zIm...
33
  	if (claim_base == 0)
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
34
  		claim_base = _ALIGN_UP((unsigned long)_end, ONE_MB);
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
35
36
37
38
39
40
  
  	for(; claim_base < RAM_END; claim_base += ONE_MB) {
  #ifdef DEBUG
  		printf("    trying: 0x%08lx
  \r", claim_base);
  #endif
034e55e6c   Cédric Le Goater   powerpc/boot: Rew...
41
42
  		addr = (unsigned long) of_claim(claim_base, size, 0);
  		if (addr != PROM_ERROR)
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  			break;
  	}
  	if (addr == 0)
  		return NULL;
  	claim_base = PAGE_ALIGN(claim_base + size);
  	return (void *)addr;
  }
  
  static void of_image_hdr(const void *hdr)
  {
  	const Elf64_Ehdr *elf64 = hdr;
  
  	if (elf64->e_ident[EI_CLASS] == ELFCLASS64) {
  		/*
  		 * Maintain a "magic" minimum address. This keeps some older
  		 * firmware platforms running.
  		 */
  		if (claim_base < PROG_START)
  			claim_base = PROG_START;
  	}
  }
0c9fa2914   Benjamin Herrenschmidt   powerpc/zImage: m...
64
  static void of_platform_init(unsigned long a1, unsigned long a2, void *promptr)
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
65
  {
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
66
67
  	platform_ops.image_hdr = of_image_hdr;
  	platform_ops.malloc = of_try_claim;
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
68
  	platform_ops.exit = of_exit;
79c854192   David Gibson   [POWERPC] zImage:...
69
  	platform_ops.vmlinux_alloc = of_vmlinux_alloc;
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
70
71
72
73
  
  	dt_ops.finddevice = of_finddevice;
  	dt_ops.getprop = of_getprop;
  	dt_ops.setprop = of_setprop;
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
74

2e6016133   David Gibson   [POWERPC] Split l...
75
  	of_console_init();
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
76

2e6016133   David Gibson   [POWERPC] Split l...
77
  	of_init(promptr);
cd197ffcf   David Gibson   [POWERPC] zImage:...
78
  	loader_info.promptr = promptr;
390cbb56a   Paul Mackerras   [POWERPC] Fix det...
79
80
81
82
  	if (a1 && a2 && a2 != 0xdeadbeef) {
  		loader_info.initrd_addr = a1;
  		loader_info.initrd_size = a2;
  	}
b2c5f6192   Mark A. Greer   [POWERPC] Start a...
83
  }
0c9fa2914   Benjamin Herrenschmidt   powerpc/zImage: m...
84
85
86
87
88
89
90
91
92
93
  
  void platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  		   unsigned long r6, unsigned long r7)
  {
  	/* Detect OF vs. ePAPR boot */
  	if (r5)
  		of_platform_init(r3, r4, (void *)r5);
  	else
  		epapr_platform_init(r3, r4, r5, r6, r7);
  }