Linux Audio

Check our new training course

Loading...
v4.6
 
  1
  2/*
  3 * IBM ASM Service Processor Device Driver
  4 *
  5 * This program is free software; you can redistribute it and/or modify
  6 * it under the terms of the GNU General Public License as published by
  7 * the Free Software Foundation; either version 2 of the License, or
  8 * (at your option) any later version.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 18 *
 19 * Copyright (C) IBM Corporation, 2004
 20 *
 21 * Author: Max Asböck <amax@us.ibm.com>
 22 *
 23 */
 24
 25#include <linux/kernel.h>
 26#include <linux/types.h>
 27#include <linux/errno.h>
 28#include <linux/list.h>
 29#include <linux/wait.h>
 30#include <linux/spinlock.h>
 31#include <linux/slab.h>
 32#include <linux/module.h>
 33#include <linux/interrupt.h>
 34#include <linux/kref.h>
 35#include <linux/device.h>
 36#include <linux/input.h>
 37#include <linux/time64.h>
 38
 39/* Driver identification */
 40#define DRIVER_NAME	"ibmasm"
 41#define DRIVER_VERSION  "1.0"
 42#define DRIVER_AUTHOR   "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
 43#define DRIVER_DESC     "IBM ASM Service Processor Driver"
 44
 45#define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
 46#define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
 47
 48extern int ibmasm_debug;
 49#define dbg(STR, ARGS...)					\
 50	do {							\
 51		if (ibmasm_debug)				\
 52			printk(KERN_DEBUG STR , ##ARGS);	\
 53	} while (0)
 54
 55static inline char *get_timestamp(char *buf)
 56{
 57	struct timespec64 now;
 58
 59	ktime_get_real_ts64(&now);
 60	sprintf(buf, "%llu.%.08lu", (long long)now.tv_sec,
 61				now.tv_nsec / NSEC_PER_USEC);
 62	return buf;
 63}
 64
 65#define IBMASM_CMD_PENDING	0
 66#define IBMASM_CMD_COMPLETE	1
 67#define IBMASM_CMD_FAILED	2
 68
 69#define IBMASM_CMD_TIMEOUT_NORMAL	45
 70#define IBMASM_CMD_TIMEOUT_EXTRA	240
 71
 72#define IBMASM_CMD_MAX_BUFFER_SIZE	0x8000
 73
 74#define REVERSE_HEARTBEAT_TIMEOUT	120
 75
 76#define HEARTBEAT_BUFFER_SIZE		0x400
 77
 78#ifdef IA64
 79#define IBMASM_DRIVER_VPD "Lin64 6.08      "
 80#else
 81#define IBMASM_DRIVER_VPD "Lin32 6.08      "
 82#endif
 83
 84#define SYSTEM_STATE_OS_UP      5
 85#define SYSTEM_STATE_OS_DOWN    4
 86
 87#define IBMASM_NAME_SIZE	16
 88
 89#define IBMASM_NUM_EVENTS	10
 90#define IBMASM_EVENT_MAX_SIZE	2048u
 91
 92
 93struct command {
 94	struct list_head	queue_node;
 95	wait_queue_head_t	wait;
 96	unsigned char		*buffer;
 97	size_t			buffer_size;
 98	int			status;
 99	struct kref		kref;
100	spinlock_t		*lock;
101};
102#define to_command(c) container_of(c, struct command, kref)
103
104void ibmasm_free_command(struct kref *kref);
105static inline void command_put(struct command *cmd)
106{
107	unsigned long flags;
108	spinlock_t *lock = cmd->lock;
109
110	spin_lock_irqsave(lock, flags);
111	kref_put(&cmd->kref, ibmasm_free_command);
112	spin_unlock_irqrestore(lock, flags);
113}
114
115static inline void command_get(struct command *cmd)
116{
117	kref_get(&cmd->kref);
118}
119
120
121struct ibmasm_event {
122	unsigned int	serial_number;
123	unsigned int	data_size;
124	unsigned char	data[IBMASM_EVENT_MAX_SIZE];
125};
126
127struct event_buffer {
128	struct ibmasm_event	events[IBMASM_NUM_EVENTS];
129	unsigned int		next_serial_number;
130	unsigned int		next_index;
131	struct list_head	readers;
132};
133
134struct event_reader {
135	int			cancelled;
136	unsigned int		next_serial_number;
137	wait_queue_head_t	wait;
138	struct list_head	node;
139	unsigned int		data_size;
140	unsigned char		data[IBMASM_EVENT_MAX_SIZE];
141};
142
143struct reverse_heartbeat {
144	wait_queue_head_t	wait;
145	unsigned int		stopped;
146};
147
148struct ibmasm_remote {
149	struct input_dev *keybd_dev;
150	struct input_dev *mouse_dev;
151};
152
153struct service_processor {
154	struct list_head	node;
155	spinlock_t		lock;
156	void __iomem		*base_address;
157	unsigned int		irq;
158	struct command		*current_command;
159	struct command		*heartbeat;
160	struct list_head	command_queue;
161	struct event_buffer	*event_buffer;
162	char			dirname[IBMASM_NAME_SIZE];
163	char			devname[IBMASM_NAME_SIZE];
164	unsigned int		number;
165	struct ibmasm_remote	remote;
166	int			serial_line;
167	struct device		*dev;
168};
169
170/* command processing */
171struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size);
172void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
173void ibmasm_wait_for_response(struct command *cmd, int timeout);
174void ibmasm_receive_command_response(struct service_processor *sp, void *response,  size_t size);
175
176/* event processing */
177int ibmasm_event_buffer_init(struct service_processor *sp);
178void ibmasm_event_buffer_exit(struct service_processor *sp);
179void ibmasm_receive_event(struct service_processor *sp, void *data,  unsigned int data_size);
180void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
181void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
182int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
183void ibmasm_cancel_next_event(struct event_reader *reader);
184
185/* heartbeat - from SP to OS */
186void ibmasm_register_panic_notifier(void);
187void ibmasm_unregister_panic_notifier(void);
188int ibmasm_heartbeat_init(struct service_processor *sp);
189void ibmasm_heartbeat_exit(struct service_processor *sp);
190void ibmasm_receive_heartbeat(struct service_processor *sp,  void *message, size_t size);
191
192/* reverse heartbeat - from OS to SP */
193void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
194int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
195void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
196
197/* dot commands */
198void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
199int ibmasm_send_driver_vpd(struct service_processor *sp);
200int ibmasm_send_os_state(struct service_processor *sp, int os_state);
201
202/* low level message processing */
203int ibmasm_send_i2o_message(struct service_processor *sp);
204irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id);
205
206/* remote console */
207void ibmasm_handle_mouse_interrupt(struct service_processor *sp);
208int ibmasm_init_remote_input_dev(struct service_processor *sp);
209void ibmasm_free_remote_input_dev(struct service_processor *sp);
210
211/* file system */
212int ibmasmfs_register(void);
213void ibmasmfs_unregister(void);
214void ibmasmfs_add_sp(struct service_processor *sp);
215
216/* uart */
217#if IS_ENABLED(CONFIG_SERIAL_8250)
218void ibmasm_register_uart(struct service_processor *sp);
219void ibmasm_unregister_uart(struct service_processor *sp);
220#else
221#define ibmasm_register_uart(sp)	do { } while(0)
222#define ibmasm_unregister_uart(sp)	do { } while(0)
223#endif
v5.4
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2
  3/*
  4 * IBM ASM Service Processor Device Driver
  5 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 * Copyright (C) IBM Corporation, 2004
  7 *
  8 * Author: Max Asböck <amax@us.ibm.com>
 
  9 */
 10
 11#include <linux/kernel.h>
 12#include <linux/types.h>
 13#include <linux/errno.h>
 14#include <linux/list.h>
 15#include <linux/wait.h>
 16#include <linux/spinlock.h>
 17#include <linux/slab.h>
 18#include <linux/module.h>
 19#include <linux/interrupt.h>
 20#include <linux/kref.h>
 21#include <linux/device.h>
 22#include <linux/input.h>
 23#include <linux/time64.h>
 24
 25/* Driver identification */
 26#define DRIVER_NAME	"ibmasm"
 27#define DRIVER_VERSION  "1.0"
 28#define DRIVER_AUTHOR   "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
 29#define DRIVER_DESC     "IBM ASM Service Processor Driver"
 30
 31#define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
 32#define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
 33
 34extern int ibmasm_debug;
 35#define dbg(STR, ARGS...)					\
 36	do {							\
 37		if (ibmasm_debug)				\
 38			printk(KERN_DEBUG STR , ##ARGS);	\
 39	} while (0)
 40
 41static inline char *get_timestamp(char *buf)
 42{
 43	struct timespec64 now;
 44
 45	ktime_get_real_ts64(&now);
 46	sprintf(buf, "%llu.%.08lu", (long long)now.tv_sec,
 47				now.tv_nsec / NSEC_PER_USEC);
 48	return buf;
 49}
 50
 51#define IBMASM_CMD_PENDING	0
 52#define IBMASM_CMD_COMPLETE	1
 53#define IBMASM_CMD_FAILED	2
 54
 55#define IBMASM_CMD_TIMEOUT_NORMAL	45
 56#define IBMASM_CMD_TIMEOUT_EXTRA	240
 57
 58#define IBMASM_CMD_MAX_BUFFER_SIZE	0x8000
 59
 60#define REVERSE_HEARTBEAT_TIMEOUT	120
 61
 62#define HEARTBEAT_BUFFER_SIZE		0x400
 63
 64#ifdef IA64
 65#define IBMASM_DRIVER_VPD "Lin64 6.08      "
 66#else
 67#define IBMASM_DRIVER_VPD "Lin32 6.08      "
 68#endif
 69
 70#define SYSTEM_STATE_OS_UP      5
 71#define SYSTEM_STATE_OS_DOWN    4
 72
 73#define IBMASM_NAME_SIZE	16
 74
 75#define IBMASM_NUM_EVENTS	10
 76#define IBMASM_EVENT_MAX_SIZE	2048u
 77
 78
 79struct command {
 80	struct list_head	queue_node;
 81	wait_queue_head_t	wait;
 82	unsigned char		*buffer;
 83	size_t			buffer_size;
 84	int			status;
 85	struct kref		kref;
 86	spinlock_t		*lock;
 87};
 88#define to_command(c) container_of(c, struct command, kref)
 89
 90void ibmasm_free_command(struct kref *kref);
 91static inline void command_put(struct command *cmd)
 92{
 93	unsigned long flags;
 94	spinlock_t *lock = cmd->lock;
 95
 96	spin_lock_irqsave(lock, flags);
 97	kref_put(&cmd->kref, ibmasm_free_command);
 98	spin_unlock_irqrestore(lock, flags);
 99}
100
101static inline void command_get(struct command *cmd)
102{
103	kref_get(&cmd->kref);
104}
105
106
107struct ibmasm_event {
108	unsigned int	serial_number;
109	unsigned int	data_size;
110	unsigned char	data[IBMASM_EVENT_MAX_SIZE];
111};
112
113struct event_buffer {
114	struct ibmasm_event	events[IBMASM_NUM_EVENTS];
115	unsigned int		next_serial_number;
116	unsigned int		next_index;
117	struct list_head	readers;
118};
119
120struct event_reader {
121	int			cancelled;
122	unsigned int		next_serial_number;
123	wait_queue_head_t	wait;
124	struct list_head	node;
125	unsigned int		data_size;
126	unsigned char		data[IBMASM_EVENT_MAX_SIZE];
127};
128
129struct reverse_heartbeat {
130	wait_queue_head_t	wait;
131	unsigned int		stopped;
132};
133
134struct ibmasm_remote {
135	struct input_dev *keybd_dev;
136	struct input_dev *mouse_dev;
137};
138
139struct service_processor {
140	struct list_head	node;
141	spinlock_t		lock;
142	void __iomem		*base_address;
143	unsigned int		irq;
144	struct command		*current_command;
145	struct command		*heartbeat;
146	struct list_head	command_queue;
147	struct event_buffer	*event_buffer;
148	char			dirname[IBMASM_NAME_SIZE];
149	char			devname[IBMASM_NAME_SIZE];
150	unsigned int		number;
151	struct ibmasm_remote	remote;
152	int			serial_line;
153	struct device		*dev;
154};
155
156/* command processing */
157struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size);
158void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
159void ibmasm_wait_for_response(struct command *cmd, int timeout);
160void ibmasm_receive_command_response(struct service_processor *sp, void *response,  size_t size);
161
162/* event processing */
163int ibmasm_event_buffer_init(struct service_processor *sp);
164void ibmasm_event_buffer_exit(struct service_processor *sp);
165void ibmasm_receive_event(struct service_processor *sp, void *data,  unsigned int data_size);
166void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
167void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
168int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
169void ibmasm_cancel_next_event(struct event_reader *reader);
170
171/* heartbeat - from SP to OS */
172void ibmasm_register_panic_notifier(void);
173void ibmasm_unregister_panic_notifier(void);
174int ibmasm_heartbeat_init(struct service_processor *sp);
175void ibmasm_heartbeat_exit(struct service_processor *sp);
176void ibmasm_receive_heartbeat(struct service_processor *sp,  void *message, size_t size);
177
178/* reverse heartbeat - from OS to SP */
179void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
180int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
181void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
182
183/* dot commands */
184void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
185int ibmasm_send_driver_vpd(struct service_processor *sp);
186int ibmasm_send_os_state(struct service_processor *sp, int os_state);
187
188/* low level message processing */
189int ibmasm_send_i2o_message(struct service_processor *sp);
190irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id);
191
192/* remote console */
193void ibmasm_handle_mouse_interrupt(struct service_processor *sp);
194int ibmasm_init_remote_input_dev(struct service_processor *sp);
195void ibmasm_free_remote_input_dev(struct service_processor *sp);
196
197/* file system */
198int ibmasmfs_register(void);
199void ibmasmfs_unregister(void);
200void ibmasmfs_add_sp(struct service_processor *sp);
201
202/* uart */
203#if IS_ENABLED(CONFIG_SERIAL_8250)
204void ibmasm_register_uart(struct service_processor *sp);
205void ibmasm_unregister_uart(struct service_processor *sp);
206#else
207#define ibmasm_register_uart(sp)	do { } while(0)
208#define ibmasm_unregister_uart(sp)	do { } while(0)
209#endif