#include <linux/pci.h>
 #include <linux/string.h>
 #include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/bootmem.h>
 
 #include <asm/io.h>
 #include <asm/prom.h>
        const u32 *regs;
        struct pci_dn *pdn;
 
-       if (mem_init_done)
-               pdn = kmalloc(sizeof(*pdn), GFP_KERNEL);
-       else
-               pdn = alloc_bootmem(sizeof(*pdn));
+       pdn = alloc_maybe_bootmem(sizeof(*pdn), GFP_KERNEL);
        if (pdn == NULL)
                return NULL;
        memset(pdn, 0, sizeof(*pdn));
 
 endif
 
 ifeq ($(CONFIG_PPC_MERGE),y)
-obj-y                  := string.o
+obj-y                  := string.o alloc.o
 obj-$(CONFIG_PPC32)    += div64.o copy_32.o checksum_32.o
 endif
 
 
--- /dev/null
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/bootmem.h>
+
+#include <asm/system.h>
+
+void * __init_refok alloc_maybe_bootmem(size_t size, gfp_t mask)
+{
+       if (mem_init_done)
+               return kmalloc(size, mask);
+       else
+               return alloc_bootmem(size);
+}
 
 
        size = 256;
        config = &private->fake_config[devno][fn];
-       if (mem_init_done)
-               *config = kzalloc(size, GFP_KERNEL);
-       else
-               *config = alloc_bootmem(size);
+       *config = alloc_maybe_bootmem(size, GFP_KERNEL);
        if (*config == NULL) {
                printk(KERN_ERR "PCI: "
                       "not enough memory for fake configuration space\n");
 
        size = sizeof(struct celleb_pci_resource);
        res = &private->res[devno][fn];
-       if (mem_init_done)
-               *res = kzalloc(size, GFP_KERNEL);
-       else
-               *res = alloc_bootmem(size);
+       *res = alloc_maybe_bootmem(size, GFP_KERNEL);
        if (*res == NULL) {
                printk(KERN_ERR
                       "PCI: not enough memory for resource data space\n");
 
 static void __init celleb_alloc_private_mem(struct pci_controller *hose)
 {
-       if (mem_init_done)
-               hose->private_data =
-                       kzalloc(sizeof(struct celleb_pci_private), GFP_KERNEL);
-       else
-               hose->private_data =
-                       alloc_bootmem(sizeof(struct celleb_pci_private));
+       hose->private_data =
+               alloc_maybe_bootmem(sizeof(struct celleb_pci_private),
+                       GFP_KERNEL);
 }
 
 int __init celleb_setup_phb(struct pci_controller *phb)
 
  */
 
 #include <linux/irq.h>
-#include <linux/bootmem.h>
 #include <linux/bitmap.h>
 #include <linux/msi.h>
 #include <asm/mpic.h>
        size = BITS_TO_LONGS(mpic->irq_count) * sizeof(long);
        pr_debug("mpic: allocator bitmap size is 0x%x bytes\n", size);
 
-       if (mem_init_done)
-               mpic->hwirq_bitmap = kmalloc(size, GFP_KERNEL);
-       else
-               mpic->hwirq_bitmap = alloc_bootmem(size);
+       mpic->hwirq_bitmap = alloc_maybe_bootmem(size, GFP_KERNEL);
 
        if (!mpic->hwirq_bitmap) {
                pr_debug("mpic: ENOMEM allocating allocator bitmap!\n");
 
 extern unsigned long memory_limit;
 extern unsigned long klimit;
 
+extern void *alloc_maybe_bootmem(size_t size, gfp_t mask);
+
 extern int powersave_nap;      /* set if nap mode can be used in idle loop */
 
 /*