Merge branch 'master' into vfs-dev
authorMinep <zelong56@gmail.com>
Tue, 9 Aug 2022 14:29:17 +0000 (15:29 +0100)
committerMinep <zelong56@gmail.com>
Tue, 9 Aug 2022 14:29:17 +0000 (15:29 +0100)
1  2 
lunaix-os/hal/ahci/ahci.c
lunaix-os/hal/pci.c
lunaix-os/includes/hal/ahci/hba.h

index 53981a00415b4cdd2860fb4ea314f6bb95d8709a,aadb41b2aaf8ca294ec80d78b86799ffafa71e9c..39e511c33fde391a965c9b455daf06dc35312b54
@@@ -16,7 -16,6 +16,7 @@@
  
  #include <hal/pci.h>
  #include <klibc/string.h>
 +#include <lunaix/block.h>
  #include <lunaix/mm/mmio.h>
  #include <lunaix/mm/pmm.h>
  #include <lunaix/mm/valloc.h>
@@@ -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;
  
          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));
  
          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 50fe80d6c109fa7ffa8e04121b7b7d65f0393cf0,8c397b031b85f739b2331aeb2b512cb3931756b9..d6267682475ff74fafdffc7e23eb0796c5caad6b
@@@ -11,7 -11,7 +11,7 @@@
  #include <hal/acpi/acpi.h>
  #include <hal/apic.h>
  #include <hal/pci.h>
 -#include <lunaix/mm/kalloc.h>
 +#include <lunaix/mm/valloc.h>
  #include <lunaix/spike.h>
  #include <lunaix/syslog.h>
  
@@@ -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);
  }
  
index 91ecfedc3545ef4b34d7f3d57d2bedfe6f22c2a5,f65a93d460563202679337bf66d8706dda49eb69..334acd508a7dda0562478b00f88b35aed7acac9e
@@@ -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);