aic7770_osm.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * Linux driver attachment glue for aic7770 based controllers.
  3.  *
  4.  * Copyright (c) 2000-2001 Adaptec Inc.
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions, and the following disclaimer,
  12.  *    without modification.
  13.  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  14.  *    substantially similar to the "NO WARRANTY" disclaimer below
  15.  *    ("Disclaimer") and any redistribution must be conditioned upon
  16.  *    including a substantially similar Disclaimer requirement for further
  17.  *    binary redistribution.
  18.  * 3. Neither the names of the above-listed copyright holders nor the names
  19.  *    of any contributors may be used to endorse or promote products derived
  20.  *    from this software without specific prior written permission.
  21.  *
  22.  * Alternatively, this software may be distributed under the terms of the
  23.  * GNU General Public License ("GPL") version 2 as published by the Free
  24.  * Software Foundation.
  25.  *
  26.  * NO WARRANTY
  27.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  30.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31.  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  35.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  36.  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37.  * POSSIBILITY OF SUCH DAMAGES.
  38.  *
  39.  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7770_osm.c#11 $
  40.  */
  41. #include "aic7xxx_osm.h"
  42. #define MINSLOT 1
  43. #define NUMSLOTS 16
  44. #define IDOFFSET 0x80
  45. int
  46. aic7770_linux_probe(Scsi_Host_Template *template)
  47. {
  48. #if defined(__i386__) || defined(__alpha__)
  49. struct aic7770_identity *entry;
  50. struct ahc_softc *ahc;
  51. int i, slot;
  52. int eisaBase;
  53. int found;
  54. eisaBase = 0x1000 + AHC_EISA_SLOT_OFFSET;
  55. found = 0;
  56. for (slot = 1; slot < NUMSLOTS; eisaBase+=0x1000, slot++) {
  57. uint32_t eisa_id;
  58. size_t  id_size;
  59. if (check_region(eisaBase, AHC_EISA_IOSIZE) != 0)
  60. continue;
  61. eisa_id = 0;
  62. id_size = sizeof(eisa_id);
  63. for (i = 0; i < 4; i++) {
  64. /* VLcards require priming*/
  65. outb(0x80 + i, eisaBase + IDOFFSET);
  66. eisa_id |= inb(eisaBase + IDOFFSET + i)
  67.    << ((id_size-i-1) * 8);
  68. }
  69. if (eisa_id & 0x80000000)
  70. continue;  /* no EISA card in slot */
  71. entry = aic7770_find_device(eisa_id);
  72. if (entry != NULL) {
  73. char  buf[80];
  74. char *name;
  75. int  error;
  76. /*
  77.  * Allocate a softc for this card and
  78.  * set it up for attachment by our
  79.  * common detect routine.
  80.  */
  81. sprintf(buf, "ahc_eisa:%d", slot);
  82. name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
  83. if (name == NULL)
  84. break;
  85. strcpy(name, buf);
  86. ahc = ahc_alloc(template, name);
  87. if (ahc == NULL) {
  88. /*
  89.  * If we can't allocate this one,
  90.  * chances are we won't be able to
  91.  * allocate future card structures.
  92.  */
  93. break;
  94. }
  95. error = aic7770_config(ahc, entry, eisaBase);
  96. if (error != 0) {
  97. ahc->bsh.ioport = 0;
  98. ahc_free(ahc);
  99. continue;
  100. }
  101. found++;
  102. }
  103. }
  104. return (found);
  105. #else
  106. return (0);
  107. #endif
  108. }
  109. int
  110. aic7770_map_registers(struct ahc_softc *ahc, u_int port)
  111. {
  112. /*
  113.  * Lock out other contenders for our i/o space.
  114.  */
  115. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
  116. request_region(port, AHC_EISA_IOSIZE, "aic7xxx");
  117. #else
  118. if (request_region(port, AHC_EISA_IOSIZE, "aic7xxx") == 0)
  119. return (ENOMEM);
  120. #endif
  121. ahc->tag = BUS_SPACE_PIO;
  122. ahc->bsh.ioport = port;
  123. return (0);
  124. }
  125. int
  126. aic7770_map_int(struct ahc_softc *ahc, u_int irq)
  127. {
  128. int error;
  129. int shared;
  130. shared = 0;
  131. if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0)
  132. shared = SA_SHIRQ;
  133. error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc);
  134. if (error == 0)
  135. ahc->platform_data->irq = irq;
  136. return (-error);
  137. }