blob: c08de77f398af7b835412dc73c97758b4b20c70e [file] [log] [blame]
Benjamin Herrenschmidt27f44882011-09-19 18:27:58 +00001/*
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
Michael Ellermand800ba12015-02-17 20:01:53 +110012#ifndef _ASM_POWERPC_OPAL_H
13#define _ASM_POWERPC_OPAL_H
Benjamin Herrenschmidt27f44882011-09-19 18:27:58 +000014
Michael Ellermand800ba12015-02-17 20:01:53 +110015#include <asm/opal-api.h>
Shreyas B. Prabhu8eb8ac82014-12-10 00:26:51 +053016
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000017#ifndef __ASSEMBLY__
18
Michael Neulingbfd25d72014-03-25 11:43:08 +110019#include <linux/notifier.h>
20
Michael Ellermand800ba12015-02-17 20:01:53 +110021/* We calculate number of sg entries based on PAGE_SIZE */
22#define SG_ENTRIES_PER_NODE ((PAGE_SIZE - 16) / sizeof(struct opal_sg_entry))
Neelesh Gupta47083452014-12-13 23:31:05 +053023
Vasant Hegde6f68b5e2013-08-27 15:09:52 +053024/* /sys/firmware/opal */
25extern struct kobject *opal_kobj;
26
Joel Stanleybfc36892014-04-01 14:28:19 +103027/* /ibm,opal */
28extern struct device_node *opal_node;
29
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000030/* API functions */
Joel Stanleye28b05e2014-04-01 14:28:20 +103031int64_t opal_invalid_call(void);
Benjamin Herrenschmidt4f893632013-09-23 12:05:02 +100032int64_t opal_console_write(int64_t term_number, __be64 *length,
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000033 const uint8_t *buffer);
Benjamin Herrenschmidt4f893632013-09-23 12:05:02 +100034int64_t opal_console_read(int64_t term_number, __be64 *length,
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000035 uint8_t *buffer);
36int64_t opal_console_write_buffer_space(int64_t term_number,
Benjamin Herrenschmidt4f893632013-09-23 12:05:02 +100037 __be64 *length);
Anton Blanchard6feff6d2013-09-23 12:05:05 +100038int64_t opal_rtc_read(__be32 *year_month_day,
39 __be64 *hour_minute_second_millisecond);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000040int64_t opal_rtc_write(uint32_t year_month_day,
41 uint64_t hour_minute_second_millisecond);
Neelesh Gupta16b1d262014-10-14 14:08:36 +053042int64_t opal_tpo_read(uint64_t token, __be32 *year_mon_day, __be32 *hour_min);
43int64_t opal_tpo_write(uint64_t token, uint32_t year_mon_day,
44 uint32_t hour_min);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000045int64_t opal_cec_power_down(uint64_t request);
46int64_t opal_cec_reboot(void);
47int64_t opal_read_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
48int64_t opal_write_nvram(uint64_t buffer, uint64_t size, uint64_t offset);
Anton Blanchard5e4da532013-09-23 12:05:06 +100049int64_t opal_handle_interrupt(uint64_t isn, __be64 *outstanding_event_mask);
Benjamin Herrenschmidt4f893632013-09-23 12:05:02 +100050int64_t opal_poll_events(__be64 *outstanding_event_mask);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000051int64_t opal_pci_set_hub_tce_memory(uint64_t hub_id, uint64_t tce_mem_addr,
52 uint64_t tce_mem_size);
53int64_t opal_pci_set_phb_tce_memory(uint64_t phb_id, uint64_t tce_mem_addr,
54 uint64_t tce_mem_size);
55int64_t opal_pci_config_read_byte(uint64_t phb_id, uint64_t bus_dev_func,
56 uint64_t offset, uint8_t *data);
57int64_t opal_pci_config_read_half_word(uint64_t phb_id, uint64_t bus_dev_func,
Anton Blanchard5e4da532013-09-23 12:05:06 +100058 uint64_t offset, __be16 *data);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000059int64_t opal_pci_config_read_word(uint64_t phb_id, uint64_t bus_dev_func,
Anton Blanchard5e4da532013-09-23 12:05:06 +100060 uint64_t offset, __be32 *data);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000061int64_t opal_pci_config_write_byte(uint64_t phb_id, uint64_t bus_dev_func,
62 uint64_t offset, uint8_t data);
63int64_t opal_pci_config_write_half_word(uint64_t phb_id, uint64_t bus_dev_func,
64 uint64_t offset, uint16_t data);
65int64_t opal_pci_config_write_word(uint64_t phb_id, uint64_t bus_dev_func,
66 uint64_t offset, uint32_t data);
67int64_t opal_set_xive(uint32_t isn, uint16_t server, uint8_t priority);
Anton Blanchard5e4da532013-09-23 12:05:06 +100068int64_t opal_get_xive(uint32_t isn, __be16 *server, uint8_t *priority);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000069int64_t opal_register_exception_handler(uint64_t opal_exception,
70 uint64_t handler_address,
71 uint64_t glue_cache_line);
72int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number,
73 uint8_t *freeze_state,
Anton Blanchard5e4da532013-09-23 12:05:06 +100074 __be16 *pci_error_type,
75 __be64 *phb_status);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000076int64_t opal_pci_eeh_freeze_clear(uint64_t phb_id, uint64_t pe_number,
77 uint64_t eeh_action_token);
Gavin Shan5ca27ef2014-07-21 14:42:31 +100078int64_t opal_pci_eeh_freeze_set(uint64_t phb_id, uint64_t pe_number,
79 uint64_t eeh_action_token);
Gavin Shan5b642342014-09-30 12:38:55 +100080int64_t opal_pci_err_inject(uint64_t phb_id, uint32_t pe_no, uint32_t type,
81 uint32_t func, uint64_t addr, uint64_t mask);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000082int64_t opal_pci_shpc(uint64_t phb_id, uint64_t shpc_action, uint8_t *state);
83
84
85
86int64_t opal_pci_phb_mmio_enable(uint64_t phb_id, uint16_t window_type,
87 uint16_t window_num, uint16_t enable);
88int64_t opal_pci_set_phb_mem_window(uint64_t phb_id, uint16_t window_type,
89 uint16_t window_num,
90 uint64_t starting_real_address,
91 uint64_t starting_pci_address,
Guo Chao262af552014-07-21 14:42:30 +100092 uint64_t size);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +000093int64_t opal_pci_map_pe_mmio_window(uint64_t phb_id, uint16_t pe_number,
94 uint16_t window_type, uint16_t window_num,
95 uint16_t segment_num);
96int64_t opal_pci_set_phb_table_memory(uint64_t phb_id, uint64_t rtt_addr,
97 uint64_t ivt_addr, uint64_t ivt_len,
98 uint64_t reject_array_addr,
99 uint64_t peltv_addr);
100int64_t opal_pci_set_pe(uint64_t phb_id, uint64_t pe_number, uint64_t bus_dev_func,
101 uint8_t bus_compare, uint8_t dev_compare, uint8_t func_compare,
102 uint8_t pe_action);
103int64_t opal_pci_set_peltv(uint64_t phb_id, uint32_t parent_pe, uint32_t child_pe,
104 uint8_t state);
105int64_t opal_pci_set_mve(uint64_t phb_id, uint32_t mve_number, uint32_t pe_number);
106int64_t opal_pci_set_mve_enable(uint64_t phb_id, uint32_t mve_number,
107 uint32_t state);
108int64_t opal_pci_get_xive_reissue(uint64_t phb_id, uint32_t xive_number,
109 uint8_t *p_bit, uint8_t *q_bit);
110int64_t opal_pci_set_xive_reissue(uint64_t phb_id, uint32_t xive_number,
111 uint8_t p_bit, uint8_t q_bit);
Gavin Shan137436c2013-04-25 19:20:59 +0000112int64_t opal_pci_msi_eoi(uint64_t phb_id, uint32_t hw_irq);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000113int64_t opal_pci_set_xive_pe(uint64_t phb_id, uint32_t pe_number,
114 uint32_t xive_num);
115int64_t opal_get_xive_source(uint64_t phb_id, uint32_t xive_num,
Anton Blanchard5e4da532013-09-23 12:05:06 +1000116 __be32 *interrupt_source_number);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000117int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number, uint32_t xive_num,
Anton Blanchard5e4da532013-09-23 12:05:06 +1000118 uint8_t msi_range, __be32 *msi_address,
119 __be32 *message_data);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000120int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number,
121 uint32_t xive_num, uint8_t msi_range,
Anton Blanchard5e4da532013-09-23 12:05:06 +1000122 __be64 *msi_address, __be32 *message_data);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000123int64_t opal_start_cpu(uint64_t thread_number, uint64_t start_address);
124int64_t opal_query_cpu_status(uint64_t thread_number, uint8_t *thread_status);
125int64_t opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines);
126int64_t opal_pci_map_pe_dma_window(uint64_t phb_id, uint16_t pe_number, uint16_t window_id,
127 uint16_t tce_levels, uint64_t tce_table_addr,
128 uint64_t tce_table_size, uint64_t tce_page_size);
129int64_t opal_pci_map_pe_dma_window_real(uint64_t phb_id, uint16_t pe_number,
130 uint16_t dma_window_number, uint64_t pci_start_addr,
131 uint64_t pci_mem_size);
132int64_t opal_pci_reset(uint64_t phb_id, uint8_t reset_scope, uint8_t assert_state);
133
Gavin Shan23773232013-06-20 13:21:05 +0800134int64_t opal_pci_get_hub_diag_data(uint64_t hub_id, void *diag_buffer,
135 uint64_t diag_buffer_len);
136int64_t opal_pci_get_phb_diag_data(uint64_t phb_id, void *diag_buffer,
137 uint64_t diag_buffer_len);
138int64_t opal_pci_get_phb_diag_data2(uint64_t phb_id, void *diag_buffer,
139 uint64_t diag_buffer_len);
Benjamin Herrenschmidtf11fe552011-11-29 18:22:50 +0000140int64_t opal_pci_fence_phb(uint64_t phb_id);
Gavin Shan9be3bec2014-01-03 17:47:13 +0800141int64_t opal_pci_reinit(uint64_t phb_id, uint64_t reinit_scope, uint64_t data);
Benjamin Herrenschmidtf11fe552011-11-29 18:22:50 +0000142int64_t opal_pci_mask_pe_error(uint64_t phb_id, uint16_t pe_number, uint8_t error_type, uint8_t mask_action);
143int64_t opal_set_slot_led_status(uint64_t phb_id, uint64_t slot_id, uint8_t led_type, uint8_t led_action);
Anton Blanchard5e4da532013-09-23 12:05:06 +1000144int64_t opal_get_epow_status(__be64 *status);
Benjamin Herrenschmidtf11fe552011-11-29 18:22:50 +0000145int64_t opal_set_system_attention_led(uint8_t led_action);
Guo Chaoddf03222014-06-09 16:58:51 +0800146int64_t opal_pci_next_error(uint64_t phb_id, __be64 *first_frozen_pe,
147 __be16 *pci_error_type, __be16 *severity);
Gavin Shan23773232013-06-20 13:21:05 +0800148int64_t opal_pci_poll(uint64_t phb_id);
Benjamin Herrenschmidt13906db2013-08-21 13:03:20 +1000149int64_t opal_return_cpu(void);
Michael Neulingbffe6bd2014-08-19 14:47:59 +1000150int64_t opal_check_token(uint64_t token);
Benjamin Herrenschmidt49266162014-05-20 11:01:28 +1000151int64_t opal_reinit_cpus(uint64_t flags);
Benjamin Herrenschmidtf11fe552011-11-29 18:22:50 +0000152
Benjamin Herrenschmidt2f3f38e2014-02-28 16:20:29 +1100153int64_t opal_xscom_read(uint32_t gcid, uint64_t pcb_addr, __be64 *val);
154int64_t opal_xscom_write(uint32_t gcid, uint64_t pcb_addr, uint64_t val);
Benjamin Herrenschmidtcc0efb52013-07-15 13:03:09 +1000155
156int64_t opal_lpc_write(uint32_t chip_id, enum OpalLPCAddressType addr_type,
157 uint32_t addr, uint32_t data, uint32_t sz);
158int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type,
Benjamin Herrenschmidt803c2d22013-12-13 15:56:06 +1100159 uint32_t addr, __be32 *data, uint32_t sz);
Stewart Smith774fea12014-02-28 11:58:32 +1100160
Anton Blanchard2bad7422014-04-22 15:01:22 +1000161int64_t opal_read_elog(uint64_t buffer, uint64_t size, uint64_t log_id);
Anton Blanchard14ad0c52014-04-22 15:01:25 +1000162int64_t opal_get_elog_size(__be64 *log_id, __be64 *size, __be64 *elog_type);
Stewart Smith774fea12014-02-28 11:58:32 +1100163int64_t opal_write_elog(uint64_t buffer, uint64_t size, uint64_t offset);
164int64_t opal_send_ack_elog(uint64_t log_id);
165void opal_resend_pending_logs(void);
166
Vasant Hegde50bd6152013-10-24 16:04:58 +0530167int64_t opal_validate_flash(uint64_t buffer, uint32_t *size, uint32_t *result);
168int64_t opal_manage_flash(uint8_t op);
169int64_t opal_update_flash(uint64_t blk_list);
Stewart Smithc7e64b92014-03-03 10:25:42 +1100170int64_t opal_dump_init(uint8_t dump_type);
Anton Blanchard2d6b63b2014-04-22 15:01:27 +1000171int64_t opal_dump_info(__be32 *dump_id, __be32 *dump_size);
172int64_t opal_dump_info2(__be32 *dump_id, __be32 *dump_size, __be32 *dump_type);
Stewart Smithc7e64b92014-03-03 10:25:42 +1100173int64_t opal_dump_read(uint32_t dump_id, uint64_t buffer);
174int64_t opal_dump_ack(uint32_t dump_id);
175int64_t opal_dump_resend_notification(void);
Benjamin Herrenschmidtcc0efb52013-07-15 13:03:09 +1000176
Anton Blanchard2bad7422014-04-22 15:01:22 +1000177int64_t opal_get_msg(uint64_t buffer, uint64_t size);
178int64_t opal_check_completion(uint64_t buffer, uint64_t size, uint64_t token);
Vasant Hegdef7d98d12014-01-15 17:02:04 +1100179int64_t opal_sync_host_reboot(void);
Neelesh Gupta4029cd62014-03-07 11:02:09 +0530180int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
Anton Blanchard2bad7422014-04-22 15:01:22 +1000181 uint64_t length);
Neelesh Gupta4029cd62014-03-07 11:02:09 +0530182int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
Anton Blanchard2bad7422014-04-22 15:01:22 +1000183 uint64_t length);
Anton Blanchard9000c172014-03-28 16:34:10 +1100184int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
Mahesh Salgaonkar0ef95b42014-07-29 18:40:07 +0530185int64_t opal_handle_hmi(void);
Vasant Hegdeb09c2ec2014-08-09 11:15:45 +0530186int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
187int64_t opal_unregister_dump_region(uint32_t id);
Shreyas B. Prabhu77b54e92014-12-10 00:26:53 +0530188int64_t opal_slw_set_reg(uint64_t cpu_pir, uint64_t sprn, uint64_t val);
Ian Munsie09521732014-10-08 19:54:59 +1100189int64_t opal_pci_set_phb_cxl_mode(uint64_t phb_id, uint64_t mode, uint64_t pe_number);
Jeremy Kerr608b2862014-11-06 11:38:27 +0800190int64_t opal_ipmi_send(uint64_t interface, struct opal_ipmi_msg *msg,
191 uint64_t msg_len);
192int64_t opal_ipmi_recv(uint64_t interface, struct opal_ipmi_msg *msg,
193 uint64_t *msg_len);
Neelesh Gupta47083452014-12-13 23:31:05 +0530194int64_t opal_i2c_request(uint64_t async_token, uint32_t bus_id,
195 struct opal_i2c_request *oreq);
Mahesh Salgaonkar24366362013-11-18 15:35:58 +0530196
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000197/* Internal functions */
Anton Blancharde2c8b932014-04-22 15:01:23 +1000198extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
199 int depth, void *data);
Mahesh Salgaonkar55672ec2013-12-16 10:46:24 +0530200extern int early_init_dt_scan_recoverable_ranges(unsigned long node,
201 const char *uname, int depth, void *data);
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000202
203extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
204extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
205
206extern void hvc_opal_init_early(void);
207
Gavin Shan1bc98de2013-06-20 18:13:22 +0800208extern int opal_notifier_register(struct notifier_block *nb);
Benjamin Herrenschmidt798af002014-03-28 13:36:31 +1100209extern int opal_notifier_unregister(struct notifier_block *nb);
210
Michael Ellermand7cf83f2015-02-17 20:01:54 +1100211extern int opal_message_notifier_register(enum opal_msg_type msg_type,
Mahesh Salgaonkar24366362013-11-18 15:35:58 +0530212 struct notifier_block *nb);
Michael Ellermandf60f572015-03-26 20:03:16 +1100213extern int opal_message_notifier_unregister(enum opal_msg_type msg_type,
Neelesh Guptab921e902015-02-11 11:57:23 +0530214 struct notifier_block *nb);
Gavin Shan1bc98de2013-06-20 18:13:22 +0800215extern void opal_notifier_enable(void);
216extern void opal_notifier_disable(void);
217extern void opal_notifier_update_evt(uint64_t evt_mask, uint64_t evt_val);
218
Neelesh Gupta8d724822014-03-07 11:00:24 +0530219extern int __opal_async_get_token(void);
220extern int opal_async_get_token_interruptible(void);
221extern int __opal_async_release_token(int token);
222extern int opal_async_release_token(int token);
223extern int opal_async_wait_response(uint64_t token, struct opal_msg *msg);
Neelesh Gupta7224adb2014-03-07 11:03:27 +0530224extern int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data);
Neelesh Gupta8d724822014-03-07 11:00:24 +0530225
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000226struct rtc_time;
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000227extern unsigned long opal_get_boot_time(void);
228extern void opal_nvram_init(void);
Vasant Hegde50bd6152013-10-24 16:04:58 +0530229extern void opal_flash_init(void);
Vasant Hegde2196c6f2014-04-09 22:48:55 +0530230extern void opal_flash_term_callback(void);
Stewart Smith774fea12014-02-28 11:58:32 +1100231extern int opal_elog_init(void);
Stewart Smithc7e64b92014-03-03 10:25:42 +1100232extern void opal_platform_dump_init(void);
Neelesh Gupta4029cd62014-03-07 11:02:09 +0530233extern void opal_sys_param_init(void);
Joel Stanleybfc36892014-04-01 14:28:19 +1030234extern void opal_msglog_init(void);
Benjamin Herrenschmidt628daa82011-09-19 17:45:01 +0000235
Benjamin Herrenschmidted79ba92011-09-19 17:45:04 +0000236extern int opal_machine_check(struct pt_regs *regs);
Mahesh Salgaonkar55672ec2013-12-16 10:46:24 +0530237extern bool opal_mce_check_early_recovery(struct pt_regs *regs);
Mahesh Salgaonkar0869b6f2014-07-29 18:40:01 +0530238extern int opal_hmi_exception_early(struct pt_regs *regs);
239extern int opal_handle_hmi_exception(struct pt_regs *regs);
Benjamin Herrenschmidted79ba92011-09-19 17:45:04 +0000240
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000241extern void opal_shutdown(void);
Vaidyanathan Srinivasan97eb001f2014-02-26 05:38:43 +0530242extern int opal_resync_timebase(void);
Benjamin Herrenschmidt73ed1482013-05-10 16:59:18 +1000243
Benjamin Herrenschmidt3fafe9c2013-07-15 13:03:11 +1000244extern void opal_lpc_init(void);
245
Anton Blanchard3441f042014-04-22 15:01:26 +1000246struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
247 unsigned long vmalloc_size);
248void opal_free_sg_list(struct opal_sg_list *sg);
249
Benjamin Herrenschmidt14a43e62011-09-19 17:44:57 +0000250#endif /* __ASSEMBLY__ */
Benjamin Herrenschmidt27f44882011-09-19 18:27:58 +0000251
Michael Ellermand800ba12015-02-17 20:01:53 +1100252#endif /* _ASM_POWERPC_OPAL_H */