aic7770_osm.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Linux driver attachment glue for aic7770 based controllers.
  3. *
  4. * Copyright (c) 2000-2003 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#14 $
  40. */
  41. #include "aic7xxx_osm.h"
  42. #include <linux/device.h>
  43. #include <linux/eisa.h>
  44. #define EISA_MFCTR_CHAR0(ID) (char)(((ID>>26) & 0x1F) | '@') /* Bits 26-30 */
  45. #define EISA_MFCTR_CHAR1(ID) (char)(((ID>>21) & 0x1F) | '@') /* Bits 21-25 */
  46. #define EISA_MFCTR_CHAR2(ID) (char)(((ID>>16) & 0x1F) | '@') /* Bits 16-20 */
  47. #define EISA_PRODUCT_ID(ID) (short)((ID>>4) & 0xFFF) /* Bits 4-15 */
  48. #define EISA_REVISION_ID(ID) (uint8_t)(ID & 0x0F) /* Bits 0-3 */
  49. static int aic7770_eisa_dev_probe(struct device *dev);
  50. static int aic7770_eisa_dev_remove(struct device *dev);
  51. static struct eisa_driver aic7770_driver = {
  52. .driver = {
  53. .name = "aic7xxx",
  54. .probe = aic7770_eisa_dev_probe,
  55. .remove = aic7770_eisa_dev_remove,
  56. }
  57. };
  58. typedef struct device *aic7770_dev_t;
  59. static int aic7770_linux_config(struct aic7770_identity *entry,
  60. aic7770_dev_t dev, u_int eisaBase);
  61. int
  62. ahc_linux_eisa_init(void)
  63. {
  64. struct eisa_device_id *eid;
  65. struct aic7770_identity *id;
  66. int i;
  67. if (aic7xxx_probe_eisa_vl == 0)
  68. return -ENODEV;
  69. /*
  70. * Linux requires the EISA IDs to be specified in
  71. * the EISA ID string format. Perform the conversion
  72. * and setup a table with a NUL terminal entry.
  73. */
  74. aic7770_driver.id_table = malloc(sizeof(struct eisa_device_id) *
  75. (ahc_num_aic7770_devs + 1),
  76. M_DEVBUF, M_NOWAIT);
  77. if (aic7770_driver.id_table == NULL)
  78. return -ENOMEM;
  79. for (eid = (struct eisa_device_id *)aic7770_driver.id_table,
  80. id = aic7770_ident_table, i = 0;
  81. i < ahc_num_aic7770_devs; eid++, id++, i++) {
  82. sprintf(eid->sig, "%c%c%c%03X%01X",
  83. EISA_MFCTR_CHAR0(id->full_id),
  84. EISA_MFCTR_CHAR1(id->full_id),
  85. EISA_MFCTR_CHAR2(id->full_id),
  86. EISA_PRODUCT_ID(id->full_id),
  87. EISA_REVISION_ID(id->full_id));
  88. eid->driver_data = i;
  89. }
  90. eid->sig[0] = 0;
  91. return eisa_driver_register(&aic7770_driver);
  92. }
  93. void
  94. ahc_linux_eisa_exit(void)
  95. {
  96. if(aic7xxx_probe_eisa_vl != 0 && aic7770_driver.id_table != NULL) {
  97. eisa_driver_unregister(&aic7770_driver);
  98. free(aic7770_driver.id_table, M_DEVBUF);
  99. }
  100. }
  101. static int
  102. aic7770_linux_config(struct aic7770_identity *entry, aic7770_dev_t dev,
  103. u_int eisaBase)
  104. {
  105. struct ahc_softc *ahc;
  106. char buf[80];
  107. char *name;
  108. int error;
  109. /*
  110. * Allocate a softc for this card and
  111. * set it up for attachment by our
  112. * common detect routine.
  113. */
  114. sprintf(buf, "ahc_eisa:%d", eisaBase >> 12);
  115. name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
  116. if (name == NULL)
  117. return (ENOMEM);
  118. strcpy(name, buf);
  119. ahc = ahc_alloc(&aic7xxx_driver_template, name);
  120. if (ahc == NULL)
  121. return (ENOMEM);
  122. error = aic7770_config(ahc, entry, eisaBase);
  123. if (error != 0) {
  124. ahc->bsh.ioport = 0;
  125. ahc_free(ahc);
  126. return (error);
  127. }
  128. dev->driver_data = (void *)ahc;
  129. if (aic7xxx_detect_complete)
  130. error = ahc_linux_register_host(ahc, &aic7xxx_driver_template);
  131. return (error);
  132. }
  133. int
  134. aic7770_map_registers(struct ahc_softc *ahc, u_int port)
  135. {
  136. /*
  137. * Lock out other contenders for our i/o space.
  138. */
  139. if (request_region(port, AHC_EISA_IOSIZE, "aic7xxx") == 0)
  140. return (ENOMEM);
  141. ahc->tag = BUS_SPACE_PIO;
  142. ahc->bsh.ioport = port;
  143. return (0);
  144. }
  145. int
  146. aic7770_map_int(struct ahc_softc *ahc, u_int irq)
  147. {
  148. int error;
  149. int shared;
  150. shared = 0;
  151. if ((ahc->flags & AHC_EDGE_INTERRUPT) == 0)
  152. shared = SA_SHIRQ;
  153. error = request_irq(irq, ahc_linux_isr, shared, "aic7xxx", ahc);
  154. if (error == 0)
  155. ahc->platform_data->irq = irq;
  156. return (-error);
  157. }
  158. static int
  159. aic7770_eisa_dev_probe(struct device *dev)
  160. {
  161. struct eisa_device *edev;
  162. edev = to_eisa_device(dev);
  163. return (aic7770_linux_config(aic7770_ident_table + edev->id.driver_data,
  164. dev, edev->base_addr+AHC_EISA_SLOT_OFFSET));
  165. }
  166. static int
  167. aic7770_eisa_dev_remove(struct device *dev)
  168. {
  169. struct ahc_softc *ahc;
  170. u_long l;
  171. /*
  172. * We should be able to just perform
  173. * the free directly, but check our
  174. * list for extra sanity.
  175. */
  176. ahc_list_lock(&l);
  177. ahc = ahc_find_softc((struct ahc_softc *)dev->driver_data);
  178. if (ahc != NULL) {
  179. u_long s;
  180. ahc_lock(ahc, &s);
  181. ahc_intr_enable(ahc, FALSE);
  182. ahc_unlock(ahc, &s);
  183. ahc_free(ahc);
  184. }
  185. ahc_list_unlock(&l);
  186. return (0);
  187. }