merge mainline into arm
This commit is contained in:
commit
8e71d87482
490 changed files with 29659 additions and 8612 deletions
|
@ -75,6 +75,8 @@ struct grub_ahci_hba_port
|
|||
enum grub_ahci_hba_port_command
|
||||
{
|
||||
GRUB_AHCI_HBA_PORT_CMD_ST = 0x01,
|
||||
GRUB_AHCI_HBA_PORT_CMD_SPIN_UP = 0x02,
|
||||
GRUB_AHCI_HBA_PORT_CMD_POWER_ON = 0x04,
|
||||
GRUB_AHCI_HBA_PORT_CMD_FRE = 0x10,
|
||||
GRUB_AHCI_HBA_PORT_CMD_CR = 0x8000,
|
||||
GRUB_AHCI_HBA_PORT_CMD_FR = 0x4000,
|
||||
|
@ -136,7 +138,7 @@ struct grub_ahci_device
|
|||
static grub_err_t
|
||||
grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
||||
struct grub_disk_ata_pass_through_parms *parms,
|
||||
int spinup);
|
||||
int spinup, int reset);
|
||||
|
||||
|
||||
enum
|
||||
|
@ -162,8 +164,513 @@ enum
|
|||
static struct grub_ahci_device *grub_ahci_devices;
|
||||
static int numdevs;
|
||||
|
||||
static int
|
||||
grub_ahci_pciinit (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid __attribute__ ((unused)),
|
||||
void *data __attribute__ ((unused)))
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
grub_uint32_t class;
|
||||
grub_uint32_t bar;
|
||||
unsigned i, nports;
|
||||
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;
|
||||
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5);
|
||||
|
||||
bar = grub_pci_read (addr);
|
||||
|
||||
if ((bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK
|
||||
| GRUB_PCI_ADDR_MEM_PREFETCH))
|
||||
!= (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32))
|
||||
return 0;
|
||||
|
||||
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);
|
||||
|
||||
hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK,
|
||||
sizeof (hba));
|
||||
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);
|
||||
|
||||
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");
|
||||
|
||||
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
||||
|
||||
grub_dprintf ("ahci", "err[1]: %x\n",
|
||||
hba->ports[1].sata_error);
|
||||
|
||||
if (!(hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN))
|
||||
grub_dprintf ("ahci", "AHCI is in compat mode. Switching\n");
|
||||
else
|
||||
grub_dprintf ("ahci", "AHCI is in AHCI mode.\n");
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
grub_dprintf ("ahci", "err[1]: %x\n",
|
||||
hba->ports[1].sata_error);
|
||||
|
||||
grub_dprintf ("ahci", "GLC:%x\n", hba->global_control);
|
||||
|
||||
nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1;
|
||||
|
||||
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;
|
||||
|
||||
for (i = 0; i < nports; i++)
|
||||
failed_adevs[i] = 0;
|
||||
for (i = 0; i < nports; i++)
|
||||
{
|
||||
if (!(hba->ports_implemented & (1 << i)))
|
||||
{
|
||||
adevs[i] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
adevs[i] = grub_zalloc (sizeof (*adevs[i]));
|
||||
if (!adevs[i])
|
||||
return 1;
|
||||
|
||||
adevs[i]->hba = hba;
|
||||
adevs[i]->port = i;
|
||||
adevs[i]->present = 1;
|
||||
adevs[i]->num = numdevs++;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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",
|
||||
(int) ((char *) &adevs[i]->hba->ports[adevs[i]->port].task_file_data -
|
||||
(char *) adevs[i]->hba),
|
||||
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",
|
||||
(int) ((char *) &adevs[i]->hba->ports[adevs[i]->port].task_file_data -
|
||||
(char *) adevs[i]->hba),
|
||||
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])
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
for (i = 0; i < nports; i++)
|
||||
if (adevs[i])
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices),
|
||||
GRUB_AS_LIST (adevs[i]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_initialize (void)
|
||||
{
|
||||
grub_pci_iterate (grub_ahci_pciinit, NULL);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_fini_hw (int noreturn __attribute__ ((unused)))
|
||||
{
|
||||
struct grub_ahci_device *dev;
|
||||
|
||||
for (dev = grub_ahci_devices; dev; dev = dev->next)
|
||||
{
|
||||
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;
|
||||
}
|
||||
grub_dma_free (dev->command_list_chunk);
|
||||
grub_dma_free (dev->command_table_chunk);
|
||||
grub_dma_free (dev->rfis);
|
||||
dev->command_list_chunk = NULL;
|
||||
dev->command_table_chunk = NULL;
|
||||
dev->rfis = NULL;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
init_port (struct grub_ahci_device *dev)
|
||||
reinit_port (struct grub_ahci_device *dev)
|
||||
{
|
||||
struct grub_pci_dma_chunk *command_list;
|
||||
struct grub_pci_dma_chunk *command_table;
|
||||
|
@ -254,194 +761,13 @@ init_port (struct grub_ahci_device *dev)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_ahci_pciinit (grub_pci_device_t dev,
|
||||
grub_pci_id_t pciid __attribute__ ((unused)),
|
||||
void *data __attribute__ ((unused)))
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
grub_uint32_t class;
|
||||
grub_uint32_t bar;
|
||||
unsigned i, nports;
|
||||
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;
|
||||
|
||||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG5);
|
||||
bar = grub_pci_read (addr);
|
||||
|
||||
if ((bar & (GRUB_PCI_ADDR_SPACE_MASK | GRUB_PCI_ADDR_MEM_TYPE_MASK
|
||||
| GRUB_PCI_ADDR_MEM_PREFETCH))
|
||||
!= (GRUB_PCI_ADDR_SPACE_MEMORY | GRUB_PCI_ADDR_MEM_TYPE_32))
|
||||
return 0;
|
||||
|
||||
hba = grub_pci_device_map_range (dev, bar & GRUB_PCI_ADDR_MEM_MASK,
|
||||
sizeof (hba));
|
||||
|
||||
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");
|
||||
|
||||
if (!(hba->global_control & GRUB_AHCI_HBA_GLOBAL_CONTROL_AHCI_EN))
|
||||
grub_dprintf ("ahci", "AHCI is in compat mode. Switching\n");
|
||||
else
|
||||
grub_dprintf ("ahci", "AHCI is in AHCI mode.\n");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
nports = (hba->cap & GRUB_AHCI_HBA_CAP_NPORTS_MASK) + 1;
|
||||
|
||||
grub_dprintf ("ahci", "%d AHCI ports\n", nports);
|
||||
|
||||
for (i = 0; i < nports; i++)
|
||||
{
|
||||
struct grub_ahci_device *adev;
|
||||
grub_uint32_t st;
|
||||
|
||||
if (!(hba->ports_implemented & (1 << i)))
|
||||
continue;
|
||||
|
||||
grub_dprintf ("ahci", "status %d:%x\n", i, hba->ports[i].status);
|
||||
/* FIXME: support hotplugging. */
|
||||
st = hba->ports[i].status;
|
||||
if ((st & 0xf) != 0x3 && (st & 0xf) != 0x1)
|
||||
continue;
|
||||
|
||||
adev = grub_malloc (sizeof (*adev));
|
||||
if (!adev)
|
||||
return 1;
|
||||
|
||||
adev->hba = hba;
|
||||
adev->port = i;
|
||||
adev->present = 1;
|
||||
adev->num = numdevs++;
|
||||
|
||||
if (init_port (adev))
|
||||
{
|
||||
grub_free (adev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_ahci_devices),
|
||||
GRUB_AS_LIST (adev));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_initialize (void)
|
||||
{
|
||||
grub_pci_iterate (grub_ahci_pciinit, NULL);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_fini_hw (int noreturn __attribute__ ((unused)))
|
||||
{
|
||||
struct grub_ahci_device *dev;
|
||||
|
||||
for (dev = grub_ahci_devices; dev; dev = dev->next)
|
||||
{
|
||||
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;
|
||||
}
|
||||
grub_dma_free (dev->command_list_chunk);
|
||||
grub_dma_free (dev->command_table_chunk);
|
||||
grub_dma_free (dev->rfis);
|
||||
dev->command_list_chunk = NULL;
|
||||
dev->command_table_chunk = NULL;
|
||||
dev->rfis = NULL;
|
||||
}
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_restore_hw (void)
|
||||
{
|
||||
struct grub_ahci_device **pdev;
|
||||
|
||||
for (pdev = &grub_ahci_devices; *pdev; pdev = &((*pdev)->next))
|
||||
if (init_port (*pdev))
|
||||
if (reinit_port (*pdev))
|
||||
{
|
||||
struct grub_ahci_device *odev;
|
||||
odev = *pdev;
|
||||
|
@ -504,10 +830,54 @@ static const int register_map[11] = { 3 /* Features */,
|
|||
9 /* LBA48 mid */,
|
||||
10 /* LBA48 high */ };
|
||||
|
||||
static grub_err_t
|
||||
grub_ahci_reset_port (struct grub_ahci_device *dev, int force)
|
||||
{
|
||||
grub_uint64_t endtime;
|
||||
|
||||
dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error;
|
||||
|
||||
if (force || (dev->hba->ports[dev->port].command_issue & 1)
|
||||
|| (dev->hba->ports[dev->port].task_file_data & 0x80))
|
||||
{
|
||||
struct grub_disk_ata_pass_through_parms parms2;
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
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 stop CR");
|
||||
dev->hba->ports[dev->port].command &= ~GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
return grub_error (GRUB_ERR_IO, "couldn't stop CR");
|
||||
}
|
||||
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);
|
||||
}
|
||||
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 spinup, int reset)
|
||||
{
|
||||
struct grub_pci_dma_chunk *bufc;
|
||||
grub_uint64_t endtime;
|
||||
|
@ -517,25 +887,15 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
if ((dev->hba->ports[dev->port].task_file_data & 0x80))
|
||||
{
|
||||
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;
|
||||
}
|
||||
dev->hba->ports[dev->port].command |= GRUB_AHCI_HBA_PORT_CMD_ST;
|
||||
endtime = grub_get_time_ms () + (spinup ? 10000 : 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 start CR\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
dev->hba->ports[dev->port].sata_error = dev->hba->ports[dev->port].sata_error;
|
||||
|
||||
|
@ -551,10 +911,9 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|||
|
||||
bufc = grub_memalign_dma32 (1024, parms->size + (parms->size & 1));
|
||||
|
||||
dev->hba->ports[dev->port].command |= 8;
|
||||
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x, CL=%p\n",
|
||||
dev->hba->ports[dev->port].task_file_data,
|
||||
dev->command_list);
|
||||
/* FIXME: support port multipliers. */
|
||||
dev->command_list[0].config
|
||||
= (5 << GRUB_AHCI_CONFIG_CFIS_LENGTH_SHIFT)
|
||||
|
@ -564,17 +923,28 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|||
| (parms->cmdsize ? GRUB_AHCI_CONFIG_ATAPI : 0)
|
||||
| (parms->write ? GRUB_AHCI_CONFIG_WRITE : GRUB_AHCI_CONFIG_READ)
|
||||
| (parms->taskfile.cmd == 8 ? (1 << 8) : 0);
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
dev->command_list[0].transfered = 0;
|
||||
dev->command_list[0].command_table_base
|
||||
= grub_dma_get_phys (dev->command_table_chunk);
|
||||
|
||||
grub_memset ((char *) dev->command_list[0].unused, 0,
|
||||
sizeof (dev->command_list[0].unused));
|
||||
|
||||
grub_memset ((char *) &dev->command_table[0], 0,
|
||||
sizeof (dev->command_table[0]));
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
if (parms->cmdsize)
|
||||
grub_memcpy ((char *) dev->command_table[0].command, parms->cmd,
|
||||
parms->cmdsize);
|
||||
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
|
||||
dev->command_table[0].cfis[0] = GRUB_AHCI_FIS_REG_H2D;
|
||||
dev->command_table[0].cfis[1] = 0x80;
|
||||
for (i = 0; i < sizeof (parms->taskfile.raw); i++)
|
||||
|
@ -593,8 +963,7 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|||
|
||||
dev->command_table[0].prdt[0].data_base = grub_dma_get_phys (bufc);
|
||||
dev->command_table[0].prdt[0].unused = 0;
|
||||
dev->command_table[0].prdt[0].size = (parms->size + (parms->size & 1) - 1)
|
||||
| GRUB_AHCI_INTERRUPT_ON_COMPLETE;
|
||||
dev->command_table[0].prdt[0].size = (parms->size - 1);
|
||||
|
||||
grub_dprintf ("ahci", "PRDT = %" PRIxGRUB_UINT64_T ", %x, %x (%"
|
||||
PRIuGRUB_SIZE ")\n",
|
||||
|
@ -610,11 +979,19 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|||
grub_dprintf ("ahci", "AHCI command schedulded\n");
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
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);
|
||||
|
||||
dev->hba->ports[dev->port].inten = 0xffffffff;//(1 << 2) | (1 << 5);
|
||||
dev->hba->ports[dev->port].intstatus = 0xffffffff;//(1 << 2) | (1 << 5);
|
||||
grub_dprintf ("ahci", "AHCI inten = %x\n",
|
||||
dev->hba->ports[dev->port].inten);
|
||||
grub_dprintf ("ahci", "AHCI tfd = %x\n",
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
dev->hba->ports[dev->port].command_issue |= 1;
|
||||
dev->hba->ports[dev->port].sata_active = 1;
|
||||
dev->hba->ports[dev->port].command_issue = 1;
|
||||
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);
|
||||
|
@ -623,11 +1000,15 @@ grub_ahci_readwrite_real (struct grub_ahci_device *dev,
|
|||
while ((dev->hba->ports[dev->port].command_issue & 1))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
{
|
||||
grub_dprintf ("ahci", "AHCI status <%x %x %x>\n",
|
||||
grub_dprintf ("ahci", "AHCI status <%x %x %x %x>\n",
|
||||
dev->hba->ports[dev->port].command_issue,
|
||||
dev->hba->ports[dev->port].sata_active,
|
||||
dev->hba->ports[dev->port].intstatus,
|
||||
dev->hba->ports[dev->port].task_file_data);
|
||||
dev->hba->ports[dev->port].command_issue = 0;
|
||||
err = grub_error (GRUB_ERR_IO, "AHCI transfer timed out");
|
||||
if (!reset)
|
||||
grub_ahci_reset_port (dev, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -672,7 +1053,7 @@ grub_ahci_readwrite (grub_ata_t disk,
|
|||
struct grub_disk_ata_pass_through_parms *parms,
|
||||
int spinup)
|
||||
{
|
||||
return grub_ahci_readwrite_real (disk->data, parms, spinup);
|
||||
return grub_ahci_readwrite_real (disk->data, parms, spinup, 0);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
|
@ -713,13 +1094,7 @@ static struct grub_preboot *fini_hnd;
|
|||
|
||||
GRUB_MOD_INIT(ahci)
|
||||
{
|
||||
/* To prevent two drivers operating on the same disks. */
|
||||
grub_disk_firmware_is_tainted = 1;
|
||||
if (grub_disk_firmware_fini)
|
||||
{
|
||||
grub_disk_firmware_fini ();
|
||||
grub_disk_firmware_fini = NULL;
|
||||
}
|
||||
grub_stop_disk_firmware ();
|
||||
|
||||
/* AHCI initialization. */
|
||||
grub_ahci_initialize ();
|
||||
|
|
|
@ -95,7 +95,7 @@ grub_arcdisk_iterate_iter (const char *name,
|
|||
struct grub_arcdisk_iterate_ctx *ctx = data;
|
||||
|
||||
if (!(comp->type == GRUB_ARC_COMPONENT_TYPE_DISK
|
||||
|| comp->type == GRUB_ARC_COMPONENT_TYPE_DISK
|
||||
|| comp->type == GRUB_ARC_COMPONENT_TYPE_FLOPPY
|
||||
|| comp->type == GRUB_ARC_COMPONENT_TYPE_TAPE))
|
||||
return 0;
|
||||
return ctx->hook (name, ctx->hook_data);
|
||||
|
@ -113,7 +113,11 @@ grub_arcdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
|||
return grub_arc_iterate_devs (grub_arcdisk_iterate_iter, &ctx, 1);
|
||||
}
|
||||
|
||||
#ifdef GRUB_CPU_MIPSEL
|
||||
#define RAW_SUFFIX "partition(0)"
|
||||
#else
|
||||
#define RAW_SUFFIX "partition(10)"
|
||||
#endif
|
||||
|
||||
static grub_err_t
|
||||
reopen (const char *name, int writable)
|
||||
|
@ -153,9 +157,7 @@ reopen (const char *name, int writable)
|
|||
static grub_err_t
|
||||
grub_arcdisk_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
char *fullname, *optr;
|
||||
const char *iptr;
|
||||
int state = 0;
|
||||
char *fullname;
|
||||
grub_err_t err;
|
||||
grub_arc_err_t r;
|
||||
struct grub_arc_fileinfo info;
|
||||
|
@ -163,35 +165,7 @@ grub_arcdisk_open (const char *name, grub_disk_t disk)
|
|||
|
||||
if (grub_memcmp (name, "arc/", 4) != 0)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not arc device");
|
||||
fullname = grub_malloc (2 * grub_strlen (name) + sizeof (RAW_SUFFIX));
|
||||
if (!fullname)
|
||||
return grub_errno;
|
||||
optr = fullname;
|
||||
for (iptr = name + 4; *iptr; iptr++)
|
||||
if (state == 0)
|
||||
{
|
||||
if (!grub_isdigit (*iptr))
|
||||
*optr++ = *iptr;
|
||||
else
|
||||
{
|
||||
*optr++ = '(';
|
||||
*optr++ = *iptr;
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (grub_isdigit (*iptr))
|
||||
*optr++ = *iptr;
|
||||
else
|
||||
{
|
||||
*optr++ = ')';
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
if (state)
|
||||
*optr++ = ')';
|
||||
grub_memcpy (optr, RAW_SUFFIX, sizeof (RAW_SUFFIX));
|
||||
fullname = grub_arc_alt_name_to_norm (name, RAW_SUFFIX);
|
||||
disk->data = fullname;
|
||||
grub_dprintf ("arcdisk", "opening %s\n", fullname);
|
||||
|
||||
|
|
|
@ -382,6 +382,8 @@ grub_ata_real_open (int id, int bus)
|
|||
err = grub_ata_identify (ata);
|
||||
if (err)
|
||||
{
|
||||
if (!grub_errno)
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATA device");
|
||||
grub_free (ata);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -199,16 +199,8 @@ scan_disk (const char *name, int accept_diskfilter)
|
|||
scan_depth--;
|
||||
return 0;
|
||||
}
|
||||
if (scan_disk_partition_iter (disk, 0, (void *) name))
|
||||
{
|
||||
scan_depth--;
|
||||
return 1;
|
||||
}
|
||||
if (grub_partition_iterate (disk, scan_disk_partition_iter, (void *) name))
|
||||
{
|
||||
scan_depth--;
|
||||
return 1;
|
||||
}
|
||||
scan_disk_partition_iter (disk, 0, (void *) name);
|
||||
grub_partition_iterate (disk, scan_disk_partition_iter, (void *) name);
|
||||
grub_disk_close (disk);
|
||||
scan_depth--;
|
||||
return 0;
|
||||
|
|
|
@ -329,18 +329,28 @@ name_devices (struct grub_efidisk_data *devices)
|
|||
{
|
||||
grub_efi_device_path_t *dp;
|
||||
grub_efi_block_io_media_t *m;
|
||||
int is_floppy = 0;
|
||||
|
||||
dp = d->last_device_path;
|
||||
if (! dp)
|
||||
continue;
|
||||
|
||||
m = d->block_io->media;
|
||||
if (m->logical_partition)
|
||||
if (GRUB_EFI_DEVICE_PATH_TYPE (dp) == GRUB_EFI_ACPI_DEVICE_PATH_TYPE
|
||||
&& GRUB_EFI_DEVICE_PATH_SUBTYPE (dp)
|
||||
== GRUB_EFI_ACPI_DEVICE_PATH_SUBTYPE)
|
||||
{
|
||||
grub_efi_acpi_device_path_t *acpi
|
||||
= (grub_efi_acpi_device_path_t *) dp;
|
||||
/* Floppy EISA ID. */
|
||||
if (acpi->hid == 0x60441d0 || acpi->hid == 0x70041d0
|
||||
|| acpi->hid == 0x70141d1)
|
||||
is_floppy = 1;
|
||||
}
|
||||
if (is_floppy)
|
||||
{
|
||||
/* Only one partition in a non-media device. Assume that this
|
||||
is a floppy drive. */
|
||||
#ifdef DEBUG_NAMES
|
||||
grub_printf ("adding a floppy by guessing: ");
|
||||
grub_printf ("adding a floppy: ");
|
||||
grub_efi_print_device_path (d->device_path);
|
||||
#endif
|
||||
add_device (&fd_devices, d);
|
||||
|
@ -528,9 +538,9 @@ grub_efidisk_close (struct grub_disk *disk __attribute__ ((unused)))
|
|||
grub_dprintf ("efidisk", "closing %s\n", disk->name);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
static grub_efi_status_t
|
||||
grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf, int wr)
|
||||
{
|
||||
/* For now, use the disk io interface rather than the block io's. */
|
||||
struct grub_efidisk_data *d;
|
||||
|
@ -540,14 +550,38 @@ grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
|
|||
d = disk->data;
|
||||
bio = d->block_io;
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
grub_size_t len;
|
||||
len = 0x500;
|
||||
if (len > size)
|
||||
len = size;
|
||||
status = efi_call_5 ((wr ? bio->write_blocks : bio->read_blocks), bio,
|
||||
bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) len << disk->log_sector_size,
|
||||
buf);
|
||||
size -= len;
|
||||
buf += len << disk->log_sector_size;
|
||||
sector += len;
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return status;
|
||||
}
|
||||
return GRUB_EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efidisk_read (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
{
|
||||
grub_efi_status_t status;
|
||||
|
||||
grub_dprintf ("efidisk",
|
||||
"reading 0x%lx sectors at the sector 0x%llx from %s\n",
|
||||
(unsigned long) size, (unsigned long long) sector, disk->name);
|
||||
|
||||
status = efi_call_5 (bio->read_blocks, bio, bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) size << disk->log_sector_size,
|
||||
buf);
|
||||
status = grub_efidisk_readwrite (disk, sector, size, buf, 0);
|
||||
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return grub_error (GRUB_ERR_READ_ERROR,
|
||||
N_("failure reading sector 0x%llx from `%s'"),
|
||||
|
@ -561,22 +595,14 @@ static grub_err_t
|
|||
grub_efidisk_write (struct grub_disk *disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, const char *buf)
|
||||
{
|
||||
/* For now, use the disk io interface rather than the block io's. */
|
||||
struct grub_efidisk_data *d;
|
||||
grub_efi_block_io_t *bio;
|
||||
grub_efi_status_t status;
|
||||
|
||||
d = disk->data;
|
||||
bio = d->block_io;
|
||||
|
||||
grub_dprintf ("efidisk",
|
||||
"writing 0x%lx sectors at the sector 0x%llx to %s\n",
|
||||
(unsigned long) size, (unsigned long long) sector, disk->name);
|
||||
|
||||
status = efi_call_5 (bio->write_blocks, bio, bio->media->media_id,
|
||||
(grub_efi_uint64_t) sector,
|
||||
(grub_efi_uintn_t) size << disk->log_sector_size,
|
||||
(void *) buf);
|
||||
status = grub_efidisk_readwrite (disk, sector, size, (char *) buf, 1);
|
||||
|
||||
if (status != GRUB_EFI_SUCCESS)
|
||||
return grub_error (GRUB_ERR_WRITE_ERROR,
|
||||
N_("failure writing sector 0x%llx to `%s'"),
|
||||
|
@ -597,22 +623,27 @@ static struct grub_disk_dev grub_efidisk_dev =
|
|||
.next = 0
|
||||
};
|
||||
|
||||
void
|
||||
grub_efidisk_init (void)
|
||||
{
|
||||
enumerate_disks ();
|
||||
grub_disk_dev_register (&grub_efidisk_dev);
|
||||
}
|
||||
|
||||
void
|
||||
grub_efidisk_fini (void)
|
||||
{
|
||||
free_devices (fd_devices);
|
||||
free_devices (hd_devices);
|
||||
free_devices (cd_devices);
|
||||
fd_devices = 0;
|
||||
hd_devices = 0;
|
||||
cd_devices = 0;
|
||||
grub_disk_dev_unregister (&grub_efidisk_dev);
|
||||
}
|
||||
|
||||
void
|
||||
grub_efidisk_init (void)
|
||||
{
|
||||
grub_disk_firmware_fini = grub_efidisk_fini;
|
||||
|
||||
enumerate_disks ();
|
||||
grub_disk_dev_register (&grub_efidisk_dev);
|
||||
}
|
||||
|
||||
/* Some utility functions to map GRUB devices with EFI devices. */
|
||||
grub_efi_handle_t
|
||||
grub_efidisk_get_device_handle (grub_disk_t disk)
|
||||
|
|
|
@ -31,6 +31,8 @@ static grub_ieee1275_ihandle_t last_ihandle;
|
|||
struct ofdisk_hash_ent
|
||||
{
|
||||
char *devpath;
|
||||
int is_boot;
|
||||
int is_cdrom;
|
||||
/* Pointer to shortest available name on nodes representing canonical names,
|
||||
otherwise NULL. */
|
||||
const char *shortest;
|
||||
|
@ -69,17 +71,28 @@ ofdisk_hash_add_real (char *devpath)
|
|||
struct ofdisk_hash_ent *p;
|
||||
struct ofdisk_hash_ent **head = &ofdisk_hash[ofdisk_hash_fn(devpath)];
|
||||
|
||||
p = grub_malloc(sizeof (*p));
|
||||
p = grub_zalloc (sizeof (*p));
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
p->devpath = devpath;
|
||||
p->next = *head;
|
||||
p->shortest = 0;
|
||||
*head = p;
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
check_string_cdrom (const char *str)
|
||||
{
|
||||
const char *ptr = grub_strrchr (str, '/');
|
||||
|
||||
if (ptr)
|
||||
ptr++;
|
||||
else
|
||||
ptr = str;
|
||||
return (grub_strncmp (ptr, "cdrom", 5) == 0);
|
||||
}
|
||||
|
||||
static struct ofdisk_hash_ent *
|
||||
ofdisk_hash_add (char *devpath, char *curcan)
|
||||
{
|
||||
|
@ -92,6 +105,8 @@ ofdisk_hash_add (char *devpath, char *curcan)
|
|||
if (!curcan)
|
||||
{
|
||||
p->shortest = devpath;
|
||||
if (check_string_cdrom (devpath))
|
||||
p->is_cdrom = 1;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -101,6 +116,9 @@ ofdisk_hash_add (char *devpath, char *curcan)
|
|||
else
|
||||
grub_free (curcan);
|
||||
|
||||
if (check_string_cdrom (devpath) || check_string_cdrom (curcan))
|
||||
pcan->is_cdrom = 1;
|
||||
|
||||
if (!pcan)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
else
|
||||
|
@ -267,7 +285,7 @@ grub_ofdisk_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
|
|||
}
|
||||
}
|
||||
|
||||
if (grub_strncmp (ent->shortest, "cdrom", 5) == 0)
|
||||
if (!ent->is_boot && ent->is_cdrom)
|
||||
continue;
|
||||
|
||||
{
|
||||
|
@ -491,10 +509,44 @@ static struct grub_disk_dev grub_ofdisk_dev =
|
|||
.next = 0
|
||||
};
|
||||
|
||||
void
|
||||
grub_ofdisk_init (void)
|
||||
static void
|
||||
insert_bootpath (void)
|
||||
{
|
||||
grub_disk_dev_register (&grub_ofdisk_dev);
|
||||
char *bootpath;
|
||||
grub_ssize_t bootpath_size;
|
||||
char *type;
|
||||
|
||||
if (grub_ieee1275_get_property_length (grub_ieee1275_chosen, "bootpath",
|
||||
&bootpath_size)
|
||||
|| bootpath_size <= 0)
|
||||
{
|
||||
/* Should never happen. */
|
||||
grub_printf ("/chosen/bootpath property missing!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
bootpath = (char *) grub_malloc ((grub_size_t) bootpath_size + 64);
|
||||
if (! bootpath)
|
||||
{
|
||||
grub_print_error ();
|
||||
return;
|
||||
}
|
||||
grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", bootpath,
|
||||
(grub_size_t) bootpath_size + 1, 0);
|
||||
bootpath[bootpath_size] = '\0';
|
||||
|
||||
/* Transform an OF device path to a GRUB path. */
|
||||
|
||||
type = grub_ieee1275_get_device_type (bootpath);
|
||||
if (!(type && grub_strcmp (type, "network") == 0))
|
||||
{
|
||||
struct ofdisk_hash_ent *op;
|
||||
char *device = grub_ieee1275_get_devname (bootpath);
|
||||
op = ofdisk_hash_add (device, NULL);
|
||||
op->is_boot = 1;
|
||||
}
|
||||
grub_free (type);
|
||||
grub_free (bootpath);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -508,6 +560,16 @@ grub_ofdisk_fini (void)
|
|||
grub_disk_dev_unregister (&grub_ofdisk_dev);
|
||||
}
|
||||
|
||||
void
|
||||
grub_ofdisk_init (void)
|
||||
{
|
||||
grub_disk_firmware_fini = grub_ofdisk_fini;
|
||||
|
||||
insert_bootpath ();
|
||||
|
||||
grub_disk_dev_register (&grub_ofdisk_dev);
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size)
|
||||
{
|
||||
|
|
|
@ -530,13 +530,7 @@ static struct grub_ata_dev grub_pata_dev =
|
|||
|
||||
GRUB_MOD_INIT(ata_pthru)
|
||||
{
|
||||
/* To prevent two drivers operating on the same disks. */
|
||||
grub_disk_firmware_is_tainted = 1;
|
||||
if (grub_disk_firmware_fini)
|
||||
{
|
||||
grub_disk_firmware_fini ();
|
||||
grub_disk_firmware_fini = NULL;
|
||||
}
|
||||
grub_stop_disk_firmware ();
|
||||
|
||||
/* ATA initialization. */
|
||||
grub_pata_initialize ();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue