~ubuntu-branches/debian/stretch/grub2/stretch

« back to all changes in this revision

Viewing changes to disk/ata.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <grub/time.h>
25
25
#include <grub/pci.h>
26
26
#include <grub/scsi.h>
 
27
#include <grub/cs5536.h>
27
28
 
28
29
/* At the moment, only two IDE ports are supported.  */
29
 
static const grub_port_t grub_ata_ioaddress[] = { 0x1f0, 0x170 };
30
 
static const grub_port_t grub_ata_ioaddress2[] = { 0x3f6, 0x376 };
 
30
static const grub_port_t grub_ata_ioaddress[] = { GRUB_ATA_CH0_PORT1,
 
31
                                                  GRUB_ATA_CH1_PORT1 };
 
32
static const grub_port_t grub_ata_ioaddress2[] = { GRUB_ATA_CH0_PORT2, 
 
33
                                                   GRUB_ATA_CH1_PORT2 };
31
34
 
32
35
static struct grub_ata_device *grub_ata_devices;
33
36
 
332
335
}
333
336
 
334
337
static grub_err_t
335
 
grub_ata_device_initialize (int port, int device, int addr, int addr2)
 
338
check_device (struct grub_ata_device *dev)
336
339
{
337
 
  struct grub_ata_device *dev;
338
 
  struct grub_ata_device **devp;
339
 
 
340
 
  grub_dprintf ("ata", "detecting device %d,%d (0x%x, 0x%x)\n",
341
 
                port, device, addr, addr2);
342
 
 
343
 
  dev = grub_malloc (sizeof(*dev));
344
 
  if (! dev)
345
 
    return grub_errno;
346
 
 
347
 
  /* Setup the device information.  */
348
 
  dev->port = port;
349
 
  dev->device = device;
350
 
  dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE;
351
 
  dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE;
352
 
  dev->next = NULL;
353
 
 
354
340
  grub_ata_regset (dev, GRUB_ATA_REG_DISK, dev->device << 4);
355
341
  grub_ata_wait ();
356
342
 
362
348
  grub_uint8_t sec = grub_ata_regget (dev, GRUB_ATA_REG_SECTORS);
363
349
  grub_dprintf ("ata", "sectors=0x%x\n", sec);
364
350
  if (sec != 0x5A)
365
 
    {
366
 
      grub_free(dev);
367
 
      return 0;
368
 
    }
 
351
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no device connected");
369
352
 
370
353
  /* The above test may detect a second (slave) device
371
354
     connected to a SATA controller which supports only one
374
357
     ATAPI commands (RESET, DIAGNOSTIC) may clear this bit.  */
375
358
 
376
359
  /* Use the IDENTIFY DEVICE command to query the device.  */
377
 
  if (grub_ata_identify (dev))
378
 
    {
379
 
      grub_free (dev);
380
 
      return 0;
381
 
    }
 
360
  return grub_ata_identify (dev);
 
361
}
 
362
 
 
363
static grub_err_t
 
364
grub_ata_device_initialize (int port, int device, int addr, int addr2)
 
365
{
 
366
  struct grub_ata_device *dev;
 
367
  struct grub_ata_device **devp;
 
368
  grub_err_t err;
 
369
 
 
370
  grub_dprintf ("ata", "detecting device %d,%d (0x%x, 0x%x)\n",
 
371
                port, device, addr, addr2);
 
372
 
 
373
  dev = grub_malloc (sizeof(*dev));
 
374
  if (! dev)
 
375
    return grub_errno;
 
376
 
 
377
  /* Setup the device information.  */
 
378
  dev->port = port;
 
379
  dev->device = device;
 
380
  dev->ioaddress = addr + GRUB_MACHINE_PCI_IO_BASE;
 
381
  dev->ioaddress2 = addr2 + GRUB_MACHINE_PCI_IO_BASE;
 
382
  dev->next = NULL;
382
383
 
383
384
  /* Register the device.  */
384
385
  for (devp = &grub_ata_devices; *devp; devp = &(*devp)->next);
385
386
  *devp = dev;
386
387
 
 
388
  err = check_device (dev);
 
389
  if (err)
 
390
    grub_print_error ();
 
391
 
387
392
  return 0;
388
393
}
389
394
 
408
413
  class = grub_pci_read (addr);
409
414
 
410
415
  /* AMD CS5536 Southbridge.  */
411
 
  if (pciid == 0x208f1022)
 
416
  if (pciid == GRUB_CS5536_PCIID)
412
417
    {
413
418
      cs5536 = 1;
414
419
      nports = 1;
666
671
  for (dev = grub_ata_devices; dev; dev = dev->next)
667
672
    {
668
673
      char devname[10];
 
674
      grub_err_t err;
 
675
 
 
676
      err = check_device (dev);
 
677
      if (err)
 
678
        {
 
679
          grub_errno = GRUB_ERR_NONE;
 
680
          continue;
 
681
        }
669
682
 
670
683
      if (dev->atapi)
671
684
        continue;
684
697
grub_ata_open (const char *name, grub_disk_t disk)
685
698
{
686
699
  struct grub_ata_device *dev;
 
700
  grub_err_t err;
687
701
 
688
702
  for (dev = grub_ata_devices; dev; dev = dev->next)
689
703
    {
700
714
  if (dev->atapi)
701
715
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not an ATA harddisk");
702
716
 
 
717
  err = check_device (dev);
 
718
 
 
719
  if (err)
 
720
    return err;
 
721
 
703
722
  disk->total_sectors = dev->size;
704
723
 
705
724
  disk->id = (unsigned long) dev;
756
775
  for (dev = grub_ata_devices; dev; dev = dev->next)
757
776
    {
758
777
      char devname[10];
 
778
 
 
779
      grub_err_t err;
 
780
 
 
781
      err = check_device (dev);
 
782
      if (err)
 
783
        {
 
784
          grub_errno = GRUB_ERR_NONE;
 
785
          continue;
 
786
        }
 
787
 
759
788
      grub_snprintf (devname, sizeof (devname),
760
789
                     "ata%d", dev->port * 2 + dev->device);
761
790
 
826
855
{
827
856
  struct grub_ata_device *dev;
828
857
  struct grub_ata_device *devfnd = 0;
 
858
  grub_err_t err;
829
859
 
830
860
  for (dev = grub_ata_devices; dev; dev = dev->next)
831
861
    {
845
875
  if (! devfnd)
846
876
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATAPI device");
847
877
 
 
878
  err = check_device (devfnd);
 
879
  if (err)
 
880
    return err;
 
881
 
 
882
  if (! devfnd->atapi)
 
883
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such ATAPI device");
 
884
 
848
885
  scsi->data = devfnd;
849
886
 
850
887
  return GRUB_ERR_NONE;