Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 114630
b: refs/heads/master
c: 5006d1a
h: refs/heads/master
v: v3
  • Loading branch information
Benjamin Herrenschmidt committed Oct 13, 2008
1 parent cee58b3 commit 898158c
Show file tree
Hide file tree
Showing 21 changed files with 651 additions and 463 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4c3ed7d61bd474380e0d3e1eb0da164942f7c84e
refs/heads/master: 5006d1aae813727cc77cc56cca9e90ef748650ce
144 changes: 108 additions & 36 deletions trunk/arch/powerpc/boot/addnote.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Usage: addnote zImage
* Usage: addnote zImage [note.elf]
*
* If note.elf is supplied, it is the name of an ELF file that contains
* an RPA note to use instead of the built-in one. Alternatively, the
* note.elf file may be empty, in which case the built-in RPA note is
* used (this is to simplify how this is invoked from the wrapper script).
*/
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -43,27 +48,29 @@ char rpaname[] = "IBM,RPA-Client-Config";
*/
#define N_RPA_DESCR 8
unsigned int rpanote[N_RPA_DESCR] = {
0, /* lparaffinity */
64, /* min_rmo_size */
1, /* lparaffinity */
128, /* min_rmo_size */
0, /* min_rmo_percent */
40, /* max_pft_size */
46, /* max_pft_size */
1, /* splpar */
-1, /* min_load */
0, /* new_mem_def */
1, /* ignore_my_client_config */
1, /* new_mem_def */
0, /* ignore_my_client_config */
};

#define ROUNDUP(len) (((len) + 3) & ~3)

unsigned char buf[512];
unsigned char notebuf[512];

#define GET_16BE(off) ((buf[off] << 8) + (buf[(off)+1]))
#define GET_32BE(off) ((GET_16BE(off) << 16) + GET_16BE((off)+2))
#define GET_16BE(b, off) (((b)[off] << 8) + ((b)[(off)+1]))
#define GET_32BE(b, off) ((GET_16BE((b), (off)) << 16) + \
GET_16BE((b), (off)+2))

#define PUT_16BE(off, v) (buf[off] = ((v) >> 8) & 0xff, \
buf[(off) + 1] = (v) & 0xff)
#define PUT_32BE(off, v) (PUT_16BE((off), (v) >> 16), \
PUT_16BE((off) + 2, (v)))
#define PUT_16BE(b, off, v) ((b)[off] = ((v) >> 8) & 0xff, \
(b)[(off) + 1] = (v) & 0xff)
#define PUT_32BE(b, off, v) (PUT_16BE((b), (off), (v) >> 16), \
PUT_16BE((b), (off) + 2, (v)))

/* Structure of an ELF file */
#define E_IDENT 0 /* ELF header */
Expand All @@ -88,15 +95,71 @@ unsigned char buf[512];

unsigned char elf_magic[4] = { 0x7f, 'E', 'L', 'F' };

unsigned char *read_rpanote(const char *fname, int *nnp)
{
int notefd, nr, i;
int ph, ps, np;
int note, notesize;

notefd = open(fname, O_RDONLY);
if (notefd < 0) {
perror(fname);
exit(1);
}
nr = read(notefd, notebuf, sizeof(notebuf));
if (nr < 0) {
perror("read note");
exit(1);
}
if (nr == 0) /* empty file */
return NULL;
if (nr < E_HSIZE ||
memcmp(&notebuf[E_IDENT+EI_MAGIC], elf_magic, 4) != 0 ||
notebuf[E_IDENT+EI_CLASS] != ELFCLASS32 ||
notebuf[E_IDENT+EI_DATA] != ELFDATA2MSB)
goto notelf;
close(notefd);

/* now look for the RPA-note */
ph = GET_32BE(notebuf, E_PHOFF);
ps = GET_16BE(notebuf, E_PHENTSIZE);
np = GET_16BE(notebuf, E_PHNUM);
if (ph < E_HSIZE || ps < PH_HSIZE || np < 1)
goto notelf;

for (i = 0; i < np; ++i, ph += ps) {
if (GET_32BE(notebuf, ph + PH_TYPE) != PT_NOTE)
continue;
note = GET_32BE(notebuf, ph + PH_OFFSET);
notesize = GET_32BE(notebuf, ph + PH_FILESZ);
if (notesize < 34 || note + notesize > nr)
continue;
if (GET_32BE(notebuf, note) != strlen(rpaname) + 1 ||
GET_32BE(notebuf, note + 8) != 0x12759999 ||
strcmp((char *)&notebuf[note + 12], rpaname) != 0)
continue;
/* looks like an RPA note, return it */
*nnp = notesize;
return &notebuf[note];
}
/* no RPA note found */
return NULL;

notelf:
fprintf(stderr, "%s is not a big-endian 32-bit ELF image\n", fname);
exit(1);
}

