Kernel rambuff patch

Since the driver does DMA into memory, it needs to have access to memory that is "reserved" for use by the DT3155 driver. This leads to a kernel patch to allocate a chunk of phsical memory early in kernel initialization (before the filesystem caches and VM system get a chance to place said memory under their management). This is done by means of a small set of patches known as the "rambuff" patches, in conjuntion with adding an append line to lilo.conf to indicate how much memory should be reserved in this manner.
In our case, the lilo line looks like:

image=/boot/vmlinuz-2.2.16-3-rambuff
        label=linux
        initrd=/boot/initrd-2.2.16-3.img
        read-only
        append="rambuff=512"
        root=/dev/sda8

The patch itself affects the following 3 files:

The changes to main.c need to be placed in the proper place in the file (I show a line of context AFTER the lines to be added in this case). The changes to ksyms.c and resource.c are just appended to the end of the files.

Changes to main.c


extern long rambuff_init(long, long);
extern void rambuff_setup(char *str, int *ints);
extern void device_setup(void);

....

	{ "rambuff=", rambuff_setup },
        { "panic=", panic_setup },

....

	memory_start = rambuff_init(memory_start, memory_end);
        memory_start = kmem_cache_init(memory_start, memory_end);

Changes to ksyms.c

extern long rambuff_address;
extern long rambuff_length;

EXPORT_SYMBOL(rambuff_address);
EXPORT_SYMBOL(rambuff_length);

/* THE END */

Changes to resource.c


/* Called from init/main.c to reserve RAM buffer. */
long rambuff_address = 0;
long rambuff_length  = 0;

void rambuff_setup(char *str, int *ints)
{
        int i;
        long p = 0;
        printk("rambuff_setup: (%d)", ints[0]);
        for (i = 1; i <= ints[0]; i++) {
                printk("%08ld[%3d] ", p, ints[i]);
                p += ints[i] * PAGE_SIZE;
        }
        printk("\n");
        rambuff_length = p;
}

long rambuff_init(long memory_start, long memory_end)
{
        long p;

        if (rambuff_length <= 0) {
                printk("rambuff_init: Nothing to do\n");
                return memory_start;
        }

        /* round up to a page boundary
         */
        p = (memory_start + PAGE_SIZE -1) & ~(PAGE_SIZE -1);

        /* We must leave at least 4M after we allocate.
         */
        if ((memory_end - p - rambuff_length) < 4*1024*1024) {
                rambuff_length = memory_end -p -4*1024*1024;
                if (rambuff_length < 128*1024) {
                        /* XXX - use kmalloc instead */
                        rambuff_length = 0;
                        rambuff_address = 0;
                        printk("rambuff_init: Aborted\n");
                        return memory_start;
                }
        }

        if (rambuff_length) {
                rambuff_address = p;
                printk("rambuff_init: %08x -> %08x -- %ld\n",
                        memory_start, rambuff_address, rambuff_length);
                memory_start = p + rambuff_length;
        }

        return memory_start;
}

/* THE END */

After adding this code, rebuilding the kernel, running lilo, and rebooting, you should see messages like this:

May 18 10:54:11 Pickaxe kernel: rambuff_setup: (1)00000000[512]
May 18 10:54:11 Pickaxe kernel: rambuff_init: c03c3e30 -> c03c4000 -- 2097152
May 18 10:54:11 Pickaxe kernel: Calibrating delay loop... 796.26 BogoMIPS

Messages like the following indicate that you did not give the append option to the kernel (check /etc/lilo.conf and rerun lilo).

May 17 18:48:32 Pickaxe kernel: rambuff_init: Nothing to do
May 17 18:48:32 Pickaxe kernel: Calibrating delay loop... 796.26 BogoMIPS

Have any comments? Questions? Drop me a line!

Adventures in Computing / ttrebisky@as.arizona.edu