QEMU - Add an IDE drive.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
avibag
Posts: 8
Joined: Sat Oct 24, 2020 11:24 am

QEMU - Add an IDE drive.

Post 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!
Octocontrabass
Member
Member
Posts: 5562
Joined: Mon Mar 25, 2013 7:01 pm

Re: QEMU - Add an IDE drive.

Post 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.)
avibag
Posts: 8
Joined: Sat Oct 24, 2020 11:24 am

Re: QEMU - Add an IDE drive.

Post 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.
jaihsonk
Posts: 24
Joined: Thu Jul 14, 2022 10:46 am
Libera.chat IRC: json
Location: Canada
Contact:

Re: QEMU - Add an IDE drive.

Post by jaihsonk »

Would that script support both master and slave disks?
Octocontrabass
Member
Member
Posts: 5562
Joined: Mon Mar 25, 2013 7:01 pm

Re: QEMU - Add an IDE drive.

Post 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.
Post Reply