OSDev.org
https://forum.osdev.org/

QEMU - Add an IDE drive.
https://forum.osdev.org/viewtopic.php?f=1&t=46821
Page 1 of 1

Author:  avibag [ Wed Jul 21, 2021 1:05 pm ]
Post subject:  QEMU - Add an IDE drive.

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:
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!

Author:  Octocontrabass [ Wed Jul 21, 2021 5:22 pm ]
Post subject:  Re: QEMU - Add an IDE drive.

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.)

Author:  avibag [ Thu Jul 22, 2021 12:11 am ]
Post subject:  Re: QEMU - Add an IDE drive.

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:
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.

Author:  jaihsonk [ Tue Jan 31, 2023 3:57 pm ]
Post subject:  Re: QEMU - Add an IDE drive.

Would that script support both master and slave disks?

Author:  Octocontrabass [ Tue Jan 31, 2023 4:33 pm ]
Post subject:  Re: QEMU - Add an IDE drive.

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/