2010-07-19 19:22:54 +00:00
|
|
|
|
/*
|
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
|
* Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
|
|
|
|
|
*
|
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <grub/dl.h>
|
|
|
|
|
#include <grub/disk.h>
|
|
|
|
|
#include <grub/mm.h>
|
|
|
|
|
#include <grub/time.h>
|
|
|
|
|
#include <grub/pci.h>
|
2010-12-24 15:07:53 +00:00
|
|
|
|
#include <grub/ata.h>
|
2010-07-19 19:22:54 +00:00
|
|
|
|
#include <grub/scsi.h>
|
2010-12-24 15:07:53 +00:00
|
|
|
|
#include <grub/misc.h>
|
|
|
|
|
#include <grub/list.h>
|
2010-12-25 11:11:54 +00:00
|
|
|
|
#include <grub/loader.h>
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
2011-06-23 22:29:21 +00:00
|
|
|
|
GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
struct grub_ahci_cmd_head
|
|
|
|
|
{
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_uint32_t config;
|
|
|
|
|
grub_uint32_t transfered;
|
|
|
|
|
grub_uint64_t command_table_base;
|
|
|
|
|
grub_uint32_t unused[4];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct grub_ahci_prdt_entry
|
|
|
|
|
{
|
|
|
|
|
grub_uint64_t data_base;
|
|
|
|
|
grub_uint32_t unused;
|
|
|
|
|
grub_uint32_t size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct grub_ahci_cmd_table
|
|
|
|
|
{
|
|
|
|
|
grub_uint8_t cfis[0x40];
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_uint8_t command[0x10];
|
|
|
|
|
grub_uint8_t reserved[0x30];
|
2010-12-24 15:07:53 +00:00
|
|
|
|
struct grub_ahci_prdt_entry prdt[1];
|
2010-07-19 19:22:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct grub_ahci_hba_port
|
|
|
|
|
{
|
|
|
|
|
grub_uint64_t command_list_base;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_uint64_t fis_base;
|
|
|
|
|
grub_uint32_t intstatus;
|
|
|
|
|
grub_uint32_t inten;
|
|
|
|
|
grub_uint32_t command;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_uint32_t unused1;
|
|
|
|
|
grub_uint32_t task_file_data;
|
|
|
|
|
grub_uint32_t sig;
|
2010-12-24 18:48:55 +00:00
|
|
|
|
grub_uint32_t status;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_uint32_t unused2;
|
|
|
|
|
grub_uint32_t sata_error;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
grub_uint32_t sata_active;
|
|
|
|
|
grub_uint32_t command_issue;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_uint32_t unused3;
|
|
|
|
|
grub_uint32_t fbs;
|
|
|
|
|
grub_uint32_t unused4[15];
|
2010-07-19 19:22:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
enum grub_ahci_hba_port_command
|
|
|
|
|
{
|
|
|
|
|
GRUB_AHCI_HBA_PORT_CMD_ST = 0x01,
|
2013-04-27 15:18:02 +00:00
|
|
|
|
GRUB_AHCI_HBA_PORT_CMD_SPIN_UP = 0x02,
|
|
|
|
|
GRUB_AHCI_HBA_PORT_CMD_POWER_ON = 0x04,
|
2010-12-25 02:06:07 +00:00
|
|
|
|
GRUB_AHCI_HBA_PORT_CMD_FRE = 0x10,
|
|
|
|
|
GRUB_AHCI_HBA_PORT_CMD_CR = 0x8000,
|
|
|
|
|
GRUB_AHCI_HBA_PORT_CMD_FR = 0x4000,
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
struct grub_ahci_hba
|
|
|
|
|
{
|
|
|
|
|
grub_uint32_t cap;
|
|
|
|
|
grub_uint32_t global_control;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_uint32_t intr_status;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
grub_uint32_t ports_implemented;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_uint32_t unused1[6];
|
2010-07-19 19:22:54 +00:00
|
|
|
|
grub_uint32_t bios_handoff;
|
|
|
|
|
grub_uint32_t unused2[53];
|
|
|
|
|
struct grub_ahci_hba_port ports[32];
|
|
|
|
|
};
|
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
struct grub_ahci_received_fis
|
|
|
|
|
{
|
|
|
|
|
char raw[4096];
|
|
|
|
|
};
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
GRUB_AHCI_HBA_CAP_NPORTS_MASK = 0x1f
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
2010-12-25 02:06:07 +00:00
|
|
|
|
GRUB_AHCI_HBA_GLOBAL_CONTROL_RESET = 0x00000001,
|
2010-12-24 15:07:53 +00:00
|
|
|
|
GRUB_AHCI_HBA_GLOBAL_CONTROL_INTR_EN = 0x00000002,
|
|
|
|
|
GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN = 0x80000000,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED = 1,
|
|
|
|
|
GRUB_AHCI_BIOS_HANDOFF_OS_OWNED = 2,
|
|
|
|
|
GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED = 8,
|
|
|
|
|
GRUB_AHCI_BIOS_HANDOFF_RWC = 8
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
struct grub_ahci_device
|
|
|
|
|
{
|
|
|
|
|
struct grub_ahci_device *next;
|
2012-01-24 12:31:12 +00:00
|
|
|
|
struct grub_ahci_device **prev;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
volatile struct grub_ahci_hba *hba;
|
|
|
|
|
int port;
|
|
|
|
|
int num;
|
|
|
|
|
struct grub_pci_dma_chunk *command_list_chunk;
|
|
|
|
|
volatile struct grub_ahci_cmd_head *command_list;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
struct grub_pci_dma_chunk *command_table_chunk;
|
|
|
|
|
volatile struct grub_ahci_cmd_table *command_table;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
struct grub_pci_dma_chunk *rfis;
|
2011-05-16 15:17:04 +00:00
|
|
|
|
int present;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
2011-05-16 15:17:04 +00:00
|
|
|
|
struct grub_disk_ata_pass_through_parms *parms,
|
2013-04-27 15:18:02 +00:00
|
|
|
|
int spinup, int reset);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
GRUB_AHCI_CONFIG_READ = 0,
|
|
|
|
|
GRUB_AHCI_CONFIG_CFIS_LENGTH_MASK = 0x1f,
|
|
|
|
|
GRUB_AHCI_CONFIG_ATAPI = 0x20,
|
|
|
|
|
GRUB_AHCI_CONFIG_WRITE = 0x40,
|
|
|
|
|
GRUB_AHCI_CONFIG_PREFETCH = 0x80,
|
|
|
|
|
GRUB_AHCI_CONFIG_RESET = 0x100,
|
|
|
|
|
GRUB_AHCI_CONFIG_BIST = 0x200,
|
|
|
|
|
GRUB_AHCI_CONFIG_CLEAR_R_OK = 0x400,
|
|
|
|
|
GRUB_AHCI_CONFIG_PMP_MASK = 0xf000,
|
|
|
|
|
GRUB_AHCI_CONFIG_PRDT_LENGTH_MASK = 0xffff0000,
|
|
|
|
|
};
|
|
|
|
|
#define GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT 0
|
|
|
|
|
#define GRUB_AHCI_CONFIG_PMP_SHIFT 12
|
|
|
|
|
#define GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT 16
|
|
|
|
|
#define GRUB_AHCI_INTERRUPT_ON_COMPLETE 0x80000000
|
|
|
|
|
|
|
|
|
|
#define GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH 0x200000
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
static struct grub_ahci_device *grub_ahci_devices;
|
|
|
|
|
static int numdevs;
|
|
|
|
|
|
2013-01-13 01:10:41 +00:00
|
|
|
|
static int
|
2010-07-19 19:22:54 +00:00
|
|
|
|
grub_ahci_pciinit (grub_pci_device_t dev,
|
2013-01-13 01:10:41 +00:00
|
|
|
|
grub_pci_id_t pciid __attribute__ ((unused)),
|
|
|
|
|
void *data __attribute__ ((unused)))
|
2010-07-19 19:22:54 +00:00
|
|
|
|
{
|
|
|
|
|
grub_pci_address_t addr;
|
|
|
|
|
grub_uint32_t class;
|
|
|
|
|
grub_uint32_t bar;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
unsigned i, nports;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
volatile struct grub_ahci_hba *hba;
|
|
|
|
|
|
|
|
|
|
/* Read class. */
|
|
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
|
|
|
|
class = grub_pci_read (addr);
|
|
|
|
|
|
|
|
|
|
/* Check if this class ID matches that of a PCI IDE Controller. */
|
|
|
|
|
if (class >> 8 != 0x010601)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
#ifdef GRUB_MACHINE_QEMU
|
|
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
|
|
|
|
|
grub_pci_write_word (addr, 0x107);
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
|
|
|
|
|
#ifdef GRUB_MACHINE_QEMU
|
|
|
|
|
grub_pci_write (addr, 0xf4000000);
|
|
|
|
|
#endif
|
2010-07-19 19:22:54 +00:00
|
|
|
|
bar = grub_pci_read (addr);
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
if ((bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK
|
|
|
|
|
| GRUB_PCI_ADDR_MEM_PREFETCH))
|
2010-07-19 19:22:54 +00:00
|
|
|
|
!= (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
addr = grub_pci_make_address (dev, GRUB_PCI_REG_COMMAND);
|
|
|
|
|
grub_pci_write_word (addr, grub_pci_read_word (addr) |
|
|
|
|
|
GRUB_PCI_COMMAND_IO_ENABLED
|
|
|
|
|
| GRUB_PCI_COMMAND_MEM_ENABLED
|
|
|
|
|
| GRUB_PCI_COMMAND_BUS_MASTER);
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK,
|
|
|
|
|
sizeof (hba));
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "dev: %x:%x.%x\n", dev.bus, dev.device, dev.function);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "tfd[0]: %x\n",
|
|
|
|
|
hba->ports[0].task_file_data);
|
|
|
|
|
grub_dprintf ("ahci", "cmd[0]: %x\n",
|
|
|
|
|
hba->ports[0].command);
|
|
|
|
|
grub_dprintf ("ahci", "st[0]: %x\n",
|
|
|
|
|
hba->ports[0].status);
|
|
|
|
|
grub_dprintf ("ahci", "err[0]: %x\n",
|
|
|
|
|
hba->ports[0].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "tfd[1]: %x\n",
|
|
|
|
|
hba->ports[1].task_file_data);
|
|
|
|
|
grub_dprintf ("ahci", "cmd[1]: %x\n",
|
|
|
|
|
hba->ports[1].command);
|
|
|
|
|
grub_dprintf ("ahci", "st[1]: %x\n",
|
|
|
|
|
hba->ports[1].status);
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
|
|
|
|
hba->ports[1].sata_error = hba->ports[1].sata_error;
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "BH:%x\n", hba->bios_handoff);
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
|
|
|
|
if (! (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_OS_OWNED))
|
|
|
|
|
{
|
|
|
|
|
grub_uint64_t endtime;
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "Requesting AHCI ownership\n");
|
|
|
|
|
hba->bios_handoff = (hba->bios_handoff & ~GRUB_AHCI_BIOS_HANDOFF_RWC)
|
|
|
|
|
| GRUB_AHCI_BIOS_HANDOFF_OS_OWNED;
|
|
|
|
|
grub_dprintf ("ahci", "Waiting for BIOS to give up ownership\n");
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED)
|
|
|
|
|
&& grub_get_time_ms () < endtime);
|
|
|
|
|
if (hba->bios_handoff & GRUB_AHCI_BIOS_HANDOFF_BIOS_OWNED)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "Forcibly taking ownership\n");
|
|
|
|
|
hba->bios_handoff = GRUB_AHCI_BIOS_HANDOFF_OS_OWNED;
|
|
|
|
|
hba->bios_handoff |= GRUB_AHCI_BIOS_HANDOFF_OS_OWNERSHIP_CHANGED;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
grub_dprintf ("ahci", "AHCI ownership obtained\n");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
grub_dprintf ("ahci", "AHCI is already in OS mode\n");
|
2010-12-25 02:06:07 +00:00
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
2011-12-12 21:20:14 +00:00
|
|
|
|
if (!(hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN))
|
2011-01-03 14:59:20 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI is in compat mode. Switching\n");
|
|
|
|
|
else
|
|
|
|
|
grub_dprintf ("ahci", "AHCI is in AHCI mode.\n");
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
|
|
|
|
|
|
|
|
|
/* {
|
|
|
|
|
grub_uint64_t endtime;
|
|
|
|
|
hba->global_control |= 1;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while (hba->global_control & 1)
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't reset AHCI\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
2011-01-03 14:59:20 +00:00
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN;
|
|
|
|
|
grub_millisleep (1);
|
|
|
|
|
if (hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == 5)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "Couldn't put AHCI in AHCI mode\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
2011-01-03 14:59:20 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
hba->global_control |= GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN;
|
|
|
|
|
grub_millisleep (1);
|
|
|
|
|
if (hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == 5)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "Couldn't put AHCI in AHCI mode\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-04-27 15:18:02 +00:00
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err[1]: %x\n",
|
|
|
|
|
hba->ports[1].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
|
|
|
|
|
nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1;
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "%d AHCI ports, PI = 0x%x\n", nports,
|
|
|
|
|
hba->ports_implemented);
|
|
|
|
|
|
|
|
|
|
struct grub_ahci_device *adevs[GRUB_AHCI_HBA_CAP_NPORTS_MASK + 1];
|
|
|
|
|
struct grub_ahci_device *failed_adevs[GRUB_AHCI_HBA_CAP_NPORTS_MASK + 1];
|
|
|
|
|
grub_uint32_t fr_running = 0;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
failed_adevs[i] = 0;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!(hba->ports_implemented & (1 << i)))
|
2013-04-27 15:18:02 +00:00
|
|
|
|
{
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-12-24 18:48:55 +00:00
|
|
|
|
|
2013-04-27 19:49:14 +00:00
|
|
|
|
adevs[i] = grub_zalloc (sizeof (*adevs[i]));
|
2013-04-27 15:18:02 +00:00
|
|
|
|
if (!adevs[i])
|
2010-07-19 19:22:54 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
adevs[i]->hba = hba;
|
|
|
|
|
adevs[i]->port = i;
|
|
|
|
|
adevs[i]->present = 1;
|
|
|
|
|
adevs[i]->num = numdevs++;
|
|
|
|
|
}
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
{
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error = adevs[i]->hba->ports[adevs[i]->port].sata_error;
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
|
|
|
|
|
adevs[i]->command_list_chunk = grub_memalign_dma32 (1024, sizeof (struct grub_ahci_cmd_head));
|
|
|
|
|
if (!adevs[i]->command_list_chunk)
|
|
|
|
|
{
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
adevs[i]->command_table_chunk = grub_memalign_dma32 (1024,
|
|
|
|
|
sizeof (struct grub_ahci_cmd_table));
|
|
|
|
|
if (!adevs[i]->command_table_chunk)
|
|
|
|
|
{
|
|
|
|
|
grub_dma_free (adevs[i]->command_list_chunk);
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adevs[i]->command_list = grub_dma_get_virt (adevs[i]->command_list_chunk);
|
|
|
|
|
adevs[i]->command_table = grub_dma_get_virt (adevs[i]->command_table_chunk);
|
|
|
|
|
adevs[i]->command_list->command_table_base
|
|
|
|
|
= grub_dma_get_phys (adevs[i]->command_table_chunk);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "found device ahci%d (port %d), command_table = %p, command_list = %p\n",
|
|
|
|
|
adevs[i]->num, adevs[i]->port, grub_dma_get_virt (adevs[i]->command_table_chunk),
|
|
|
|
|
grub_dma_get_virt (adevs[i]->command_list_chunk));
|
|
|
|
|
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grub_uint64_t endtime;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop FR on port %d\n", i);
|
|
|
|
|
failed_adevs[i] = adevs[i];
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop CR on port %d\n", i);
|
|
|
|
|
failed_adevs[i] = adevs[i];
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
{
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].inten = 0;
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].intstatus = ~0;
|
|
|
|
|
// adevs[i]->hba->ports[adevs[i]->port].fbs = 0;
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
|
|
|
|
|
adevs[i]->rfis = grub_memalign_dma32 (4096,
|
|
|
|
|
sizeof (struct grub_ahci_received_fis));
|
|
|
|
|
grub_memset ((char *) grub_dma_get_virt (adevs[i]->rfis), 0,
|
|
|
|
|
sizeof (struct grub_ahci_received_fis));
|
|
|
|
|
grub_memset ((char *) grub_dma_get_virt (adevs[i]->command_list_chunk), 0,
|
|
|
|
|
sizeof (struct grub_ahci_cmd_head));
|
|
|
|
|
grub_memset ((char *) grub_dma_get_virt (adevs[i]->command_table_chunk), 0,
|
|
|
|
|
sizeof (struct grub_ahci_cmd_table));
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].fis_base = grub_dma_get_phys (adevs[i]->rfis);
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command_list_base
|
|
|
|
|
= grub_dma_get_phys (adevs[i]->command_list_chunk);
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && !(adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && !(adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't start FR on port %d\n", i);
|
|
|
|
|
failed_adevs[i] = adevs[i];
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
fr_running |= (1 << i);
|
|
|
|
|
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_SPIN_UP;
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_POWER_ON;
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= 1 << 28;
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 10ms should actually be enough. */
|
|
|
|
|
endtime = grub_get_time_ms () + 100;
|
|
|
|
|
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].status & 7) != 3)
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].status & 7) != 3)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't detect device on port %d\n", i);
|
|
|
|
|
failed_adevs[i] = adevs[i];
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_POWER_ON;
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_SPIN_UP;
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error = ~0;
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "offset: %x, tfd:%x, CMD: %x\n",
|
2013-04-28 13:17:43 +00:00
|
|
|
|
(int) ((char *) &adevs[i]->hba->ports[adevs[i]->port].task_file_data -
|
|
|
|
|
(char *) adevs[i]->hba),
|
2013-04-27 15:18:02 +00:00
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].task_file_data,
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "offset: %x, tfd:%x, CMD: %x\n",
|
2013-04-28 13:17:43 +00:00
|
|
|
|
(int) ((char *) &adevs[i]->hba->ports[adevs[i]->port].task_file_data -
|
|
|
|
|
(char *) adevs[i]->hba),
|
2013-04-27 15:18:02 +00:00
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].task_file_data,
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "err: %x\n",
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].sata_error);
|
|
|
|
|
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command
|
|
|
|
|
= (adevs[i]->hba->ports[adevs[i]->port].command & 0x0fffffff) | (1 << 28) | 2 | 4;
|
|
|
|
|
|
|
|
|
|
/* struct grub_disk_ata_pass_through_parms parms2;
|
|
|
|
|
grub_memset (&parms2, 0, sizeof (parms2));
|
|
|
|
|
parms2.taskfile.cmd = 8;
|
|
|
|
|
grub_ahci_readwrite_real (dev, &parms2, 1, 1);*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endtime = grub_get_time_ms () + 10000;
|
|
|
|
|
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].task_file_data & 0x88))
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && (adevs[i]->hba->ports[adevs[i]->port].task_file_data & 0x88))
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "port %d is busy\n", i);
|
|
|
|
|
failed_adevs[i] = adevs[i];
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
adevs[i]->hba->ports[adevs[i]->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST;
|
|
|
|
|
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && !(adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i] && !(adevs[i]->hba->ports[adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't start CR on port %d\n", i);
|
|
|
|
|
failed_adevs[i] = adevs[i];
|
|
|
|
|
adevs[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (failed_adevs[i] && (fr_running & (1 << i)))
|
|
|
|
|
failed_adevs[i]->hba->ports[failed_adevs[i]->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while (grub_get_time_ms () < endtime)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (failed_adevs[i] && (fr_running & (1 << i)) && (failed_adevs[i]->hba->ports[failed_adevs[i]->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
break;
|
|
|
|
|
if (i == nports)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (failed_adevs[i])
|
|
|
|
|
{
|
2013-04-27 19:49:14 +00:00
|
|
|
|
grub_dma_free (failed_adevs[i]->command_list_chunk);
|
|
|
|
|
grub_dma_free (failed_adevs[i]->command_table_chunk);
|
|
|
|
|
grub_dma_free (failed_adevs[i]->rfis);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nports; i++)
|
|
|
|
|
if (adevs[i])
|
|
|
|
|
{
|
|
|
|
|
grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices),
|
|
|
|
|
GRUB_AS_LIST (adevs[i]));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_initialize (void)
|
|
|
|
|
{
|
2013-01-13 01:10:41 +00:00
|
|
|
|
grub_pci_iterate (grub_ahci_pciinit, NULL);
|
2010-07-19 19:22:54 +00:00
|
|
|
|
return grub_errno;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-25 11:11:54 +00:00
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_fini_hw (int noreturn __attribute__ ((unused)))
|
|
|
|
|
{
|
2011-01-03 14:59:20 +00:00
|
|
|
|
struct grub_ahci_device *dev;
|
2010-12-25 11:11:54 +00:00
|
|
|
|
|
2011-01-03 14:59:20 +00:00
|
|
|
|
for (dev = grub_ahci_devices; dev; dev = dev->next)
|
2010-12-25 11:11:54 +00:00
|
|
|
|
{
|
2011-01-03 14:59:20 +00:00
|
|
|
|
grub_uint64_t endtime;
|
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop FR\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop CR\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-12-25 11:11:54 +00:00
|
|
|
|
grub_dma_free (dev->command_list_chunk);
|
|
|
|
|
grub_dma_free (dev->command_table_chunk);
|
|
|
|
|
grub_dma_free (dev->rfis);
|
2011-01-03 14:59:20 +00:00
|
|
|
|
dev->command_list_chunk = NULL;
|
|
|
|
|
dev->command_table_chunk = NULL;
|
|
|
|
|
dev->rfis = NULL;
|
2010-12-25 11:11:54 +00:00
|
|
|
|
}
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
static int
|
|
|
|
|
reinit_port (struct grub_ahci_device *dev)
|
|
|
|
|
{
|
|
|
|
|
struct grub_pci_dma_chunk *command_list;
|
|
|
|
|
struct grub_pci_dma_chunk *command_table;
|
|
|
|
|
grub_uint64_t endtime;
|
|
|
|
|
|
|
|
|
|
command_list = grub_memalign_dma32 (1024, sizeof (struct grub_ahci_cmd_head));
|
|
|
|
|
if (!command_list)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
command_table = grub_memalign_dma32 (1024,
|
|
|
|
|
sizeof (struct grub_ahci_cmd_table));
|
|
|
|
|
if (!command_table)
|
|
|
|
|
{
|
|
|
|
|
grub_dma_free (command_list);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "found device ahci%d (port %d)\n", dev->num, dev->port);
|
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop FR\n");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop CR\n");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].fbs = 2;
|
|
|
|
|
|
|
|
|
|
dev->rfis = grub_memalign_dma32 (4096,
|
|
|
|
|
sizeof (struct grub_ahci_received_fis));
|
|
|
|
|
grub_memset ((char *) grub_dma_get_virt (dev->rfis), 0,
|
|
|
|
|
sizeof (struct grub_ahci_received_fis));
|
|
|
|
|
dev->hba->ports[dev->port].fis_base = grub_dma_get_phys (dev->rfis);
|
|
|
|
|
dev->hba->ports[dev->port].command_list_base
|
|
|
|
|
= grub_dma_get_phys (command_list);
|
|
|
|
|
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't start FR\n");
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST;
|
|
|
|
|
while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't start CR\n");
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_CR;
|
|
|
|
|
goto out_stop_fr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].command
|
|
|
|
|
= (dev->hba->ports[dev->port].command & 0x0fffffff) | (1 << 28) | 2 | 4;
|
|
|
|
|
|
|
|
|
|
dev->command_list_chunk = command_list;
|
|
|
|
|
dev->command_list = grub_dma_get_virt (command_list);
|
|
|
|
|
dev->command_table_chunk = command_table;
|
|
|
|
|
dev->command_table = grub_dma_get_virt (command_table);
|
|
|
|
|
dev->command_list->command_table_base
|
|
|
|
|
= grub_dma_get_phys (command_table);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
out_stop_fr:
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_FR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't stop FR\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
out:
|
|
|
|
|
grub_dma_free (command_list);
|
|
|
|
|
grub_dma_free (command_table);
|
|
|
|
|
grub_dma_free (dev->rfis);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-25 11:11:54 +00:00
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_restore_hw (void)
|
|
|
|
|
{
|
2011-01-03 14:59:20 +00:00
|
|
|
|
struct grub_ahci_device **pdev;
|
|
|
|
|
|
|
|
|
|
for (pdev = &grub_ahci_devices; *pdev; pdev = &((*pdev)->next))
|
2013-04-27 15:18:02 +00:00
|
|
|
|
if (reinit_port (*pdev))
|
2011-01-03 14:59:20 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_ahci_device *odev;
|
|
|
|
|
odev = *pdev;
|
|
|
|
|
*pdev = (*pdev)->next;
|
|
|
|
|
grub_free (odev);
|
|
|
|
|
}
|
|
|
|
|
return GRUB_ERR_NONE;
|
2010-12-25 11:11:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-01-20 15:52:15 +00:00
|
|
|
|
grub_ahci_iterate (grub_ata_dev_iterate_hook_t hook, void *hook_data,
|
|
|
|
|
grub_disk_pull_t pull)
|
2010-07-19 19:22:54 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_ahci_device *dev;
|
|
|
|
|
|
2011-07-07 10:21:53 +00:00
|
|
|
|
if (pull != GRUB_DISK_PULL_NONE)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
FOR_LIST_ELEMENTS(dev, grub_ahci_devices)
|
2013-01-20 15:52:15 +00:00
|
|
|
|
if (hook (GRUB_SCSI_SUBSYSTEM_AHCI, dev->num, hook_data))
|
2010-07-19 19:22:54 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
static int
|
|
|
|
|
find_free_cmd_slot (struct grub_ahci_device *dev)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
if (dev->hda->ports[dev->port].command_issue & (1 << i))
|
|
|
|
|
continue;
|
|
|
|
|
if (dev->hda->ports[dev->port].sata_active & (1 << i))
|
|
|
|
|
continue;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
GRUB_AHCI_FIS_REG_H2D = 0x27
|
|
|
|
|
};
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
static const int register_map[11] = { 3 /* Features */,
|
|
|
|
|
12 /* Sectors */,
|
|
|
|
|
4 /* LBA low */,
|
|
|
|
|
5 /* LBA mid */,
|
|
|
|
|
6 /* LBA high */,
|
|
|
|
|
7 /* Device */,
|
|
|
|
|
2 /* CMD register */,
|
|
|
|
|
13 /* Sectors 48 */,
|
|
|
|
|
8 /* LBA48 low */,
|
|
|
|
|
9 /* LBA48 mid */,
|
|
|
|
|
10 /* LBA48 high */ };
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_reset_port (struct grub_ahci_device *dev, int force)
|
2010-07-19 19:22:54 +00:00
|
|
|
|
{
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_uint64_t endtime;
|
2013-04-27 15:18:02 +00:00
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
if (force || (dev->hba->ports[dev->port].command_issue & 1)
|
|
|
|
|
|| (dev->hba->ports[dev->port].task_file_data & 0x80))
|
2010-12-25 02:06:07 +00:00
|
|
|
|
{
|
2013-04-27 15:18:02 +00:00
|
|
|
|
struct grub_disk_ata_pass_through_parms parms2;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
2011-01-03 14:59:20 +00:00
|
|
|
|
endtime = grub_get_time_ms () + 1000;
|
|
|
|
|
while ((dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "couldn't stop CR");
|
|
|
|
|
return grub_error (GRUB_ERR_IO, "couldn't stop CR");
|
|
|
|
|
}
|
|
|
|
|
dev->hba->ports[dev->port].command |= 8;
|
|
|
|
|
while (dev->hba->ports[dev->port].command & 8)
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
|
|
|
|
grub_dprintf ("ahci", "couldn't set CLO\n");
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_FRE;
|
|
|
|
|
return grub_error (GRUB_ERR_IO, "couldn't set CLO");
|
2011-01-03 14:59:20 +00:00
|
|
|
|
}
|
2013-04-27 15:18:02 +00:00
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST;
|
2011-01-03 14:59:20 +00:00
|
|
|
|
while (!(dev->hba->ports[dev->port].command & GRUB_AHCI_HBA_PORT_CMD_CR))
|
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "couldn't stop CR");
|
|
|
|
|
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
|
|
|
|
return grub_error (GRUB_ERR_IO, "couldn't stop CR");
|
2011-01-03 14:59:20 +00:00
|
|
|
|
}
|
2013-04-27 15:18:02 +00:00
|
|
|
|
dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error;
|
|
|
|
|
grub_memset (&parms2, 0, sizeof (parms2));
|
|
|
|
|
parms2.taskfile.cmd = 8;
|
|
|
|
|
return grub_ahci_readwrite_real (dev, &parms2, 1, 1);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
}
|
2013-04-27 15:18:02 +00:00
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|
|
|
|
struct grub_disk_ata_pass_through_parms *parms,
|
|
|
|
|
int spinup, int reset)
|
|
|
|
|
{
|
|
|
|
|
struct grub_pci_dma_chunk *bufc;
|
|
|
|
|
grub_uint64_t endtime;
|
|
|
|
|
unsigned i;
|
|
|
|
|
grub_err_t err = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
|
|
|
|
|
|
|
|
|
if (!reset)
|
|
|
|
|
grub_ahci_reset_port (dev, 0);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data = 0;
|
|
|
|
|
dev->hba->ports[dev->port].command_issue = 0;
|
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
|
|
|
|
|
dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
|
|
|
|
grub_dprintf("ahci", "grub_ahci_read (size=%llu, cmdsize = %llu)\n",
|
|
|
|
|
(unsigned long long) parms->size,
|
|
|
|
|
(unsigned long long) parms->cmdsize);
|
|
|
|
|
|
|
|
|
|
if (parms->cmdsize != 0 && parms->cmdsize != 12 && parms->cmdsize != 16)
|
2012-02-08 18:26:01 +00:00
|
|
|
|
return grub_error (GRUB_ERR_BUG, "incorrect ATAPI command size");
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
|
|
|
|
if (parms->size > GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH)
|
2012-02-08 18:26:01 +00:00
|
|
|
|
return grub_error (GRUB_ERR_BUG, "too big data buffer");
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
|
|
|
|
bufc = grub_memalign_dma32 (1024, parms->size + (parms->size & 1));
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x, CL=%p\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data,
|
|
|
|
|
dev->command_list);
|
2010-12-24 15:07:53 +00:00
|
|
|
|
/* FIXME: support port multipliers. */
|
|
|
|
|
dev->command_list[0].config
|
2010-12-25 02:06:07 +00:00
|
|
|
|
= (5 << GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT)
|
|
|
|
|
// | GRUB_AHCI_CONFIG_CLEAR_R_OK
|
2010-12-24 15:07:53 +00:00
|
|
|
|
| (0 << GRUB_AHCI_CONFIG_PMP_SHIFT)
|
|
|
|
|
| (1 << GRUB_AHCI_CONFIG_PRDT_LENGTH_SHIFT)
|
|
|
|
|
| (parms->cmdsize ? GRUB_AHCI_CONFIG_ATAPI : 0)
|
2010-12-25 02:06:07 +00:00
|
|
|
|
| (parms->write ? GRUB_AHCI_CONFIG_WRITE : GRUB_AHCI_CONFIG_READ)
|
|
|
|
|
| (parms->taskfile.cmd == 8 ? (1 << 8) : 0);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
dev->command_list[0].transfered = 0;
|
|
|
|
|
dev->command_list[0].command_table_base
|
|
|
|
|
= grub_dma_get_phys (dev->command_table_chunk);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_memset ((char *) dev->command_list[0].unused, 0,
|
|
|
|
|
sizeof (dev->command_list[0].unused));
|
2013-04-27 15:18:02 +00:00
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_memset ((char *) &dev->command_table[0], 0,
|
|
|
|
|
sizeof (dev->command_table[0]));
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
if (parms->cmdsize)
|
|
|
|
|
grub_memcpy ((char *) dev->command_table[0].command, parms->cmd,
|
|
|
|
|
parms->cmdsize);
|
|
|
|
|
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
dev->command_table[0].cfis[0] = GRUB_AHCI_FIS_REG_H2D;
|
2010-12-24 18:48:55 +00:00
|
|
|
|
dev->command_table[0].cfis[1] = 0x80;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
for (i = 0; i < sizeof (parms->taskfile.raw); i++)
|
2010-12-24 18:48:55 +00:00
|
|
|
|
dev->command_table[0].cfis[register_map[i]] = parms->taskfile.raw[i];
|
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
|
dev->command_table[0].cfis[0], dev->command_table[0].cfis[1],
|
|
|
|
|
dev->command_table[0].cfis[2], dev->command_table[0].cfis[3],
|
|
|
|
|
dev->command_table[0].cfis[4], dev->command_table[0].cfis[5],
|
|
|
|
|
dev->command_table[0].cfis[6], dev->command_table[0].cfis[7]);
|
|
|
|
|
grub_dprintf ("ahci", "cfis: %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
|
|
|
|
dev->command_table[0].cfis[8], dev->command_table[0].cfis[9],
|
|
|
|
|
dev->command_table[0].cfis[10], dev->command_table[0].cfis[11],
|
|
|
|
|
dev->command_table[0].cfis[12], dev->command_table[0].cfis[13],
|
|
|
|
|
dev->command_table[0].cfis[14], dev->command_table[0].cfis[15]);
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
|
|
|
|
dev->command_table[0].prdt[0].data_base = grub_dma_get_phys (bufc);
|
|
|
|
|
dev->command_table[0].prdt[0].unused = 0;
|
2013-04-27 15:18:02 +00:00
|
|
|
|
dev->command_table[0].prdt[0].size = (parms->size - 1);
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
2011-06-27 06:43:13 +00:00
|
|
|
|
grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%"
|
|
|
|
|
PRIuGRUB_SIZE ")\n",
|
2010-12-25 02:06:07 +00:00
|
|
|
|
dev->command_table[0].prdt[0].data_base,
|
|
|
|
|
dev->command_table[0].prdt[0].unused,
|
|
|
|
|
dev->command_table[0].prdt[0].size,
|
|
|
|
|
(char *) &dev->command_table[0].prdt[0]
|
|
|
|
|
- (char *) &dev->command_table[0]);
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
if (parms->write)
|
|
|
|
|
grub_memcpy ((char *) grub_dma_get_virt (bufc), parms->buffer, parms->size);
|
|
|
|
|
|
|
|
|
|
grub_dprintf ("ahci", "AHCI command schedulded\n");
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI inten = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].inten);
|
|
|
|
|
grub_dprintf ("ahci", "AHCI intstatus = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].intstatus);
|
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
dev->hba->ports[dev->port].inten = 0xffffffff;//(1 << 2) | (1 << 5);
|
|
|
|
|
dev->hba->ports[dev->port].intstatus = 0xffffffff;//(1 << 2) | (1 << 5);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI inten = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].inten);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
dev->hba->ports[dev->port].sata_active = 1;
|
|
|
|
|
dev->hba->ports[dev->port].command_issue = 1;
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI sig = %x\n", dev->hba->ports[dev->port].sig);
|
|
|
|
|
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
2013-03-25 09:32:56 +00:00
|
|
|
|
endtime = grub_get_time_ms () + (spinup ? 10000 : 5000);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
while ((dev->hba->ports[dev->port].command_issue & 1))
|
2010-12-24 15:07:53 +00:00
|
|
|
|
if (grub_get_time_ms () > endtime)
|
|
|
|
|
{
|
2013-04-27 15:18:02 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI status <%x %x %x %x>\n",
|
2010-12-25 02:06:07 +00:00
|
|
|
|
dev->hba->ports[dev->port].command_issue,
|
2013-04-27 15:18:02 +00:00
|
|
|
|
dev->hba->ports[dev->port].sata_active,
|
2010-12-25 02:06:07 +00:00
|
|
|
|
dev->hba->ports[dev->port].intstatus,
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data);
|
2013-04-27 15:18:02 +00:00
|
|
|
|
dev->hba->ports[dev->port].command_issue = 0;
|
2012-02-08 18:26:01 +00:00
|
|
|
|
err = grub_error (GRUB_ERR_IO, "AHCI transfer timed out");
|
2013-04-27 15:18:02 +00:00
|
|
|
|
if (!reset)
|
|
|
|
|
grub_ahci_reset_port (dev, 1);
|
2010-12-25 02:06:07 +00:00
|
|
|
|
break;
|
2010-12-24 15:07:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_dprintf ("ahci", "AHCI command completed <%x %x %x %x %x, %x %x>\n",
|
|
|
|
|
dev->hba->ports[dev->port].command_issue,
|
|
|
|
|
dev->hba->ports[dev->port].intstatus,
|
|
|
|
|
dev->hba->ports[dev->port].task_file_data,
|
|
|
|
|
dev->command_list[0].transfered,
|
|
|
|
|
dev->hba->ports[dev->port].sata_error,
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x00],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x18]);
|
|
|
|
|
grub_dprintf ("ahci",
|
|
|
|
|
"last PIO FIS %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x08],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x09],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0a],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0b],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0c],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0d],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0e],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x0f]);
|
|
|
|
|
grub_dprintf ("ahci",
|
|
|
|
|
"last REG FIS %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x10],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x11],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x12],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x13],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x14],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x15],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x16],
|
|
|
|
|
((grub_uint32_t *) grub_dma_get_virt (dev->rfis))[0x17]);
|
2010-12-24 15:07:53 +00:00
|
|
|
|
|
|
|
|
|
if (!parms->write)
|
|
|
|
|
grub_memcpy (parms->buffer, (char *) grub_dma_get_virt (bufc), parms->size);
|
|
|
|
|
grub_dma_free (bufc);
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
2010-12-25 02:06:07 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
|
grub_ahci_readwrite (grub_ata_t disk,
|
2011-05-16 15:17:04 +00:00
|
|
|
|
struct grub_disk_ata_pass_through_parms *parms,
|
|
|
|
|
int spinup)
|
2010-12-25 02:06:07 +00:00
|
|
|
|
{
|
2013-04-27 15:18:02 +00:00
|
|
|
|
return grub_ahci_readwrite_real (disk->data, parms, spinup, 0);
|
2010-07-19 19:22:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static grub_err_t
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_ahci_open (int id, int devnum, struct grub_ata *ata)
|
2010-07-19 19:22:54 +00:00
|
|
|
|
{
|
|
|
|
|
struct grub_ahci_device *dev;
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
if (id != GRUB_SCSI_SUBSYSTEM_AHCI)
|
|
|
|
|
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an AHCI device");
|
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
FOR_LIST_ELEMENTS(dev, grub_ahci_devices)
|
2010-12-24 18:48:55 +00:00
|
|
|
|
if (dev->num == devnum)
|
|
|
|
|
break;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
|
|
|
|
if (! dev)
|
|
|
|
|
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such AHCI device");
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_dprintf ("ahci", "opening AHCI dev `ahci%d'\n", dev->num);
|
|
|
|
|
|
|
|
|
|
ata->data = dev;
|
2010-12-25 02:12:49 +00:00
|
|
|
|
ata->dma = 1;
|
2012-01-29 18:00:30 +00:00
|
|
|
|
ata->maxbuffer = GRUB_AHCI_PRDT_MAX_CHUNK_LENGTH;
|
2011-05-16 15:17:04 +00:00
|
|
|
|
ata->present = &dev->present;
|
2010-07-19 19:22:54 +00:00
|
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
static struct grub_ata_dev grub_ahci_dev =
|
2010-07-19 19:22:54 +00:00
|
|
|
|
{
|
|
|
|
|
.iterate = grub_ahci_iterate,
|
|
|
|
|
.open = grub_ahci_open,
|
2010-12-24 15:07:53 +00:00
|
|
|
|
.readwrite = grub_ahci_readwrite,
|
2010-07-19 19:22:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-12 23:28:14 +00:00
|
|
|
|
static struct grub_preboot *fini_hnd;
|
2010-12-25 11:11:54 +00:00
|
|
|
|
|
2010-07-19 19:22:54 +00:00
|
|
|
|
GRUB_MOD_INIT(ahci)
|
|
|
|
|
{
|
|
|
|
|
/* To prevent two drivers operating on the same disks. */
|
2010-12-25 02:06:07 +00:00
|
|
|
|
grub_disk_firmware_is_tainted = 1;
|
|
|
|
|
if (grub_disk_firmware_fini)
|
2010-07-19 19:22:54 +00:00
|
|
|
|
{
|
|
|
|
|
grub_disk_firmware_fini ();
|
|
|
|
|
grub_disk_firmware_fini = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* AHCI initialization. */
|
|
|
|
|
grub_ahci_initialize ();
|
|
|
|
|
|
|
|
|
|
/* AHCI devices are handled by scsi.mod. */
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_ata_dev_register (&grub_ahci_dev);
|
2010-12-25 11:11:54 +00:00
|
|
|
|
|
|
|
|
|
fini_hnd = grub_loader_register_preboot_hook (grub_ahci_fini_hw,
|
|
|
|
|
grub_ahci_restore_hw,
|
|
|
|
|
GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK);
|
2010-07-19 19:22:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GRUB_MOD_FINI(ahci)
|
|
|
|
|
{
|
2010-12-25 11:11:54 +00:00
|
|
|
|
grub_ahci_fini_hw (0);
|
|
|
|
|
grub_loader_unregister_preboot_hook (fini_hnd);
|
|
|
|
|
|
2010-12-24 15:07:53 +00:00
|
|
|
|
grub_ata_dev_unregister (&grub_ahci_dev);
|
2010-07-19 19:22:54 +00:00
|
|
|
|
}
|