Changeset 148


Ignore:
Timestamp:
Mar 27, 2013, 5:55:26 AM (12 years ago)
Author:
David Azarewicz
Message:

Fix spin-up / power-up issue on some hardware
Changes to debug output
Fixup makefiles

Location:
trunk/src/os2ahci
Files:
1 added
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/Makefile

    r144 r148  
    11###############################################################################
    2 # Makefile - makefile for os2ahci driver, c600 tool chain
     2# Makefile - makefile for os2ahci driver using WATCOM compiler
    33#
    4 # Copyright (c) 2011 thi.guten Software Development
    5 # Copyright (c) 2011 Mensys B.V.
    6 #
    7 # Authors: Christian Mueller, Markus Thielen
     4# Copyright (c) 2010 Christian Mueller, Markus Thielen.
     5# Parts copied from/inspired by the Linux AHCI driver;
     6# those parts are (c) Linux AHCI/ATA maintainers
    87#
    98#  This program is free software; you can redistribute it and/or modify
     
    2019#  along with this program; if not, write to the Free Software
    2120#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    22 #
     21
     22
     23###############################################################################
     24# Environment
     25
     26.ERASE
     27.SUFFIXES
     28.SUFFIXES: .lst .obj .c .asm .lib .def
     29
     30# Define default build version if not specified in environment
     31BLD_MAJOR=1
     32BLD_MINOR=26 # must be 2 digits
     33BLD_REV=0 # not used at this time
     34
     35!ifndef %WATCOM # if not defined in the environment
     36!error WATCOM must be set in the environment.
     37!endif
     38WATCOM=$(%WATCOM)
     39
     40!ifndef %DDK # if not defined in the environment
     41!error DDK must be set in the environment.
     42!endif
     43DDK=$(%DDK)
     44
     45!ifdef %VENDOR
     46VENDOR=$(%VENDOR)
     47!else
     48VENDOR=Mensys BV
     49!endif
     50
     51!ifdef %BLD_MAJOR
     52BLD_MAJOR=$(%BLD_MAJOR)
     53!endif
     54
     55!ifdef %BLD_MINOR
     56BLD_MINOR=$(%BLD_MINOR)
     57!endif
     58
     59CC_INCLUDE = -I..\include &
     60             -I$(DDK)\base\h &
     61             -I$(DDK)\base\ibmh &
     62             -I$(DDK)\base\src\dev\dasd\diskh &
     63             -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls &
     64
     65AS_INCLUDE = -I=$(DDK)\base\inc &
     66             -I=$(DDK)\base\src\dev\dasd\diskinc
     67
     68LIB_DIRS   = $(DDK)\base\lib\ &
     69             $(DDK)\base\src\dev\dasd\devhlp\ &
     70             $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\
    2371
    2472###############################################################################
    2573# Tool Chain
    2674#
     75# This makefile uses the Watcom 16-bit compiler, Watcom Assembler and Linker.
     76# The updated DDK devhelp.h is required and a copy is in the include directory
     77# of this project.
     78#
    2779
    28 AS         = $(DDK)\tools\alp.exe
    29 CC         = cl
    30 LD         = $(DDK)\base\tools\link.exe
     80%PATH=..\..\tools;$(WATCOM)\BINP;$(WATCOM)\BINW;
     81AS         = wasm
     82CC         = wcc
    3183MAPSYM     = $(DDK)\base\tools\mapsym.exe
    32 BLDLEVEL   = cmd.exe /c ..\..\tools\bldlvl.cmd
    33 BLDDATE    = cmd.exe /c ..\..\tools\blddate.cmd
    3484
    35 AFLAGS     = -Mb
    36 CFLAGS     = -c -nologo -Asnw -W2 -G2ms -Zlpd -Fc -Zi -DECS_BUILD
    37 LFLAGS     = /noe /nod /packd /a:16 /batch /map /line
    38 
    39 ###############################################################################
    40 # Environment
    41 
    42 # main path to OS/2 DDK; this needs to be set before this makefile will work
    43 !ifndef DDK
    44 DDK          = i:\ddk
     85!ifdef __LOADDLL__
     86!loaddll wcc   $(WATCOM)\BINP\DLL\wccd.dll
     87!loaddll wlink $(WATCOM)\BINP\DLL\wlinkd.dll
    4588!endif
    4689
    47 # main path to 16 bit C compiler
    48 !ifndef CC16
    49 CC16         = i:\c600
    50 !endif
    51 
    52 CC_INCLUDE   = -I..\include \
    53                -I$(DDK)\base\h \
    54                -I$(DDK)\base\ibmh \
    55                -I$(DDK)\base\src\dev\dasd\diskh \
    56                -I$(DDK)\base\src\dev\thinkpad\dockii\apmcalls \
    57 #               -I$(CC16)\include
    58 
    59 AS_INCLUDE   = -I:$(DDK)\base\inc \
    60                -I:$(DDK)\base\src\dev\dasd\diskinc
    61 
    62 LIB_DIRS     = $(DDK)\base\lib\ \
    63                $(DDK)\base\src\dev\dasd\devhlp\ \
    64                $(DDK)\base\src\dev\thinkpad\dockii\apmcalls\ \
    65 #               $(CC16)\lib\ \
    66 
     90AFLAGS = -q
     91#CFLAGS = -ei -5 -d3 -hc -bt=os2 -ms -zu -w3 -wcd=138 -wcd=300 -ecc -zp1 -q -s -zgp -zfp -oi
     92# In order to build the SMP safe version you must have the updated devhelp.h and define OS2AHCI_SMP.
     93CFLAGS = -ei -5 -d0 -bt=os2 -ms -zu -w=0 -ecc -zp=1 -q -s -zgp -zfp -oi -DOS2AHCI_SMP
     94CFLAGS_DEBUG = -ei -5 -d3 -hc -bt=os2 -ms -zu -ecc -zp=1 -q -s -zgp -zfp -od
    6795
    6896###############################################################################
    6997# Main dependencies
    7098
    71 TARGET   = os2ahci.add
     99LIBS = addcalls doscalls rmcalls apmcalls
    72100
    73 LIBS     = addcalls dhcalls doscalls slibcep rmcalls apmcalls
     101SRCS = init.asm math.asm libc.c os2ahci.c pci.c ahci.c ata.c atapi.c &
     102       ctxhook.c trace.c ioctl.c apm.c
    74103
    75 SRCS     = init.asm libc.c os2ahci.c pci.c ahci.c ata.c atapi.c ctxhook.c \
    76            apm.c ioctl.c trace.c
     104OBJS = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj &
     105       ctxhook.obj trace.obj ioctl.obj apm.obj
    77106
    78 OBJS     = init.obj libc.obj os2ahci.obj pci.obj ahci.obj ata.obj atapi.obj \
    79            ctxhook.obj apm.obj ioctl.obj trace.obj
     107INCS = os2ahci.h ahci.h
    80108
    81 INCS     = os2ahci.h ahci.h version.h ioctl.h ..\include\ahci-idc.h
     109all: os2ahci.add os2ahci.sym
    82110
    83 
    84 all: $(TARGET)
    85 
    86 clean:
    87         rm -f $(OBJS) $(TARGET) *.cod *.lst *.def *.map *.sym *.err *.lnk \
    88                 bldday.h
    89 
     111clean: .symbolic
     112    rm -f $(OBJS) os2ahci.add *.cod *.lst *.def *.map *.sym *.err *.lnk version.h
    90113
    91114###############################################################################
    92115# Object/source dependencies
    93116
    94 init.obj:     init.asm   Makefile
     117libc.obj: libc.c Makefile $(INCS)
    95118
    96 libc.obj:     libc.c     Makefile $(INCS)
     119os2ahci.obj: os2ahci.c Makefile $(INCS) version.h ioctl.h
    97120
    98 os2ahci.obj:  os2ahci.c  Makefile $(INCS) bldday.h ioctl.h
     121pci.obj: pci.c Makefile $(INCS)
    99122
    100 pci.obj:      pci.c      Makefile $(INCS)
     123ahci.obj: ahci.c Makefile $(INCS) ata.h atapi.h
    101124
    102 ahci.obj:     ahci.c     Makefile $(INCS) ata.h atapi.h
     125ata.obj: ata.c Makefile $(INCS) ata.h
    103126
    104 ata.obj:      ata.c      Makefile $(INCS) ata.h
     127atapi.obj: atapi.c Makefile $(INCS) atapi.h ata.h
    105128
    106 atapi.obj:    atapi.c    Makefile $(INCS) ata.h atapi.h
     129ctxhook.obj: ctxhook.c Makefile $(INCS) ata.h atapi.h
    107130
    108 ctxhook.obj:  ctxhook.c  Makefile $(INCS) ata.h atapi.h
     131apm.obj: apm.c Makefile $(INCS)
    109132
    110 apm.obj:      apm.c      Makefile $(INCS)
     133ioctl.obj: ioctl.c Makefile $(INCS) ioctl.h atapi.h
    111134
    112 ioctl.obj:    ioctl.c    Makefile $(INCS) ata.h atapi.h ioctl.h
    113 
    114 trace.obj:    trace.c    Makefile $(INCS)
    115 
    116 os2ahci.def:  version.h  os2ahci.def.template
     135trace.obj: trace.c Makefile $(INCS)
    117136
    118137###############################################################################
     
    121140# emacs TAGS file creation
    122141# NOTE: OS/2 emacs etags.exe expects an empty file named c:\dev\null...
    123 tags:   $(SRCS) $(INCS) Makefile
    124         etags.exe $(SRCS) $(INCS) $(DDK)\base\src\dev\dasd\diskh\dhcalls.h \
    125         $(DDK)\base\src\dev\dasd\diskh\iorb.h \
    126         $(DDK)\base\h\bsedos16.h \
    127         $(DDK)\base\h\devcmd.h \
    128         $(DDK)\base\h\reqpkt.h
     142tags:   $(SRCS) $(INCS)
     143    etags.exe $(SRCS) $(INCS)
    129144
    130 bldday.h:
    131         $(BLDDATE) > bldday.h
     145version.h: Makefile .always
     146    @%create $^@
     147    @%append $^@ /* Autogenerated by Makefile */
     148    @%append $^@ $#define VERSION $(BLD_MAJOR)$(BLD_MINOR) /* driver version (2 implied decimals) */
     149    @AddToFile $^@,$#define BLD_YEAR,DATEYEAR
     150    @AddToFile $^@,$#define BLD_MONTH,DATEMONTH
     151    @AddToFile $^@,$#define BLD_DAY,DATEDAY
    132152
    133 .asm.obj:
    134         $(AS) $(AFLAGS) $(AS_INCLUDE) $*.asm
    135         wdis -l $*.obj
     153.asm.obj: .autodepend
     154    $(AS) $(AFLAGS) $(AS_INCLUDE) $[@
     155    #wdis -l $^@
    136156
    137 .c.obj:
    138         $(CC) $(CFLAGS) $(CC_INCLUDE) $*.c
    139         wdis -l $*.obj
     157.c.obj: .autodepend
     158    $(CC) $(CFLAGS) $(CC_INCLUDE) $[@
     159    #wdis -l $^@
    140160
    141 os2ahci.def:
    142         $(BLDLEVEL) os2ahci.def.template os2ahci.def version.h
     161os2ahci.add: $(OBJS) Makefile
     162    # Target name, system and type
     163    @%create $*.lnk
     164    @%append $*.lnk name $*.add
     165    @%append $*.lnk sys os2 dll
     166    # Merge BLDLEVEL information
     167        @AddToFile.cmd $*.lnk,option description,BLDLEVEL,$(VENDOR),$(BLD_MAJOR).$(BLD_MINOR),AHCI Driver (c) Mensys BV 2013
     168    # Set various options
     169    @%append $*.lnk option protmode
     170    @%append $*.lnk option map
     171    @%append $*.lnk option quiet
     172    @%append $*.lnk option nocase
     173    @%append $*.lnk option stack=0
     174    # Generate directives for objects, libraries and library search-paths
     175    @for %f in ($(OBJS)) do @%append $*.lnk file %f
     176    @for %f in ($(LIBS)) do @%append $*.lnk lib %f
     177    @for %f in ($(LIB_DIRS)) do @%append $*.lnk libpath %f
     178    # Attributes for the DATA and CODE segments
     179    @%append $*.lnk segment type DATA SHARED
     180    @%append $*.lnk segment type CODE IOPL
     181    # Order segments by class
     182    @%append $*.lnk order
     183    @%append $*.lnk clname 'DATA'
     184    @%append $*.lnk clname 'CONST'
     185    @%append $*.lnk clname 'BSS'
     186    @%append $*.lnk clname 'CODE'
     187    # Link the stuff together and build the target
     188    wlink  @$*.lnk
     189    @%erase $*.lnk
    143190
     191os2ahci.sym: os2ahci.map
     192        wat2map.cmd $[@ $^*.ma1
     193        $(MAPSYM) $^*.ma1
     194        @%erase $^*.ma1
    144195
    145 $(TARGET): $(OBJS) os2ahci.def Makefile
    146         $(LD) $(LFLAGS) $(OBJS),$(TARGET),$*.map,$(LIB_DIRS) $(LIBS),$*.def
    147         $(MAPSYM) os2ahci
  • trunk/src/os2ahci/README

    r147 r148  
    1616
    1717Copyright (c) 2011 thi.guten Software Development
    18 Copyright (c) 2011 Mensys B.V.
     18Copyright (c) 2011-2013 Mensys B.V.
    1919
    2020Authors: Christian Mueller, Markus Thielen
     
    5151as modifications will also be published as outlined in the GNU GPL2.
    5252
     53Please note that builds other than the official binary delivered as
     54part of eComStation releases or downloaded from ecomstation.nl are
     55not officially supported by Mensys.
     56
     57
     58Building The Driver
     59-------------------
     60
     61The toolchain required for compilation consists of:
     62
     63 - IBM OS/2 DDK version 9.23 or later (see ddk\base\h\version.mak)
     64   (Used for include files and qgrep)
     65 - Open Watcom C/C++ package
     66   (available from: http://www.openwatcom.org/index.php/Downloads)
     67 - WCC 16-bit C Compiler (part of the Open Watcom package)
     68 - WASM Assembler (part of the Open Watcom package)
     69 - WLINK Linker (part of the Open Watcom package)
     70 - MAPSYM (part of the DDK)
     71
     72Simply use "wmake" or "wmake -a" to build the driver.
     73
     74The driver can also be built using the DDK tools, but this build
     75is depreciated and is not kept up-to-date.
     76
    5377The toolchain required for compilation consists of:
    5478
     
    5781 - ALP Assembler (part of DDK)
    5882 - link.exe (part of DDK)
    59 
    60 Please note that builds other than the official binary delivered as
    61 part of eComStation releases or downloaded from ecomstation.nl are
    62 not officially supported by Mensys.
    63 
    64 
    65 Open Watcom Build
    66 -----------------
    67 
    68 The Open Watcom Build is fixed and now produces a working driver.
    69 
    70 The toolchain required for compilation with Open Watcom consists of:
    71 
    72  - IBM OS/2 DDK version 9.23 or later (see ddk\base\h\version.mak)
    73    (Used for include files and qgrep)
    74  - Open Watcom C/C++ package
    75    (available from: http://www.openwatcom.org/index.php/Downloads)
    76  - WCC 16-bits C Compiler (part of the Open Watcom package)
    77  - WASM Assembler (part of the Open Watcom package)
    78  - WLINK Linker (part of the Open Watcom package)
    79  - QGREP (part of DDK)
    80 
    81 Please note that the Open Watcom Build is not as extensively tested as the
    82 normal DDK Build so don't use it on production systems yet.
    83 
    84 Use the _wbuild.cmd script or run wmake -ms -f wmakefile to build it.
    85 When switching between building with the DDK and Open Watcom,
    86 be sure to do a clean first.
    87 
     83 - MAPSYM (part of the DDK)
     84
     85Use "nmake -f Makefile.old" or "nmake -f Makefile.old -a" to build
     86the driver.
     87
     88When switching between building with the DDK and Open Watcom, it is
     89recommended to do a clean first (wmake clean or nmake -f Makefile.old clean).
    8890
    8991
  • trunk/src/os2ahci/_ibuild.cmd

    r144 r148  
    11@echo off
    2 nmake
     2nmake -f Makefile.old
    33
  • trunk/src/os2ahci/_iclean.cmd

    r144 r148  
    11@echo off
    2 nmake clean
     2nmake -f Makefile.old clean
  • trunk/src/os2ahci/_wbuild.cmd

    r144 r148  
    11@echo off
    2 wmake -ms -f wmakefile
     2rem set VENDOR=Mensys BV
     3rem set BLD_MAJOR=1
     4rem set BLD_MINOR=26
     5rem set WATCOM=i:\Watcom
     6rem set DDK=i:\ddk
     7wmake
  • trunk/src/os2ahci/_wclean.cmd

    r144 r148  
    11@echo off
    2 wmake -ms -f wmakefile clean
     2wmake clean
  • trunk/src/os2ahci/ahci.c

    r145 r148  
    142142  }
    143143
     144  ddprintf("ahci_save_bios_config: BIOS AHCI mode is %d\n", ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN);
     145
    144146  if ((ai->bios_config[HOST_CTL / sizeof(u32)] & HOST_AHCI_EN) == 0 &&
    145147      ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
     
    165167
    166168      if (i == HOST_CAP) {
    167         printf(" -");
    168         if (val & HOST_CAP_64)         printf(" 64bit");
    169         if (val & HOST_CAP_NCQ)        printf(" ncq");
    170         if (val & HOST_CAP_SNTF)       printf(" sntf");
    171         if (val & HOST_CAP_MPS)        printf(" mps");
    172         if (val & HOST_CAP_SSS)        printf(" sss");
    173         if (val & HOST_CAP_ALPM)       printf(" alpm");
    174         if (val & HOST_CAP_LED)        printf(" led");
    175         if (val & HOST_CAP_CLO)        printf(" clo");
    176         if (val & HOST_CAP_ONLY)       printf(" ahci_only");
    177         if (val & HOST_CAP_PMP)        printf(" pmp");
    178         if (val & HOST_CAP_FBS)        printf(" fbs");
    179         if (val & HOST_CAP_PIO_MULTI)  printf(" pio_multi");
    180         if (val & HOST_CAP_SSC)        printf(" ssc");
    181         if (val & HOST_CAP_PART)       printf(" part");
    182         if (val & HOST_CAP_CCC)        printf(" ccc");
    183         if (val & HOST_CAP_EMS)        printf(" ems");
    184         if (val & HOST_CAP_SXS)        printf(" sxs");
    185         printf(" cmd_slots:%d", (u16) ((val >> 8) & 0x1f) + 1);
    186         printf(" ports:%d",     (u16) (val & 0x1f) + 1);
     169        printf_nts(" -");
     170        if (val & HOST_CAP_64)         printf_nts(" 64bit");
     171        if (val & HOST_CAP_NCQ)        printf_nts(" ncq");
     172        if (val & HOST_CAP_SNTF)       printf_nts(" sntf");
     173        if (val & HOST_CAP_MPS)        printf_nts(" mps");
     174        if (val & HOST_CAP_SSS)        printf_nts(" sss");
     175        if (val & HOST_CAP_ALPM)       printf_nts(" alpm");
     176        if (val & HOST_CAP_LED)        printf_nts(" led");
     177        if (val & HOST_CAP_CLO)        printf_nts(" clo");
     178        if (val & HOST_CAP_ONLY)       printf_nts(" ahci_only");
     179        if (val & HOST_CAP_PMP)        printf_nts(" pmp");
     180        if (val & HOST_CAP_FBS)        printf_nts(" fbs");
     181        if (val & HOST_CAP_PIO_MULTI)  printf_nts(" pio_multi");
     182        if (val & HOST_CAP_SSC)        printf_nts(" ssc");
     183        if (val & HOST_CAP_PART)       printf_nts(" part");
     184        if (val & HOST_CAP_CCC)        printf_nts(" ccc");
     185        if (val & HOST_CAP_EMS)        printf_nts(" ems");
     186        if (val & HOST_CAP_SXS)        printf_nts(" sxs");
     187        printf_nts(" cmd_slots:%d", (u16) ((val >> 8) & 0x1f) + 1);
     188        printf_nts(" ports:%d",     (u16) (val & 0x1f) + 1);
    187189
    188190      } else if (i == HOST_CTL) {
    189         printf(" -");
    190         if (val & HOST_AHCI_EN)        printf(" ahci_enabled");
    191         if (val & HOST_IRQ_EN)         printf(" irq_enabled");
    192         if (val & HOST_RESET)          printf(" resetting");
     191        printf_nts(" -");
     192        if (val & HOST_AHCI_EN)        printf_nts(" ahci_enabled");
     193        if (val & HOST_IRQ_EN)         printf_nts(" irq_enabled");
     194        if (val & HOST_RESET)          printf_nts(" resetting");
    193195
    194196      } else if (i == HOST_CAP2) {
    195         printf(" -");
    196         if (val & HOST_CAP2_BOH)       printf(" boh");
    197         if (val & HOST_CAP2_NVMHCI)    printf(" nvmhci");
    198         if (val & HOST_CAP2_APST)      printf(" apst");
     197        printf_nts(" -");
     198        if (val & HOST_CAP2_BOH)       printf_nts(" boh");
     199        if (val & HOST_CAP2_NVMHCI)    printf_nts(" nvmhci");
     200        if (val & HOST_CAP2_APST)      printf_nts(" apst");
    199201      }
    200       printf("\n");
     202      printf_nts("\n");
    201203    }
    202204  }
     
    287289int ahci_restore_bios_config(AD_INFO *ai)
    288290{
    289   ddprintf("restoring AHCI BIOS configuration\n");
     291  ddprintf("ahci_restore_bios_config: restoring AHCI BIOS configuration on adapter %d\n", ad_no(ai));
    290292
    291293  /* Restore saved BIOS configuration; please note that HOST_CTL is restored
     
    349351int ahci_restore_initial_config(AD_INFO *ai)
    350352{
    351   ddprintf("restoring initial configuration\n");
     353  ddprintf("ahci_restore_initial_config: restoring initial configuration on adapter %d\n", ad_no(ai));
    352354
    353355  /* restore saved BIOS configuration */
     
    448450
    449451  /* couldn't enable AHCI mode */
    450   dprintf("failed to enable AHCI mode on adapter #%d\n", ad_no(ai));
     452  dprintf("failed to enable AHCI mode on adapter %d\n", ad_no(ai));
    451453  return(1);
     454}
     455
     456int ahci_reset_controller(AD_INFO *ai)
     457{
     458    u32 tmp;
     459    int timeout = 1000;
     460
     461    dprintf("controller reset starting on adapter %d\n", ad_no(ai));
     462    /* we must be in AHCI mode, before using anything
     463     * AHCI-specific, such as HOST_RESET.
     464     */
     465    ahci_enable_ahci(ai);
     466
     467    /* global controller reset */
     468    tmp = readl(ai->mmio + HOST_CTL);
     469    if ((tmp & HOST_RESET) == 0) {
     470        writel(ai->mmio + HOST_CTL, tmp | HOST_RESET);
     471        readl(ai->mmio + HOST_CTL); /* flush */
     472    }
     473
     474    /*
     475     * to perform host reset, OS should set HOST_RESET
     476     * and poll until this bit is read to be "0".
     477     * reset must complete within 1 second, or
     478     * the hardware should be considered fried.
     479     */
     480    while (((tmp = readl(ai->mmio + HOST_CTL)) & HOST_RESET) == HOST_RESET) {
     481        mdelay(10);
     482        timeout -= 10;
     483        if (timeout <= 0) {
     484          dprintf("controller reset failed (0x%lx)\n", tmp);
     485          return(-1);
     486        }
     487    }
     488
     489    /* turn on AHCI mode */
     490    ahci_enable_ahci(ai);
     491
     492    /* Some registers might be cleared on reset.  Restore
     493     * initial values.
     494     */
     495    ahci_restore_initial_config(ai);
     496
     497        if (ai->pci->vendor == PCI_VENDOR_ID_INTEL) {
     498                u32 tmp16 = 0;
     499
     500        ddprintf("ahci_reset_controller: intel detected\n");
     501                /* configure PCS */
     502                pci_read_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), &tmp16);
     503                if ((tmp16 & ai->port_map) != ai->port_map) {
     504            ddprintf("ahci_reset_controller: updating PCS %x/%x\n", (u16)tmp16, ai->port_map);
     505                        tmp16 |= ai->port_map;
     506                        pci_write_conf(ai->bus, ai->dev_func, 0x92, sizeof(u16), tmp16);
     507                }
     508        }
     509
     510    return 0;
    452511}
    453512
     
    487546  }
    488547
     548  ahci_reset_controller(ai);
     549
    489550  if (ahci_enable_ahci(ai)) {
    490551    goto exit_port_scan;
     
    492553
    493554  /* perform port scan */
    494   dprintf("scanning ports on adapter #%d\n", ad_no(ai));
     555  dprintf("ahci_scan_ports: scanning ports on adapter %d\n", ad_no(ai));
    495556  for (p = 0; p < AHCI_MAX_PORTS; p++) {
    496557    if (ai->port_map & (1UL << p)) {
     558
     559      dprintf("ahci_scan_ports: Wait till not busy on port %d\n", p);
     560      /* wait until all active commands have completed on this port */
     561      while (ahci_port_busy(ai, p)) {
     562        msleep(250);
     563      }
    497564
    498565      if (!init_complete) {
     
    506573        rc = ahci_reset_port(ai, p, 0);
    507574      } else {
    508         ddprintf("(re)starting port #%d\n", p);
     575        ddprintf("ahci_scan_ports: (re)starting port %d\n", p);
    509576        ahci_stop_port(ai, p);
    510577        rc = ahci_start_port(ai, p, 0);
     
    517584
    518585      /* this port seems to have a device attached and ready for commands */
    519       ddprintf("port #%d seems to be attached to a device; probing...\n", p);
     586      ddprintf("ahci_scan_ports: port %d seems to be attached to a device; probing...\n", p);
    520587
    521588      /* Get ATA(PI) identity. The so-called signature gives us a hint whether
     
    575642  int i;
    576643
    577   dprintf("completing initialization of adapter #%d\n", ad_no(ai));
     644  dprintf("ahci_complete_init: completing initialization of adapter #%d\n", ad_no(ai));
    578645
    579646  /* register IRQ handlers; each IRQ level is registered only once */
     
    609676    if (ai->port_map & (1UL << p)) {
    610677      if (init_reset) {
     678        dprintf("ahci_complete_init: resetting port %d\n", p);
    611679        ahci_reset_port(ai, p, 1);
    612680      } else {
    613         dprintf("restarting port #%d\n", p);
     681        dprintf("ahci_complete_init: restarting port #%d\n", p);
    614682        ahci_stop_port(ai, p);
    615683        ahci_start_port(ai, p, 1);
     
    648716  u8 _far *port_mmio = port_base(ai, p);
    649717  u32 tmp;
    650   int timeout = 5000;
    651 
    652   dprintf("resetting port %d.%d\n", ad_no(ai), p);
     718  int timeout;
     719
     720  dprintf("ahci_reset_port: resetting port %d.%d\n", ad_no(ai), p);
    653721  if (debug > 1) {
    654     printf("command engine status:\n");
     722    printf(" PORT_CMD       = 0x%lx\n", readl(port_mmio + PORT_CMD));
     723    printf("ahci_reset_port: command engine status:\n");
    655724    printf(" PORT_SCR_ACT   = 0x%lx\n", readl(port_mmio + PORT_SCR_ACT));
    656725    printf(" PORT_CMD_ISSUE = 0x%lx\n", readl(port_mmio + PORT_CMD_ISSUE));
     
    673742  writel(port_mmio + PORT_SCR_ERR, tmp);
    674743
     744  /* power up and spin up the drive if necessary */
     745  if (((tmp = readl(port_mmio + PORT_CMD)) & (PORT_CMD_SPIN_UP|PORT_CMD_POWER_ON)) != (PORT_CMD_SPIN_UP|PORT_CMD_POWER_ON)) {
     746    writel(port_mmio + PORT_CMD, tmp | PORT_CMD_SPIN_UP | PORT_CMD_POWER_ON);
     747  }
     748
    675749  /* set link speed and power management options */
    676   ddprintf("setting link speed and power management options\n");
    677   tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000ff0UL;
     750  ddprintf("ahci_reset_port: setting link speed and power management options\n");
     751  tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x00000fffUL; //DAZ
    678752  tmp |= ((u32) link_speed[ad_no(ai)][p] & 0x0f) << 4;
    679753  tmp |= ((u32) link_power[ad_no(ai)][p] & 0x0f) << 8;
    680   writel(port_mmio + PORT_SCR_CTL, tmp);
     754  //DAZ writel(port_mmio + PORT_SCR_CTL, tmp);
    681755
    682756  /* issue COMRESET on the port */
    683   ddprintf("issuing COMRESET on port\n");
    684   tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x0000000fUL;
     757  ddprintf("ahci_reset_port: issuing COMRESET on port %d\n", p);
     758  //DAZ tmp = readl(port_mmio + PORT_SCR_CTL) & ~0x0000000fUL;
    685759  writel(port_mmio + PORT_SCR_CTL, tmp | 1);
    686760  readl(port_mmio + PORT_SCR_CTL);  /* flush */
     
    693767
    694768  /* wait for communication to be re-established after port reset */
     769  timeout = 5000;
    695770  while (((tmp = readl(port_mmio + PORT_SCR_STAT)) & 3) != 3) {
    696771    mdelay(10);
     
    708783
    709784  /* start port so we can receive the COMRESET FIS */
    710   ddprintf("starting port again\n");
     785  ddprintf("ahci_reset_port: starting port %d again\n", p);
    711786  ahci_start_port(ai, p, ei);
    712787
    713788  /* wait for device to be ready ((PxTFD & (BSY | DRQ | ERR)) == 0) */
     789  timeout = 5000;
    714790  while (((tmp = readl(port_mmio + PORT_TFDATA)) & 0x89) != 0) {
    715791    mdelay(10);
     
    722798    }
    723799  }
    724   ddprintf(" PORT_TFDATA   = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
     800  ddprintf("ahci_reset_port: PORT_TFDATA   = 0x%lx\n", readl(port_mmio + PORT_TFDATA));
    725801
    726802  return(0);
     
    734810  u8 _far *port_mmio = port_base(ai, p);
    735811  u32 status;
    736 
     812  //int timeout;
     813
     814  dprintf("ahci_start_port %d.%d\n", ad_no(ai), p);
    737815  /* 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
     829
    738830  status = readl(port_mmio + PORT_SCR_STAT);
    739   ddprintf(" PORT_SCR_STAT = 0x%lx\n", status);
     831  ddprintf("ahci_start_port: PORT_SCR_STAT = 0x%lx\n", status);
    740832  if ((status & 0xf) != 3) {
    741833    return(-1);
     
    744836  /* clear SError, if any */
    745837  status = readl(port_mmio + PORT_SCR_ERR);
    746   ddprintf(" PORT_SCR_ERR  = 0x%lx\n", status);
     838  ddprintf("ahci_start_port: PORT_SCR_ERR  = 0x%lx\n", status);
    747839  writel(port_mmio + PORT_SCR_ERR, status);
    748840
     
    827919  u32 tmp;
    828920  int rc;
     921
     922  dprintf("ahci_stop_port %d.%d\n", ad_no(ai), p);
    829923
    830924  /* disable port interrupts */
  • trunk/src/os2ahci/libc.c

    r118 r148  
    5858                                                ULONG parm2);
    5959static int              mdelay_cal_end         (void);
    60 static void             printf_nts             (const char *fmt, ...);
    6160
    6261/* ------------------------ global/static variables ------------------------ */
     
    284283
    285284  spin_lock(com_lock);
    286  
     285
    287286  if (ts) {
    288287    /* include timestamp */
     
    351350 * Print messages to COM port with no time stamp
    352351 */
    353 static void printf_nts(const char *fmt, ...)
     352void printf_nts(const char *fmt, ...)
    354353{
    355354  va_list va;
     
    509508      len -= l;
    510509    }
    511    
     510
    512511    pos += sg_list[i].XferBufLen;
    513512  }
  • trunk/src/os2ahci/os2ahci.c

    r147 r148  
    2626
    2727#include "os2ahci.h"
    28 #include "bldday.h"
    29 
    3028#include "ioctl.h"
    3129
     
    357355  ciprintf(init_msg, drv_name, VERSION / 100, VERSION % 100);
    358356
    359 #ifdef ECS_BUILD
    360   ciprintf("This driver is licensed for use only in conjunction with eComStation.\n");
    361 #else
    362   ciprintf("This is the Open Watcom build.\n");
    363 #endif
     357//#ifdef ECS_BUILD
     358//  ciprintf("This driver is licensed for use only in conjunction with eComStation.\n");
     359//#else
     360//  ciprintf("This is the Open Watcom build.\n");
     361//#endif
    364362
    365363  if (debug) {
    366364    /* initialize com port for debug output */
    367     init_com();
     365    //DAZ init_com();
    368366  }
    369367
     
    781779      }
    782780      init_complete = 1;
     781
     782      /* DAZ turn off COM port output */
     783      com_base = 0;
    783784
    784785      /* release all adapters */
  • trunk/src/os2ahci/os2ahci.def.template

    r144 r148  
    11library os2ahci
    2 Description '$@#Mensys:0.0.0#@##1## 2011/05/02 11:41:00      ECSDEVEL::::00::@@AHCI Driver. (c) Mensys BV 2011'
    32protmode
    43
  • trunk/src/os2ahci/os2ahci.h

    r145 r148  
    157157#define DevHelp_FreeSpinLock(sph)      0
    158158
    159 #define DevHelp_AquireSpinLock(sph)    if ((sph) != 0)                \
     159#define DevHelp_AcquireSpinLock(sph)    if ((sph) != 0)                \
    160160                                         panic("recursive spinlock"); \
    161161                                       (sph) = disable()
     
    168168
    169169/* shortcut macros */
    170 #define spin_lock(sl)     DevHelp_AquireSpinLock(sl)
     170#define spin_lock(sl)     DevHelp_AcquireSpinLock(sl)
    171171#define spin_unlock(sl)   DevHelp_ReleaseSpinLock(sl)
    172172
     
    476476extern void        vfprintf      (const char *fmt, va_list va);
    477477extern void _cdecl printf        (const char *fmt, ...);
     478extern void _cdecl printf_nts    (const char *fmt, ...);
    478479extern void        cprintf       (const char *fmt, ...);
    479480extern void        phex          (const void _far *p, int len, const char *fmt, ...);
     
    500501extern void        trace_exit    (void);
    501502extern void        trace_write   (u8 _far *s, int len);
    502 extern u16         trace_read    (void _far *buf, u16 cb_buf);
    503 extern u16         trace_bytes_avail(void);
     503extern u16         trace_read    (u8 _far *buf, u16 cb_buf);
     504//NOT_USED extern u16         trace_bytes_avail(void);
    504505extern u16         trace_char_dev(RP_RWV _far *rwrb);
    505506
     
    511512extern char     *vendor_from_id (u16 vendor);
    512513extern char     *device_from_id (u16 device);
     514UCHAR pci_read_conf    (UCHAR bus, UCHAR dev_func, UCHAR indx,
     515                        UCHAR size, ULONG _far *val);
     516UCHAR pci_write_conf   (UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
     517                        ULONG val);
    513518
    514519/* ctxhook.c */
  • trunk/src/os2ahci/pci.c

    r123 r148  
    147147
    148148static void  add_pci_device   (PCI_ID *pci_id, OH_DATA _far *data);
    149 static UCHAR pci_read_conf    (UCHAR bus, UCHAR dev_func, UCHAR indx,
    150                                UCHAR size, ULONG _far *val);
    151 static UCHAR pci_write_conf   (UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
    152                                ULONG val);
    153149static int   oemhlp_call      (UCHAR subfunction, OH_PARM _far *parm,
    154150                               OH_DATA _far *data);
     
    698694    ret = RMAllocResource(rm_drvh, ad_info->rm_bars + i, &resource);
    699695    if (ret != RMRC_SUCCESS) {
    700       cprintf("%s: couldn't register [MM]IO region (rc = %s)\n", 
     696      cprintf("%s: couldn't register [MM]IO region (rc = %s)\n",
    701697              drv_name, rmerr(ret));
    702698      goto add_pci_fail;
     
    813809 * Read PCI configuration space register
    814810 */
    815 static UCHAR pci_read_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
     811UCHAR pci_read_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
    816812                           ULONG _far *val)
    817813{
     
    838834 * Write PCI configuration space register
    839835 */
    840 static UCHAR pci_write_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
     836UCHAR pci_write_conf(UCHAR bus, UCHAR dev_func, UCHAR indx, UCHAR size,
    841837                            ULONG val)
    842838{
  • trunk/src/os2ahci/trace.c

    r122 r148  
    4242  u16 writep;      /* current write offset in buffer */
    4343  u16 readp;       /* current read offset in buffer */
    44   int empty;       /* != 0 if buffer is empty */
     44  u16 mask;        /* The mask for wrapping the buffer pointers */
    4545} ahci_trace_buf;
    4646
     
    4949/******************************************************************************
    5050 * initialize AHCI circular trace buffer
    51  * 
     51 *
    5252 * NOTE: this func must be called during INIT time since it allocates
    5353 *       a GDT selector for the trace ring buffer
     
    6060  ahci_trace_buf.writep = 0;
    6161  ahci_trace_buf.readp = 0;
    62   ahci_trace_buf.empty = 1;
     62  ahci_trace_buf.mask = AHCI_TRACE_BUF_SIZE - 1;
    6363
    6464  if (ahci_trace_buf.phys_addr == 0) {
     
    9595
    9696  }
    97  
    98  
     97
     98
    9999}
    100100
     
    126126 * Note: This func wraps the buffer if necessary, so the caller does not
    127127 *       need to call repeatedly until everything is written.
    128  *       
     128 *
    129129 */
    130130void trace_write(u8 _far *s, int len)
    131131{
    132   u16 cbw; /* bytes we can store before buffer wrap occurrs */
    133   u16 cb;
    134   USHORT awake_cnt;
    135  
     132  //NOT USED USHORT awake_cnt;
     133
    136134  if (ahci_trace_buf.phys_addr == 0) {
    137135    /* tracing not active */
    138136    return;
    139137  }
    140  
    141   cbw = AHCI_TRACE_BUF_SIZE - ahci_trace_buf.writep;
    142 
    143   while (len > 0) {
    144     cb = cbw < len ? cbw : len;
    145     if (cb && ahci_trace_buf.empty) {
    146       ahci_trace_buf.empty = 0;
    147     }
    148     memcpy(ahci_trace_buf.tbuf + ahci_trace_buf.writep, s, cb);
    149     s += cb;
    150     ahci_trace_buf.writep += cb;
    151     len -= cb;
    152 
    153     /* wrap? */
    154     if (ahci_trace_buf.writep >= AHCI_TRACE_BUF_SIZE) {
    155       ahci_trace_buf.writep = 0;
    156       cbw = AHCI_TRACE_BUF_SIZE;
    157     }
    158   }
    159        
     138
     139  while (len) {
     140    /* The following line causes filling the trace buffer to stop when full.
     141     * Comment the following line to keep filling and see the last buffer of data.
     142     * Uncomment the following line to stop filling / see the first buffer of data.
     143     */
     144    if ( ((ahci_trace_buf.writep+1) & ahci_trace_buf.mask) == ahci_trace_buf.readp ) break; /* buffer is full */
     145
     146    ahci_trace_buf.tbuf[ahci_trace_buf.writep] = *s++;
     147    ahci_trace_buf.writep++;
     148    ahci_trace_buf.writep &= ahci_trace_buf.mask;
     149
     150    /* keep the latest full buffer of information */
     151    if (ahci_trace_buf.writep == ahci_trace_buf.readp)
     152      ahci_trace_buf.readp = (ahci_trace_buf.readp+1) & ahci_trace_buf.mask;
     153
     154    len--;
     155  }
     156
    160157  /* wake up processes waiting for data from trace buffer */
    161   DevHelp_ProcRun(ahci_trace_buf.phys_addr, &awake_cnt);
     158  //NOT_USED DevHelp_ProcRun(ahci_trace_buf.phys_addr, &awake_cnt);
    162159
    163160}
     
    167164 * returns the number of bytes written to the caller's buffer
    168165 *
    169  * NOTE: the caller is expected to call this func repeatedly 
     166 * NOTE: the caller is expected to call this func repeatedly
    170167 *       (up to two times) until it returns 0
    171168 */
    172 u16 trace_read(void _far *buf, u16 cb_buf)
     169u16 trace_read(u8 _far *buf, u16 cb_buf)
    173170{
    174171  u16 cb_avail;
    175172  u16 cb_read;
    176173
    177   if (ahci_trace_buf.phys_addr == NULL || ahci_trace_buf.empty) {
    178     return 0;
    179   }
    180  
    181   /* get number of bytes in buffer */
    182   if (ahci_trace_buf.readp < ahci_trace_buf.writep) {
    183     /* read pointer is smaller than write pointer; no wrap in between */
    184     cb_avail = ahci_trace_buf.writep - ahci_trace_buf.readp;
    185   } else {
    186     /* read pointer is larger than (or same as) write pointer;
    187      * read up to buffer end and let caller come again (if necessary)
    188      */
    189     cb_avail = AHCI_TRACE_BUF_SIZE - ahci_trace_buf.readp;
    190   }
    191 
    192   /* determine number of bytes we actually can return */
    193   cb_read = cb_buf > cb_avail ? cb_avail : cb_buf;
    194 
    195   memcpy(buf, ahci_trace_buf.tbuf + ahci_trace_buf.readp, cb_read);
    196  
    197   /* update read pointer */
    198   ahci_trace_buf.readp += cb_read;
    199   if (ahci_trace_buf.readp >= AHCI_TRACE_BUF_SIZE) {
    200     ahci_trace_buf.readp = 0;
    201   }
    202  
    203   /* check if buffer is empty now */
    204   if (ahci_trace_buf.readp == ahci_trace_buf.writep) {
    205     ahci_trace_buf.empty = 1;
    206   }
    207      
     174  if (ahci_trace_buf.phys_addr == NULL) return 0;
     175
     176  for (cb_read = 0; cb_read < cb_buf && ( ahci_trace_buf.readp != ahci_trace_buf.writep ); cb_read++)
     177  {
     178    *buf++ = ahci_trace_buf.tbuf[ahci_trace_buf.readp];
     179    ahci_trace_buf.readp++;
     180    ahci_trace_buf.readp &= ahci_trace_buf.mask;
     181  }
     182
    208183  return cb_read;
    209184}
    210185
     186#ifdef NOT_USED
    211187/******************************************************************************
    212188 * return number of bytes we can read from the trace buffer
     
    214190u16 trace_bytes_avail(void)
    215191{
    216  
    217   if (ahci_trace_buf.empty) {
    218     return 0;
    219   }
     192
     193  if (ahci_trace_buf.writep == ahci_trace_buf.readp ) return 0; /* buffer is empty */
    220194
    221195  if (ahci_trace_buf.readp <= ahci_trace_buf.writep) {
     
    231205  return AHCI_TRACE_BUF_SIZE - ahci_trace_buf.readp + ahci_trace_buf.writep;
    232206}
    233 
     207#endif
    234208
    235209/******************************************************************************
     
    243217  USHORT mode = 0;
    244218
    245   /* block process until data is available in the trace buffer;
    246    * see also comment in ioctl.c next to DevHelp_ProcBlock
    247    * concerning spin_lock and ProcBlock interaction
    248    */
    249   while (ahci_trace_buf.empty) {
     219  spin_lock(com_lock);
     220  #ifdef NOT_USED
     221  /* block process until data is available in the trace buffer. */
     222  while (ahci_trace_buf.writep == ahci_trace_buf.readp ) { /* buffer is empty */
    250223    spin_lock(com_lock);
    251 #   ifndef OS2AHCI_SMP
     224      #ifndef OS2AHCI_SMP
    252225      com_lock = 0;
    253 #   endif
    254       if (DevHelp_ProcBlock((ULONG) ahci_trace_buf.phys_addr, 
     226      #endif
     227      if (DevHelp_ProcBlock((ULONG) ahci_trace_buf.phys_addr,
    255228                            (ULONG) -1, 0) == WAIT_INTERRUPTED) {
    256229        /* user pressed Ctrl+C or whatever */
     
    260233    spin_lock(com_lock);
    261234  }
     235  #endif
    262236
    263237  /* get pointer to caller's buffer */
Note: See TracChangeset for help on using the changeset viewer.