int
main(int ac, char **av)
{
int fd, n, i;
int ph, ps, np;
int nnote, nnote2, ns;
unsigned char *rpap;

if (ac != 2) {
fprintf(stderr, "Usage: %s elf-file\n", av[0]);
if (ac != 2 && ac != 3) {
fprintf(stderr, "Usage: %s elf-file [rpanote.elf]\n", av[0]);
exit(1);
}
fd = open(av[1], O_RDWR);
Expand All @@ -107,6 +170,7 @@ main(int ac, char **av)

nnote = 12 + ROUNDUP(strlen(arch) + 1) + sizeof(descr);
nnote2 = 12 + ROUNDUP(strlen(rpaname) + 1) + sizeof(rpanote);
rpap = NULL;

n = read(fd, buf, sizeof(buf));
if (n < 0) {
Expand All @@ -124,16 +188,19 @@ main(int ac, char **av)
exit(1);
}

ph = GET_32BE(E_PHOFF);
ps = GET_16BE(E_PHENTSIZE);
np = GET_16BE(E_PHNUM);
if (ac == 3)
rpap = read_rpanote(av[2], &nnote2);

ph = GET_32BE(buf, E_PHOFF);
ps = GET_16BE(buf, E_PHENTSIZE);
np = GET_16BE(buf, E_PHNUM);
if (ph < E_HSIZE || ps < PH_HSIZE || np < 1)
goto notelf;
if (ph + (np + 2) * ps + nnote + nnote2 > n)
goto nospace;

for (i = 0; i < np; ++i) {
if (GET_32BE(ph + PH_TYPE) == PT_NOTE) {
if (GET_32BE(buf, ph + PH_TYPE) == PT_NOTE) {
fprintf(stderr, "%s already has a note entry\n",
av[1]);
exit(0);
Expand All @@ -148,37 +215,42 @@ main(int ac, char **av)

/* fill in the program header entry */
ns = ph + 2 * ps;
PUT_32BE(ph + PH_TYPE, PT_NOTE);
PUT_32BE(ph + PH_OFFSET, ns);
PUT_32BE(ph + PH_FILESZ, nnote);
PUT_32BE(buf, ph + PH_TYPE, PT_NOTE);
PUT_32BE(buf, ph + PH_OFFSET, ns);
PUT_32BE(buf, ph + PH_FILESZ, nnote);

/* fill in the note area we point to */
/* XXX we should probably make this a proper section */
PUT_32BE(ns, strlen(arch) + 1);
PUT_32BE(ns + 4, N_DESCR * 4);
PUT_32BE(ns + 8, 0x1275);
PUT_32BE(buf, ns, strlen(arch) + 1);
PUT_32BE(buf, ns + 4, N_DESCR * 4);
PUT_32BE(buf, ns + 8, 0x1275);
strcpy((char *) &buf[ns + 12], arch);
ns += 12 + strlen(arch) + 1;
for (i = 0; i < N_DESCR; ++i, ns += 4)
PUT_32BE(ns, descr[i]);
PUT_32BE(buf, ns, descr[i]);

/* fill in the second program header entry and the RPA note area */
ph += ps;
PUT_32BE(ph + PH_TYPE, PT_NOTE);
PUT_32BE(ph + PH_OFFSET, ns);
PUT_32BE(ph + PH_FILESZ, nnote2);
PUT_32BE(buf, ph + PH_TYPE, PT_NOTE);
PUT_32BE(buf, ph + PH_OFFSET, ns);
PUT_32BE(buf, ph + PH_FILESZ, nnote2);

/* fill in the note area we point to */
PUT_32BE(ns, strlen(rpaname) + 1);
PUT_32BE(ns + 4, sizeof(rpanote));
PUT_32BE(ns + 8, 0x12759999);
strcpy((char *) &buf[ns + 12], rpaname);
ns += 12 + ROUNDUP(strlen(rpaname) + 1);
for (i = 0; i < N_RPA_DESCR; ++i, ns += 4)
PUT_32BE(ns, rpanote[i]);
if (rpap) {
/* RPA note supplied in file, just copy the whole thing over */
memcpy(buf + ns, rpap, nnote2);
} else {
PUT_32BE(buf, ns, strlen(rpaname) + 1);
PUT_32BE(buf, ns + 4, sizeof(rpanote));
PUT_32BE(buf, ns + 8, 0x12759999);
strcpy((char *) &buf[ns + 12], rpaname);
ns += 12 + ROUNDUP(strlen(rpaname) + 1);
for (i = 0; i < N_RPA_DESCR; ++i, ns += 4)
PUT_32BE(buf, ns, rpanote[i]);
}

/* Update the number of program headers */
PUT_16BE(E_PHNUM, np + 2);
PUT_16BE(buf, E_PHNUM, np + 2);

/* write back */
lseek(fd, (long) 0, SEEK_SET);
Expand Down
4 changes: 3 additions & 1 deletion trunk/arch/powerpc/boot/wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ fi
# post-processing needed for some platforms
case "$platform" in
pseries|chrp)
$objbin/addnote "$ofile"
${CROSS}objcopy -O binary -j .fakeelf "$kernel" "$ofile".rpanote
$objbin/addnote "$ofile" "$ofile".rpanote
rm -r "$ofile".rpanote
;;
coff)
${CROSS}objcopy -O aixcoff-rs6000 --set-start "$entry" "$ofile"
Expand Down
3 changes: 2 additions & 1 deletion trunk/arch/powerpc/include/asm/smp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern void __cpu_die(unsigned int cpu);

#else
/* for UP */
#define hard_smp_processor_id() 0
#define hard_smp_processor_id() get_hard_smp_processor_id(0)
#define smp_setup_cpu_maps()

#endif /* CONFIG_SMP */
Expand Down Expand Up @@ -122,6 +122,7 @@ static inline int get_hard_smp_processor_id(int cpu)

static inline void set_hard_smp_processor_id(int cpu, int phys)
{
boot_cpuid_phys = phys;
}
#endif /* !CONFIG_SMP */
#endif /* !CONFIG_PPC64 */
Expand Down
8 changes: 5 additions & 3 deletions trunk/arch/powerpc/kernel/misc_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,10 @@ _GLOBAL(kernel_thread)
li r4,0 /* new sp (unused) */
li r0,__NR_clone
sc
cmpwi 0,r3,0 /* parent or child? */
bne 1f /* return if parent */
bns+ 1f /* did system call indicate error? */
neg r3,r3 /* if so, make return code negative */
1: cmpwi 0,r3,0 /* parent or child? */
bne 2f /* return if parent */
li r0,0 /* make top-level stack frame */
stwu r0,-16(r1)
mtlr r30 /* fn addr in lr */
Expand All @@ -911,7 +913,7 @@ _GLOBAL(kernel_thread)
li r0,__NR_exit /* exit if function returns */
li r3,0
sc
1: lwz r30,8(r1)
2: lwz r30,8(r1)
lwz r31,12(r1)
addi r1,r1,16
blr
Expand Down
8 changes: 5 additions & 3 deletions trunk/arch/powerpc/kernel/misc_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,10 @@ _GLOBAL(kernel_thread)
li r4,0 /* new sp (unused) */
li r0,__NR_clone
sc
cmpdi 0,r3,0 /* parent or child? */
bne 1f /* return if parent */
bns+ 1f /* did system call indicate error? */
neg r3,r3 /* if so, make return code negative */
1: cmpdi 0,r3,0 /* parent or child? */
bne 2f /* return if parent */
li r0,0
stdu r0,-STACK_FRAME_OVERHEAD(r1)
ld r2,8(r29)
Expand All @@ -438,7 +440,7 @@ _GLOBAL(kernel_thread)
li r0,__NR_exit /* exit after child exits */
li r3,0
sc
1: addi r1,r1,STACK_FRAME_OVERHEAD
2: addi r1,r1,STACK_FRAME_OVERHEAD
ld r29,-24(r1)
ld r30,-16(r1)
blr
Expand Down
10 changes: 5 additions & 5 deletions trunk/arch/powerpc/kernel/prom_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ static struct fake_elf {
u32 ignore_me;
} rpadesc;
} rpanote;
} fake_elf = {
} fake_elf __section(.fakeelf) = {
.elfhdr = {
.e_ident = { 0x7f, 'E', 'L', 'F',
ELFCLASS32, ELFDATA2MSB, EV_CURRENT },
Expand Down Expand Up @@ -774,13 +774,13 @@ static struct fake_elf {
.type = 0x12759999,
.name = "IBM,RPA-Client-Config",
.rpadesc = {
.lpar_affinity = 0,
.min_rmo_size = 64, /* in megabytes */
.lpar_affinity = 1,
.min_rmo_size = 128, /* in megabytes */
.min_rmo_percent = 0,
.max_pft_size = 48, /* 2^48 bytes max PFT size */
.max_pft_size = 46, /* 2^46 bytes max PFT size */
.splpar = 1,
.min_load = ~0U,
.new_mem_def = 0
.new_mem_def = 1
}
}
};
Expand Down
3 changes: 1 addition & 2 deletions trunk/arch/powerpc/kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ void smp_message_recv(int msg)
generic_smp_call_function_interrupt();
break;
case PPC_MSG_RESCHEDULE:
/* XXX Do we have to do this? */
set_need_resched();
/* we notice need_resched on exit */
break;
case PPC_MSG_CALL_FUNC_SINGLE:
generic_smp_call_function_single_interrupt();
Expand Down
3 changes: 3 additions & 0 deletions trunk/arch/powerpc/kernel/vmlinux.lds.S
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ SECTIONS
*(.rela*)
}

/* Fake ELF header containing RPA note; for addnote */
.fakeelf : AT(ADDR(.fakeelf) - LOAD_OFFSET) { *(.fakeelf) }

/* freed after init ends here */
. = ALIGN(PAGE_SIZE);
__init_end = .;
Expand Down
Loading

0 comments on commit 898158c

Please sign in to comment.