From: Minep Date: Tue, 9 Aug 2022 14:29:17 +0000 (+0100) Subject: Merge branch 'master' into vfs-dev X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/0e1309c02f0703c050df09b71346dab60fc6df87?hp=-c Merge branch 'master' into vfs-dev --- 0e1309c02f0703c050df09b71346dab60fc6df87 diff --combined lunaix-os/hal/ahci/ahci.c index 53981a0,aadb41b..39e511c --- a/lunaix-os/hal/ahci/ahci.c +++ b/lunaix-os/hal/ahci/ahci.c @@@ -16,7 -16,6 +16,7 @@@ #include #include +#include #include #include #include @@@ -161,7 -160,7 +161,7 @@@ ahci_init( // 需要通过全部置位去清空这些寄存器(相当的奇怪……) port_regs[HBA_RPxSERR] = -1; - port_regs[HBA_RPxIE] |= (HBA_PxINTR_D2HR); + port_regs[HBA_RPxIE] |= (HBA_PxINTR_DPS); hba.ports[i] = port; @@@ -176,8 -175,6 +176,8 @@@ if (!ahci_init_device(port)) { kprintf(KERROR "fail to init device"); } + + block_mount_disk(port->device); } } @@@ -280,7 -277,7 +280,7 @@@ hba_prepare_cmd(struct hba_port* port // 构建命令头(Command Header)和命令表(Command Table) struct hba_cmdh* cmd_header = &port->cmdlst[slot]; - struct hba_cmdt* cmd_table = vcalloc_dma(sizeof(struct hba_cmdt)); + struct hba_cmdt* cmd_table = vzalloc_dma(sizeof(struct hba_cmdt)); memset(cmd_header, 0, sizeof(*cmd_header)); @@@ -293,7 -290,7 +293,7 @@@ cmd_header->prdt_len = 1; cmd_table->entries[0] = (struct hba_prdte){ .data_base = vmm_v2p(buffer), - .byte_count = size - 1 }; + .byte_count = (size - 1) | (0x80000000) }; } *cmdh = cmd_header; @@@ -319,8 -316,7 +319,8 @@@ ahci_init_device(struct hba_port* port // 清空任何待响应的中断 port->regs[HBA_RPxIS] = 0; - port->device = vcalloc(sizeof(struct hba_device)); + port->device = vzalloc(sizeof(struct hba_device)); + port->device->port = port; // 在命令表中构建命令FIS struct sata_reg_fis* cmd_fis = (struct sata_reg_fis*)cmd_table->command_fis; diff --combined lunaix-os/hal/pci.c index 50fe80d,8c397b0..d626768 --- a/lunaix-os/hal/pci.c +++ b/lunaix-os/hal/pci.c @@@ -11,7 -11,7 +11,7 @@@ #include #include #include -#include +#include #include #include @@@ -55,7 -55,7 +55,7 @@@ pci_probe_device(int bus, int dev, int pci_reg_t intr = pci_read_cspace(base, 0x3c); pci_reg_t class = pci_read_cspace(base, 0x8); - struct pci_device* device = lxmalloc(sizeof(struct pci_device)); + struct pci_device* device = valloc(sizeof(struct pci_device)); *device = (struct pci_device){ .cspace_base = base, .class_info = class, .device_info = reg1, @@@ -181,13 -181,22 +181,22 @@@ pci_setup_msi(struct pci_device* device pci_write_cspace( device->cspace_base, PCI_MSI_ADDR(device->msi_loc), msi_addr); - pci_write_cspace( - device->cspace_base, PCI_MSI_DATA(device->msi_loc), msi_data & 0xffff); pci_reg_t reg1 = pci_read_cspace(device->cspace_base, device->msi_loc); + pci_reg_t msg_ctl = reg1 >> 16; + + int offset = !!(msg_ctl & MSI_CAP_64BIT) * 4; + pci_write_cspace(device->cspace_base, + PCI_MSI_DATA(device->msi_loc, offset), + msi_data & 0xffff); + + if ((msg_ctl & MSI_CAP_MASK)) { + pci_write_cspace( + device->cspace_base, PCI_MSI_MASK(device->msi_loc, offset), 0); + } // manipulate the MSI_CTRL to allow device using MSI to request service. - reg1 = ((((reg1 >> 16) & ~0x70) | MSI_CAP_ENABLE) << 16) | (reg1 & 0xffff); + reg1 = (reg1 & 0xff8fffff) | 0x10000; pci_write_cspace(device->cspace_base, device->msi_loc, reg1); } diff --combined lunaix-os/includes/hal/ahci/hba.h index 91ecfed,f65a93d..334acd5 --- a/lunaix-os/includes/hal/ahci/hba.h +++ b/lunaix-os/includes/hal/ahci/hba.h @@@ -32,7 -32,7 +32,7 @@@ #define HBA_PxCMD_ST (1) #define HBA_PxINTR_DMA (1 << 2) #define HBA_PxINTR_D2HR (1) - #define HBA_PxINTR_DPE (1 << 5) + #define HBA_PxINTR_DPS (1 << 5) #define HBA_PxTFD_ERR (1) #define HBA_PxTFD_BSY (1 << 7) #define HBA_PxTFD_DRQ (1 << 3) @@@ -105,16 -105,15 +105,16 @@@ struct hba_devic uint32_t alignment_offset; uint32_t block_per_sec; uint32_t capabilities; + struct hba_port* port; struct { - int (*identify)(struct hba_port* port); - int (*read_buffer)(struct hba_port* port, + int (*identify)(struct hba_device* dev); + int (*read_buffer)(struct hba_device* dev, uint64_t lba, void* buffer, uint32_t size); - int (*write_buffer)(struct hba_port* port, + int (*write_buffer)(struct hba_device* dev, uint64_t lba, void* buffer, uint32_t size);