opal.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * PowerNV OPAL definitions.
  3. *
  4. * Copyright 2011 IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_POWERPC_OPAL_H
  12. #define _ASM_POWERPC_OPAL_H
  13. #include <asm/opal-api.h>
  14. #ifndef __ASSEMBLY__
  15. #include <linux/notifier.h>
  16. /* We calculate number of sg entries based on PAGE_SIZE */
  17. #define SG_ENTRIES_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct opal_sg_entry))
  18. /* Default time to sleep or delay between OPAL_BUSY/OPAL_BUSY_EVENT loops */
  19. #define OPAL_BUSY_DELAY_MS 10
  20. /* /sys/firmware/opal */
  21. extern struct kobject *opal_kobj;
  22. /* /ibm,opal */
  23. extern struct device_node *opal_node;
  24. /* API functions */
  25. int64_t opal_invalid_call(void);
  26. int64_t opal_console_write(int64_t term_number, __be64 *length,
  27. const uint8_t *buffer);
  28. int64_t opal_console_read(int64_t term_number, __be64 *length,
  29. uint8_t *buffer);
  30. int64_t opal_console_write_buffer_space(int64_t term_number,
  31. __be64 *length);
  32. int64_t opal_console_flush(int64_t term_number);
  33. int64_t opal_rtc_read(__be32 *year_month_day,
  34. __be64 *hour_minute_second_millisecond);
  35. int64_t opal_rtc_write(uint32_t year_month_day,
  36. uint64_t hour_minute_second_millisecond);
  37. int64_t opal_tpo_read(uint64_t token, __be32 *year_mon_day, __be32 *hour_min);
  38. int64_t opal_tpo_write(uint64_t token, uint32_t year_mon_day,
  39. uint32_t hour_min);
  40. int64_t opal_cec_power_down(uint64_t request);
  41. int64_t opal_cec_reboot(void);
  42. int64_t opal_cec_reboot2(uint32_t reboot_type, char *diag);
  43. int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
  44. int64_t opal_write_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
  45. int64_t opal_handle_interrupt(uint64_t isn, __be64 *outstanding_event_mask);
  46. int64_t opal_poll_events(__be64 *outstanding_event_mask);
  47. int64_t opal_pci_set_hub_tce_memory(uint64_t hub_id, uint64_t tce_mem_addr,
  48. uint64_t tce_mem_size);
  49. int64_t opal_pci_set_phb_tce_memory(uint64_t phb_id, uint64_t tce_mem_addr,
  50. uint64_t tce_mem_size);
  51. int64_t opal_pci_config_read_byte(uint64_t phb_id, uint64_t bus_dev_func,
  52. uint64_t offset, uint8_t *data);
  53. int64_t opal_pci_config_read_half_word(uint64_t phb_id, uint64_t bus_dev_func,
  54. uint64_t offset, __be16 *data);
  55. int64_t opal_pci_config_read_word(uint64_t phb_id, uint64_t bus_dev_func,
  56. uint64_t offset, __be32 *data);
  57. int64_t opal_pci_config_write_byte(uint64_t phb_id, uint64_t bus_dev_func,
  58. uint64_t offset, uint8_t data);
  59. int64_t opal_pci_config_write_half_word(uint64_t phb_id, uint64_t bus_dev_func,
  60. uint64_t offset, uint16_t data);
  61. int64_t opal_pci_config_write_word(uint64_t phb_id, uint64_t bus_dev_func,
  62. uint64_t offset, uint32_t data);
  63. int64_t opal_set_xive(uint32_t isn, uint16_t server, uint8_t priority);
  64. int64_t opal_rm_set_xive(uint32_t isn, uint16_t server, uint8_t priority);
  65. int64_t opal_get_xive(uint32_t isn, __be16 *server, uint8_t *priority);
  66. int64_t opal_register_exception_handler(uint64_t opal_exception,
  67. uint64_t handler_address,
  68. uint64_t glue_cache_line);
  69. int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number,
  70. uint8_t *freeze_state,
  71. __be16 *pci_error_type,
  72. __be64 *phb_status);
  73. int64_t opal_pci_eeh_freeze_clear(uint64_t phb_id, uint64_t pe_number,
  74. uint64_t eeh_action_token);
  75. int64_t opal_pci_eeh_freeze_set(uint64_t phb_id, uint64_t pe_number,
  76. uint64_t eeh_action_token);
  77. int64_t opal_pci_err_inject(uint64_t phb_id, uint32_t pe_no, uint32_t type,
  78. uint32_t func, uint64_t addr, uint64_t mask);
  79. int64_t opal_pci_shpc(uint64_t phb_id, uint64_t shpc_action, uint8_t *state);
  80. int64_t opal_pci_phb_mmio_enable(uint64_t phb_id, uint16_t window_type,
  81. uint16_t window_num, uint16_t enable);
  82. int64_t opal_pci_set_phb_mem_window(uint64_t phb_id, uint16_t window_type,
  83. uint16_t window_num,
  84. uint64_t starting_real_address,
  85. uint64_t starting_pci_address,
  86. uint64_t size);
  87. int64_t opal_pci_map_pe_mmio_window(uint64_t phb_id, uint16_t pe_number,
  88. uint16_t window_type, uint16_t window_num,
  89. uint16_t segment_num);
  90. int64_t opal_pci_set_phb_table_memory(uint64_t phb_id, uint64_t rtt_addr,
  91. uint64_t ivt_addr, uint64_t ivt_len,
  92. uint64_t reject_array_addr,
  93. uint64_t peltv_addr);
  94. int64_t opal_pci_set_pe(uint64_t phb_id, uint64_t pe_number, uint64_t bus_dev_func,
  95. uint8_t bus_compare, uint8_t dev_compare, uint8_t func_compare,
  96. uint8_t pe_action);
  97. int64_t opal_pci_set_peltv(uint64_t phb_id, uint32_t parent_pe, uint32_t child_pe,
  98. uint8_t state);
  99. int64_t opal_pci_set_mve(uint64_t phb_id, uint32_t mve_number, uint32_t pe_number);
  100. int64_t opal_pci_set_mve_enable(uint64_t phb_id, uint32_t mve_number,
  101. uint32_t state);
  102. int64_t opal_pci_get_xive_reissue(uint64_t phb_id, uint32_t xive_number,
  103. uint8_t *p_bit, uint8_t *q_bit);
  104. int64_t opal_pci_set_xive_reissue(uint64_t phb_id, uint32_t xive_number,
  105. uint8_t p_bit, uint8_t q_bit);
  106. int64_t opal_pci_msi_eoi(uint64_t phb_id, uint32_t hw_irq);
  107. int64_t opal_pci_set_xive_pe(uint64_t phb_id, uint32_t pe_number,
  108. uint32_t xive_num);
  109. int64_t opal_get_xive_source(uint64_t phb_id, uint32_t xive_num,
  110. __be32 *interrupt_source_number);
  111. int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number, uint32_t xive_num,
  112. uint8_t msi_range, __be32 *msi_address,
  113. __be32 *message_data);
  114. int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number,
  115. uint32_t xive_num, uint8_t msi_range,
  116. __be64 *msi_address, __be32 *message_data);
  117. int64_t opal_start_cpu(uint64_t thread_number, uint64_t start_address);
  118. int64_t opal_query_cpu_status(uint64_t thread_number, uint8_t *thread_status);
  119. int64_t opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines);
  120. int64_t opal_pci_map_pe_dma_window(uint64_t phb_id, uint16_t pe_number, uint16_t window_id,
  121. uint16_t tce_levels, uint64_t tce_table_addr,
  122. uint64_t tce_table_size, uint64_t tce_page_size);
  123. int64_t opal_pci_map_pe_dma_window_real(uint64_t phb_id, uint16_t pe_number,
  124. uint16_t dma_window_number, uint64_t pci_start_addr,
  125. uint64_t pci_mem_size);
  126. int64_t opal_pci_reset(uint64_t id, uint8_t reset_scope, uint8_t assert_state);
  127. int64_t opal_pci_get_hub_diag_data(uint64_t hub_id, void *diag_buffer,
  128. uint64_t diag_buffer_len);
  129. int64_t opal_pci_get_phb_diag_data(uint64_t phb_id, void *diag_buffer,
  130. uint64_t diag_buffer_len);
  131. int64_t opal_pci_get_phb_diag_data2(uint64_t phb_id, void *diag_buffer,
  132. uint64_t diag_buffer_len);
  133. int64_t opal_pci_fence_phb(uint64_t phb_id);
  134. int64_t opal_pci_reinit(uint64_t phb_id, uint64_t reinit_scope, uint64_t data);
  135. int64_t opal_pci_mask_pe_error(uint64_t phb_id, uint16_t pe_number, uint8_t error_type, uint8_t mask_action);
  136. int64_t opal_set_slot_led_status(uint64_t phb_id, uint64_t slot_id, uint8_t led_type, uint8_t led_action);
  137. int64_t opal_get_epow_status(__be16 *epow_status, __be16 *num_epow_classes);
  138. int64_t opal_get_dpo_status(__be64 *dpo_timeout);
  139. int64_t opal_set_system_attention_led(uint8_t led_action);
  140. int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe,
  141. __be16 *pci_error_type, __be16 *severity);
  142. int64_t opal_pci_poll(uint64_t id);
  143. int64_t opal_return_cpu(void);
  144. int64_t opal_check_token(uint64_t token);
  145. int64_t opal_reinit_cpus(uint64_t flags);
  146. int64_t opal_xscom_read(uint32_t gcid, uint64_t pcb_addr, __be64 *val);
  147. int64_t opal_xscom_write(uint32_t gcid, uint64_t pcb_addr, uint64_t val);
  148. int64_t opal_lpc_write(uint32_t chip_id, enum OpalLPCAddressType addr_type,
  149. uint32_t addr, uint32_t data, uint32_t sz);
  150. int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type,
  151. uint32_t addr, __be32 *data, uint32_t sz);
  152. int64_t opal_read_elog(uint64_t buffer, uint64_t size, uint64_t log_id);
  153. int64_t opal_get_elog_size(__be64 *log_id, __be64 *size, __be64 *elog_type);
  154. int64_t opal_write_elog(uint64_t buffer, uint64_t size, uint64_t offset);
  155. int64_t opal_send_ack_elog(uint64_t log_id);
  156. void opal_resend_pending_logs(void);
  157. int64_t opal_validate_flash(uint64_t buffer, uint32_t *size, uint32_t *result);
  158. int64_t opal_manage_flash(uint8_t op);
  159. int64_t opal_update_flash(uint64_t blk_list);
  160. int64_t opal_dump_init(uint8_t dump_type);
  161. int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
  162. int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
  163. int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
  164. int64_t opal_dump_ack(uint32_t dump_id);
  165. int64_t opal_dump_resend_notification(void);
  166. int64_t opal_get_msg(uint64_t buffer, uint64_t size);
  167. int64_t opal_write_oppanel_async(uint64_t token, oppanel_line_t *lines,
  168. uint64_t num_lines);
  169. int64_t opal_check_completion(uint64_t buffer, uint64_t size, uint64_t token);
  170. int64_t opal_sync_host_reboot(void);
  171. int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
  172. uint64_t length);
  173. int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
  174. uint64_t length);
  175. int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
  176. int64_t opal_handle_hmi(void);
  177. int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
  178. int64_t opal_unregister_dump_region(uint32_t id);
  179. int64_t opal_slw_set_reg(uint64_t cpu_pir, uint64_t sprn, uint64_t val);
  180. int64_t opal_config_cpu_idle_state(uint64_t state, uint64_t flag);
  181. int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t pe_number);
  182. int64_t opal_ipmi_send(uint64_t interface, struct opal_ipmi_msg *msg,
  183. uint64_t msg_len);
  184. int64_t opal_ipmi_recv(uint64_t interface, struct opal_ipmi_msg *msg,
  185. uint64_t *msg_len);
  186. int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id,
  187. struct opal_i2c_request *oreq);
  188. int64_t opal_prd_msg(struct opal_prd_msg *msg);
  189. int64_t opal_leds_get_ind(char *loc_code, __be64 *led_mask,
  190. __be64 *led_value, __be64 *max_led_type);
  191. int64_t opal_leds_set_ind(uint64_t token, char *loc_code, const u64 led_mask,
  192. const u64 led_value, __be64 *max_led_type);
  193. int64_t opal_flash_read(uint64_t id, uint64_t offset, uint64_t buf,
  194. uint64_t size, uint64_t token);
  195. int64_t opal_flash_write(uint64_t id, uint64_t offset, uint64_t buf,
  196. uint64_t size, uint64_t token);
  197. int64_t opal_flash_erase(uint64_t id, uint64_t offset, uint64_t size,
  198. uint64_t token);
  199. int64_t opal_get_device_tree(uint32_t phandle, uint64_t buf, uint64_t len);
  200. int64_t opal_pci_get_presence_state(uint64_t id, uint64_t data);
  201. int64_t opal_pci_get_power_state(uint64_t id, uint64_t data);
  202. int64_t opal_pci_set_power_state(uint64_t async_token, uint64_t id,
  203. uint64_t data);
  204. int64_t opal_pci_poll2(uint64_t id, uint64_t data);
  205. int64_t opal_int_get_xirr(uint32_t *out_xirr, bool just_poll);
  206. int64_t opal_int_set_cppr(uint8_t cppr);
  207. int64_t opal_int_eoi(uint32_t xirr);
  208. int64_t opal_int_set_mfrr(uint32_t cpu, uint8_t mfrr);
  209. int64_t opal_pci_tce_kill(uint64_t phb_id, uint32_t kill_type,
  210. uint32_t pe_num, uint32_t tce_size,
  211. uint64_t dma_addr, uint32_t npages);
  212. int64_t opal_rm_pci_tce_kill(uint64_t phb_id, uint32_t kill_type,
  213. uint32_t pe_num, uint32_t tce_size,
  214. uint64_t dma_addr, uint32_t npages);
  215. /* Internal functions */
  216. extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
  217. int depth, void *data);
  218. extern int early_init_dt_scan_recoverable_ranges(unsigned long node,
  219. const char *uname, int depth, void *data);
  220. extern void opal_configure_cores(void);
  221. extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
  222. extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
  223. extern void hvc_opal_init_early(void);
  224. extern int opal_notifier_register(struct notifier_block *nb);
  225. extern int opal_notifier_unregister(struct notifier_block *nb);
  226. extern int opal_message_notifier_register(enum opal_msg_type msg_type,
  227. struct notifier_block *nb);
  228. extern int opal_message_notifier_unregister(enum opal_msg_type msg_type,
  229. struct notifier_block *nb);
  230. extern void opal_notifier_enable(void);
  231. extern void opal_notifier_disable(void);
  232. extern void opal_notifier_update_evt(uint64_t evt_mask, uint64_t evt_val);
  233. extern int __opal_async_get_token(void);
  234. extern int opal_async_get_token_interruptible(void);
  235. extern int __opal_async_release_token(int token);
  236. extern int opal_async_release_token(int token);
  237. extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
  238. extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
  239. struct rtc_time;
  240. extern unsigned long opal_get_boot_time(void);
  241. extern void opal_nvram_init(void);
  242. extern void opal_flash_update_init(void);
  243. extern void opal_flash_term_callback(void);
  244. extern int opal_elog_init(void);
  245. extern void opal_platform_dump_init(void);
  246. extern void opal_sys_param_init(void);
  247. extern void opal_msglog_init(void);
  248. extern void opal_msglog_sysfs_init(void);
  249. extern int opal_async_comp_init(void);
  250. extern int opal_sensor_init(void);
  251. extern int opal_hmi_handler_init(void);
  252. extern int opal_event_init(void);
  253. extern int opal_machine_check(struct pt_regs *regs);
  254. extern bool opal_mce_check_early_recovery(struct pt_regs *regs);
  255. extern int opal_hmi_exception_early(struct pt_regs *regs);
  256. extern int opal_handle_hmi_exception(struct pt_regs *regs);
  257. extern void opal_shutdown(void);
  258. extern int opal_resync_timebase(void);
  259. extern void opal_lpc_init(void);
  260. extern void opal_kmsg_init(void);
  261. extern int opal_event_request(unsigned int opal_event_nr);
  262. struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
  263. unsigned long vmalloc_size);
  264. void opal_free_sg_list(struct opal_sg_list *sg);
  265. extern int opal_error_code(int rc);
  266. ssize_t opal_msglog_copy(char *to, loff_t pos, size_t count);
  267. static inline int opal_get_async_rc(struct opal_msg msg)
  268. {
  269. if (msg.msg_type != OPAL_MSG_ASYNC_COMP)
  270. return OPAL_PARAMETER;
  271. else
  272. return be64_to_cpu(msg.params[1]);
  273. }
  274. void opal_wake_poller(void);
  275. #endif /* __ASSEMBLY__ */
  276. #endif /* _ASM_POWERPC_OPAL_H */