Skip to contentSkip to conversation

mount PCI-express RAM memory as block device

DISCUSSION Shakthi Kannan 3 participants 5 messages Jan 7, 2005 – Jan 11, 2005

lore
Share & tools
lore
#0 lore raw

Greetings!

I would like to know as to how we can mount a filesystem for RAM memory on a PCI-express card. System for development is x86 with 2.4.22 kernel.

I, initially wrote a ramdisk driver to read/write data between buffer and RAM. Here, I have used:
device->data = vmalloc (device->size);
where:
- device is the device driver structure variable
- data = unsigned char *
- size = unsigned int

I am able to load the above block driver and mount a filesystem using:
dd if=/dev/zero of=/dev/sbull bs=1k count=64 mkdir /mnt/mysbull
mke2fs -vm0 /dev/sbull 64
mount /dev/sbull /mnt/mysbull

For PCI device driver, I have modifed the above to directly ioremap device->data as follows:
device->data = ioremap_nocache (BASE_ADDRESS, BASE_SIZE);
Have successfully done:
dd if=/dev/zero of=/dev/sbull bs=1k count=64 mkdir /mnt/mysbull
mke2fs -vm0 /dev/sbull 64

But, when I proceed to mount a filesystem, it fails. mount /dev/sbull /mnt/mysbull

mount:error while guessing filesystem type
mount: you must specify the filesystem type

Also, if I give "fsck -v /dev/sbull", it returns with improper filesystem super block. Even if I specify "-t ext2" for mount, it fails. I even tried a loopback device mount, but it fails too:
mount -o loop /dev/sbull /mnt/mysbull

FAT: bogus logical sector size 0
VFS: Can't find a valid FAT filesystem on dev FA:00

How can I map the RAM memory on the PCI card, even though I don't allocate any memory (during ioremap) and display that to the end user as a mounted filesystem so that he/she can read/write files to it?

Any help/pointers to links is appreciated.

Thanks,

K Shakthi

__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250

#1 lore raw
Quoted 50 lines · Shakthi Kannan

Greetings!

I would like to know as to how we can mount a filesystem for RAM memory on a PCI-express card. System for development is x86 with 2.4.22 kernel.

I, initially wrote a ramdisk driver to read/write data between buffer and RAM. Here, I have used:
device->data = vmalloc (device->size);
where:
- device is the device driver structure variable
- data = unsigned char *
- size = unsigned int

I am able to load the above block driver and mount a filesystem using:
dd if=/dev/zero of=/dev/sbull bs=1k count=64 mkdir /mnt/mysbull
mke2fs -vm0 /dev/sbull 64
mount /dev/sbull /mnt/mysbull

For PCI device driver, I have modifed the above to directly ioremap device->data as follows:
device->data = ioremap_nocache (BASE_ADDRESS, BASE_SIZE);
Have successfully done:
dd if=/dev/zero of=/dev/sbull bs=1k count=64 mkdir /mnt/mysbull
mke2fs -vm0 /dev/sbull 64

But, when I proceed to mount a filesystem, it fails. mount /dev/sbull /mnt/mysbull

mount:error while guessing filesystem type
mount: you must specify the filesystem type

Also, if I give "fsck -v /dev/sbull", it returns with improper filesystem super block. Even if I specify "-t ext2" for mount, it fails. I even tried a loopback device mount, but it fails too:
mount -o loop /dev/sbull /mnt/mysbull

FAT: bogus logical sector size 0
VFS: Can't find a valid FAT filesystem on dev FA:00

How can I map the RAM memory on the PCI card, even though I don't allocate any memory (during ioremap) and display that to the end user as a mounted filesystem so that he/she can read/write files to it?

Quoted 6 lines

Any help/pointers to links is appreciated.

Thanks,

K Shakthi

When you ioremap() in the kernel, you get a cookie that you can use (in the kernel) to copy data to and from the device.

This doesn't allow a user to copy data directly. Instead, in your read() and write() routines, you use the appropriate copy_to/from_user() routines. If the device is not a block device, then you will have to mount it through the loop device. If it is a block device, you can mount it directly after initialization.

Quoted 1 line

From your explanation, it looks like the BASE_ADDRESS is not

the device's on-board memory, but instead, its control registers, i.e., a simple implementation bug.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.10 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.

#2 lore raw

Hi,

Thanks for your replies Dick Johnson and Arnd Bergmann.

Quoted 5 lines · --- linux-os

From your explanation, it looks like the BASE_ADDRESS is not
the device's on-board memory, but instead, its control
registers, i.e., a simple implementation bug.

The BASE_ADDRESS is a physical address (0xfe8f0000) that points to the RAM memory on the PCI card, which I tried to remap so that the kernel can address it using memcpy.

Initially, I wrote a pci driver (character driver interface) to test memory read/write operations to this physical address (after ioremap) using readl/writel. This worked fine.

Quoted 5 lines · --- linux-os

When you ioremap() in the kernel, you get a cookie that you can use (in the kernel) to copy data to and from the device.
This doesn't allow a user to copy data directly. Instead, in your read() and write() routines, you

use > the appropriate copy_to/from_user() routines.

This being a block driver I only define block_device_operations. How would I declare and use the file_operations read(), write() routines?

Quoted 4 lines

If the device is not a block device, then you will have to mount it through the loop device. If it is a block device, you can mount it directly after initialization.

Which is where it fails.

Quoted 6 lines · --- Arnd Bergmann

If you are completely stuck on 2.4.22, it might be easier to
use the old slram driver instead of phram, but generally you
should try to hack on a modern kernel level like 2.6.10 anyway.

I shall test it with the 2.6.10 kernel.

Thanks again,

K Shakthi

__________________________________
Do you Yahoo!?
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com

#3 lore raw

Hi,

Quoted 7 lines · --- "Arnd Bergmann

You could use the MTD block driver with on the phram

device by simply specifying the address/size of the memory as a module parameter. If you need autodetection, the easiest way to do that would be including the phram MTD driver in your pci device driver.

I studied the slram.c and rd.c device drivers. The ramdisk driver that I had written earlier, similar to the above, had worked fine. With respect to PCI express, I had to modify just the memory tranfer function. The memcpy functions translate to byte access. But, PCI express is dword access. So, I wrote my own memory copy to do long read/write using readl(), writel(). The block device driver works fine.

Thanks,

K Shakthi

=====
-----------------------------------------------------
K Shakthi
Specsoft (Hexaware Technologies), ASIC Design Center
http://www.geocities.com/shakthimaan
-----------------------------------------------------

__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail

#4 lore raw
In reply to Shakthi Kannan
Quoted 4 lines · Shakthi Kannan

I would like to know as to how we can mount a
filesystem for RAM memory on a PCI-express card.
System for development is x86 with 2.4.22 kernel.

You could use the MTD block driver with on the phram device by simply specifying the address/size of the memory as a module parameter. If you need autodetection, the easiest way to do that would be including the phram MTD driver in your pci device driver.

If you are completely stuck on 2.4.22, it might be easier to use the old slram driver instead of phram, but generally you should try to hack on a modern kernel level like 2.6.10 anyway.

	Arnd <><