Changeset 182 for trunk/src/os2ahci/ahci.c
- Timestamp:
- Dec 13, 2016, 10:30:24 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/os2ahci/ahci.c
r181 r182 207 207 #endif 208 208 209 int AllocPortData(AD_INFO *ai, int p) 210 { 211 if (ai->ports[p]) return 0; 212 ai->ports[p] = MemAlloc(sizeof(P_INFO)); 213 if (ai->ports[p] == NULL) return 1; 214 memset(ai->ports[p], 0, sizeof(P_INFO)); 215 return 0; 216 } 217 218 FreePortData(AD_INFO *ai, int p) 219 { 220 } 221 222 /****************************************************************************** 223 * Save BIOS configuration of AHCI adapter. As a side effect, this also saves 224 * generic configuration information which we may have to restore after an 225 * adapter reset. 226 * 227 * NOTE: This function also saves working copies of the CAP and CAP2 registers 228 * as well as the initial port map in the AD_INFO structure after 229 * removing features which are known to cause trouble on this specific 230 * piece of hardware. 231 */ 232 int ahci_save_bios_config(AD_INFO *ai) 209 /****************************************************************************** 210 * setup the CAPS and other adapter information for this adapter. 211 * 212 * This function saves working copies of the CAP and CAP2 registers 213 * as well as the initial port map in the AD_INFO structure after 214 * removing features which are known to cause trouble on this specific 215 * piece of hardware. 216 */ 217 int ahci_config_caps(AD_INFO *ai) 233 218 { 234 219 int ports; 235 220 int i; 236 221 237 /* save BIOS configuration */ 238 for (i = 0; i < HOST_CAP2; i += sizeof(u32)) 239 { 240 ai->bios_config[i / sizeof(u32)] = readl(ai->mmio + i); 241 } 242 243 DPRINTF(3,"ahci_save_bios_config: BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN); 222 ai->cap = readl(ai->mmio + HOST_CAP); 223 ai->port_map = readl(ai->mmio + HOST_PORTS_IMPL); 244 224 245 225 /* HOST_CAP2 only exists for AHCI V1.2 and later */ 246 if (ai->bios_config[HOST_VERSION / sizeof(u32)] >= 0x00010200L) 247 { 248 ai->bios_config[HOST_CAP2 / sizeof(u32)] = readl(ai->mmio + HOST_CAP2); 249 } 250 else 251 { 252 ai->bios_config[HOST_CAP2 / sizeof(u32)] = 0; 253 } 254 255 if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 && 256 ai->pci_vendor == PCI_VENDOR_ID_INTEL) 257 { 258 /* Adapter is not in AHCI mode and the spec says a COMRESET is 259 * required when switching from SATA to AHCI mode and vice versa. 260 */ 261 init_reset = 1; 262 } 263 264 DUMP_HOST_REGS(2,ai,1); 265 266 /* Save working copies of CAP, CAP2 and port_map and remove broken feature 267 * bits. This is largely copied from the Linux AHCI driver -- the wisdom 268 * around quirks and faulty hardware is hard to come by... 269 */ 270 ai->cap = ai->bios_config[HOST_CAP / sizeof(u32)]; 271 ai->cap2 = ai->bios_config[HOST_CAP2 / sizeof(u32)]; 272 ai->port_map = ai->bios_config[HOST_PORTS_IMPL / sizeof(u32)]; 226 if (readl(ai->mmio + HOST_VERSION) >= 0x00010200L) ai->cap2 = readl(ai->mmio + HOST_CAP2); 273 227 274 228 if (ai->pci->board >= sizeof(initial_flags) / sizeof(*initial_flags)) … … 289 243 } 290 244 245 /* Remove broken feature bits. This is largely copied from the Linux AHCI driver -- the wisdom 246 * around quirks and faulty hardware is hard to come by... 247 */ 291 248 if ((ai->cap & HOST_CAP_NCQ) && (ai->flags & AHCI_HFLAG_NO_NCQ)) 292 249 { … … 332 289 for (i = 0; i < AHCI_MAX_PORTS; i++) 333 290 { 334 if (ai->port_map & (1UL << i)) 335 { 336 ports--; 337 } 291 if (ai->port_map & (1UL << i)) ports--; 338 292 } 339 293 if (ports < 0) … … 347 301 /* set maximum command slot number */ 348 302 ai->cmd_max = ((ai->cap >> 8) & 0x1f); 303 304 return(0); 305 } 306 307 /****************************************************************************** 308 * Save BIOS configuration of AHCI adapter. As a side effect, this also saves 309 * generic configuration information which we may have to restore after an 310 * adapter reset. 311 */ 312 int ahci_save_bios_config(AD_INFO *ai) 313 { 314 int i; 315 316 /* save BIOS configuration */ 317 for (i = 0; i < HOST_CAP2; i += sizeof(u32)) 318 { 319 ai->bios_config[i / sizeof(u32)] = readl(ai->mmio + i); 320 } 321 322 DPRINTF(3,"ahci_save_bios_config: BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN); 323 324 if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 && ai->pci_vendor == PCI_VENDOR_ID_INTEL) 325 { 326 /* Adapter is not in AHCI mode and the spec says a COMRESET is 327 * required when switching from SATA to AHCI mode and vice versa. 328 */ 329 init_reset = 1; 330 } 331 332 DUMP_HOST_REGS(2,ai,1); 349 333 350 334 return(0); … … 649 633 /* this port seems to have a device attached and ready for commands */ 650 634 DPRINTF(1,"ahci_scan_ports: port %d seems to be attached to a device; probing...\n", p); 635 636 #ifdef DAZ_NEW_CODE 637 ai->dma_buf[p] = MemAllocAlign(AHCI_PORT_PRIV_DMA_SZ, 1024); 638 ai->dma_buf_phys[p] = MemPhysAdr(ai->dma_buf[p]); 639 #endif 651 640 652 641 /* Get ATA(PI) identity. The so-called signature gives us a hint whether … … 681 670 /* no device attached to this port */ 682 671 ai->port_map &= ~(1UL << p); 683 // DAZ free port structure here 672 #ifdef DAZ_NEW_CODE 673 if (ai->dma_buf[p]) MemFree(ai->dma_buf[p]); 674 ai->dma_buf[p] = NULL; 675 #endif 684 676 } 685 677
Note:
See TracChangeset
for help on using the changeset viewer.