Changeset 154


Ignore:
Timestamp:
Apr 10, 2013, 6:47:05 PM (12 years ago)
Author:
David Azarewicz
Message:

Begin adding user info output.
Added LVM support.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/Makefile

    r153 r154  
    3030# Define default build version if not specified in environment
    3131BLD_MAJOR=1
    32 BLD_MINOR=26 # must be 2 digits
     32BLD_MINOR=27 # must be 2 digits
    3333BLD_REV=0 # not used at this time
    3434
     
    149149    @AddToFile $^@,$#define BLD_MONTH,DATEMONTH
    150150    @AddToFile $^@,$#define BLD_DAY,DATEDAY
    151         @AddToFile $^@,$#define BLDLEVEL,BLDLEVEL2,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) Mensys BV 2013
     151    @AddToFile $^@,$#define BLDLEVEL,BLDLEVEL2,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) Mensys BV 2013,$(FIXPACK)
    152152
    153153.asm.obj: .autodepend
     
    188188
    189189os2ahci.sym: os2ahci.map
    190         wat2map.cmd $[@ $^*.ma1
    191         $(MAPSYM) $^*.ma1
    192         @%erase $^*.ma1
     190    wat2map.cmd $[@ $^*.ma1
     191    $(MAPSYM) $^*.ma1
     192    @%erase $^*.ma1
    193193
  • trunk/src/os2ahci/README

    r153 r154  
    106106Option                 Description
    107107------------------------------------------------------------------------------
    108 /c:<addr>              Set debug COM port base address in hex (default = 3f8);
     108/c:<addr>              Set debug COM port base address in hex (default = 0);
    109109                       if used, this option should come before any /d options.
    110110                       If <addr> is set to 0, the COM port is turned off and
     
    113113                       command "type os2ahci$"; see the OS2AHCI project page
    114114                       at http://svn.ecomstation.nl/ahci/wiki/AhciTrace
    115                        for more info.
     115                       for more info. COM0=3f8, COM1=2f8
    116116/d                     Debug output on COM port/trace buffer; multiple "/d"
    117117                       options will increase verbosity:
  • trunk/src/os2ahci/ahci.c

    r148 r154  
    144144  ddprintf("ahci_save_bios_config: BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN);
    145145
     146#if 0
    146147  if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
    147148      ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
     
    151152    init_reset = 1;
    152153  }
     154#endif
    153155
    154156  /* HOST_CAP2 only exists for AHCI V1.2 and later */
     
    676678    if (ai->port_map & (1UL << p)) {
    677679      if (init_reset) {
    678         dprintf("ahci_complete_init: resetting port %d\n", p);
     680        ddprintf("ahci_complete_init: resetting port %d\n", p);
    679681        ahci_reset_port(ai, p, 1);
    680682      } else {
    681         dprintf("ahci_complete_init: restarting port #%d\n", p);
     683        ddprintf("ahci_complete_init: restarting port #%d\n", p);
    682684        ahci_stop_port(ai, p);
    683685        ahci_start_port(ai, p, 1);
     
    718720  int timeout;
    719721
    720   dprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p);
     722  ddprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p);
    721723  if (debug > 1) {
    722724    printf(" PORT_CMD       = 0x%lx\n", readl(port_mmio + PORT_CMD));
     
    749751  /* set link speed and power management options */
    750752  ddprintf("ahci_reset_port: setting link speed and power management options\n");
    751   tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000fffUL; //DAZ
     753  tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000fffUL;
    752754  tmp |= ((u32) link_speed[ad_no(ai)][p] & 0x0f) << 4;
    753755  tmp |= ((u32) link_power[ad_no(ai)][p] & 0x0f) << 8;
    754   //DAZ writel(port_mmio + PORT_SCR_CTL, tmp);
     756  writel(port_mmio + PORT_SCR_CTL, tmp);
    755757
    756758  /* issue COMRESET on the port */
    757759  ddprintf("ahci_reset_port: issuing COMRESET on port %d\n", p);
    758   //DAZ tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x0000000fUL;
    759760  writel(port_mmio + PORT_SCR_CTL, tmp | 1);
    760761  readl(port_mmio + PORT_SCR_CTL);  /* flush */
     
    810811  u8 _far *port_mmio = port_base(ai, p);
    811812  u32 status;
    812   //int timeout;
    813 
    814   dprintf("ahci_start_port %d.%d\n", ad_no(ai), p);
     813
     814  ddprintf("ahci_start_port %d.%d\n", ad_no(ai), p);
    815815  /* check whether device presence is detected and link established */
    816 
    817 #if 0
    818   /* wait for communication to be re-established after port reset */
    819   timeout = 5000;
    820   while (((status = readl(port_mmio + PORT_SCR_STAT)) & 3) != 3) {
    821     mdelay(10);
    822     timeout -= 10;
    823     if (timeout <= 0) {
    824       dprintf("ahci_start_port #%d (PORT_SCR_STAT = 0x%lx)\n", p, status);
    825       return(-1);
    826     }
    827   }
    828 #endif
    829816
    830817  status = readl(port_mmio + PORT_SCR_STAT);
     
    920907  int rc;
    921908
    922   dprintf("ahci_stop_port %d.%d\n", ad_no(ai), p);
     909  ddprintf("ahci_stop_port %d.%d\n", ad_no(ai), p);
    923910
    924911  /* disable port interrupts */
     
    11951182
    11961183  /* restart/reset port (includes the necessary port configuration) */
    1197   if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
    1198       ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
     1184  if (init_reset) {
    11991185    /* As outlined in ahci_restore_bios_config(), switching back and
    12001186     * forth between SATA and AHCI mode requires a COMRESET to force
     
    18031789}
    18041790
    1805 
  • trunk/src/os2ahci/ata.c

    r153 r154  
    442442
    443443/******************************************************************************
     444 * Try to read LVM information from the disk. If found, use the LVM geometry.
     445 * This function will only work at init time. A better strategy would be to
     446 * calculate the geometry during ahci_scan_ports and save it away and then just
     447 * return the saved values when ata_get_geometry() is called.
     448 */
     449int is_lvm_geometry(IORBH _far *iorb)
     450{
     451  ADD_WORKSPACE _far *aws = add_workspace(iorb);
     452  AD_INFO *ai = ad_infos + iorb_unit_adapter(iorb);
     453  GEOMETRY _far *geometry = ((IORB_GEOMETRY _far *) iorb)->pGeometry;
     454  PDLA_Table_Sector pDLA;
     455  int p = iorb_unit_port(iorb);
     456  int d = iorb_unit_device(iorb);
     457  int rc;
     458  ULONG sector;
     459
     460  if (init_complete) return 0; /* We cannot use ahci_exec_polled_cmd() after init_complete */
     461
     462  if (use_lvm_info) {
     463    ddprintf("is_lvm_geometry (%d.%d.%d)\n", ad_no(ai), p, d);
     464
     465    for (sector = 255; sector >= 63; sector >>= 1) {
     466      rc = ahci_exec_polled_cmd(ai, p, 0, 500, ATA_CMD_READ,
     467             AP_SECTOR_28, (u32) sector-1,
     468             AP_COUNT, (u16) 1,
     469             AP_VADDR, (void _far *) aws->buf, 512,
     470             AP_DEVICE, 0x40,
     471             AP_END);
     472      if (rc) continue;
     473
     474      pDLA = (PDLA_Table_Sector)aws->buf;
     475      ddphex(pDLA, sizeof(DLA_Table_Sector), "DLA sector %d:\n", sector-1);
     476
     477      if ((pDLA->DLA_Signature1 == DLA_TABLE_SIGNATURE1) && (pDLA->DLA_Signature2 == DLA_TABLE_SIGNATURE2)) {
     478        ddprintf("is_lvm_geometry found at sector %d\n", sector);
     479        geometry->TotalCylinders = pDLA->Cylinders;
     480        geometry->NumHeads = pDLA->Heads_Per_Cylinder;
     481        geometry->SectorsPerTrack = pDLA->Sectors_Per_Track;
     482        return 1;
     483      }
     484    }
     485  }
     486
     487  return 0;
     488}
     489
     490/******************************************************************************
    444491 * Post processing function for ata_get_geometry(): convert the ATA identify
    445492 * information to OS/2 IOCC_GEOMETRY information.
     
    452499  int a = iorb_unit_adapter(iorb);
    453500  int p = iorb_unit_port(iorb);
     501  char *Method;
    454502
    455503  /* Fill-in geometry information; the ATA-8 spec declares the geometry
     
    500548  }
    501549
     550  Method = "None";
    502551  /* fabricate the remaining geometry fields */
    503552  if (track_size[a][p] != 0) {
     
    511560                                 ((u32) geometry->NumHeads *
    512561                                  (u32) geometry->SectorsPerTrack);
    513 
     562    Method = "Custom";
    514563  } else if (CUR_HEADS(id_buf) > 0 && CUR_CYLS(id_buf) > 0 &&
    515564             CUR_SECTORS(id_buf) > 0 &&
     
    521570    geometry->SectorsPerTrack = CUR_SECTORS(id_buf);
    522571    geometry->TotalCylinders  = CUR_CYLS(id_buf);
    523 
     572    Method = "BIOS";
    524573  } else if (ATA_HEADS(id_buf) > 0 && ATA_CYLS(id_buf) > 0 &&
    525574             ATA_SECTORS(id_buf) > 0) {
     
    528577    geometry->SectorsPerTrack = ATA_SECTORS(id_buf);
    529578    geometry->TotalCylinders  = ATA_CYLS(id_buf);
    530 
     579    Method = "ATA";
    531580  } else {
    532581    /* use typical SCSI geometry */
     
    536585                                 ((u32) geometry->NumHeads *
    537586                                  (u32) geometry->SectorsPerTrack);
    538   }
     587    Method = "SCSI";
     588  }
     589
     590  if (is_lvm_geometry(iorb)) Method = "LVM";
    539591
    540592  if (debug) {
    541     printf("geometry information:\n");
    542     printf("  heads:     %d\n", (u16) geometry->NumHeads);
    543     printf("  sectors:   %d\n", (u16) geometry->SectorsPerTrack);
    544     printf("  cylinders: %d\n", (u16) geometry->TotalCylinders);
    545     printf("  capacity:  %ldMB\n", (u32) (geometry->TotalSectors / 2048));
     593    printf("Drive geometry: %d cylinders, %d heads, %d sectors per track (%ldMB) (%s)\n",
     594        (u16) geometry->TotalCylinders, (u16) geometry->NumHeads, (u16) geometry->SectorsPerTrack,
     595        (u32) (geometry->TotalSectors / 2048), Method);
    546596  }
    547597
  • trunk/src/os2ahci/libc.c

    r153 r154  
    6262
    6363/* debug COM port base address */
    64 u16 com_base = 0x03f8;
     64u16 com_base = 0;
    6565
    6666static char  hex_digits[] = "0123456789abcdef";
     
    295295  len += vsprintf(buf + len, fmt, va);
    296296
    297    if (com_base == 0) {
    298      /* write debug message to trace buffer, not COM port */
    299      trace_write(buf, len);
    300      spin_unlock(com_lock);
    301      return;
    302    }
     297  if (com_base == 0) {
     298    /* write debug message to trace buffer, not COM port */
     299    trace_write(buf, len);
     300    spin_unlock(com_lock);
     301    return;
     302  }
    303303
    304304  /* write debug message to serial port */
  • trunk/src/os2ahci/os2ahci.c

    r153 r154  
    9090int             verbosity = 1;     /* == 1 -> show sign on banner
    9191                                    *  > 1 -> show adapter info during boot */
     92int             use_lvm_info = 1;
    9293
    9394PFN             Device_Help = 0;   /* pointer to device helper entry point */
     
    343344        break;
    344345
     346      case 'z':
     347        use_lvm_info = !invert_option;
     348        break;
     349
    345350      case 'v':
    346351        /* be verbose during boot */
     
    377382  if (TRACE_ACTIVE) {
    378383    /* debug is on, but COM port is off -> use our trace buffer */
    379     trace_init();
    380   }
    381   dprintf("BldLevel: %s\n", BldLevel);
    382   dprintf("CmdLine: %Fs\n", cmd_line);
     384    trace_init(AHCI_TRACE_BUF_SIZE);
     385  } else {
     386    trace_init(AHCI_INFO_BUF_SIZE);
     387  }
     388
     389  printf_nts("BldLevel: %s\n", BldLevel);
     390  printf_nts("CmdLine: %Fs\n", cmd_line);
    383391
    384392  /* scan PCI bus for supported devices */
     
    390398    mdelay_cal();
    391399
    392     if (DevHelp_RegisterDeviceClass(drv_name, (PFN) add_entry, 0, 1,
    393                                     &add_handle)) {
     400    if (DevHelp_RegisterDeviceClass(drv_name, (PFN) add_entry, 0, 1, &add_handle)) {
    394401      cprintf("%s: couldn't register device class\n", drv_name);
    395402      goto init_fail;
     
    466473    case OS2AHCI_IDC_BIOSMODE:
    467474      /* reconfigure adapters in BIOS/int13 mode; needed for generating
    468        * trap dumps on some machines. This is called by ACPI.PSD.
     475       * trap dumps on some machines. This was intended to be called by ACPI.PSD,
     476       * but that is never done. This is obslete. The kernel exit accomplishes
     477       * this instead.
    469478       *
    470479       * To enter BIOS mode, we flush all write caches, turn off interrupts
     
    500509USHORT char_dev_input(RP_RWV _far *rwrb)
    501510{
    502   if (TRACE_ACTIVE) {
    503     return(trace_char_dev(rwrb));
    504   }
    505   return(STDON | STATUS_ERR_UNKCMD);
     511  return(trace_char_dev(rwrb));
    506512}
    507513
     
    804810      init_complete = 1;
    805811
    806       /* DAZ turn off COM port output */
     812      /* DAZ turn off COM port output if on */
    807813      com_base = 0;
    808814
     
    814820      /* register APM hook */
    815821      apm_init();
     822
     823      if (!TRACE_ACTIVE) build_user_info();
    816824    }
    817825    iorb_done(iorb);
     
    15711579  dprintf("Registered kernel exit routine for INT13 mode\n");
    15721580}
     1581
  • trunk/src/os2ahci/os2ahci.h

    r153 r154  
    119119
    120120/* TRACE macros (for our internal ring buffer trace) */
     121#define AHCI_TRACE_BUF_SIZE  0x8000U /* 32k */
     122#define AHCI_INFO_BUF_SIZE  0x1000U /* 4k */
    121123#define TRACE_ACTIVE  (debug > 0 && com_base == 0)
    122124
     
    386388  BUF_TO_SG                            /* copy from buffer to S/G list */
    387389} SG_MEMCPY_DIRECTION;
     390
     391/* Define the size of a disk name.  Disk Names are user defined names given to physical disk drives in the system. */
     392#define DLA_TABLE_SIGNATURE1  0x424D5202L
     393#define DLA_TABLE_SIGNATURE2  0x44464D50L
     394#define DISK_NAME_SIZE    20
     395
     396typedef struct _DLA_Table_Sector { /* DTS */
     397     ULONG DLA_Signature1;         /* The magic signature (part 1) of a Drive Letter Assignment Table. */
     398     ULONG DLA_Signature2;         /* The magic signature (part 2) of a Drive Letter Assignment Table. */
     399     ULONG DLA_CRC;                /* The 32 bit CRC for this sector.  Calculated assuming that this field and all unused space in the sector is 0. */
     400     ULONG Disk_Serial_Number;     /* The serial number assigned to this disk. */
     401     ULONG Boot_Disk_Serial_Number;/* The serial number of the disk used to boot the system.  This is for conflict resolution when multiple volumes
     402                                      want the same drive letter.  Since LVM.EXE will not let this situation happen, the only way to get this situation
     403                                      is for the disk to have been altered by something other than LVM.EXE, or if a disk drive has been moved from one
     404                                      machine to another.  If the drive has been moved, then it should have a different Boot_Disk_Serial_Number.  Thus,
     405                                      we can tell which disk drive is the "foreign" drive and therefore reject its claim for the drive letter in question.
     406                                      If we find that all of the claimaints have the same Boot_Disk_Serial_Number, then we must assign drive letters on
     407                                      a first come, first serve basis.                                          */
     408     ULONG Install_Flags;          /* Used by the Install program. */
     409     ULONG Cylinders;
     410     ULONG Heads_Per_Cylinder;
     411     ULONG Sectors_Per_Track;
     412     char  Disk_Name[DISK_NAME_SIZE];  /* The name assigned to the disk containing this sector. */
     413     UCHAR Reboot;                 /* For use by Install.  Used to keep track of reboots initiated by install. */
     414     BYTE  Reserved[3];            /* Alignment. */
     415                                   /* These are the four entries which correspond to the entries in the partition table. */
     416} DLA_Table_Sector, *PDLA_Table_Sector;
    388417
    389418/* -------------------------- function prototypes -------------------------- */
     
    498527
    499528/* trace.c */
    500 extern void        trace_init    (void);
     529extern void        trace_init    (u16);
    501530extern void        trace_exit    (void);
    502531extern void        trace_write   (u8 _far *s, int len);
    503532extern u16         trace_read    (u8 _far *buf, u16 cb_buf);
    504 //NOT_USED extern u16         trace_bytes_avail(void);
    505533extern u16         trace_char_dev(RP_RWV _far *rwrb);
     534extern void        build_user_info(void);
    506535
    507536/* pci.c */
     
    544573extern int           force_write_cache; /* if != 0, force write cache */
    545574extern int           verbosity;     /* if != 0, show some info during boot */
     575extern int           use_lvm_info;
    546576
    547577extern HDRIVER       rm_drvh;       /* resource manager driver handle */
  • trunk/src/os2ahci/trace.c

    r153 r154  
    2828
    2929/* -------------------------- macros and constants ------------------------- */
    30 
    31 #define AHCI_TRACE_BUF_SIZE  0x8000U /* 32k */
    3230
    3331/* ------------------------ typedefs and structures ------------------------ */
     
    5351 *       a GDT selector for the trace ring buffer
    5452 */
    55 void trace_init(void)
     53void trace_init(u16 usBufSize)
    5654{
    5755  SEL sel = 0;
     56
     57  if (ahci_trace_buf.phys_addr) return;
    5858
    5959  /* initialize ring buffer logic */
    6060  ahci_trace_buf.writep = 0;
    6161  ahci_trace_buf.readp = 0;
    62   ahci_trace_buf.mask = AHCI_TRACE_BUF_SIZE - 1;
     62  ahci_trace_buf.mask = usBufSize - 1;
    6363
    6464  if (ahci_trace_buf.phys_addr == 0) {
    6565    /* allocate buffer */
    66     if (DevHelp_AllocPhys((ULONG) AHCI_TRACE_BUF_SIZE, MEMTYPE_ABOVE_1M,
     66    if (DevHelp_AllocPhys((ULONG) usBufSize, MEMTYPE_ABOVE_1M,
    6767                         &(ahci_trace_buf.phys_addr))) {
    6868      /* failed above 1MB, try below */
    69       if (DevHelp_AllocPhys((ULONG) AHCI_TRACE_BUF_SIZE, MEMTYPE_BELOW_1M,
     69      if (DevHelp_AllocPhys((ULONG) usBufSize, MEMTYPE_BELOW_1M,
    7070                            &(ahci_trace_buf.phys_addr))) {
    7171        /* failed, too. Give up */
    7272        ahci_trace_buf.phys_addr = 0;
    7373        cprintf("%s warning: failed to allocate %dk trace buffer\n",
    74                 drv_name, AHCI_TRACE_BUF_SIZE / 1024);
     74                drv_name, usBufSize / 1024);
    7575        return;
    7676      }
     
    8080    if (DevHelp_AllocGDTSelector(&sel, 1) ||
    8181        DevHelp_PhysToGDTSelector(ahci_trace_buf.phys_addr,
    82                                   AHCI_TRACE_BUF_SIZE, sel)) {
     82                                  usBufSize, sel)) {
    8383      /* failed; free GDT selector and physical memory we allocated before */
    8484      if (sel) {
     
    9595
    9696  }
    97 
    98 
    9997}
    10098
     
    182180  return cb_read;
    183181}
    184 
    185 #ifdef NOT_USED
    186 /******************************************************************************
    187  * return number of bytes we can read from the trace buffer
    188  */
    189 u16 trace_bytes_avail(void)
    190 {
    191 
    192   if (ahci_trace_buf.writep == ahci_trace_buf.readp ) return 0; /* buffer is empty */
    193 
    194   if (ahci_trace_buf.readp <= ahci_trace_buf.writep) {
    195     /* read pointer is smaller than write pointer; no wrap in between */
    196     if (ahci_trace_buf.writep == ahci_trace_buf.readp) {
    197       /* full buffer available */
    198       return AHCI_TRACE_BUF_SIZE;
    199     }
    200     return ahci_trace_buf.writep - ahci_trace_buf.readp;
    201   }
    202 
    203   /* read pointer is larger than write pointer; buffer wrapped */
    204   return AHCI_TRACE_BUF_SIZE - ahci_trace_buf.readp + ahci_trace_buf.writep;
    205 }
    206 #endif
    207182
    208183/******************************************************************************
     
    251226  return(STDON);
    252227}
     228
     229/******************************************************************************
     230 * Create adapter/port/device list for user output.
     231 */
     232void build_user_info(void)
     233{
     234  int a;
     235  int p;
     236  int d;
     237
     238  for (a = 0; a < ad_info_cnt; a++) {
     239    AD_INFO *ai = ad_infos + a;
     240
     241    printf_nts("Adapter %d: %d:%d:%d irq=%d addr=0x%lx\n", a,
     242      ai->bus, ai->dev_func>>3, ai->dev_func&7,
     243      ai->irq, ai->mmio_phys);
     244
     245    for (p = 0; p <= ai->port_max; p++) {
     246      P_INFO *pi = &ai->ports[p];
     247
     248      printf_nts("  Port %d:\n", p);
     249
     250      for (d = 0; d <= pi->dev_max; d++) {
     251        if (!pi->devs[d].present) continue;
     252        printf_nts("    Drive %d: atapi=%d, removable=%d\n", d, pi->devs[d].atapi, pi->devs[d].removable);
     253      }
     254    }
     255  }
     256}
     257
  • trunk/tools/AddToFile.cmd

    r149 r154  
    4646
    4747  when (What='DATEYEAR') then do
    48     rc=lineout(OutFile, String||' '||SUBSTR(DATE('S'), 1, 4));
     48    rc=lineout(OutFile, String||' '||FORMAT(SUBSTR(DATE('S'), 1, 4)));
    4949    rc=lineout(OutFile);
    5050  end
    5151
    5252  when (What='DATEMONTH') then do
    53     rc=lineout(OutFile, String||' '||SUBSTR(DATE('S'), 5, 2));
     53    rc=lineout(OutFile, String||' '||FORMAT(SUBSTR(DATE('S'), 5, 2)));
    5454    rc=lineout(OutFile);
    5555  end
    5656
    5757  when (What='DATEDAY') then do
    58     rc=lineout(OutFile, String||' '||SUBSTR(DATE('S'), 7, 2));
     58    rc=lineout(OutFile, String||' '||FORMAT(SUBSTR(DATE('S'), 7, 2)));
    5959    rc=lineout(OutFile);
    6060  end
Note: See TracChangeset for help on using the changeset viewer.