MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / Port

Method Port

Kernel/src/storage/ahciport.cpp:15–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14namespace AHCI{
15 Port::Port(int num, hba_port_t* portStructure, hba_mem_t* hbaMem){
16 registers = portStructure;
17
18 registers->cmd &= ~HBA_PxCMD_ST;
19 registers->cmd &= ~HBA_PxCMD_FRE;
20
21 stopCMD(registers);
22
23 uintptr_t phys;
24
25 // Command list entry size = 32
26 // Command list entry maxim count = 32
27 // Command list maxim size = 32*32 = 1K per port
28 phys = Memory::AllocatePhysicalMemoryBlock();
29 registers->clb = (uint32_t)(phys & 0xFFFFFFFF);
30 registers->clbu = (uint32_t)(phys >> 32);
31
32 // FIS entry size = 256 bytes per port
33 phys = Memory::AllocatePhysicalMemoryBlock();
34 registers->fb = (uint32_t)(phys & 0xFFFFFFFF);
35 registers->fbu = (uint32_t)(phys >> 32);
36
37 // Command list size = 256*32 = 8K per port
38 commandList = (hba_cmd_header_t*)Memory::GetIOMapping(static_cast<uintptr_t>(registers->clb));
39 memset(commandList, 0, PAGE_SIZE_4K);
40
41 // FIS
42 fis = reinterpret_cast<hba_fis_t*>(Memory::GetIOMapping(static_cast<uintptr_t>(registers->fb)));
43 memset((void*)(fis), 0, PAGE_SIZE_4K);
44
45 fis->dsfis.fis_type = FIS_TYPE_DMA_SETUP;
46 fis->psfis.fis_type = FIS_TYPE_PIO_SETUP;
47 fis->rfis.fis_type = FIS_TYPE_REG_D2H;
48 fis->sdbfis[0] = FIS_TYPE_DEV_BITS;
49
50 for(int i = 0; i < 8 /*Support for 8 command slots*/; i++){
51 commandList[i].prdtl = 1;
52
53 phys = Memory::AllocatePhysicalMemoryBlock();
54 commandList[i].ctba = (uint32_t)(phys & 0xFFFFFFFF);
55 commandList[i].ctbau = (uint32_t)(phys >> 32);
56
57 commandTables[i] = (hba_cmd_tbl_t*)Memory::GetIOMapping(phys);
58 memset(commandTables[i],0,PAGE_SIZE_4K);
59 }
60
61 registers->sctl |= (SCTL_PORT_IPM_NOPART | SCTL_PORT_IPM_NOSLUM | SCTL_PORT_IPM_NODSLP);
62
63 if(hbaMem->cap & AHCI_CAP_SALP){
64 registers->cmd &= ~HBA_PxCMD_ASP; // Disable aggressive slumber and partial
65 }
66
67 registers->is = 0; // Clear interrupts
68 registers->ie = 1;
69 registers->fbs &= ~(0xFFFFF000U);
70
71 registers->cmd |= HBA_PxCMD_POD;
72 registers->cmd |= HBA_PxCMD_SUD;

Callers

nothing calls this directly

Calls 14

stopCMDFunction · 0.85
GetIOMappingFunction · 0.85
memsetFunction · 0.85
WarningFunction · 0.85
InfoFunction · 0.85
KernelAllocate4KPagesFunction · 0.85
KernelMapVirtualMemory4KFunction · 0.85
ErrorFunction · 0.85
SetValueMethod · 0.80
WaitFunction · 0.50
IdentifyFunction · 0.50

Tested by

no test coverage detected