Help / Advice On Creating a Kernel Module

Yello,

I'm running a BF561 and what I'm basically trying to do is allow a Linux program on CoreA to read buffers that are being written to by a bare metal encoder running on CoreB. The buffers and varibles I need to be able to access have fixed memory locations in L3 and L2 Cache, the larger buffers and variables will be read on the Linux side, some of the others will need to be able to change bytes.

Now my main question is where or not it's possible to get the kernel process to pass to the Linux process a pointer so the linux process can read the buffer directly rather then have to copy the data. I know that the kernel module can directly address memory but I don't know how to then pass that to the Linux process. So can someone point me in the right direction, thanks

If it helps the bare metal process is a AD's H.264 encoder, and I need to be able to read the output NAL table and Stream buffer from linux, so they can be transmitted on to an end PC. I'm basically writting a mini ICC.

Kind Regards,

Nathan Skidmore

Parents
  • Nevermind, finally got to the point where I needed this to work and have spent all day with it and worked it out ^^

    Kernel Module:

    static unsigned char *gStreamBuf[NUM_INSTANCES][NUM_STREAM_BUFFERS];    // Points to the stream buffer in SDRAM

    ...

    static int __init encoder_icc_init (void)
    {
        // Points gStreamBuf to the stream buffers in L3 cache
        gStreamBuf[0][0] = (unsigned char *)0x02800000;

    ...

    }

    long encoder_icc_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
    {
        switch (cmd)
        {

    ...

            case (1):
            {
                eInstanceFlags[1].active = ~eInstanceFlags[1].active;
                printk ("Encoder ICC Module: Buffer Address %x\n", (unsigned int) &gStreamBuf[0][0]);
                printk ("Encoder ICC Module: Buffer Pointer %x\n", (unsigned int) gStreamBuf[0][0]);

                ret = put_user ((unsigned int)gStreamBuf[0][0], (unsigned int*) arg);
                if (ret)
                {
                    return -EFAULT;
                }
                else
                {
                    return 0;
                }
            }
            break;

    ...

        }
    }

    Linux Program:

    unsigned char *gStreamBuf;

    int main() {

    ...

    ret = ioctl(fd, 1, (unsigned int) &gStreamBuf);

    ...

    }

    I've skipped out all the code for creating and opening the device driver / kernel module so thats just the code to do what I was aiming for.

Reply
  • Nevermind, finally got to the point where I needed this to work and have spent all day with it and worked it out ^^

    Kernel Module:

    static unsigned char *gStreamBuf[NUM_INSTANCES][NUM_STREAM_BUFFERS];    // Points to the stream buffer in SDRAM

    ...

    static int __init encoder_icc_init (void)
    {
        // Points gStreamBuf to the stream buffers in L3 cache
        gStreamBuf[0][0] = (unsigned char *)0x02800000;

    ...

    }

    long encoder_icc_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
    {
        switch (cmd)
        {

    ...

            case (1):
            {
                eInstanceFlags[1].active = ~eInstanceFlags[1].active;
                printk ("Encoder ICC Module: Buffer Address %x\n", (unsigned int) &gStreamBuf[0][0]);
                printk ("Encoder ICC Module: Buffer Pointer %x\n", (unsigned int) gStreamBuf[0][0]);

                ret = put_user ((unsigned int)gStreamBuf[0][0], (unsigned int*) arg);
                if (ret)
                {
                    return -EFAULT;
                }
                else
                {
                    return 0;
                }
            }
            break;

    ...

        }
    }

    Linux Program:

    unsigned char *gStreamBuf;

    int main() {

    ...

    ret = ioctl(fd, 1, (unsigned int) &gStreamBuf);

    ...

    }

    I've skipped out all the code for creating and opening the device driver / kernel module so thats just the code to do what I was aiming for.

Children
No Data