VirtualBox

Changeset 38897 in vbox for trunk/src/VBox/Devices/PC


Ignore:
Timestamp:
Sep 28, 2011 1:33:26 PM (13 years ago)
Author:
vboxsync
Message:

Broke out PCI utility routines as they are not tied to AHCI.

Location:
trunk/src/VBox/Devices/PC/BIOS-new
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/PC/BIOS-new/ahci.c

    r38851 r38897  
    2626#include "ebda.h"
    2727#include "inlines.h"
     28#include "pciutil.h"
    2829
    2930#define VBOX_AHCI_DEBUG         0
     
    7677     *  to save memory. - Must be aligned on a 1K boundary.
    7778     */
    78     uint32_t        abCmdHdr[0x8];
     79    uint32_t        aCmdHdr[0x8];
    7980    /** Align the next structure on a 128 byte boundary. */
    8081    uint8_t         abAlignment1[0x60];
     
    113114#define AhciData ((ahci_t *) 0)
    114115
    115 /** Supported methods of the PCI BIOS. */
    116 #define PCIBIOS_ID                      0xb1
    117 #define PCIBIOS_PCI_BIOS_PRESENT        0x01
    118 #define PCIBIOS_FIND_PCI_DEVICE         0x02
    119 #define PCIBIOS_FIND_CLASS_CODE         0x03
    120 #define PCIBIOS_GENERATE_SPECIAL_CYCLE  0x06
    121 #define PCIBIOS_READ_CONFIG_BYTE        0x08
    122 #define PCIBIOS_READ_CONFIG_WORD        0x09
    123 #define PCIBIOS_READ_CONFIG_DWORD       0x0a
    124 #define PCIBIOS_WRITE_CONFIG_BYTE       0x0b
    125 #define PCIBIOS_WRITE_CONFIG_WORD       0x0c
    126 #define PCIBIOS_WRITE_CONFIG_DWORD      0x0d
    127 #define PCIBIOS_GET_IRQ_ROUTING_OPTIONS 0x0e
    128 #define PCIBIOS_SET_PCI_IRQ             0x0f
    129 
    130 /** Status codes. */
    131 #define SUCCESSFUL                      0x00
    132 #define FUNC_NOT_SUPPORTED              0x81
    133 #define BAD_VENDOR_ID                   0x83
    134 #define DEVICE_NOT_FOUND                0x86
    135 #define BAD_REGISTER_NUMBER             0x87
    136 #define SET_FAILED                      0x88
    137 #define BUFFER_TOO_SMALL                0x89
    138 
    139116/** PCI configuration fields. */
    140117#define PCI_CONFIG_CAP                  0x34
     
    210187
    211188
    212 /* Warning: Destroys high bits of ECX. */
    213 uint16_t pci_find_class(uint16_t op, uint32_t dev_class, uint16_t start_bdf);
    214 #pragma aux pci_find_class =    \
    215     ".386"                  \
    216     "shl    ecx, 16"        \
    217     "mov    cx, dx"         \
    218     "int    0x1a"           \
    219     "cmp    ah, 0"          \
    220     "je     found"          \
    221     "mov    bx, 0xffff"     \
    222     "found:"                \
    223     parm [ax] [cx dx] [si] value [bx];
    224 
    225 uint16_t pci_read_cfgw(uint16_t op, uint16_t bus_dev_fn, uint16_t reg);
    226 #pragma aux pci_read_cfgw = \
    227     "int    0x1a"           \
    228     parm [ax] [bx] [di] value [cx];
    229 
    230 uint8_t pci_read_cfgb(uint16_t op, uint16_t bus_dev_fn, uint16_t reg);
    231 #pragma aux pci_read_cfgb = \
    232     "int    0x1a"           \
    233     parm [ax] [bx] [di] value [cx];
    234 
    235 /* Warning: Destroys high bits of ECX. */
    236 uint32_t pci_read_cfgd(uint16_t op, uint16_t bus_dev_fn, uint16_t reg);
    237 #pragma aux pci_read_cfgd = \
    238     ".386"                  \
    239     "int    0x1a"           \
    240     "mov    ax, cx"         \
    241     "shr    ecx, 16"        \
    242     parm [ax] [bx] [di] value [cx ax];
    243 
    244189/* Warning: Destroys high bits of EAX. */
    245190uint32_t inpd(uint16_t port);
     
    263208
    264209/**
    265  * Returns the bus/device/function of a PCI device with
    266  * the given class code.
    267  *
    268  * @returns bus/device/fn in a 16-bit integer where
    269  *          where the upper byte contains the bus number
    270  *          and lower one the device and function number.
    271  *          VBOX_AHCI_NO_DEVICE if no device was found.
    272  * @param   dev_class   The PCI class code to search for.
    273  */
    274 uint16_t pci_find_classcode(uint32_t dev_class)
    275 {
    276     return pci_find_class((PCIBIOS_ID << 8) | PCIBIOS_FIND_CLASS_CODE, dev_class, 0);
    277 }
    278 
    279 uint32_t pci_read_config_byte(uint8_t bus, uint8_t dev_fn, uint8_t reg)
    280 {
    281     return pci_read_cfgw((PCIBIOS_ID << 8) | PCIBIOS_READ_CONFIG_BYTE, (bus << 8) | dev_fn, reg);
    282 }
    283 
    284 uint32_t pci_read_config_word(uint8_t bus, uint8_t dev_fn, uint8_t reg)
    285 {
    286     return pci_read_cfgw((PCIBIOS_ID << 8) | PCIBIOS_READ_CONFIG_WORD, (bus << 8) | dev_fn, reg);
    287 }
    288 
    289 uint32_t pci_read_config_dword(uint8_t bus, uint8_t dev_fn, uint8_t reg)
    290 {
    291     return pci_read_cfgd((PCIBIOS_ID << 8) | PCIBIOS_READ_CONFIG_DWORD, (bus << 8) | dev_fn, reg);
    292 }
    293 
    294 #if 0 /* Disabled to save space because they are not needed. Might become useful in the future. */
    295 /**
    296  * Returns the bus/device/function of a PCI device with
    297  * the given vendor and device id.
    298  *
    299  * @returns bus/device/fn in one 16bit integer where
    300  *          where the upper byte contains the bus number
    301  *          and lower one the device and function number.
    302  *          VBOX_AHCI_NO_DEVICE if no device was found.
    303  * @param   u16Vendor    The vendor ID.
    304  * @param   u16Device    The device ID.
    305  */
    306 uint16_t pci_find_device(uint16_t u16Vendor, uint16_t u16Device)
    307 {
    308     uint16_t    u16BusDevFn;
    309 
    310 ASM_START
    311     push bp
    312     mov  bp, sp
    313 
    314     mov ah, #PCIBIOS_ID
    315     mov al, #PCIBIOS_FIND_PCI_DEVICE
    316     mov cx, _pci_find_device.u16Device + 2[bp]
    317     mov dx, _pci_find_device.u16Vendor + 2[bp]
    318     mov si, #0                                    ; First controller
    319     int 0x1a
    320 
    321     ; Return from PCIBIOS
    322     cmp ah, #SUCCESSFUL
    323     jne pci_find_device_not_found
    324 
    325     mov _pci_find_device.u16BusDevFn + 2[bp], bx
    326     jmp pci_find_device_done
    327 
    328 pci_find_device_not_found:
    329     mov _pci_find_device.u16BusDevFn + 2[bp], #VBOX_AHCI_NO_DEVICE
    330 
    331 pci_find_device_done:
    332     pop bp
    333 ASM_END
    334 
    335     return u16BusDevFn;
    336 }
    337 
    338 void pci_write_config_byte(u8Bus, u8DevFn, u8Reg, u8Val)
    339     uint8_t u8Bus, u8DevFn, u8Reg, u8Val;
    340 {
    341 ASM_START
    342     push bp
    343     mov  bp, sp
    344 
    345     mov ah, #PCIBIOS_ID
    346     mov al, #PCIBIOS_WRITE_CONFIG_BYTE
    347     mov bh, _pci_write_config_byte.u8Bus + 2[bp]
    348     mov bl, _pci_write_config_byte.u8DevFn + 2[bp]
    349     mov di, _pci_write_config_byte.u8Reg + 2[bp]
    350     mov cl, _pci_write_config_byte.u8Val + 2[bp]
    351     int 0x1a
    352 
    353     ; Return from PCIBIOS
    354     pop bp
    355 ASM_END
    356 }
    357 
    358 void pci_write_config_word(uint8_t u8Bus, uint8_t u8DevFn, uint8_t u8Reg, uint16_t u16Val)
    359 {
    360 ASM_START
    361     push bp
    362     mov  bp, sp
    363 
    364     mov ah, #PCIBIOS_ID
    365     mov al, #PCIBIOS_WRITE_CONFIG_WORD
    366     mov bh, _pci_write_config_word.u8Bus + 2[bp]
    367     mov bl, _pci_write_config_word.u8DevFn + 2[bp]
    368     mov di, _pci_write_config_word.u8Reg + 2[bp]
    369     mov cx, _pci_write_config_word.u16Val + 2[bp]
    370     int 0x1a
    371 
    372     ; Return from PCIBIOS
    373     pop bp
    374 ASM_END
    375 }
    376 
    377 void pci_write_config_dword(uint8_t u8Bus, uint8_t u8DevFn, uint8_t u8Reg, uint32_t u32Val)
    378 {
    379 ASM_START
    380     push bp
    381     mov  bp, sp
    382 
    383     mov ah, #PCIBIOS_ID
    384     mov al, #PCIBIOS_WRITE_CONFIG_WORD
    385     mov bh, _pci_write_config_dword.u8Bus + 2[bp]
    386     mov bl, _pci_write_config_dword.u8DevFn + 2[bp]
    387     mov di, _pci_write_config_dword.u8Reg + 2[bp]
    388     mov cx, _pci_write_config_dword.u32Val + 2[bp]
    389     int 0x1a
    390 
    391     ; Return from PCIBIOS
    392     pop bp
    393 ASM_END
    394 }
    395 #endif /* 0 */
    396 
    397 /**
    398210 * Sets a given set of bits in a register.
    399211 */
     
    465277        u32Val |= cFisDWords;
    466278
    467         ahci->abCmdHdr[0] = u32Val;
    468         ahci->abCmdHdr[1] = cbData;
    469         ahci->abCmdHdr[2] = ahci_addr_to_phys(&ahci->abCmd[0]);
     279        ahci->aCmdHdr[0] = u32Val;
     280        ahci->aCmdHdr[1] = cbData;
     281        ahci->aCmdHdr[2] = ahci_addr_to_phys(&ahci->abCmd[0]);
    470282
    471283        /* Enable Command and FIS receive engine. */
     
    562374         */
    563375        //@todo: merge memsets?
    564         _fmemset(&ahci->abCmdHdr[0], 0, 0x20);
     376        _fmemset(&ahci->aCmdHdr[0], 0, 0x20);
    565377        _fmemset(&ahci->abCmd[0], 0, 0x84);
    566378        _fmemset(&ahci->abFisRecv[0], 0, 0x60);
     
    606418     */
    607419    //@todo: just one memset?
    608     _fmemset(&ahci->abCmdHdr[0], 0, sizeof(ahci->abCmdHdr));
     420    _fmemset(&ahci->aCmdHdr[0], 0, sizeof(ahci->aCmdHdr));
    609421    _fmemset(&ahci->abCmd[0], 0, sizeof(ahci->abCmd));
    610422    _fmemset(&ahci->abFisRecv[0], 0, sizeof(ahci->abFisRecv));
     
    615427    VBOXAHCI_PORT_WRITE_REG(u16IoBase, u8Port, AHCI_REG_PORT_FBU, 0);
    616428
    617     u32PhysAddr = ahci_addr_to_phys(&ahci->abCmdHdr);
     429    u32PhysAddr = ahci_addr_to_phys(&ahci->aCmdHdr);
    618430    VBOXAHCI_DEBUG("AHCI: CMD list area %lx\n", u32PhysAddr);
    619431    VBOXAHCI_PORT_WRITE_REG(u16IoBase, u8Port, AHCI_REG_PORT_CLB, u32PhysAddr);
  • trunk/src/VBox/Devices/PC/BIOS-new/makefile

    r38848 r38897  
    3131        keyboard.obj disk.obj serial.obj system.obj timepci.obj &
    3232        ps2mouse.obj parallel.obj logo.obj scsi.obj ahci.obj &
    33         pcibio32.obj orgs.obj
     33        pciutil.obj pcibio32.obj orgs.obj
    3434
    3535vbxbios.rom : vbxbios.bin
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette