Page 1 of 1

QEMU - Add an IDE drive.

Posted: Wed Jul 21, 2021 1:05 pm
by avibag
Hi

I want to develop an IDE driver (using https://wiki.osdev.org/PCI_IDE_Controller). In that article, it says that an IDE should be listed in the PCI with class 0x1 and subclass 0x1. This is my code of finding PCI devices: (Please ignore the mess... It just for testing. I will rewrite it later..)

Code: Select all

void PCI::check_device(uint8_t bus, uint8_t device)
{
    uint16_t vendor_id = get_vendor_id(bus, device, 0);
    if (vendor_id == PCI_VENDOR_ID_DEVICE_DOES_NOT_EXIST)
        return;
    uint8_t header_type = get_header_type(bus, device, 0);
    if (header_type & PCI_HAS_MULTIPLE_FUNCTIONS_MASK)
    {
        for (int function = 0; function < PCI_NUMBER_OF_DEVICES_PER_BUS; function++)
        {
            uint8_t class_code = get_class_code(bus, device, function);
            uint8_t sub_class_code = get_sub_class_code(bus, device, function);

            kprintf("Class Code: %x, Sub Class Code: %x", (int) class_code, (int) (sub_class_code));
        }
    }
    else
    {
        uint8_t class_code = get_class_code(bus, device, 0);
        uint8_t sub_class_code = get_sub_class_code(bus, device, 0);

        kprintf("Class Code: %x, Sub Class Code: %x", (int) class_code, (int) (sub_class_code));
    }
}
When I run this code, I don't get any IDE device (I do get another devices).
So I went to Google, to check how to add an IDE disk to my emulator (QEMU). I didn't find how to do that.

Can someone please help me?

Thank's!

Re: QEMU - Add an IDE drive.

Posted: Wed Jul 21, 2021 5:22 pm
by Octocontrabass
What's your QEMU command line? You have to be using a configuration with a PCI IDE controller to see a PCI IDE controller.

Shouldn't that be PCI_NUMBER_OF_FUNCTIONS_PER_DEVICE?

Which devices are you able to find? (Vendor and device IDs can be more useful than class codes for figuring this out.)

Re: QEMU - Add an IDE drive.

Posted: Thu Jul 22, 2021 12:11 am
by avibag
Hi

Thank you for your reply

Finally I did managed to find a way to add an IDE controller, now I can see it in the list:

Code: Select all

qemu -device piix3-ide,id=ide -drive id=disk,file=image.img,format=raw,if=none -device ide-hd,drive=disk,bus=ide.0
But thanks anyway.
Octocontrabass wrote: Shouldn't that be PCI_NUMBER_OF_FUNCTIONS_PER_DEVICE?
Oh, right. Did not notice. Thank you.

Re: QEMU - Add an IDE drive.

Posted: Tue Jan 31, 2023 3:57 pm
by jaihsonk
Would that script support both master and slave disks?

Re: QEMU - Add an IDE drive.

Posted: Tue Jan 31, 2023 4:33 pm
by Octocontrabass
Which script are you talking about? The code in the first post enumerates PCI (except it has at least one bug). The QEMU command line can attach disks in any position on QEMU's emulated PCI IDE controller.