ocp.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * ocp.h
  3. *
  4. * (c) Benjamin Herrenschmidt (benh@kernel.crashing.org)
  5. * Mipsys - France
  6. *
  7. * Derived from work (c) Armin Kuster akuster@pacbell.net
  8. *
  9. * Additional support and port to 2.6 LDM/sysfs by
  10. * Matt Porter <mporter@kernel.crashing.org>
  11. * Copyright 2003-2004 MontaVista Software, Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * TODO: - Add get/put interface & fixup locking to provide same API for
  19. * 2.4 and 2.5
  20. * - Rework PM callbacks
  21. */
  22. #ifdef __KERNEL__
  23. #ifndef __OCP_H__
  24. #define __OCP_H__
  25. #include <linux/init.h>
  26. #include <linux/list.h>
  27. #include <linux/config.h>
  28. #include <linux/devfs_fs_kernel.h>
  29. #include <linux/device.h>
  30. #include <asm/mmu.h>
  31. #include <asm/ocp_ids.h>
  32. #include <asm/rwsem.h>
  33. #include <asm/semaphore.h>
  34. #ifdef CONFIG_PPC_OCP
  35. #define OCP_MAX_IRQS 7
  36. #define MAX_EMACS 4
  37. #define OCP_IRQ_NA -1 /* used when ocp device does not have an irq */
  38. #define OCP_IRQ_MUL -2 /* used for ocp devices with multiply irqs */
  39. #define OCP_NULL_TYPE -1 /* used to mark end of list */
  40. #define OCP_CPM_NA 0 /* No Clock or Power Management avaliable */
  41. #define OCP_PADDR_NA 0 /* No MMIO registers */
  42. #define OCP_ANY_ID (~0)
  43. #define OCP_ANY_INDEX -1
  44. extern struct list_head ocp_devices;
  45. extern struct rw_semaphore ocp_devices_sem;
  46. struct ocp_device_id {
  47. unsigned int vendor, function; /* Vendor and function ID or OCP_ANY_ID */
  48. unsigned long driver_data; /* Data private to the driver */
  49. };
  50. /*
  51. * Static definition of an OCP device.
  52. *
  53. * @vendor: Vendor code. It is _STRONGLY_ discouraged to use
  54. * the vendor code as a way to match a unique device,
  55. * though I kept that possibility open, you should
  56. * really define different function codes for different
  57. * device types
  58. * @function: This is the function code for this device.
  59. * @index: This index is used for mapping the Nth function of a
  60. * given core. This is typically used for cross-driver
  61. * matching, like looking for a given MAL or ZMII from
  62. * an EMAC or for getting to the proper set of DCRs.
  63. * Indices are no longer magically calculated based on
  64. * structure ordering, they have to be actually coded
  65. * into the ocp_def to avoid any possible confusion
  66. * I _STRONGLY_ (again ? wow !) encourage anybody relying
  67. * on index mapping to encode the "target" index in an
  68. * associated structure pointed to by "additions", see
  69. * how it's done for the EMAC driver.
  70. * @paddr: Device physical address (may not mean anything...)
  71. * @irq: Interrupt line for this device (TODO: think about making
  72. * an array with this)
  73. * @pm: Currently, contains the bitmask in CPMFR DCR for the device
  74. * @additions: Optionally points to a function specific structure
  75. * providing additional informations for a given device
  76. * instance. It's currently used by the EMAC driver for MAL
  77. * channel & ZMII port mapping among others.
  78. * @show: Optionally points to a function specific structure
  79. * providing a sysfs show routine for additions fields.
  80. */
  81. struct ocp_def {
  82. unsigned int vendor;
  83. unsigned int function;
  84. int index;
  85. phys_addr_t paddr;
  86. int irq;
  87. unsigned long pm;
  88. void *additions;
  89. void (*show)(struct device *);
  90. };
  91. /* Struct for a given device instance */
  92. struct ocp_device {
  93. struct list_head link;
  94. char name[80]; /* device name */
  95. struct ocp_def *def; /* device definition */
  96. void *drvdata; /* driver data for this device */
  97. struct ocp_driver *driver;
  98. u32 current_state; /* Current operating state. In ACPI-speak,
  99. this is D0-D3, D0 being fully functional,
  100. and D3 being off. */
  101. struct device dev;
  102. };
  103. struct ocp_driver {
  104. struct list_head node;
  105. char *name;
  106. const struct ocp_device_id *id_table; /* NULL if wants all devices */
  107. int (*probe) (struct ocp_device *dev); /* New device inserted */
  108. void (*remove) (struct ocp_device *dev); /* Device removed (NULL if not a hot-plug capable driver) */
  109. int (*suspend) (struct ocp_device *dev, pm_message_t state); /* Device suspended */
  110. int (*resume) (struct ocp_device *dev); /* Device woken up */
  111. struct device_driver driver;
  112. };
  113. #define to_ocp_dev(n) container_of(n, struct ocp_device, dev)
  114. #define to_ocp_drv(n) container_of(n, struct ocp_driver, driver)
  115. /* Similar to the helpers above, these manipulate per-ocp_dev
  116. * driver-specific data. Currently stored as ocp_dev::ocpdev,
  117. * a void pointer, but it is not present on older kernels.
  118. */
  119. static inline void *
  120. ocp_get_drvdata(struct ocp_device *pdev)
  121. {
  122. return pdev->drvdata;
  123. }
  124. static inline void
  125. ocp_set_drvdata(struct ocp_device *pdev, void *data)
  126. {
  127. pdev->drvdata = data;
  128. }
  129. #if defined (CONFIG_PM)
  130. /*
  131. * This is right for the IBM 405 and 440 but will need to be
  132. * generalized if the OCP stuff gets used on other processors.
  133. */
  134. static inline void
  135. ocp_force_power_off(struct ocp_device *odev)
  136. {
  137. mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) | odev->def->pm);
  138. }
  139. static inline void
  140. ocp_force_power_on(struct ocp_device *odev)
  141. {
  142. mtdcr(DCRN_CPMFR, mfdcr(DCRN_CPMFR) & ~odev->def->pm);
  143. }
  144. #else
  145. #define ocp_force_power_off(x) (void)(x)
  146. #define ocp_force_power_on(x) (void)(x)
  147. #endif
  148. /* Register/Unregister an OCP driver */
  149. extern int ocp_register_driver(struct ocp_driver *drv);
  150. extern void ocp_unregister_driver(struct ocp_driver *drv);
  151. /* Build list of devices */
  152. extern int ocp_early_init(void) __init;
  153. /* Find a device by index */
  154. extern struct ocp_device *ocp_find_device(unsigned int vendor, unsigned int function, int index);
  155. /* Get a def by index */
  156. extern struct ocp_def *ocp_get_one_device(unsigned int vendor, unsigned int function, int index);
  157. /* Add a device by index */
  158. extern int ocp_add_one_device(struct ocp_def *def);
  159. /* Remove a device by index */
  160. extern int ocp_remove_one_device(unsigned int vendor, unsigned int function, int index);
  161. /* Iterate over devices and execute a routine */
  162. extern void ocp_for_each_device(void(*callback)(struct ocp_device *, void *arg), void *arg);
  163. /* Sysfs support */
  164. #define OCP_SYSFS_ADDTL(type, format, name, field) \
  165. static ssize_t \
  166. show_##name##_##field(struct device *dev, struct device_attribute *attr, char *buf) \
  167. { \
  168. struct ocp_device *odev = to_ocp_dev(dev); \
  169. type *add = odev->def->additions; \
  170. \
  171. return sprintf(buf, format, add->field); \
  172. } \
  173. static DEVICE_ATTR(name##_##field, S_IRUGO, show_##name##_##field, NULL);
  174. #ifdef CONFIG_IBM_OCP
  175. #include <asm/ibm_ocp.h>
  176. #endif
  177. #endif /* CONFIG_PPC_OCP */
  178. #endif /* __OCP_H__ */
  179. #endif /* __KERNEL__ */