isa.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 2009 Marcel Moolenaar
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  20. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  22. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #include <sys/cdefs.h>
  28. __FBSDID("$FreeBSD$");
  29. #include <sys/param.h>
  30. #include <sys/bus.h>
  31. #include <sys/malloc.h>
  32. #include <machine/bus.h>
  33. #include <sys/rman.h>
  34. #include <machine/intr_machdep.h>
  35. #include <machine/resource.h>
  36. #include <isa/isareg.h>
  37. #include <isa/isavar.h>
  38. #include <isa/isa_common.h>
  39. void
  40. isa_init(device_t dev)
  41. {
  42. }
  43. struct resource *
  44. isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
  45. u_long start, u_long end, u_long count, u_int flags)
  46. {
  47. struct isa_device* idev = DEVTOISA(child);
  48. struct resource_list *rl = &idev->id_resources;
  49. int isdefault, passthrough, rids;
  50. isdefault = RMAN_IS_DEFAULT_RANGE(start, end) ? 1 : 0;
  51. passthrough = (device_get_parent(child) != bus) ? 1 : 0;
  52. if (!passthrough && !isdefault &&
  53. resource_list_find(rl, type, *rid) == NULL) {
  54. switch (type) {
  55. case SYS_RES_IOPORT: rids = ISA_PNP_NPORT; break;
  56. case SYS_RES_IRQ: rids = ISA_PNP_NIRQ; break;
  57. case SYS_RES_MEMORY: rids = ISA_PNP_NMEM; break;
  58. default: rids = 0; break;
  59. }
  60. if (*rid < 0 || *rid >= rids)
  61. return (NULL);
  62. resource_list_add(rl, type, *rid, start, end, count);
  63. }
  64. return (resource_list_alloc(rl, bus, child, type, rid, start, end,
  65. count, flags));
  66. }
  67. int
  68. isa_release_resource(device_t bus, device_t child, int type, int rid,
  69. struct resource *r)
  70. {
  71. struct isa_device* idev = DEVTOISA(child);
  72. struct resource_list *rl = &idev->id_resources;
  73. return (resource_list_release(rl, bus, child, type, rid, r));
  74. }