diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-07-18 06:20:23 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-07-18 06:20:23 -0400 |
commit | cd569ef5d6ff9f43e9504f1ffc7fdbe356518149 (patch) | |
tree | 9a4ab5e600fd09e991aa1fbb69adb1c7950898a4 /drivers | |
parent | 6879827f4e08da219c99b91e4e1d793a924103e3 (diff) | |
parent | 5b664cb235e97afbf34db9c4d77f08ebd725335e (diff) |
Merge branch 'linus' into x86/urgent
Diffstat (limited to 'drivers')
251 files changed, 17411 insertions, 11337 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index bba867391a85..735f5ea17473 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig | |||
@@ -336,6 +336,15 @@ config ACPI_EC | |||
336 | the battery and thermal drivers. If you are compiling for a | 336 | the battery and thermal drivers. If you are compiling for a |
337 | mobile system, say Y. | 337 | mobile system, say Y. |
338 | 338 | ||
339 | config ACPI_PCI_SLOT | ||
340 | tristate "PCI slot detection driver" | ||
341 | default n | ||
342 | help | ||
343 | This driver will attempt to discover all PCI slots in your system, | ||
344 | and creates entries in /sys/bus/pci/slots/. This feature can | ||
345 | help you correlate PCI bus addresses with the physical geography | ||
346 | of your slots. If you are unsure, say N. | ||
347 | |||
339 | config ACPI_POWER | 348 | config ACPI_POWER |
340 | bool | 349 | bool |
341 | default y | 350 | default y |
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 40b0fcae4c78..52a4cd4b81d0 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -21,7 +21,7 @@ obj-$(CONFIG_X86) += blacklist.o | |||
21 | # | 21 | # |
22 | # ACPI Core Subsystem (Interpreter) | 22 | # ACPI Core Subsystem (Interpreter) |
23 | # | 23 | # |
24 | obj-y += osl.o utils.o \ | 24 | obj-y += osl.o utils.o reboot.o\ |
25 | dispatcher/ events/ executer/ hardware/ \ | 25 | dispatcher/ events/ executer/ hardware/ \ |
26 | namespace/ parser/ resources/ tables/ \ | 26 | namespace/ parser/ resources/ tables/ \ |
27 | utilities/ | 27 | utilities/ |
@@ -48,6 +48,7 @@ obj-$(CONFIG_ACPI_DOCK) += dock.o | |||
48 | obj-$(CONFIG_ACPI_BAY) += bay.o | 48 | obj-$(CONFIG_ACPI_BAY) += bay.o |
49 | obj-$(CONFIG_ACPI_VIDEO) += video.o | 49 | obj-$(CONFIG_ACPI_VIDEO) += video.o |
50 | obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o | 50 | obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o |
51 | obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o | ||
51 | obj-$(CONFIG_ACPI_POWER) += power.o | 52 | obj-$(CONFIG_ACPI_POWER) += power.o |
52 | obj-$(CONFIG_ACPI_PROCESSOR) += processor.o | 53 | obj-$(CONFIG_ACPI_PROCESSOR) += processor.o |
53 | obj-$(CONFIG_ACPI_CONTAINER) += container.o | 54 | obj-$(CONFIG_ACPI_CONTAINER) += container.o |
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index 61b6c5beb2d3..e6caf5d42e0e 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c | |||
@@ -380,6 +380,9 @@ static int __init bay_init(void) | |||
380 | if (acpi_disabled) | 380 | if (acpi_disabled) |
381 | return -ENODEV; | 381 | return -ENODEV; |
382 | 382 | ||
383 | if (acpi_disabled) | ||
384 | return -ENODEV; | ||
385 | |||
383 | /* look for dockable drive bays */ | 386 | /* look for dockable drive bays */ |
384 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | 387 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
385 | ACPI_UINT32_MAX, find_bay, &bays, NULL); | 388 | ACPI_UINT32_MAX, find_bay, &bays, NULL); |
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index a6dbcf4d9ef5..ccae305ee55d 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -295,6 +295,28 @@ int acpi_bus_set_power(acpi_handle handle, int state) | |||
295 | 295 | ||
296 | EXPORT_SYMBOL(acpi_bus_set_power); | 296 | EXPORT_SYMBOL(acpi_bus_set_power); |
297 | 297 | ||
298 | bool acpi_bus_power_manageable(acpi_handle handle) | ||
299 | { | ||
300 | struct acpi_device *device; | ||
301 | int result; | ||
302 | |||
303 | result = acpi_bus_get_device(handle, &device); | ||
304 | return result ? false : device->flags.power_manageable; | ||
305 | } | ||
306 | |||
307 | EXPORT_SYMBOL(acpi_bus_power_manageable); | ||
308 | |||
309 | bool acpi_bus_can_wakeup(acpi_handle handle) | ||
310 | { | ||
311 | struct acpi_device *device; | ||
312 | int result; | ||
313 | |||
314 | result = acpi_bus_get_device(handle, &device); | ||
315 | return result ? false : device->wakeup.flags.valid; | ||
316 | } | ||
317 | |||
318 | EXPORT_SYMBOL(acpi_bus_can_wakeup); | ||
319 | |||
298 | /* -------------------------------------------------------------------------- | 320 | /* -------------------------------------------------------------------------- |
299 | Event Management | 321 | Event Management |
300 | -------------------------------------------------------------------------- */ | 322 | -------------------------------------------------------------------------- */ |
@@ -612,7 +634,7 @@ static int __init acpi_bus_init_irq(void) | |||
612 | return 0; | 634 | return 0; |
613 | } | 635 | } |
614 | 636 | ||
615 | acpi_native_uint acpi_gbl_permanent_mmap; | 637 | u8 acpi_gbl_permanent_mmap; |
616 | 638 | ||
617 | 639 | ||
618 | void __init acpi_early_init(void) | 640 | void __init acpi_early_init(void) |
diff --git a/drivers/acpi/dispatcher/dsinit.c b/drivers/acpi/dispatcher/dsinit.c index 610b1ee102b0..949f7c75029e 100644 --- a/drivers/acpi/dispatcher/dsinit.c +++ b/drivers/acpi/dispatcher/dsinit.c | |||
@@ -151,7 +151,7 @@ acpi_ds_init_one_object(acpi_handle obj_handle, | |||
151 | ******************************************************************************/ | 151 | ******************************************************************************/ |
152 | 152 | ||
153 | acpi_status | 153 | acpi_status |
154 | acpi_ds_initialize_objects(acpi_native_uint table_index, | 154 | acpi_ds_initialize_objects(u32 table_index, |
155 | struct acpi_namespace_node * start_node) | 155 | struct acpi_namespace_node * start_node) |
156 | { | 156 | { |
157 | acpi_status status; | 157 | acpi_status status; |
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c index 2509809a36cf..4613b9ca5792 100644 --- a/drivers/acpi/dispatcher/dsmethod.c +++ b/drivers/acpi/dispatcher/dsmethod.c | |||
@@ -377,7 +377,6 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread, | |||
377 | } | 377 | } |
378 | 378 | ||
379 | info->parameters = &this_walk_state->operands[0]; | 379 | info->parameters = &this_walk_state->operands[0]; |
380 | info->parameter_type = ACPI_PARAM_ARGS; | ||
381 | 380 | ||
382 | status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, | 381 | status = acpi_ds_init_aml_walk(next_walk_state, NULL, method_node, |
383 | obj_desc->method.aml_start, | 382 | obj_desc->method.aml_start, |
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c index a818e0ddb996..6a81c4400edf 100644 --- a/drivers/acpi/dispatcher/dsopcode.c +++ b/drivers/acpi/dispatcher/dsopcode.c | |||
@@ -691,12 +691,6 @@ acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state, | |||
691 | 691 | ||
692 | status = acpi_ex_resolve_operands(op->common.aml_opcode, | 692 | status = acpi_ex_resolve_operands(op->common.aml_opcode, |
693 | ACPI_WALK_OPERANDS, walk_state); | 693 | ACPI_WALK_OPERANDS, walk_state); |
694 | |||
695 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, | ||
696 | acpi_ps_get_opcode_name(op->common.aml_opcode), | ||
697 | walk_state->num_operands, | ||
698 | "after AcpiExResolveOperands"); | ||
699 | |||
700 | if (ACPI_FAILURE(status)) { | 694 | if (ACPI_FAILURE(status)) { |
701 | ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)", | 695 | ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)", |
702 | acpi_ps_get_opcode_name(op->common.aml_opcode), | 696 | acpi_ps_get_opcode_name(op->common.aml_opcode), |
@@ -785,10 +779,6 @@ acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state, | |||
785 | return_ACPI_STATUS(status); | 779 | return_ACPI_STATUS(status); |
786 | } | 780 | } |
787 | 781 | ||
788 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, | ||
789 | acpi_ps_get_opcode_name(op->common.aml_opcode), | ||
790 | 1, "after AcpiExResolveOperands"); | ||
791 | |||
792 | obj_desc = acpi_ns_get_attached_object(node); | 782 | obj_desc = acpi_ns_get_attached_object(node); |
793 | if (!obj_desc) { | 783 | if (!obj_desc) { |
794 | return_ACPI_STATUS(AE_NOT_EXIST); | 784 | return_ACPI_STATUS(AE_NOT_EXIST); |
@@ -848,7 +838,7 @@ acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state, | |||
848 | union acpi_operand_object **operand; | 838 | union acpi_operand_object **operand; |
849 | struct acpi_namespace_node *node; | 839 | struct acpi_namespace_node *node; |
850 | union acpi_parse_object *next_op; | 840 | union acpi_parse_object *next_op; |
851 | acpi_native_uint table_index; | 841 | u32 table_index; |
852 | struct acpi_table_header *table; | 842 | struct acpi_table_header *table; |
853 | 843 | ||
854 | ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op); | 844 | ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op); |
@@ -882,10 +872,6 @@ acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state, | |||
882 | return_ACPI_STATUS(status); | 872 | return_ACPI_STATUS(status); |
883 | } | 873 | } |
884 | 874 | ||
885 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, | ||
886 | acpi_ps_get_opcode_name(op->common.aml_opcode), | ||
887 | 1, "after AcpiExResolveOperands"); | ||
888 | |||
889 | operand = &walk_state->operands[0]; | 875 | operand = &walk_state->operands[0]; |
890 | 876 | ||
891 | /* Find the ACPI table */ | 877 | /* Find the ACPI table */ |
@@ -1091,10 +1077,8 @@ acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state, | |||
1091 | return_ACPI_STATUS(status); | 1077 | return_ACPI_STATUS(status); |
1092 | } | 1078 | } |
1093 | 1079 | ||
1094 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, | 1080 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, |
1095 | acpi_ps_get_opcode_name(op->common.aml_opcode), | 1081 | acpi_ps_get_opcode_name(op->common.aml_opcode), 1); |
1096 | 1, "after AcpiExResolveOperands"); | ||
1097 | |||
1098 | /* | 1082 | /* |
1099 | * Get the bank_value operand and save it | 1083 | * Get the bank_value operand and save it |
1100 | * (at Top of stack) | 1084 | * (at Top of stack) |
diff --git a/drivers/acpi/dispatcher/dswexec.c b/drivers/acpi/dispatcher/dswexec.c index b246b9657ead..b5072fa9c920 100644 --- a/drivers/acpi/dispatcher/dswexec.c +++ b/drivers/acpi/dispatcher/dswexec.c | |||
@@ -408,14 +408,6 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state) | |||
408 | [walk_state-> | 408 | [walk_state-> |
409 | num_operands - 1]), | 409 | num_operands - 1]), |
410 | walk_state); | 410 | walk_state); |
411 | if (ACPI_SUCCESS(status)) { | ||
412 | ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS, | ||
413 | ACPI_IMODE_EXECUTE, | ||
414 | acpi_ps_get_opcode_name | ||
415 | (walk_state->opcode), | ||
416 | walk_state->num_operands, | ||
417 | "after ExResolveOperands"); | ||
418 | } | ||
419 | } | 411 | } |
420 | 412 | ||
421 | if (ACPI_SUCCESS(status)) { | 413 | if (ACPI_SUCCESS(status)) { |
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c index 1386ced332ec..b00d4af791aa 100644 --- a/drivers/acpi/dispatcher/dswstate.c +++ b/drivers/acpi/dispatcher/dswstate.c | |||
@@ -70,7 +70,7 @@ acpi_status | |||
70 | acpi_ds_result_pop(union acpi_operand_object **object, | 70 | acpi_ds_result_pop(union acpi_operand_object **object, |
71 | struct acpi_walk_state *walk_state) | 71 | struct acpi_walk_state *walk_state) |
72 | { | 72 | { |
73 | acpi_native_uint index; | 73 | u32 index; |
74 | union acpi_generic_state *state; | 74 | union acpi_generic_state *state; |
75 | acpi_status status; | 75 | acpi_status status; |
76 | 76 | ||
@@ -122,7 +122,7 @@ acpi_ds_result_pop(union acpi_operand_object **object, | |||
122 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 122 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
123 | "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, | 123 | "Obj=%p [%s] Index=%X State=%p Num=%X\n", *object, |
124 | acpi_ut_get_object_type_name(*object), | 124 | acpi_ut_get_object_type_name(*object), |
125 | (u32) index, walk_state, walk_state->result_count)); | 125 | index, walk_state, walk_state->result_count)); |
126 | 126 | ||
127 | return (AE_OK); | 127 | return (AE_OK); |
128 | } | 128 | } |
@@ -146,7 +146,7 @@ acpi_ds_result_push(union acpi_operand_object * object, | |||
146 | { | 146 | { |
147 | union acpi_generic_state *state; | 147 | union acpi_generic_state *state; |
148 | acpi_status status; | 148 | acpi_status status; |
149 | acpi_native_uint index; | 149 | u32 index; |
150 | 150 | ||
151 | ACPI_FUNCTION_NAME(ds_result_push); | 151 | ACPI_FUNCTION_NAME(ds_result_push); |
152 | 152 | ||
@@ -400,7 +400,7 @@ void | |||
400 | acpi_ds_obj_stack_pop_and_delete(u32 pop_count, | 400 | acpi_ds_obj_stack_pop_and_delete(u32 pop_count, |
401 | struct acpi_walk_state *walk_state) | 401 | struct acpi_walk_state *walk_state) |
402 | { | 402 | { |
403 | acpi_native_int i; | 403 | s32 i; |
404 | union acpi_operand_object *obj_desc; | 404 | union acpi_operand_object *obj_desc; |
405 | 405 | ||
406 | ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete); | 406 | ACPI_FUNCTION_NAME(ds_obj_stack_pop_and_delete); |
@@ -409,7 +409,7 @@ acpi_ds_obj_stack_pop_and_delete(u32 pop_count, | |||
409 | return; | 409 | return; |
410 | } | 410 | } |
411 | 411 | ||
412 | for (i = (acpi_native_int) (pop_count - 1); i >= 0; i--) { | 412 | for (i = (s32) pop_count - 1; i >= 0; i--) { |
413 | if (walk_state->num_operands == 0) { | 413 | if (walk_state->num_operands == 0) { |
414 | return; | 414 | return; |
415 | } | 415 | } |
@@ -615,14 +615,8 @@ acpi_ds_init_aml_walk(struct acpi_walk_state *walk_state, | |||
615 | walk_state->pass_number = pass_number; | 615 | walk_state->pass_number = pass_number; |
616 | 616 | ||
617 | if (info) { | 617 | if (info) { |
618 | if (info->parameter_type == ACPI_PARAM_GPE) { | 618 | walk_state->params = info->parameters; |
619 | walk_state->gpe_event_info = | 619 | walk_state->caller_return_desc = &info->return_object; |
620 | ACPI_CAST_PTR(struct acpi_gpe_event_info, | ||
621 | info->parameters); | ||
622 | } else { | ||
623 | walk_state->params = info->parameters; | ||
624 | walk_state->caller_return_desc = &info->return_object; | ||
625 | } | ||
626 | } | 620 | } |
627 | 621 | ||
628 | status = acpi_ps_init_scope(&walk_state->parser_state, op); | 622 | status = acpi_ps_init_scope(&walk_state->parser_state, op); |
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index bb7c51f712bd..1e872e79db33 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c | |||
@@ -920,6 +920,9 @@ static int __init dock_init(void) | |||
920 | if (acpi_disabled) | 920 | if (acpi_disabled) |
921 | return 0; | 921 | return 0; |
922 | 922 | ||
923 | if (acpi_disabled) | ||
924 | return 0; | ||
925 | |||
923 | /* look for a dock station */ | 926 | /* look for a dock station */ |
924 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | 927 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
925 | ACPI_UINT32_MAX, find_dock, &num, NULL); | 928 | ACPI_UINT32_MAX, find_dock, &num, NULL); |
diff --git a/drivers/acpi/events/evevent.c b/drivers/acpi/events/evevent.c index 5d30e5be1b1c..c56c5c6ea77b 100644 --- a/drivers/acpi/events/evevent.c +++ b/drivers/acpi/events/evevent.c | |||
@@ -188,7 +188,7 @@ acpi_status acpi_ev_install_xrupt_handlers(void) | |||
188 | 188 | ||
189 | static acpi_status acpi_ev_fixed_event_initialize(void) | 189 | static acpi_status acpi_ev_fixed_event_initialize(void) |
190 | { | 190 | { |
191 | acpi_native_uint i; | 191 | u32 i; |
192 | acpi_status status; | 192 | acpi_status status; |
193 | 193 | ||
194 | /* | 194 | /* |
@@ -231,7 +231,7 @@ u32 acpi_ev_fixed_event_detect(void) | |||
231 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; | 231 | u32 int_status = ACPI_INTERRUPT_NOT_HANDLED; |
232 | u32 fixed_status; | 232 | u32 fixed_status; |
233 | u32 fixed_enable; | 233 | u32 fixed_enable; |
234 | acpi_native_uint i; | 234 | u32 i; |
235 | 235 | ||
236 | ACPI_FUNCTION_NAME(ev_fixed_event_detect); | 236 | ACPI_FUNCTION_NAME(ev_fixed_event_detect); |
237 | 237 | ||
@@ -260,7 +260,7 @@ u32 acpi_ev_fixed_event_detect(void) | |||
260 | 260 | ||
261 | /* Found an active (signalled) event */ | 261 | /* Found an active (signalled) event */ |
262 | acpi_os_fixed_event_count(i); | 262 | acpi_os_fixed_event_count(i); |
263 | int_status |= acpi_ev_fixed_event_dispatch((u32) i); | 263 | int_status |= acpi_ev_fixed_event_dispatch(i); |
264 | } | 264 | } |
265 | } | 265 | } |
266 | 266 | ||
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c index 5354be44f876..c5e53aae86f7 100644 --- a/drivers/acpi/events/evgpe.c +++ b/drivers/acpi/events/evgpe.c | |||
@@ -256,7 +256,7 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info) | |||
256 | return_ACPI_STATUS(status); | 256 | return_ACPI_STATUS(status); |
257 | } | 257 | } |
258 | 258 | ||
259 | /* Mark wake-disabled or HW disable, or both */ | 259 | /* Clear the appropriate enabled flags for this GPE */ |
260 | 260 | ||
261 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { | 261 | switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { |
262 | case ACPI_GPE_TYPE_WAKE: | 262 | case ACPI_GPE_TYPE_WAKE: |
@@ -273,13 +273,23 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info) | |||
273 | /* Disable the requested runtime GPE */ | 273 | /* Disable the requested runtime GPE */ |
274 | 274 | ||
275 | ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); | 275 | ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED); |
276 | 276 | break; | |
277 | /* fallthrough */ | ||
278 | 277 | ||
279 | default: | 278 | default: |
280 | acpi_hw_write_gpe_enable_reg(gpe_event_info); | 279 | break; |
281 | } | 280 | } |
282 | 281 | ||
282 | /* | ||
283 | * Even if we don't know the GPE type, make sure that we always | ||
284 | * disable it. low_disable_gpe will just clear the enable bit for this | ||
285 | * GPE and write it. It will not write out the current GPE enable mask, | ||
286 | * since this may inadvertently enable GPEs too early, if a rogue GPE has | ||
287 | * come in during ACPICA initialization - possibly as a result of AML or | ||
288 | * other code that has enabled the GPE. | ||
289 | */ | ||
290 | status = acpi_hw_low_disable_gpe(gpe_event_info); | ||
291 | return_ACPI_STATUS(status); | ||
292 | |||
283 | return_ACPI_STATUS(AE_OK); | 293 | return_ACPI_STATUS(AE_OK); |
284 | } | 294 | } |
285 | 295 | ||
@@ -305,7 +315,7 @@ struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device, | |||
305 | { | 315 | { |
306 | union acpi_operand_object *obj_desc; | 316 | union acpi_operand_object *obj_desc; |
307 | struct acpi_gpe_block_info *gpe_block; | 317 | struct acpi_gpe_block_info *gpe_block; |
308 | acpi_native_uint i; | 318 | u32 i; |
309 | 319 | ||
310 | ACPI_FUNCTION_ENTRY(); | 320 | ACPI_FUNCTION_ENTRY(); |
311 | 321 | ||
@@ -379,8 +389,8 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list) | |||
379 | u32 status_reg; | 389 | u32 status_reg; |
380 | u32 enable_reg; | 390 | u32 enable_reg; |
381 | acpi_cpu_flags flags; | 391 | acpi_cpu_flags flags; |
382 | acpi_native_uint i; | 392 | u32 i; |
383 | acpi_native_uint j; | 393 | u32 j; |
384 | 394 | ||
385 | ACPI_FUNCTION_NAME(ev_gpe_detect); | 395 | ACPI_FUNCTION_NAME(ev_gpe_detect); |
386 | 396 | ||
@@ -462,13 +472,7 @@ u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list) | |||
462 | */ | 472 | */ |
463 | int_status |= | 473 | int_status |= |
464 | acpi_ev_gpe_dispatch(&gpe_block-> | 474 | acpi_ev_gpe_dispatch(&gpe_block-> |
465 | event_info[(i * | 475 | event_info[((acpi_size) i * ACPI_GPE_REGISTER_WIDTH) + j], j + gpe_register_info->base_gpe_number); |
466 | ACPI_GPE_REGISTER_WIDTH) | ||
467 | + | ||
468 | j], | ||
469 | (u32) j + | ||
470 | gpe_register_info-> | ||
471 | base_gpe_number); | ||
472 | } | 476 | } |
473 | } | 477 | } |
474 | } | 478 | } |
@@ -555,10 +559,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context) | |||
555 | */ | 559 | */ |
556 | info->prefix_node = | 560 | info->prefix_node = |
557 | local_gpe_event_info.dispatch.method_node; | 561 | local_gpe_event_info.dispatch.method_node; |
558 | info->parameters = | ||
559 | ACPI_CAST_PTR(union acpi_operand_object *, | ||
560 | gpe_event_info); | ||
561 | info->parameter_type = ACPI_PARAM_GPE; | ||
562 | info->flags = ACPI_IGNORE_RETURN_VALUE; | 562 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
563 | 563 | ||
564 | status = acpi_ns_evaluate(info); | 564 | status = acpi_ns_evaluate(info); |
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c index e6c4d4c49e79..73c058e2f5c2 100644 --- a/drivers/acpi/events/evgpeblk.c +++ b/drivers/acpi/events/evgpeblk.c | |||
@@ -189,8 +189,8 @@ acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info, | |||
189 | struct acpi_gpe_block_info *gpe_block) | 189 | struct acpi_gpe_block_info *gpe_block) |
190 | { | 190 | { |
191 | struct acpi_gpe_event_info *gpe_event_info; | 191 | struct acpi_gpe_event_info *gpe_event_info; |
192 | acpi_native_uint i; | 192 | u32 i; |
193 | acpi_native_uint j; | 193 | u32 j; |
194 | 194 | ||
195 | ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers); | 195 | ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers); |
196 | 196 | ||
@@ -203,7 +203,8 @@ acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info, | |||
203 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { | 203 | for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) { |
204 | gpe_event_info = | 204 | gpe_event_info = |
205 | &gpe_block-> | 205 | &gpe_block-> |
206 | event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; | 206 | event_info[((acpi_size) i * |
207 | ACPI_GPE_REGISTER_WIDTH) + j]; | ||
207 | 208 | ||
208 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == | 209 | if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
209 | ACPI_GPE_DISPATCH_HANDLER) { | 210 | ACPI_GPE_DISPATCH_HANDLER) { |
@@ -744,8 +745,8 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block) | |||
744 | struct acpi_gpe_event_info *gpe_event_info = NULL; | 745 | struct acpi_gpe_event_info *gpe_event_info = NULL; |
745 | struct acpi_gpe_event_info *this_event; | 746 | struct acpi_gpe_event_info *this_event; |
746 | struct acpi_gpe_register_info *this_register; | 747 | struct acpi_gpe_register_info *this_register; |
747 | acpi_native_uint i; | 748 | u32 i; |
748 | acpi_native_uint j; | 749 | u32 j; |
749 | acpi_status status; | 750 | acpi_status status; |
750 | 751 | ||
751 | ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks); | 752 | ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks); |
@@ -983,8 +984,8 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device, | |||
983 | struct acpi_gpe_walk_info gpe_info; | 984 | struct acpi_gpe_walk_info gpe_info; |
984 | u32 wake_gpe_count; | 985 | u32 wake_gpe_count; |
985 | u32 gpe_enabled_count; | 986 | u32 gpe_enabled_count; |
986 | acpi_native_uint i; | 987 | u32 i; |
987 | acpi_native_uint j; | 988 | u32 j; |
988 | 989 | ||
989 | ACPI_FUNCTION_TRACE(ev_initialize_gpe_block); | 990 | ACPI_FUNCTION_TRACE(ev_initialize_gpe_block); |
990 | 991 | ||
@@ -1033,7 +1034,8 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device, | |||
1033 | 1034 | ||
1034 | gpe_event_info = | 1035 | gpe_event_info = |
1035 | &gpe_block-> | 1036 | &gpe_block-> |
1036 | event_info[(i * ACPI_GPE_REGISTER_WIDTH) + j]; | 1037 | event_info[((acpi_size) i * |
1038 | ACPI_GPE_REGISTER_WIDTH) + j]; | ||
1037 | 1039 | ||
1038 | if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == | 1040 | if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == |
1039 | ACPI_GPE_DISPATCH_METHOD) | 1041 | ACPI_GPE_DISPATCH_METHOD) |
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c index 2113e58e2221..1d5670be729a 100644 --- a/drivers/acpi/events/evmisc.c +++ b/drivers/acpi/events/evmisc.c | |||
@@ -575,7 +575,7 @@ acpi_status acpi_ev_release_global_lock(void) | |||
575 | 575 | ||
576 | void acpi_ev_terminate(void) | 576 | void acpi_ev_terminate(void) |
577 | { | 577 | { |
578 | acpi_native_uint i; | 578 | u32 i; |
579 | acpi_status status; | 579 | acpi_status status; |
580 | 580 | ||
581 | ACPI_FUNCTION_TRACE(ev_terminate); | 581 | ACPI_FUNCTION_TRACE(ev_terminate); |
@@ -589,7 +589,7 @@ void acpi_ev_terminate(void) | |||
589 | /* Disable all fixed events */ | 589 | /* Disable all fixed events */ |
590 | 590 | ||
591 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { | 591 | for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) { |
592 | status = acpi_disable_event((u32) i, 0); | 592 | status = acpi_disable_event(i, 0); |
593 | if (ACPI_FAILURE(status)) { | 593 | if (ACPI_FAILURE(status)) { |
594 | ACPI_ERROR((AE_INFO, | 594 | ACPI_ERROR((AE_INFO, |
595 | "Could not disable fixed event %d", | 595 | "Could not disable fixed event %d", |
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c index 1628f5934752..236fbd1ca438 100644 --- a/drivers/acpi/events/evregion.c +++ b/drivers/acpi/events/evregion.c | |||
@@ -81,7 +81,7 @@ acpi_ev_install_handler(acpi_handle obj_handle, | |||
81 | acpi_status acpi_ev_install_region_handlers(void) | 81 | acpi_status acpi_ev_install_region_handlers(void) |
82 | { | 82 | { |
83 | acpi_status status; | 83 | acpi_status status; |
84 | acpi_native_uint i; | 84 | u32 i; |
85 | 85 | ||
86 | ACPI_FUNCTION_TRACE(ev_install_region_handlers); | 86 | ACPI_FUNCTION_TRACE(ev_install_region_handlers); |
87 | 87 | ||
@@ -151,7 +151,7 @@ acpi_status acpi_ev_install_region_handlers(void) | |||
151 | acpi_status acpi_ev_initialize_op_regions(void) | 151 | acpi_status acpi_ev_initialize_op_regions(void) |
152 | { | 152 | { |
153 | acpi_status status; | 153 | acpi_status status; |
154 | acpi_native_uint i; | 154 | u32 i; |
155 | 155 | ||
156 | ACPI_FUNCTION_TRACE(ev_initialize_op_regions); | 156 | ACPI_FUNCTION_TRACE(ev_initialize_op_regions); |
157 | 157 | ||
@@ -219,7 +219,6 @@ acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) | |||
219 | info->prefix_node = region_obj2->extra.method_REG; | 219 | info->prefix_node = region_obj2->extra.method_REG; |
220 | info->pathname = NULL; | 220 | info->pathname = NULL; |
221 | info->parameters = args; | 221 | info->parameters = args; |
222 | info->parameter_type = ACPI_PARAM_ARGS; | ||
223 | info->flags = ACPI_IGNORE_RETURN_VALUE; | 222 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
224 | 223 | ||
225 | /* | 224 | /* |
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c index 2e3d2c5e4f4d..6b94b38df07d 100644 --- a/drivers/acpi/events/evrgnini.c +++ b/drivers/acpi/events/evrgnini.c | |||
@@ -380,7 +380,7 @@ static u8 acpi_ev_is_pci_root_bridge(struct acpi_namespace_node *node) | |||
380 | acpi_status status; | 380 | acpi_status status; |
381 | struct acpica_device_id hid; | 381 | struct acpica_device_id hid; |
382 | struct acpi_compatible_id_list *cid; | 382 | struct acpi_compatible_id_list *cid; |
383 | acpi_native_uint i; | 383 | u32 i; |
384 | 384 | ||
385 | /* | 385 | /* |
386 | * Get the _HID and check for a PCI Root Bridge | 386 | * Get the _HID and check for a PCI Root Bridge |
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c index 99a7502e6a87..73bfd6bf962f 100644 --- a/drivers/acpi/events/evxfevnt.c +++ b/drivers/acpi/events/evxfevnt.c | |||
@@ -472,7 +472,6 @@ acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags) | |||
472 | } | 472 | } |
473 | 473 | ||
474 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) | 474 | ACPI_EXPORT_SYMBOL(acpi_clear_gpe) |
475 | #ifdef ACPI_FUTURE_USAGE | ||
476 | /******************************************************************************* | 475 | /******************************************************************************* |
477 | * | 476 | * |
478 | * FUNCTION: acpi_get_event_status | 477 | * FUNCTION: acpi_get_event_status |
@@ -489,6 +488,7 @@ ACPI_EXPORT_SYMBOL(acpi_clear_gpe) | |||
489 | acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) | 488 | acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) |
490 | { | 489 | { |
491 | acpi_status status = AE_OK; | 490 | acpi_status status = AE_OK; |
491 | u32 value; | ||
492 | 492 | ||
493 | ACPI_FUNCTION_TRACE(acpi_get_event_status); | 493 | ACPI_FUNCTION_TRACE(acpi_get_event_status); |
494 | 494 | ||
@@ -506,7 +506,20 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status) | |||
506 | 506 | ||
507 | status = | 507 | status = |
508 | acpi_get_register(acpi_gbl_fixed_event_info[event]. | 508 | acpi_get_register(acpi_gbl_fixed_event_info[event]. |
509 | status_register_id, event_status); | 509 | enable_register_id, &value); |
510 | if (ACPI_FAILURE(status)) | ||
511 | return_ACPI_STATUS(status); | ||
512 | |||
513 | *event_status = value; | ||
514 | |||
515 | status = | ||
516 | acpi_get_register(acpi_gbl_fixed_event_info[event]. | ||
517 | status_register_id, &value); | ||
518 | if (ACPI_FAILURE(status)) | ||
519 | return_ACPI_STATUS(status); | ||
520 | |||
521 | if (value) | ||
522 | *event_status |= ACPI_EVENT_FLAG_SET; | ||
510 | 523 | ||
511 | return_ACPI_STATUS(status); | 524 | return_ACPI_STATUS(status); |
512 | } | 525 | } |
@@ -566,7 +579,6 @@ acpi_get_gpe_status(acpi_handle gpe_device, | |||
566 | } | 579 | } |
567 | 580 | ||
568 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) | 581 | ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) |
569 | #endif /* ACPI_FUTURE_USAGE */ | ||
570 | /******************************************************************************* | 582 | /******************************************************************************* |
571 | * | 583 | * |
572 | * FUNCTION: acpi_install_gpe_block | 584 | * FUNCTION: acpi_install_gpe_block |
diff --git a/drivers/acpi/executer/exconfig.c b/drivers/acpi/executer/exconfig.c index 39d742190584..2a32c843cb4a 100644 --- a/drivers/acpi/executer/exconfig.c +++ b/drivers/acpi/executer/exconfig.c | |||
@@ -53,7 +53,7 @@ ACPI_MODULE_NAME("exconfig") | |||
53 | 53 | ||
54 | /* Local prototypes */ | 54 | /* Local prototypes */ |
55 | static acpi_status | 55 | static acpi_status |
56 | acpi_ex_add_table(acpi_native_uint table_index, | 56 | acpi_ex_add_table(u32 table_index, |
57 | struct acpi_namespace_node *parent_node, | 57 | struct acpi_namespace_node *parent_node, |
58 | union acpi_operand_object **ddb_handle); | 58 | union acpi_operand_object **ddb_handle); |
59 | 59 | ||
@@ -73,7 +73,7 @@ acpi_ex_add_table(acpi_native_uint table_index, | |||
73 | ******************************************************************************/ | 73 | ******************************************************************************/ |
74 | 74 | ||
75 | static acpi_status | 75 | static acpi_status |
76 | acpi_ex_add_table(acpi_native_uint table_index, | 76 | acpi_ex_add_table(u32 table_index, |
77 | struct acpi_namespace_node *parent_node, | 77 | struct acpi_namespace_node *parent_node, |
78 | union acpi_operand_object **ddb_handle) | 78 | union acpi_operand_object **ddb_handle) |
79 | { | 79 | { |
@@ -96,7 +96,8 @@ acpi_ex_add_table(acpi_native_uint table_index, | |||
96 | 96 | ||
97 | /* Install the new table into the local data structures */ | 97 | /* Install the new table into the local data structures */ |
98 | 98 | ||
99 | obj_desc->reference.object = ACPI_CAST_PTR(void, table_index); | 99 | obj_desc->reference.object = ACPI_CAST_PTR(void, |
100 | (unsigned long)table_index); | ||
100 | 101 | ||
101 | /* Add the table to the namespace */ | 102 | /* Add the table to the namespace */ |
102 | 103 | ||
@@ -128,12 +129,12 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state, | |||
128 | { | 129 | { |
129 | acpi_status status; | 130 | acpi_status status; |
130 | union acpi_operand_object **operand = &walk_state->operands[0]; | 131 | union acpi_operand_object **operand = &walk_state->operands[0]; |
131 | acpi_native_uint table_index; | ||
132 | struct acpi_namespace_node *parent_node; | 132 | struct acpi_namespace_node *parent_node; |
133 | struct acpi_namespace_node *start_node; | 133 | struct acpi_namespace_node *start_node; |
134 | struct acpi_namespace_node *parameter_node = NULL; | 134 | struct acpi_namespace_node *parameter_node = NULL; |
135 | union acpi_operand_object *ddb_handle; | 135 | union acpi_operand_object *ddb_handle; |
136 | struct acpi_table_header *table; | 136 | struct acpi_table_header *table; |
137 | u32 table_index; | ||
137 | 138 | ||
138 | ACPI_FUNCTION_TRACE(ex_load_table_op); | 139 | ACPI_FUNCTION_TRACE(ex_load_table_op); |
139 | 140 | ||
@@ -280,7 +281,7 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc, | |||
280 | { | 281 | { |
281 | union acpi_operand_object *ddb_handle; | 282 | union acpi_operand_object *ddb_handle; |
282 | struct acpi_table_desc table_desc; | 283 | struct acpi_table_desc table_desc; |
283 | acpi_native_uint table_index; | 284 | u32 table_index; |
284 | acpi_status status; | 285 | acpi_status status; |
285 | u32 length; | 286 | u32 length; |
286 | 287 | ||
@@ -437,7 +438,7 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle) | |||
437 | { | 438 | { |
438 | acpi_status status = AE_OK; | 439 | acpi_status status = AE_OK; |
439 | union acpi_operand_object *table_desc = ddb_handle; | 440 | union acpi_operand_object *table_desc = ddb_handle; |
440 | acpi_native_uint table_index; | 441 | u32 table_index; |
441 | struct acpi_table_header *table; | 442 | struct acpi_table_header *table; |
442 | 443 | ||
443 | ACPI_FUNCTION_TRACE(ex_unload_table); | 444 | ACPI_FUNCTION_TRACE(ex_unload_table); |
@@ -454,9 +455,9 @@ acpi_status acpi_ex_unload_table(union acpi_operand_object *ddb_handle) | |||
454 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 455 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
455 | } | 456 | } |
456 | 457 | ||
457 | /* Get the table index from the ddb_handle */ | 458 | /* Get the table index from the ddb_handle (acpi_size for 64-bit case) */ |
458 | 459 | ||
459 | table_index = (acpi_native_uint) table_desc->reference.object; | 460 | table_index = (u32) (acpi_size) table_desc->reference.object; |
460 | 461 | ||
461 | /* Invoke table handler if present */ | 462 | /* Invoke table handler if present */ |
462 | 463 | ||
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c index fd954b4ed83d..261d97516d9b 100644 --- a/drivers/acpi/executer/exconvrt.c +++ b/drivers/acpi/executer/exconvrt.c | |||
@@ -288,11 +288,11 @@ acpi_ex_convert_to_ascii(acpi_integer integer, | |||
288 | u16 base, u8 * string, u8 data_width) | 288 | u16 base, u8 * string, u8 data_width) |
289 | { | 289 | { |
290 | acpi_integer digit; | 290 | acpi_integer digit; |
291 | acpi_native_uint i; | 291 | u32 i; |
292 | acpi_native_uint j; | 292 | u32 j; |
293 | acpi_native_uint k = 0; | 293 | u32 k = 0; |
294 | acpi_native_uint hex_length; | 294 | u32 hex_length; |
295 | acpi_native_uint decimal_length; | 295 | u32 decimal_length; |
296 | u32 remainder; | 296 | u32 remainder; |
297 | u8 supress_zeros; | 297 | u8 supress_zeros; |
298 | 298 | ||
@@ -348,7 +348,7 @@ acpi_ex_convert_to_ascii(acpi_integer integer, | |||
348 | 348 | ||
349 | /* hex_length: 2 ascii hex chars per data byte */ | 349 | /* hex_length: 2 ascii hex chars per data byte */ |
350 | 350 | ||
351 | hex_length = (acpi_native_uint) ACPI_MUL_2(data_width); | 351 | hex_length = ACPI_MUL_2(data_width); |
352 | for (i = 0, j = (hex_length - 1); i < hex_length; i++, j--) { | 352 | for (i = 0, j = (hex_length - 1); i < hex_length; i++, j--) { |
353 | 353 | ||
354 | /* Get one hex digit, most significant digits first */ | 354 | /* Get one hex digit, most significant digits first */ |
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c index 60e62c4f0577..ad09696d5069 100644 --- a/drivers/acpi/executer/excreate.c +++ b/drivers/acpi/executer/excreate.c | |||
@@ -45,8 +45,6 @@ | |||
45 | #include <acpi/acinterp.h> | 45 | #include <acpi/acinterp.h> |
46 | #include <acpi/amlcode.h> | 46 | #include <acpi/amlcode.h> |
47 | #include <acpi/acnamesp.h> | 47 | #include <acpi/acnamesp.h> |
48 | #include <acpi/acevents.h> | ||
49 | #include <acpi/actables.h> | ||
50 | 48 | ||
51 | #define _COMPONENT ACPI_EXECUTER | 49 | #define _COMPONENT ACPI_EXECUTER |
52 | ACPI_MODULE_NAME("excreate") | 50 | ACPI_MODULE_NAME("excreate") |
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c index 74f1b22601b3..2be2e2bf95bf 100644 --- a/drivers/acpi/executer/exdump.c +++ b/drivers/acpi/executer/exdump.c | |||
@@ -580,25 +580,22 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth) | |||
580 | 580 | ||
581 | case ACPI_TYPE_BUFFER: | 581 | case ACPI_TYPE_BUFFER: |
582 | 582 | ||
583 | acpi_os_printf("Buffer len %X @ %p\n", | 583 | acpi_os_printf("Buffer length %.2X @ %p\n", |
584 | obj_desc->buffer.length, | 584 | obj_desc->buffer.length, |
585 | obj_desc->buffer.pointer); | 585 | obj_desc->buffer.pointer); |
586 | 586 | ||
587 | length = obj_desc->buffer.length; | ||
588 | if (length > 64) { | ||
589 | length = 64; | ||
590 | } | ||
591 | |||
592 | /* Debug only -- dump the buffer contents */ | 587 | /* Debug only -- dump the buffer contents */ |
593 | 588 | ||
594 | if (obj_desc->buffer.pointer) { | 589 | if (obj_desc->buffer.pointer) { |
595 | acpi_os_printf("Buffer Contents: "); | 590 | length = obj_desc->buffer.length; |
596 | 591 | if (length > 128) { | |
597 | for (index = 0; index < length; index++) { | 592 | length = 128; |
598 | acpi_os_printf(" %02x", | ||
599 | obj_desc->buffer.pointer[index]); | ||
600 | } | 593 | } |
601 | acpi_os_printf("\n"); | 594 | |
595 | acpi_os_printf | ||
596 | ("Buffer Contents: (displaying length 0x%.2X)\n", | ||
597 | length); | ||
598 | ACPI_DUMP_BUFFER(obj_desc->buffer.pointer, length); | ||
602 | } | 599 | } |
603 | break; | 600 | break; |
604 | 601 | ||
@@ -756,54 +753,42 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth) | |||
756 | * | 753 | * |
757 | * FUNCTION: acpi_ex_dump_operands | 754 | * FUNCTION: acpi_ex_dump_operands |
758 | * | 755 | * |
759 | * PARAMETERS: Operands - Operand list | 756 | * PARAMETERS: Operands - A list of Operand objects |
760 | * interpreter_mode - Load or Exec | 757 | * opcode_name - AML opcode name |
761 | * Ident - Identification | 758 | * num_operands - Operand count for this opcode |
762 | * num_levels - # of stack entries to dump above line | ||
763 | * Note - Output notation | ||
764 | * module_name - Caller's module name | ||
765 | * line_number - Caller's invocation line number | ||
766 | * | 759 | * |
767 | * DESCRIPTION: Dump the object stack | 760 | * DESCRIPTION: Dump the operands associated with the opcode |
768 | * | 761 | * |
769 | ******************************************************************************/ | 762 | ******************************************************************************/ |
770 | 763 | ||
771 | void | 764 | void |
772 | acpi_ex_dump_operands(union acpi_operand_object **operands, | 765 | acpi_ex_dump_operands(union acpi_operand_object **operands, |
773 | acpi_interpreter_mode interpreter_mode, | 766 | const char *opcode_name, u32 num_operands) |
774 | char *ident, | ||
775 | u32 num_levels, | ||
776 | char *note, char *module_name, u32 line_number) | ||
777 | { | 767 | { |
778 | acpi_native_uint i; | ||
779 | |||
780 | ACPI_FUNCTION_NAME(ex_dump_operands); | 768 | ACPI_FUNCTION_NAME(ex_dump_operands); |
781 | 769 | ||
782 | if (!ident) { | 770 | if (!opcode_name) { |
783 | ident = "?"; | 771 | opcode_name = "UNKNOWN"; |
784 | } | ||
785 | |||
786 | if (!note) { | ||
787 | note = "?"; | ||
788 | } | 772 | } |
789 | 773 | ||
790 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 774 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
791 | "************* Operand Stack Contents (Opcode [%s], %d Operands)\n", | 775 | "**** Start operand dump for opcode [%s], %d operands\n", |
792 | ident, num_levels)); | 776 | opcode_name, num_operands)); |
793 | 777 | ||
794 | if (num_levels == 0) { | 778 | if (num_operands == 0) { |
795 | num_levels = 1; | 779 | num_operands = 1; |
796 | } | 780 | } |
797 | 781 | ||
798 | /* Dump the operand stack starting at the top */ | 782 | /* Dump the individual operands */ |
799 | 783 | ||
800 | for (i = 0; num_levels > 0; i--, num_levels--) { | 784 | while (num_operands) { |
801 | acpi_ex_dump_operand(operands[i], 0); | 785 | acpi_ex_dump_operand(*operands, 0); |
786 | operands++; | ||
787 | num_operands--; | ||
802 | } | 788 | } |
803 | 789 | ||
804 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | 790 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
805 | "************* Operand Stack dump from %s(%d), %s\n", | 791 | "**** End operand dump for [%s]\n", opcode_name)); |
806 | module_name, line_number, note)); | ||
807 | return; | 792 | return; |
808 | } | 793 | } |
809 | 794 | ||
diff --git a/drivers/acpi/executer/exfldio.c b/drivers/acpi/executer/exfldio.c index e336b5dc7a50..9ff9d1f4615d 100644 --- a/drivers/acpi/executer/exfldio.c +++ b/drivers/acpi/executer/exfldio.c | |||
@@ -153,14 +153,15 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc, | |||
153 | /* | 153 | /* |
154 | * Slack mode only: We will go ahead and allow access to this | 154 | * Slack mode only: We will go ahead and allow access to this |
155 | * field if it is within the region length rounded up to the next | 155 | * field if it is within the region length rounded up to the next |
156 | * access width boundary. | 156 | * access width boundary. acpi_size cast for 64-bit compile. |
157 | */ | 157 | */ |
158 | if (ACPI_ROUND_UP(rgn_desc->region.length, | 158 | if (ACPI_ROUND_UP(rgn_desc->region.length, |
159 | obj_desc->common_field. | 159 | obj_desc->common_field. |
160 | access_byte_width) >= | 160 | access_byte_width) >= |
161 | (obj_desc->common_field.base_byte_offset + | 161 | ((acpi_size) obj_desc->common_field. |
162 | (acpi_native_uint) obj_desc->common_field. | 162 | base_byte_offset + |
163 | access_byte_width + field_datum_byte_offset)) { | 163 | obj_desc->common_field.access_byte_width + |
164 | field_datum_byte_offset)) { | ||
164 | return_ACPI_STATUS(AE_OK); | 165 | return_ACPI_STATUS(AE_OK); |
165 | } | 166 | } |
166 | } | 167 | } |
diff --git a/drivers/acpi/executer/exmisc.c b/drivers/acpi/executer/exmisc.c index cc956a5b5267..731414a581a6 100644 --- a/drivers/acpi/executer/exmisc.c +++ b/drivers/acpi/executer/exmisc.c | |||
@@ -329,8 +329,8 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0, | |||
329 | 329 | ||
330 | /* Result of two Strings is a String */ | 330 | /* Result of two Strings is a String */ |
331 | 331 | ||
332 | return_desc = acpi_ut_create_string_object((acpi_size) | 332 | return_desc = acpi_ut_create_string_object(((acpi_size) |
333 | (operand0->string. | 333 | operand0->string. |
334 | length + | 334 | length + |
335 | local_operand1-> | 335 | local_operand1-> |
336 | string.length)); | 336 | string.length)); |
@@ -352,8 +352,8 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0, | |||
352 | 352 | ||
353 | /* Result of two Buffers is a Buffer */ | 353 | /* Result of two Buffers is a Buffer */ |
354 | 354 | ||
355 | return_desc = acpi_ut_create_buffer_object((acpi_size) | 355 | return_desc = acpi_ut_create_buffer_object(((acpi_size) |
356 | (operand0->buffer. | 356 | operand0->buffer. |
357 | length + | 357 | length + |
358 | local_operand1-> | 358 | local_operand1-> |
359 | buffer.length)); | 359 | buffer.length)); |
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c index 3a2f8cd4c62a..5d438c32989d 100644 --- a/drivers/acpi/executer/exprep.c +++ b/drivers/acpi/executer/exprep.c | |||
@@ -503,11 +503,11 @@ acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info) | |||
503 | */ | 503 | */ |
504 | second_desc = obj_desc->common.next_object; | 504 | second_desc = obj_desc->common.next_object; |
505 | second_desc->extra.aml_start = | 505 | second_desc->extra.aml_start = |
506 | ((union acpi_parse_object *)(info->data_register_node))-> | 506 | ACPI_CAST_PTR(union acpi_parse_object, |
507 | named.data; | 507 | info->data_register_node)->named.data; |
508 | second_desc->extra.aml_length = | 508 | second_desc->extra.aml_length = |
509 | ((union acpi_parse_object *)(info->data_register_node))-> | 509 | ACPI_CAST_PTR(union acpi_parse_object, |
510 | named.length; | 510 | info->data_register_node)->named.length; |
511 | 511 | ||
512 | break; | 512 | break; |
513 | 513 | ||
diff --git a/drivers/acpi/executer/exregion.c b/drivers/acpi/executer/exregion.c index 7cd8bb54fa01..7a41c409ae4d 100644 --- a/drivers/acpi/executer/exregion.c +++ b/drivers/acpi/executer/exregion.c | |||
@@ -156,7 +156,7 @@ acpi_ex_system_memory_space_handler(u32 function, | |||
156 | /* Create a new mapping starting at the address given */ | 156 | /* Create a new mapping starting at the address given */ |
157 | 157 | ||
158 | mem_info->mapped_logical_address = | 158 | mem_info->mapped_logical_address = |
159 | acpi_os_map_memory((acpi_native_uint) address, window_size); | 159 | acpi_os_map_memory((acpi_physical_address) address, window_size); |
160 | if (!mem_info->mapped_logical_address) { | 160 | if (!mem_info->mapped_logical_address) { |
161 | ACPI_ERROR((AE_INFO, | 161 | ACPI_ERROR((AE_INFO, |
162 | "Could not map memory at %8.8X%8.8X, size %X", | 162 | "Could not map memory at %8.8X%8.8X, size %X", |
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c index 73e29e566a70..54085f16ec28 100644 --- a/drivers/acpi/executer/exresop.c +++ b/drivers/acpi/executer/exresop.c | |||
@@ -698,5 +698,9 @@ acpi_ex_resolve_operands(u16 opcode, | |||
698 | } | 698 | } |
699 | } | 699 | } |
700 | 700 | ||
701 | ACPI_DUMP_OPERANDS(walk_state->operands, | ||
702 | acpi_ps_get_opcode_name(opcode), | ||
703 | walk_state->num_operands); | ||
704 | |||
701 | return_ACPI_STATUS(status); | 705 | return_ACPI_STATUS(status); |
702 | } | 706 | } |
diff --git a/drivers/acpi/executer/exstore.c b/drivers/acpi/executer/exstore.c index 76c875bc3154..38b55e352495 100644 --- a/drivers/acpi/executer/exstore.c +++ b/drivers/acpi/executer/exstore.c | |||
@@ -343,12 +343,6 @@ acpi_ex_store(union acpi_operand_object *source_desc, | |||
343 | acpi_ut_get_object_type_name(dest_desc), | 343 | acpi_ut_get_object_type_name(dest_desc), |
344 | dest_desc)); | 344 | dest_desc)); |
345 | 345 | ||
346 | ACPI_DUMP_STACK_ENTRY(source_desc); | ||
347 | ACPI_DUMP_STACK_ENTRY(dest_desc); | ||
348 | ACPI_DUMP_OPERANDS(&dest_desc, ACPI_IMODE_EXECUTE, "ExStore", | ||
349 | 2, | ||
350 | "Target is not a Reference or Constant object"); | ||
351 | |||
352 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); | 346 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
353 | } | 347 | } |
354 | 348 | ||
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index 6cf10cbc1eee..55c17afbe669 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c | |||
@@ -148,7 +148,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer, | |||
148 | int result = 0; | 148 | int result = 0; |
149 | struct seq_file *m = file->private_data; | 149 | struct seq_file *m = file->private_data; |
150 | struct acpi_device *device = m->private; | 150 | struct acpi_device *device = m->private; |
151 | char state_string[12] = { '\0' }; | 151 | char state_string[3] = { '\0' }; |
152 | 152 | ||
153 | if (count > sizeof(state_string) - 1) | 153 | if (count > sizeof(state_string) - 1) |
154 | return -EINVAL; | 154 | return -EINVAL; |
@@ -157,6 +157,12 @@ acpi_fan_write_state(struct file *file, const char __user * buffer, | |||
157 | return -EFAULT; | 157 | return -EFAULT; |
158 | 158 | ||
159 | state_string[count] = '\0'; | 159 | state_string[count] = '\0'; |
160 | if ((state_string[0] < '0') || (state_string[0] > '3')) | ||
161 | return -EINVAL; | ||
162 | if (state_string[1] == '\n') | ||
163 | state_string[1] = '\0'; | ||
164 | if (state_string[1] != '\0') | ||
165 | return -EINVAL; | ||
160 | 166 | ||
161 | result = acpi_bus_set_power(device->handle, | 167 | result = acpi_bus_set_power(device->handle, |
162 | simple_strtoul(state_string, NULL, 0)); | 168 | simple_strtoul(state_string, NULL, 0)); |
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 9b227d4dc9c9..0f2dd81736bd 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c | |||
@@ -166,6 +166,8 @@ static int acpi_bind_one(struct device *dev, acpi_handle handle) | |||
166 | "firmware_node"); | 166 | "firmware_node"); |
167 | ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, | 167 | ret = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, |
168 | "physical_node"); | 168 | "physical_node"); |
169 | if (acpi_dev->wakeup.flags.valid) | ||
170 | device_set_wakeup_capable(dev, true); | ||
169 | } | 171 | } |
170 | 172 | ||
171 | return 0; | 173 | return 0; |
@@ -336,6 +338,9 @@ static int __init acpi_rtc_init(void) | |||
336 | if (acpi_disabled) | 338 | if (acpi_disabled) |
337 | return 0; | 339 | return 0; |
338 | 340 | ||
341 | if (acpi_disabled) | ||
342 | return 0; | ||
343 | |||
339 | if (dev) { | 344 | if (dev) { |
340 | rtc_wake_setup(); | 345 | rtc_wake_setup(); |
341 | rtc_info.wake_on = rtc_wake_on; | 346 | rtc_info.wake_on = rtc_wake_on; |
diff --git a/drivers/acpi/hardware/hwgpe.c b/drivers/acpi/hardware/hwgpe.c index 14bc4f456ae8..0b80db9d9197 100644 --- a/drivers/acpi/hardware/hwgpe.c +++ b/drivers/acpi/hardware/hwgpe.c | |||
@@ -55,6 +55,54 @@ acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, | |||
55 | 55 | ||
56 | /****************************************************************************** | 56 | /****************************************************************************** |
57 | * | 57 | * |
58 | * FUNCTION: acpi_hw_low_disable_gpe | ||
59 | * | ||
60 | * PARAMETERS: gpe_event_info - Info block for the GPE to be disabled | ||
61 | * | ||
62 | * RETURN: Status | ||
63 | * | ||
64 | * DESCRIPTION: Disable a single GPE in the enable register. | ||
65 | * | ||
66 | ******************************************************************************/ | ||
67 | |||
68 | acpi_status acpi_hw_low_disable_gpe(struct acpi_gpe_event_info *gpe_event_info) | ||
69 | { | ||
70 | struct acpi_gpe_register_info *gpe_register_info; | ||
71 | acpi_status status; | ||
72 | u32 enable_mask; | ||
73 | |||
74 | /* Get the info block for the entire GPE register */ | ||
75 | |||
76 | gpe_register_info = gpe_event_info->register_info; | ||
77 | if (!gpe_register_info) { | ||
78 | return (AE_NOT_EXIST); | ||
79 | } | ||
80 | |||
81 | /* Get current value of the enable register that contains this GPE */ | ||
82 | |||
83 | status = acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH, &enable_mask, | ||
84 | &gpe_register_info->enable_address); | ||
85 | if (ACPI_FAILURE(status)) { | ||
86 | return (status); | ||
87 | } | ||
88 | |||
89 | /* Clear just the bit that corresponds to this GPE */ | ||
90 | |||
91 | ACPI_CLEAR_BIT(enable_mask, | ||
92 | ((u32) 1 << | ||
93 | (gpe_event_info->gpe_number - | ||
94 | gpe_register_info->base_gpe_number))); | ||
95 | |||
96 | /* Write the updated enable mask */ | ||
97 | |||
98 | status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, enable_mask, | ||
99 | &gpe_register_info->enable_address); | ||
100 | |||
101 | return (status); | ||
102 | } | ||
103 | |||
104 | /****************************************************************************** | ||
105 | * | ||
58 | * FUNCTION: acpi_hw_write_gpe_enable_reg | 106 | * FUNCTION: acpi_hw_write_gpe_enable_reg |
59 | * | 107 | * |
60 | * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled | 108 | * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled |
@@ -68,7 +116,7 @@ acpi_hw_enable_wakeup_gpe_block(struct acpi_gpe_xrupt_info *gpe_xrupt_info, | |||
68 | ******************************************************************************/ | 116 | ******************************************************************************/ |
69 | 117 | ||
70 | acpi_status | 118 | acpi_status |
71 | acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info *gpe_event_info) | 119 | acpi_hw_write_gpe_enable_reg(struct acpi_gpe_event_info * gpe_event_info) |
72 | { | 120 | { |
73 | struct acpi_gpe_register_info *gpe_register_info; | 121 | struct acpi_gpe_register_info *gpe_register_info; |
74 | acpi_status status; | 122 | acpi_status status; |
@@ -138,7 +186,6 @@ acpi_status acpi_hw_clear_gpe(struct acpi_gpe_event_info * gpe_event_info) | |||
138 | * | 186 | * |
139 | ******************************************************************************/ | 187 | ******************************************************************************/ |
140 | 188 | ||
141 | #ifdef ACPI_FUTURE_USAGE | ||
142 | acpi_status | 189 | acpi_status |
143 | acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info, | 190 | acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info, |
144 | acpi_event_status * event_status) | 191 | acpi_event_status * event_status) |
@@ -198,7 +245,6 @@ acpi_hw_get_gpe_status(struct acpi_gpe_event_info * gpe_event_info, | |||
198 | unlock_and_exit: | 245 | unlock_and_exit: |
199 | return (status); | 246 | return (status); |
200 | } | 247 | } |
201 | #endif /* ACPI_FUTURE_USAGE */ | ||
202 | 248 | ||
203 | /****************************************************************************** | 249 | /****************************************************************************** |
204 | * | 250 | * |
diff --git a/drivers/acpi/namespace/nsdump.c b/drivers/acpi/namespace/nsdump.c index 5445751b8a3e..0ab22004728a 100644 --- a/drivers/acpi/namespace/nsdump.c +++ b/drivers/acpi/namespace/nsdump.c | |||
@@ -73,7 +73,7 @@ acpi_ns_dump_one_device(acpi_handle obj_handle, | |||
73 | 73 | ||
74 | void acpi_ns_print_pathname(u32 num_segments, char *pathname) | 74 | void acpi_ns_print_pathname(u32 num_segments, char *pathname) |
75 | { | 75 | { |
76 | acpi_native_uint i; | 76 | u32 i; |
77 | 77 | ||
78 | ACPI_FUNCTION_NAME(ns_print_pathname); | 78 | ACPI_FUNCTION_NAME(ns_print_pathname); |
79 | 79 | ||
@@ -515,12 +515,12 @@ acpi_ns_dump_one_object(acpi_handle obj_handle, | |||
515 | 515 | ||
516 | if (obj_type > ACPI_TYPE_LOCAL_MAX) { | 516 | if (obj_type > ACPI_TYPE_LOCAL_MAX) { |
517 | acpi_os_printf | 517 | acpi_os_printf |
518 | ("(Ptr to ACPI Object type %X [UNKNOWN])\n", | 518 | ("(Pointer to ACPI Object type %.2X [UNKNOWN])\n", |
519 | obj_type); | 519 | obj_type); |
520 | bytes_to_dump = 32; | 520 | bytes_to_dump = 32; |
521 | } else { | 521 | } else { |
522 | acpi_os_printf | 522 | acpi_os_printf |
523 | ("(Ptr to ACPI Object type %X [%s])\n", | 523 | ("(Pointer to ACPI Object type %.2X [%s])\n", |
524 | obj_type, acpi_ut_get_type_name(obj_type)); | 524 | obj_type, acpi_ut_get_type_name(obj_type)); |
525 | bytes_to_dump = | 525 | bytes_to_dump = |
526 | sizeof(union acpi_operand_object); | 526 | sizeof(union acpi_operand_object); |
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c index 14bdfa92bea0..d369164e00b0 100644 --- a/drivers/acpi/namespace/nseval.c +++ b/drivers/acpi/namespace/nseval.c | |||
@@ -138,6 +138,41 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info) | |||
138 | return_ACPI_STATUS(AE_NULL_OBJECT); | 138 | return_ACPI_STATUS(AE_NULL_OBJECT); |
139 | } | 139 | } |
140 | 140 | ||
141 | /* | ||
142 | * Calculate the number of arguments being passed to the method | ||
143 | */ | ||
144 | |||
145 | info->param_count = 0; | ||
146 | if (info->parameters) { | ||
147 | while (info->parameters[info->param_count]) | ||
148 | info->param_count++; | ||
149 | } | ||
150 | |||
151 | /* Error if too few arguments were passed in */ | ||
152 | |||
153 | if (info->param_count < info->obj_desc->method.param_count) { | ||
154 | ACPI_ERROR((AE_INFO, | ||
155 | "Insufficient arguments - " | ||
156 | "method [%4.4s] needs %d, found %d", | ||
157 | acpi_ut_get_node_name(info->resolved_node), | ||
158 | info->obj_desc->method.param_count, | ||
159 | info->param_count)); | ||
160 | return_ACPI_STATUS(AE_MISSING_ARGUMENTS); | ||
161 | } | ||
162 | |||
163 | /* Just a warning if too many arguments */ | ||
164 | |||
165 | else if (info->param_count > | ||
166 | info->obj_desc->method.param_count) { | ||
167 | ACPI_WARNING((AE_INFO, | ||
168 | "Excess arguments - " | ||
169 | "method [%4.4s] needs %d, found %d", | ||
170 | acpi_ut_get_node_name(info-> | ||
171 | resolved_node), | ||
172 | info->obj_desc->method.param_count, | ||
173 | info->param_count)); | ||
174 | } | ||
175 | |||
141 | ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:", | 176 | ACPI_DUMP_PATHNAME(info->resolved_node, "Execute Method:", |
142 | ACPI_LV_INFO, _COMPONENT); | 177 | ACPI_LV_INFO, _COMPONENT); |
143 | 178 | ||
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c index 6d6d930c8e18..e4c57510d798 100644 --- a/drivers/acpi/namespace/nsinit.c +++ b/drivers/acpi/namespace/nsinit.c | |||
@@ -542,7 +542,6 @@ acpi_ns_init_one_device(acpi_handle obj_handle, | |||
542 | info->prefix_node = device_node; | 542 | info->prefix_node = device_node; |
543 | info->pathname = METHOD_NAME__INI; | 543 | info->pathname = METHOD_NAME__INI; |
544 | info->parameters = NULL; | 544 | info->parameters = NULL; |
545 | info->parameter_type = ACPI_PARAM_ARGS; | ||
546 | info->flags = ACPI_IGNORE_RETURN_VALUE; | 545 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
547 | 546 | ||
548 | /* | 547 | /* |
diff --git a/drivers/acpi/namespace/nsload.c b/drivers/acpi/namespace/nsload.c index 2c92f6cf5ce1..a4a412b7c029 100644 --- a/drivers/acpi/namespace/nsload.c +++ b/drivers/acpi/namespace/nsload.c | |||
@@ -71,8 +71,7 @@ static acpi_status acpi_ns_delete_subtree(acpi_handle start_handle); | |||
71 | ******************************************************************************/ | 71 | ******************************************************************************/ |
72 | 72 | ||
73 | acpi_status | 73 | acpi_status |
74 | acpi_ns_load_table(acpi_native_uint table_index, | 74 | acpi_ns_load_table(u32 table_index, struct acpi_namespace_node *node) |
75 | struct acpi_namespace_node *node) | ||
76 | { | 75 | { |
77 | acpi_status status; | 76 | acpi_status status; |
78 | 77 | ||
diff --git a/drivers/acpi/namespace/nsparse.c b/drivers/acpi/namespace/nsparse.c index 46a79b0103b6..a82271a9dbb3 100644 --- a/drivers/acpi/namespace/nsparse.c +++ b/drivers/acpi/namespace/nsparse.c | |||
@@ -63,13 +63,13 @@ ACPI_MODULE_NAME("nsparse") | |||
63 | * | 63 | * |
64 | ******************************************************************************/ | 64 | ******************************************************************************/ |
65 | acpi_status | 65 | acpi_status |
66 | acpi_ns_one_complete_parse(acpi_native_uint pass_number, | 66 | acpi_ns_one_complete_parse(u32 pass_number, |
67 | acpi_native_uint table_index, | 67 | u32 table_index, |
68 | struct acpi_namespace_node * start_node) | 68 | struct acpi_namespace_node *start_node) |
69 | { | 69 | { |
70 | union acpi_parse_object *parse_root; | 70 | union acpi_parse_object *parse_root; |
71 | acpi_status status; | 71 | acpi_status status; |
72 | acpi_native_uint aml_length; | 72 | u32 aml_length; |
73 | u8 *aml_start; | 73 | u8 *aml_start; |
74 | struct acpi_walk_state *walk_state; | 74 | struct acpi_walk_state *walk_state; |
75 | struct acpi_table_header *table; | 75 | struct acpi_table_header *table; |
@@ -112,8 +112,8 @@ acpi_ns_one_complete_parse(acpi_native_uint pass_number, | |||
112 | aml_start = (u8 *) table + sizeof(struct acpi_table_header); | 112 | aml_start = (u8 *) table + sizeof(struct acpi_table_header); |
113 | aml_length = table->length - sizeof(struct acpi_table_header); | 113 | aml_length = table->length - sizeof(struct acpi_table_header); |
114 | status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, | 114 | status = acpi_ds_init_aml_walk(walk_state, parse_root, NULL, |
115 | aml_start, (u32) aml_length, | 115 | aml_start, aml_length, NULL, |
116 | NULL, (u8) pass_number); | 116 | (u8) pass_number); |
117 | } | 117 | } |
118 | 118 | ||
119 | if (ACPI_FAILURE(status)) { | 119 | if (ACPI_FAILURE(status)) { |
@@ -158,8 +158,7 @@ acpi_ns_one_complete_parse(acpi_native_uint pass_number, | |||
158 | ******************************************************************************/ | 158 | ******************************************************************************/ |
159 | 159 | ||
160 | acpi_status | 160 | acpi_status |
161 | acpi_ns_parse_table(acpi_native_uint table_index, | 161 | acpi_ns_parse_table(u32 table_index, struct acpi_namespace_node *start_node) |
162 | struct acpi_namespace_node *start_node) | ||
163 | { | 162 | { |
164 | acpi_status status; | 163 | acpi_status status; |
165 | 164 | ||
diff --git a/drivers/acpi/namespace/nsutils.c b/drivers/acpi/namespace/nsutils.c index 64c039843ed2..b0817e1127b1 100644 --- a/drivers/acpi/namespace/nsutils.c +++ b/drivers/acpi/namespace/nsutils.c | |||
@@ -73,9 +73,9 @@ acpi_name acpi_ns_find_parent_name(struct acpi_namespace_node *node_to_search); | |||
73 | ******************************************************************************/ | 73 | ******************************************************************************/ |
74 | 74 | ||
75 | void | 75 | void |
76 | acpi_ns_report_error(char *module_name, | 76 | acpi_ns_report_error(const char *module_name, |
77 | u32 line_number, | 77 | u32 line_number, |
78 | char *internal_name, acpi_status lookup_status) | 78 | const char *internal_name, acpi_status lookup_status) |
79 | { | 79 | { |
80 | acpi_status status; | 80 | acpi_status status; |
81 | u32 bad_name; | 81 | u32 bad_name; |
@@ -130,11 +130,11 @@ acpi_ns_report_error(char *module_name, | |||
130 | ******************************************************************************/ | 130 | ******************************************************************************/ |
131 | 131 | ||
132 | void | 132 | void |
133 | acpi_ns_report_method_error(char *module_name, | 133 | acpi_ns_report_method_error(const char *module_name, |
134 | u32 line_number, | 134 | u32 line_number, |
135 | char *message, | 135 | const char *message, |
136 | struct acpi_namespace_node *prefix_node, | 136 | struct acpi_namespace_node *prefix_node, |
137 | char *path, acpi_status method_status) | 137 | const char *path, acpi_status method_status) |
138 | { | 138 | { |
139 | acpi_status status; | 139 | acpi_status status; |
140 | struct acpi_namespace_node *node = prefix_node; | 140 | struct acpi_namespace_node *node = prefix_node; |
@@ -167,7 +167,8 @@ acpi_ns_report_method_error(char *module_name, | |||
167 | ******************************************************************************/ | 167 | ******************************************************************************/ |
168 | 168 | ||
169 | void | 169 | void |
170 | acpi_ns_print_node_pathname(struct acpi_namespace_node *node, char *message) | 170 | acpi_ns_print_node_pathname(struct acpi_namespace_node *node, |
171 | const char *message) | ||
171 | { | 172 | { |
172 | struct acpi_buffer buffer; | 173 | struct acpi_buffer buffer; |
173 | acpi_status status; | 174 | acpi_status status; |
@@ -296,7 +297,7 @@ u32 acpi_ns_local(acpi_object_type type) | |||
296 | 297 | ||
297 | void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info) | 298 | void acpi_ns_get_internal_name_length(struct acpi_namestring_info *info) |
298 | { | 299 | { |
299 | char *next_external_char; | 300 | const char *next_external_char; |
300 | u32 i; | 301 | u32 i; |
301 | 302 | ||
302 | ACPI_FUNCTION_ENTRY(); | 303 | ACPI_FUNCTION_ENTRY(); |
@@ -363,9 +364,9 @@ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info) | |||
363 | { | 364 | { |
364 | u32 num_segments = info->num_segments; | 365 | u32 num_segments = info->num_segments; |
365 | char *internal_name = info->internal_name; | 366 | char *internal_name = info->internal_name; |
366 | char *external_name = info->next_external_char; | 367 | const char *external_name = info->next_external_char; |
367 | char *result = NULL; | 368 | char *result = NULL; |
368 | acpi_native_uint i; | 369 | u32 i; |
369 | 370 | ||
370 | ACPI_FUNCTION_TRACE(ns_build_internal_name); | 371 | ACPI_FUNCTION_TRACE(ns_build_internal_name); |
371 | 372 | ||
@@ -400,12 +401,11 @@ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info) | |||
400 | result = &internal_name[i]; | 401 | result = &internal_name[i]; |
401 | } else if (num_segments == 2) { | 402 | } else if (num_segments == 2) { |
402 | internal_name[i] = AML_DUAL_NAME_PREFIX; | 403 | internal_name[i] = AML_DUAL_NAME_PREFIX; |
403 | result = &internal_name[(acpi_native_uint) (i + 1)]; | 404 | result = &internal_name[(acpi_size) i + 1]; |
404 | } else { | 405 | } else { |
405 | internal_name[i] = AML_MULTI_NAME_PREFIX_OP; | 406 | internal_name[i] = AML_MULTI_NAME_PREFIX_OP; |
406 | internal_name[(acpi_native_uint) (i + 1)] = | 407 | internal_name[(acpi_size) i + 1] = (char)num_segments; |
407 | (char)num_segments; | 408 | result = &internal_name[(acpi_size) i + 2]; |
408 | result = &internal_name[(acpi_native_uint) (i + 2)]; | ||
409 | } | 409 | } |
410 | } | 410 | } |
411 | 411 | ||
@@ -472,7 +472,8 @@ acpi_status acpi_ns_build_internal_name(struct acpi_namestring_info *info) | |||
472 | * | 472 | * |
473 | *******************************************************************************/ | 473 | *******************************************************************************/ |
474 | 474 | ||
475 | acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name) | 475 | acpi_status |
476 | acpi_ns_internalize_name(const char *external_name, char **converted_name) | ||
476 | { | 477 | { |
477 | char *internal_name; | 478 | char *internal_name; |
478 | struct acpi_namestring_info info; | 479 | struct acpi_namestring_info info; |
@@ -528,15 +529,15 @@ acpi_status acpi_ns_internalize_name(char *external_name, char **converted_name) | |||
528 | 529 | ||
529 | acpi_status | 530 | acpi_status |
530 | acpi_ns_externalize_name(u32 internal_name_length, | 531 | acpi_ns_externalize_name(u32 internal_name_length, |
531 | char *internal_name, | 532 | const char *internal_name, |
532 | u32 * converted_name_length, char **converted_name) | 533 | u32 * converted_name_length, char **converted_name) |
533 | { | 534 | { |
534 | acpi_native_uint names_index = 0; | 535 | u32 names_index = 0; |
535 | acpi_native_uint num_segments = 0; | 536 | u32 num_segments = 0; |
536 | acpi_native_uint required_length; | 537 | u32 required_length; |
537 | acpi_native_uint prefix_length = 0; | 538 | u32 prefix_length = 0; |
538 | acpi_native_uint i = 0; | 539 | u32 i = 0; |
539 | acpi_native_uint j = 0; | 540 | u32 j = 0; |
540 | 541 | ||
541 | ACPI_FUNCTION_TRACE(ns_externalize_name); | 542 | ACPI_FUNCTION_TRACE(ns_externalize_name); |
542 | 543 | ||
@@ -582,9 +583,8 @@ acpi_ns_externalize_name(u32 internal_name_length, | |||
582 | /* <count> 4-byte names */ | 583 | /* <count> 4-byte names */ |
583 | 584 | ||
584 | names_index = prefix_length + 2; | 585 | names_index = prefix_length + 2; |
585 | num_segments = (acpi_native_uint) (u8) | 586 | num_segments = (u8) |
586 | internal_name[(acpi_native_uint) | 587 | internal_name[(acpi_size) prefix_length + 1]; |
587 | (prefix_length + 1)]; | ||
588 | break; | 588 | break; |
589 | 589 | ||
590 | case AML_DUAL_NAME_PREFIX: | 590 | case AML_DUAL_NAME_PREFIX: |
@@ -823,7 +823,7 @@ u32 acpi_ns_opens_scope(acpi_object_type type) | |||
823 | 823 | ||
824 | acpi_status | 824 | acpi_status |
825 | acpi_ns_get_node(struct acpi_namespace_node *prefix_node, | 825 | acpi_ns_get_node(struct acpi_namespace_node *prefix_node, |
826 | char *pathname, | 826 | const char *pathname, |
827 | u32 flags, struct acpi_namespace_node **return_node) | 827 | u32 flags, struct acpi_namespace_node **return_node) |
828 | { | 828 | { |
829 | union acpi_generic_state scope_info; | 829 | union acpi_generic_state scope_info; |
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c index a8d549187c84..38be5865d95d 100644 --- a/drivers/acpi/namespace/nsxfeval.c +++ b/drivers/acpi/namespace/nsxfeval.c | |||
@@ -182,7 +182,6 @@ acpi_evaluate_object(acpi_handle handle, | |||
182 | } | 182 | } |
183 | 183 | ||
184 | info->pathname = pathname; | 184 | info->pathname = pathname; |
185 | info->parameter_type = ACPI_PARAM_ARGS; | ||
186 | 185 | ||
187 | /* Convert and validate the device handle */ | 186 | /* Convert and validate the device handle */ |
188 | 187 | ||
@@ -442,7 +441,7 @@ acpi_ns_get_device_callback(acpi_handle obj_handle, | |||
442 | u32 flags; | 441 | u32 flags; |
443 | struct acpica_device_id hid; | 442 | struct acpica_device_id hid; |
444 | struct acpi_compatible_id_list *cid; | 443 | struct acpi_compatible_id_list *cid; |
445 | acpi_native_uint i; | 444 | u32 i; |
446 | int found; | 445 | int found; |
447 | 446 | ||
448 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 447 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c index 658e5f3abae0..cb9864e39bae 100644 --- a/drivers/acpi/numa.c +++ b/drivers/acpi/numa.c | |||
@@ -120,10 +120,10 @@ acpi_table_print_srat_entry(struct acpi_subtable_header *header) | |||
120 | struct acpi_srat_mem_affinity *p = | 120 | struct acpi_srat_mem_affinity *p = |
121 | (struct acpi_srat_mem_affinity *)header; | 121 | (struct acpi_srat_mem_affinity *)header; |
122 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 122 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
123 | "SRAT Memory (0x%lx length 0x%lx type 0x%x) in proximity domain %d %s%s\n", | 123 | "SRAT Memory (0x%lx length 0x%lx) in proximity domain %d %s%s\n", |
124 | (unsigned long)p->base_address, | 124 | (unsigned long)p->base_address, |
125 | (unsigned long)p->length, | 125 | (unsigned long)p->length, |
126 | p->memory_type, p->proximity_domain, | 126 | p->proximity_domain, |
127 | (p->flags & ACPI_SRAT_MEM_ENABLED)? | 127 | (p->flags & ACPI_SRAT_MEM_ENABLED)? |
128 | "enabled" : "disabled", | 128 | "enabled" : "disabled", |
129 | (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)? | 129 | (p->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)? |
diff --git a/drivers/acpi/parser/psargs.c b/drivers/acpi/parser/psargs.c index e94463778845..d830b29b85b1 100644 --- a/drivers/acpi/parser/psargs.c +++ b/drivers/acpi/parser/psargs.c | |||
@@ -76,7 +76,7 @@ acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state) | |||
76 | { | 76 | { |
77 | u8 *aml = parser_state->aml; | 77 | u8 *aml = parser_state->aml; |
78 | u32 package_length = 0; | 78 | u32 package_length = 0; |
79 | acpi_native_uint byte_count; | 79 | u32 byte_count; |
80 | u8 byte_zero_mask = 0x3F; /* Default [0:5] */ | 80 | u8 byte_zero_mask = 0x3F; /* Default [0:5] */ |
81 | 81 | ||
82 | ACPI_FUNCTION_TRACE(ps_get_next_package_length); | 82 | ACPI_FUNCTION_TRACE(ps_get_next_package_length); |
@@ -86,7 +86,7 @@ acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state) | |||
86 | * used to encode the package length, either 0,1,2, or 3 | 86 | * used to encode the package length, either 0,1,2, or 3 |
87 | */ | 87 | */ |
88 | byte_count = (aml[0] >> 6); | 88 | byte_count = (aml[0] >> 6); |
89 | parser_state->aml += (byte_count + 1); | 89 | parser_state->aml += ((acpi_size) byte_count + 1); |
90 | 90 | ||
91 | /* Get bytes 3, 2, 1 as needed */ | 91 | /* Get bytes 3, 2, 1 as needed */ |
92 | 92 | ||
diff --git a/drivers/acpi/parser/psxface.c b/drivers/acpi/parser/psxface.c index 52581454c47c..270469aae842 100644 --- a/drivers/acpi/parser/psxface.c +++ b/drivers/acpi/parser/psxface.c | |||
@@ -333,9 +333,9 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info) | |||
333 | static void | 333 | static void |
334 | acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action) | 334 | acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action) |
335 | { | 335 | { |
336 | acpi_native_uint i; | 336 | u32 i; |
337 | 337 | ||
338 | if ((info->parameter_type == ACPI_PARAM_ARGS) && (info->parameters)) { | 338 | if (info->parameters) { |
339 | 339 | ||
340 | /* Update reference count for each parameter */ | 340 | /* Update reference count for each parameter */ |
341 | 341 | ||
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c index 89022a74faee..11acaee14d66 100644 --- a/drivers/acpi/pci_irq.c +++ b/drivers/acpi/pci_irq.c | |||
@@ -162,7 +162,7 @@ do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt) | |||
162 | !strcmp(prt->source, quirk->source) && | 162 | !strcmp(prt->source, quirk->source) && |
163 | strlen(prt->source) >= strlen(quirk->actual_source)) { | 163 | strlen(prt->source) >= strlen(quirk->actual_source)) { |
164 | printk(KERN_WARNING PREFIX "firmware reports " | 164 | printk(KERN_WARNING PREFIX "firmware reports " |
165 | "%04x:%02x:%02x[%c] connected to %s; " | 165 | "%04x:%02x:%02x PCI INT %c connected to %s; " |
166 | "changing to %s\n", | 166 | "changing to %s\n", |
167 | entry->id.segment, entry->id.bus, | 167 | entry->id.segment, entry->id.bus, |
168 | entry->id.device, 'A' + entry->pin, | 168 | entry->id.device, 'A' + entry->pin, |
@@ -429,7 +429,7 @@ acpi_pci_irq_derive(struct pci_dev *dev, | |||
429 | { | 429 | { |
430 | struct pci_dev *bridge = dev; | 430 | struct pci_dev *bridge = dev; |
431 | int irq = -1; | 431 | int irq = -1; |
432 | u8 bridge_pin = 0; | 432 | u8 bridge_pin = 0, orig_pin = pin; |
433 | 433 | ||
434 | 434 | ||
435 | if (!dev) | 435 | if (!dev) |
@@ -463,8 +463,8 @@ acpi_pci_irq_derive(struct pci_dev *dev, | |||
463 | } | 463 | } |
464 | 464 | ||
465 | if (irq < 0) { | 465 | if (irq < 0) { |
466 | printk(KERN_WARNING PREFIX "Unable to derive IRQ for device %s\n", | 466 | dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n", |
467 | pci_name(dev)); | 467 | 'A' + orig_pin); |
468 | return -1; | 468 | return -1; |
469 | } | 469 | } |
470 | 470 | ||
@@ -487,6 +487,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
487 | int triggering = ACPI_LEVEL_SENSITIVE; | 487 | int triggering = ACPI_LEVEL_SENSITIVE; |
488 | int polarity = ACPI_ACTIVE_LOW; | 488 | int polarity = ACPI_ACTIVE_LOW; |
489 | char *link = NULL; | 489 | char *link = NULL; |
490 | char link_desc[16]; | ||
490 | int rc; | 491 | int rc; |
491 | 492 | ||
492 | 493 | ||
@@ -503,7 +504,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
503 | pin--; | 504 | pin--; |
504 | 505 | ||
505 | if (!dev->bus) { | 506 | if (!dev->bus) { |
506 | printk(KERN_ERR PREFIX "Invalid (NULL) 'bus' field\n"); | 507 | dev_err(&dev->dev, "invalid (NULL) 'bus' field\n"); |
507 | return -ENODEV; | 508 | return -ENODEV; |
508 | } | 509 | } |
509 | 510 | ||
@@ -538,8 +539,7 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
538 | * driver reported one, then use it. Exit in any case. | 539 | * driver reported one, then use it. Exit in any case. |
539 | */ | 540 | */ |
540 | if (irq < 0) { | 541 | if (irq < 0) { |
541 | printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI", | 542 | dev_warn(&dev->dev, "PCI INT %c: no GSI", 'A' + pin); |
542 | pci_name(dev), ('A' + pin)); | ||
543 | /* Interrupt Line values above 0xF are forbidden */ | 543 | /* Interrupt Line values above 0xF are forbidden */ |
544 | if (dev->irq > 0 && (dev->irq <= 0xF)) { | 544 | if (dev->irq > 0 && (dev->irq <= 0xF)) { |
545 | printk(" - using IRQ %d\n", dev->irq); | 545 | printk(" - using IRQ %d\n", dev->irq); |
@@ -554,21 +554,21 @@ int acpi_pci_irq_enable(struct pci_dev *dev) | |||
554 | 554 | ||
555 | rc = acpi_register_gsi(irq, triggering, polarity); | 555 | rc = acpi_register_gsi(irq, triggering, polarity); |
556 | if (rc < 0) { | 556 | if (rc < 0) { |
557 | printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed " | 557 | dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n", |
558 | "to register GSI\n", pci_name(dev), ('A' + pin)); | 558 | 'A' + pin); |
559 | return rc; | 559 | return rc; |
560 | } | 560 | } |
561 | dev->irq = rc; | 561 | dev->irq = rc; |
562 | 562 | ||
563 | printk(KERN_INFO PREFIX "PCI Interrupt %s[%c] -> ", | ||
564 | pci_name(dev), 'A' + pin); | ||
565 | |||
566 | if (link) | 563 | if (link) |
567 | printk("Link [%s] -> ", link); | 564 | snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link); |
565 | else | ||
566 | link_desc[0] = '\0'; | ||
568 | 567 | ||
569 | printk("GSI %u (%s, %s) -> IRQ %d\n", irq, | 568 | dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n", |
570 | (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", | 569 | 'A' + pin, link_desc, irq, |
571 | (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); | 570 | (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", |
571 | (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); | ||
572 | 572 | ||
573 | return 0; | 573 | return 0; |
574 | } | 574 | } |
@@ -616,10 +616,6 @@ void acpi_pci_irq_disable(struct pci_dev *dev) | |||
616 | * (e.g. PCI_UNDEFINED_IRQ). | 616 | * (e.g. PCI_UNDEFINED_IRQ). |
617 | */ | 617 | */ |
618 | 618 | ||
619 | printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n", | 619 | dev_info(&dev->dev, "PCI INT %c disabled\n", 'A' + pin); |
620 | pci_name(dev)); | ||
621 | |||
622 | acpi_unregister_gsi(gsi); | 620 | acpi_unregister_gsi(gsi); |
623 | |||
624 | return; | ||
625 | } | 621 | } |
diff --git a/drivers/acpi/pci_slot.c b/drivers/acpi/pci_slot.c new file mode 100644 index 000000000000..b9ab030a52d5 --- /dev/null +++ b/drivers/acpi/pci_slot.c | |||
@@ -0,0 +1,368 @@ | |||
1 | /* | ||
2 | * pci_slot.c - ACPI PCI Slot Driver | ||
3 | * | ||
4 | * The code here is heavily leveraged from the acpiphp module. | ||
5 | * Thanks to Matthew Wilcox <matthew@wil.cx> for much guidance. | ||
6 | * Thanks to Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> for code | ||
7 | * review and fixes. | ||
8 | * | ||
9 | * Copyright (C) 2007 Alex Chiang <achiang@hp.com> | ||
10 | * Copyright (C) 2007 Hewlett-Packard Development Company, L.P. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms and conditions of the GNU General Public License, | ||
14 | * version 2, as published by the Free Software Foundation. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, but | ||
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License along | ||
22 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
24 | */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/types.h> | ||
30 | #include <linux/pci.h> | ||
31 | #include <linux/acpi.h> | ||
32 | #include <acpi/acpi_bus.h> | ||
33 | #include <acpi/acpi_drivers.h> | ||
34 | |||
35 | static int debug; | ||
36 | static int check_sta_before_sun; | ||
37 | |||
38 | #define DRIVER_VERSION "0.1" | ||
39 | #define DRIVER_AUTHOR "Alex Chiang <achiang@hp.com>" | ||
40 | #define DRIVER_DESC "ACPI PCI Slot Detection Driver" | ||
41 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
42 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
43 | MODULE_LICENSE("GPL"); | ||
44 | MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); | ||
45 | module_param(debug, bool, 0644); | ||
46 | |||
47 | #define _COMPONENT ACPI_PCI_COMPONENT | ||
48 | ACPI_MODULE_NAME("pci_slot"); | ||
49 | |||
50 | #define MY_NAME "pci_slot" | ||
51 | #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg) | ||
52 | #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg) | ||
53 | #define dbg(format, arg...) \ | ||
54 | do { \ | ||
55 | if (debug) \ | ||
56 | printk(KERN_DEBUG "%s: " format, \ | ||
57 | MY_NAME , ## arg); \ | ||
58 | } while (0) | ||
59 | |||
60 | #define SLOT_NAME_SIZE 20 /* Inspired by #define in acpiphp.h */ | ||
61 | |||
62 | struct acpi_pci_slot { | ||
63 | acpi_handle root_handle; /* handle of the root bridge */ | ||
64 | struct pci_slot *pci_slot; /* corresponding pci_slot */ | ||
65 | struct list_head list; /* node in the list of slots */ | ||
66 | }; | ||
67 | |||
68 | static int acpi_pci_slot_add(acpi_handle handle); | ||
69 | static void acpi_pci_slot_remove(acpi_handle handle); | ||
70 | |||
71 | static LIST_HEAD(slot_list); | ||
72 | static DEFINE_MUTEX(slot_list_lock); | ||
73 | static struct acpi_pci_driver acpi_pci_slot_driver = { | ||
74 | .add = acpi_pci_slot_add, | ||
75 | .remove = acpi_pci_slot_remove, | ||
76 | }; | ||
77 | |||
78 | static int | ||
79 | check_slot(acpi_handle handle, int *device, unsigned long *sun) | ||
80 | { | ||
81 | int retval = 0; | ||
82 | unsigned long adr, sta; | ||
83 | acpi_status status; | ||
84 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
85 | |||
86 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); | ||
87 | dbg("Checking slot on path: %s\n", (char *)buffer.pointer); | ||
88 | |||
89 | if (check_sta_before_sun) { | ||
90 | /* If SxFy doesn't have _STA, we just assume it's there */ | ||
91 | status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); | ||
92 | if (ACPI_SUCCESS(status) && !(sta & ACPI_STA_DEVICE_PRESENT)) { | ||
93 | retval = -1; | ||
94 | goto out; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); | ||
99 | if (ACPI_FAILURE(status)) { | ||
100 | dbg("_ADR returned %d on %s\n", status, (char *)buffer.pointer); | ||
101 | retval = -1; | ||
102 | goto out; | ||
103 | } | ||
104 | |||
105 | *device = (adr >> 16) & 0xffff; | ||
106 | |||
107 | /* No _SUN == not a slot == bail */ | ||
108 | status = acpi_evaluate_integer(handle, "_SUN", NULL, sun); | ||
109 | if (ACPI_FAILURE(status)) { | ||
110 | dbg("_SUN returned %d on %s\n", status, (char *)buffer.pointer); | ||
111 | retval = -1; | ||
112 | goto out; | ||
113 | } | ||
114 | |||
115 | out: | ||
116 | kfree(buffer.pointer); | ||
117 | return retval; | ||
118 | } | ||
119 | |||
120 | struct callback_args { | ||
121 | acpi_walk_callback user_function; /* only for walk_p2p_bridge */ | ||
122 | struct pci_bus *pci_bus; | ||
123 | acpi_handle root_handle; | ||
124 | }; | ||
125 | |||
126 | /* | ||
127 | * register_slot | ||
128 | * | ||
129 | * Called once for each SxFy object in the namespace. Don't worry about | ||
130 | * calling pci_create_slot multiple times for the same pci_bus:device, | ||
131 | * since each subsequent call simply bumps the refcount on the pci_slot. | ||
132 | * | ||
133 | * The number of calls to pci_destroy_slot from unregister_slot is | ||
134 | * symmetrical. | ||
135 | */ | ||
136 | static acpi_status | ||
137 | register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
138 | { | ||
139 | int device; | ||
140 | unsigned long sun; | ||
141 | char name[SLOT_NAME_SIZE]; | ||
142 | struct acpi_pci_slot *slot; | ||
143 | struct pci_slot *pci_slot; | ||
144 | struct callback_args *parent_context = context; | ||
145 | struct pci_bus *pci_bus = parent_context->pci_bus; | ||
146 | |||
147 | if (check_slot(handle, &device, &sun)) | ||
148 | return AE_OK; | ||
149 | |||
150 | slot = kmalloc(sizeof(*slot), GFP_KERNEL); | ||
151 | if (!slot) { | ||
152 | err("%s: cannot allocate memory\n", __func__); | ||
153 | return AE_OK; | ||
154 | } | ||
155 | |||
156 | snprintf(name, sizeof(name), "%u", (u32)sun); | ||
157 | pci_slot = pci_create_slot(pci_bus, device, name); | ||
158 | if (IS_ERR(pci_slot)) { | ||
159 | err("pci_create_slot returned %ld\n", PTR_ERR(pci_slot)); | ||
160 | kfree(slot); | ||
161 | } | ||
162 | |||
163 | slot->root_handle = parent_context->root_handle; | ||
164 | slot->pci_slot = pci_slot; | ||
165 | INIT_LIST_HEAD(&slot->list); | ||
166 | mutex_lock(&slot_list_lock); | ||
167 | list_add(&slot->list, &slot_list); | ||
168 | mutex_unlock(&slot_list_lock); | ||
169 | |||
170 | dbg("pci_slot: %p, pci_bus: %x, device: %d, name: %s\n", | ||
171 | pci_slot, pci_bus->number, device, name); | ||
172 | |||
173 | return AE_OK; | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * walk_p2p_bridge - discover and walk p2p bridges | ||
178 | * @handle: points to an acpi_pci_root | ||
179 | * @context: p2p_bridge_context pointer | ||
180 | * | ||
181 | * Note that when we call ourselves recursively, we pass a different | ||
182 | * value of pci_bus in the child_context. | ||
183 | */ | ||
184 | static acpi_status | ||
185 | walk_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv) | ||
186 | { | ||
187 | int device, function; | ||
188 | unsigned long adr; | ||
189 | acpi_status status; | ||
190 | acpi_handle dummy_handle; | ||
191 | acpi_walk_callback user_function; | ||
192 | |||
193 | struct pci_dev *dev; | ||
194 | struct pci_bus *pci_bus; | ||
195 | struct callback_args child_context; | ||
196 | struct callback_args *parent_context = context; | ||
197 | |||
198 | pci_bus = parent_context->pci_bus; | ||
199 | user_function = parent_context->user_function; | ||
200 | |||
201 | status = acpi_get_handle(handle, "_ADR", &dummy_handle); | ||
202 | if (ACPI_FAILURE(status)) | ||
203 | return AE_OK; | ||
204 | |||
205 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); | ||
206 | if (ACPI_FAILURE(status)) | ||
207 | return AE_OK; | ||
208 | |||
209 | device = (adr >> 16) & 0xffff; | ||
210 | function = adr & 0xffff; | ||
211 | |||
212 | dev = pci_get_slot(pci_bus, PCI_DEVFN(device, function)); | ||
213 | if (!dev || !dev->subordinate) | ||
214 | goto out; | ||
215 | |||
216 | child_context.pci_bus = dev->subordinate; | ||
217 | child_context.user_function = user_function; | ||
218 | child_context.root_handle = parent_context->root_handle; | ||
219 | |||
220 | dbg("p2p bridge walk, pci_bus = %x\n", dev->subordinate->number); | ||
221 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
222 | user_function, &child_context, NULL); | ||
223 | if (ACPI_FAILURE(status)) | ||
224 | goto out; | ||
225 | |||
226 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
227 | walk_p2p_bridge, &child_context, NULL); | ||
228 | out: | ||
229 | pci_dev_put(dev); | ||
230 | return AE_OK; | ||
231 | } | ||
232 | |||
233 | /* | ||
234 | * walk_root_bridge - generic root bridge walker | ||
235 | * @handle: points to an acpi_pci_root | ||
236 | * @user_function: user callback for slot objects | ||
237 | * | ||
238 | * Call user_function for all objects underneath this root bridge. | ||
239 | * Walk p2p bridges underneath us and call user_function on those too. | ||
240 | */ | ||
241 | static int | ||
242 | walk_root_bridge(acpi_handle handle, acpi_walk_callback user_function) | ||
243 | { | ||
244 | int seg, bus; | ||
245 | unsigned long tmp; | ||
246 | acpi_status status; | ||
247 | acpi_handle dummy_handle; | ||
248 | struct pci_bus *pci_bus; | ||
249 | struct callback_args context; | ||
250 | |||
251 | /* If the bridge doesn't have _STA, we assume it is always there */ | ||
252 | status = acpi_get_handle(handle, "_STA", &dummy_handle); | ||
253 | if (ACPI_SUCCESS(status)) { | ||
254 | status = acpi_evaluate_integer(handle, "_STA", NULL, &tmp); | ||
255 | if (ACPI_FAILURE(status)) { | ||
256 | info("%s: _STA evaluation failure\n", __func__); | ||
257 | return 0; | ||
258 | } | ||
259 | if ((tmp & ACPI_STA_DEVICE_FUNCTIONING) == 0) | ||
260 | /* don't register this object */ | ||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | status = acpi_evaluate_integer(handle, "_SEG", NULL, &tmp); | ||
265 | seg = ACPI_SUCCESS(status) ? tmp : 0; | ||
266 | |||
267 | status = acpi_evaluate_integer(handle, "_BBN", NULL, &tmp); | ||
268 | bus = ACPI_SUCCESS(status) ? tmp : 0; | ||
269 | |||
270 | pci_bus = pci_find_bus(seg, bus); | ||
271 | if (!pci_bus) | ||
272 | return 0; | ||
273 | |||
274 | context.pci_bus = pci_bus; | ||
275 | context.user_function = user_function; | ||
276 | context.root_handle = handle; | ||
277 | |||
278 | dbg("root bridge walk, pci_bus = %x\n", pci_bus->number); | ||
279 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
280 | user_function, &context, NULL); | ||
281 | if (ACPI_FAILURE(status)) | ||
282 | return status; | ||
283 | |||
284 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1, | ||
285 | walk_p2p_bridge, &context, NULL); | ||
286 | if (ACPI_FAILURE(status)) | ||
287 | err("%s: walk_p2p_bridge failure - %d\n", __func__, status); | ||
288 | |||
289 | return status; | ||
290 | } | ||
291 | |||
292 | /* | ||
293 | * acpi_pci_slot_add | ||
294 | * @handle: points to an acpi_pci_root | ||
295 | */ | ||
296 | static int | ||
297 | acpi_pci_slot_add(acpi_handle handle) | ||
298 | { | ||
299 | acpi_status status; | ||
300 | |||
301 | status = walk_root_bridge(handle, register_slot); | ||
302 | if (ACPI_FAILURE(status)) | ||
303 | err("%s: register_slot failure - %d\n", __func__, status); | ||
304 | |||
305 | return status; | ||
306 | } | ||
307 | |||
308 | /* | ||
309 | * acpi_pci_slot_remove | ||
310 | * @handle: points to an acpi_pci_root | ||
311 | */ | ||
312 | static void | ||
313 | acpi_pci_slot_remove(acpi_handle handle) | ||
314 | { | ||
315 | struct acpi_pci_slot *slot, *tmp; | ||
316 | |||
317 | mutex_lock(&slot_list_lock); | ||
318 | list_for_each_entry_safe(slot, tmp, &slot_list, list) { | ||
319 | if (slot->root_handle == handle) { | ||
320 | list_del(&slot->list); | ||
321 | pci_destroy_slot(slot->pci_slot); | ||
322 | kfree(slot); | ||
323 | } | ||
324 | } | ||
325 | mutex_unlock(&slot_list_lock); | ||
326 | } | ||
327 | |||
328 | static int do_sta_before_sun(const struct dmi_system_id *d) | ||
329 | { | ||
330 | info("%s detected: will evaluate _STA before calling _SUN\n", d->ident); | ||
331 | check_sta_before_sun = 1; | ||
332 | return 0; | ||
333 | } | ||
334 | |||
335 | static struct dmi_system_id acpi_pci_slot_dmi_table[] __initdata = { | ||
336 | /* | ||
337 | * Fujitsu Primequest machines will return 1023 to indicate an | ||
338 | * error if the _SUN method is evaluated on SxFy objects that | ||
339 | * are not present (as indicated by _STA), so for those machines, | ||
340 | * we want to check _STA before evaluating _SUN. | ||
341 | */ | ||
342 | { | ||
343 | .callback = do_sta_before_sun, | ||
344 | .ident = "Fujitsu PRIMEQUEST", | ||
345 | .matches = { | ||
346 | DMI_MATCH(DMI_BIOS_VENDOR, "FUJITSU LIMITED"), | ||
347 | DMI_MATCH(DMI_BIOS_VERSION, "PRIMEQUEST"), | ||
348 | }, | ||
349 | }, | ||
350 | {} | ||
351 | }; | ||
352 | |||
353 | static int __init | ||
354 | acpi_pci_slot_init(void) | ||
355 | { | ||
356 | dmi_check_system(acpi_pci_slot_dmi_table); | ||
357 | acpi_pci_register_driver(&acpi_pci_slot_driver); | ||
358 | return 0; | ||
359 | } | ||
360 | |||
361 | static void __exit | ||
362 | acpi_pci_slot_exit(void) | ||
363 | { | ||
364 | acpi_pci_unregister_driver(&acpi_pci_slot_driver); | ||
365 | } | ||
366 | |||
367 | module_init(acpi_pci_slot_init); | ||
368 | module_exit(acpi_pci_slot_exit); | ||
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index 81e4f081a4ae..4ab21cb1c8c7 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
@@ -292,69 +292,135 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev) | |||
292 | return 0; | 292 | return 0; |
293 | } | 293 | } |
294 | 294 | ||
295 | /** | ||
296 | * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in | ||
297 | * ACPI 3.0) _PSW (Power State Wake) | ||
298 | * @dev: Device to handle. | ||
299 | * @enable: 0 - disable, 1 - enable the wake capabilities of the device. | ||
300 | * @sleep_state: Target sleep state of the system. | ||
301 | * @dev_state: Target power state of the device. | ||
302 | * | ||
303 | * Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power | ||
304 | * State Wake) for the device, if present. On failure reset the device's | ||
305 | * wakeup.flags.valid flag. | ||
306 | * | ||
307 | * RETURN VALUE: | ||
308 | * 0 if either _DSW or _PSW has been successfully executed | ||
309 | * 0 if neither _DSW nor _PSW has been found | ||
310 | * -ENODEV if the execution of either _DSW or _PSW has failed | ||
311 | */ | ||
312 | int acpi_device_sleep_wake(struct acpi_device *dev, | ||
313 | int enable, int sleep_state, int dev_state) | ||
314 | { | ||
315 | union acpi_object in_arg[3]; | ||
316 | struct acpi_object_list arg_list = { 3, in_arg }; | ||
317 | acpi_status status = AE_OK; | ||
318 | |||
319 | /* | ||
320 | * Try to execute _DSW first. | ||
321 | * | ||
322 | * Three agruments are needed for the _DSW object: | ||
323 | * Argument 0: enable/disable the wake capabilities | ||
324 | * Argument 1: target system state | ||
325 | * Argument 2: target device state | ||
326 | * When _DSW object is called to disable the wake capabilities, maybe | ||
327 | * the first argument is filled. The values of the other two agruments | ||
328 | * are meaningless. | ||
329 | */ | ||
330 | in_arg[0].type = ACPI_TYPE_INTEGER; | ||
331 | in_arg[0].integer.value = enable; | ||
332 | in_arg[1].type = ACPI_TYPE_INTEGER; | ||
333 | in_arg[1].integer.value = sleep_state; | ||
334 | in_arg[2].type = ACPI_TYPE_INTEGER; | ||
335 | in_arg[2].integer.value = dev_state; | ||
336 | status = acpi_evaluate_object(dev->handle, "_DSW", &arg_list, NULL); | ||
337 | if (ACPI_SUCCESS(status)) { | ||
338 | return 0; | ||
339 | } else if (status != AE_NOT_FOUND) { | ||
340 | printk(KERN_ERR PREFIX "_DSW execution failed\n"); | ||
341 | dev->wakeup.flags.valid = 0; | ||
342 | return -ENODEV; | ||
343 | } | ||
344 | |||
345 | /* Execute _PSW */ | ||
346 | arg_list.count = 1; | ||
347 | in_arg[0].integer.value = enable; | ||
348 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | ||
349 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | ||
350 | printk(KERN_ERR PREFIX "_PSW execution failed\n"); | ||
351 | dev->wakeup.flags.valid = 0; | ||
352 | return -ENODEV; | ||
353 | } | ||
354 | |||
355 | return 0; | ||
356 | } | ||
357 | |||
295 | /* | 358 | /* |
296 | * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229): | 359 | * Prepare a wakeup device, two steps (Ref ACPI 2.0:P229): |
297 | * 1. Power on the power resources required for the wakeup device | 360 | * 1. Power on the power resources required for the wakeup device |
298 | * 2. Enable _PSW (power state wake) for the device if present | 361 | * 2. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power |
362 | * State Wake) for the device, if present | ||
299 | */ | 363 | */ |
300 | int acpi_enable_wakeup_device_power(struct acpi_device *dev) | 364 | int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state) |
301 | { | 365 | { |
302 | union acpi_object arg = { ACPI_TYPE_INTEGER }; | 366 | int i, err; |
303 | struct acpi_object_list arg_list = { 1, &arg }; | ||
304 | acpi_status status = AE_OK; | ||
305 | int i; | ||
306 | int ret = 0; | ||
307 | 367 | ||
308 | if (!dev || !dev->wakeup.flags.valid) | 368 | if (!dev || !dev->wakeup.flags.valid) |
309 | return -1; | 369 | return -EINVAL; |
370 | |||
371 | /* | ||
372 | * Do not execute the code below twice in a row without calling | ||
373 | * acpi_disable_wakeup_device_power() in between for the same device | ||
374 | */ | ||
375 | if (dev->wakeup.flags.prepared) | ||
376 | return 0; | ||
310 | 377 | ||
311 | arg.integer.value = 1; | ||
312 | /* Open power resource */ | 378 | /* Open power resource */ |
313 | for (i = 0; i < dev->wakeup.resources.count; i++) { | 379 | for (i = 0; i < dev->wakeup.resources.count; i++) { |
314 | ret = acpi_power_on(dev->wakeup.resources.handles[i], dev); | 380 | int ret = acpi_power_on(dev->wakeup.resources.handles[i], dev); |
315 | if (ret) { | 381 | if (ret) { |
316 | printk(KERN_ERR PREFIX "Transition power state\n"); | 382 | printk(KERN_ERR PREFIX "Transition power state\n"); |
317 | dev->wakeup.flags.valid = 0; | 383 | dev->wakeup.flags.valid = 0; |
318 | return -1; | 384 | return -ENODEV; |
319 | } | 385 | } |
320 | } | 386 | } |
321 | 387 | ||
322 | /* Execute PSW */ | 388 | /* |
323 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | 389 | * Passing 3 as the third argument below means the device may be placed |
324 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | 390 | * in arbitrary power state afterwards. |
325 | printk(KERN_ERR PREFIX "Evaluate _PSW\n"); | 391 | */ |
326 | dev->wakeup.flags.valid = 0; | 392 | err = acpi_device_sleep_wake(dev, 1, sleep_state, 3); |
327 | ret = -1; | 393 | if (!err) |
328 | } | 394 | dev->wakeup.flags.prepared = 1; |
329 | 395 | ||
330 | return ret; | 396 | return err; |
331 | } | 397 | } |
332 | 398 | ||
333 | /* | 399 | /* |
334 | * Shutdown a wakeup device, counterpart of above method | 400 | * Shutdown a wakeup device, counterpart of above method |
335 | * 1. Disable _PSW (power state wake) | 401 | * 1. Execute _DSW (Device Sleep Wake) or (deprecated in ACPI 3.0) _PSW (Power |
402 | * State Wake) for the device, if present | ||
336 | * 2. Shutdown down the power resources | 403 | * 2. Shutdown down the power resources |
337 | */ | 404 | */ |
338 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) | 405 | int acpi_disable_wakeup_device_power(struct acpi_device *dev) |
339 | { | 406 | { |
340 | union acpi_object arg = { ACPI_TYPE_INTEGER }; | 407 | int i, ret; |
341 | struct acpi_object_list arg_list = { 1, &arg }; | ||
342 | acpi_status status = AE_OK; | ||
343 | int i; | ||
344 | int ret = 0; | ||
345 | |||
346 | 408 | ||
347 | if (!dev || !dev->wakeup.flags.valid) | 409 | if (!dev || !dev->wakeup.flags.valid) |
348 | return -1; | 410 | return -EINVAL; |
349 | 411 | ||
350 | arg.integer.value = 0; | 412 | /* |
351 | /* Execute PSW */ | 413 | * Do not execute the code below twice in a row without calling |
352 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | 414 | * acpi_enable_wakeup_device_power() in between for the same device |
353 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | 415 | */ |
354 | printk(KERN_ERR PREFIX "Evaluate _PSW\n"); | 416 | if (!dev->wakeup.flags.prepared) |
355 | dev->wakeup.flags.valid = 0; | 417 | return 0; |
356 | return -1; | 418 | |
357 | } | 419 | dev->wakeup.flags.prepared = 0; |
420 | |||
421 | ret = acpi_device_sleep_wake(dev, 0, 0, 0); | ||
422 | if (ret) | ||
423 | return ret; | ||
358 | 424 | ||
359 | /* Close power resource */ | 425 | /* Close power resource */ |
360 | for (i = 0; i < dev->wakeup.resources.count; i++) { | 426 | for (i = 0; i < dev->wakeup.resources.count; i++) { |
@@ -362,7 +428,7 @@ int acpi_disable_wakeup_device_power(struct acpi_device *dev) | |||
362 | if (ret) { | 428 | if (ret) { |
363 | printk(KERN_ERR PREFIX "Transition power state\n"); | 429 | printk(KERN_ERR PREFIX "Transition power state\n"); |
364 | dev->wakeup.flags.valid = 0; | 430 | dev->wakeup.flags.valid = 0; |
365 | return -1; | 431 | return -ENODEV; |
366 | } | 432 | } |
367 | } | 433 | } |
368 | 434 | ||
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index 9dd0fa93b9e1..ec0f2d581ece 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c | |||
@@ -118,8 +118,31 @@ static const struct file_operations acpi_processor_info_fops = { | |||
118 | .release = single_release, | 118 | .release = single_release, |
119 | }; | 119 | }; |
120 | 120 | ||
121 | struct acpi_processor *processors[NR_CPUS]; | 121 | DEFINE_PER_CPU(struct acpi_processor *, processors); |
122 | struct acpi_processor_errata errata __read_mostly; | 122 | struct acpi_processor_errata errata __read_mostly; |
123 | static int set_no_mwait(const struct dmi_system_id *id) | ||
124 | { | ||
125 | printk(KERN_NOTICE PREFIX "%s detected - " | ||
126 | "disable mwait for CPU C-stetes\n", id->ident); | ||
127 | idle_nomwait = 1; | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = { | ||
132 | { | ||
133 | set_no_mwait, "IFL91 board", { | ||
134 | DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"), | ||
135 | DMI_MATCH(DMI_SYS_VENDOR, "ZEPTO"), | ||
136 | DMI_MATCH(DMI_PRODUCT_VERSION, "3215W"), | ||
137 | DMI_MATCH(DMI_BOARD_NAME, "IFL91") }, NULL}, | ||
138 | { | ||
139 | set_no_mwait, "Extensa 5220", { | ||
140 | DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"), | ||
141 | DMI_MATCH(DMI_SYS_VENDOR, "ACER"), | ||
142 | DMI_MATCH(DMI_PRODUCT_VERSION, "0100"), | ||
143 | DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL}, | ||
144 | {}, | ||
145 | }; | ||
123 | 146 | ||
124 | /* -------------------------------------------------------------------------- | 147 | /* -------------------------------------------------------------------------- |
125 | Errata Handling | 148 | Errata Handling |
@@ -265,7 +288,20 @@ static int acpi_processor_set_pdc(struct acpi_processor *pr) | |||
265 | 288 | ||
266 | if (!pdc_in) | 289 | if (!pdc_in) |
267 | return status; | 290 | return status; |
291 | if (idle_nomwait) { | ||
292 | /* | ||
293 | * If mwait is disabled for CPU C-states, the C2C3_FFH access | ||
294 | * mode will be disabled in the parameter of _PDC object. | ||
295 | * Of course C1_FFH access mode will also be disabled. | ||
296 | */ | ||
297 | union acpi_object *obj; | ||
298 | u32 *buffer = NULL; | ||
268 | 299 | ||
300 | obj = pdc_in->pointer; | ||
301 | buffer = (u32 *)(obj->buffer.pointer); | ||
302 | buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH); | ||
303 | |||
304 | } | ||
269 | status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL); | 305 | status = acpi_evaluate_object(pr->handle, "_PDC", pdc_in, NULL); |
270 | 306 | ||
271 | if (ACPI_FAILURE(status)) | 307 | if (ACPI_FAILURE(status)) |
@@ -614,14 +650,14 @@ static int acpi_processor_get_info(struct acpi_processor *pr, unsigned has_uid) | |||
614 | return 0; | 650 | return 0; |
615 | } | 651 | } |
616 | 652 | ||
617 | static void *processor_device_array[NR_CPUS]; | 653 | static DEFINE_PER_CPU(void *, processor_device_array); |
618 | 654 | ||
619 | static int __cpuinit acpi_processor_start(struct acpi_device *device) | 655 | static int __cpuinit acpi_processor_start(struct acpi_device *device) |
620 | { | 656 | { |
621 | int result = 0; | 657 | int result = 0; |
622 | acpi_status status = AE_OK; | 658 | acpi_status status = AE_OK; |
623 | struct acpi_processor *pr; | 659 | struct acpi_processor *pr; |
624 | 660 | struct sys_device *sysdev; | |
625 | 661 | ||
626 | pr = acpi_driver_data(device); | 662 | pr = acpi_driver_data(device); |
627 | 663 | ||
@@ -638,20 +674,24 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device) | |||
638 | * ACPI id of processors can be reported wrongly by the BIOS. | 674 | * ACPI id of processors can be reported wrongly by the BIOS. |
639 | * Don't trust it blindly | 675 | * Don't trust it blindly |
640 | */ | 676 | */ |
641 | if (processor_device_array[pr->id] != NULL && | 677 | if (per_cpu(processor_device_array, pr->id) != NULL && |
642 | processor_device_array[pr->id] != device) { | 678 | per_cpu(processor_device_array, pr->id) != device) { |
643 | printk(KERN_WARNING "BIOS reported wrong ACPI id " | 679 | printk(KERN_WARNING "BIOS reported wrong ACPI id " |
644 | "for the processor\n"); | 680 | "for the processor\n"); |
645 | return -ENODEV; | 681 | return -ENODEV; |
646 | } | 682 | } |
647 | processor_device_array[pr->id] = device; | 683 | per_cpu(processor_device_array, pr->id) = device; |
648 | 684 | ||
649 | processors[pr->id] = pr; | 685 | per_cpu(processors, pr->id) = pr; |
650 | 686 | ||
651 | result = acpi_processor_add_fs(device); | 687 | result = acpi_processor_add_fs(device); |
652 | if (result) | 688 | if (result) |
653 | goto end; | 689 | goto end; |
654 | 690 | ||
691 | sysdev = get_cpu_sysdev(pr->id); | ||
692 | if (sysfs_create_link(&device->dev.kobj, &sysdev->kobj, "sysdev")) | ||
693 | return -EFAULT; | ||
694 | |||
655 | status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, | 695 | status = acpi_install_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, |
656 | acpi_processor_notify, pr); | 696 | acpi_processor_notify, pr); |
657 | 697 | ||
@@ -749,7 +789,7 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb, | |||
749 | unsigned long action, void *hcpu) | 789 | unsigned long action, void *hcpu) |
750 | { | 790 | { |
751 | unsigned int cpu = (unsigned long)hcpu; | 791 | unsigned int cpu = (unsigned long)hcpu; |
752 | struct acpi_processor *pr = processors[cpu]; | 792 | struct acpi_processor *pr = per_cpu(processors, cpu); |
753 | 793 | ||
754 | if (action == CPU_ONLINE && pr) { | 794 | if (action == CPU_ONLINE && pr) { |
755 | acpi_processor_ppc_has_changed(pr); | 795 | acpi_processor_ppc_has_changed(pr); |
@@ -810,6 +850,8 @@ static int acpi_processor_remove(struct acpi_device *device, int type) | |||
810 | status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, | 850 | status = acpi_remove_notify_handler(pr->handle, ACPI_DEVICE_NOTIFY, |
811 | acpi_processor_notify); | 851 | acpi_processor_notify); |
812 | 852 | ||
853 | sysfs_remove_link(&device->dev.kobj, "sysdev"); | ||
854 | |||
813 | acpi_processor_remove_fs(device); | 855 | acpi_processor_remove_fs(device); |
814 | 856 | ||
815 | if (pr->cdev) { | 857 | if (pr->cdev) { |
@@ -819,8 +861,8 @@ static int acpi_processor_remove(struct acpi_device *device, int type) | |||
819 | pr->cdev = NULL; | 861 | pr->cdev = NULL; |
820 | } | 862 | } |
821 | 863 | ||
822 | processors[pr->id] = NULL; | 864 | per_cpu(processors, pr->id) = NULL; |
823 | processor_device_array[pr->id] = NULL; | 865 | per_cpu(processor_device_array, pr->id) = NULL; |
824 | kfree(pr); | 866 | kfree(pr); |
825 | 867 | ||
826 | return 0; | 868 | return 0; |
@@ -1014,9 +1056,9 @@ static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu) | |||
1014 | 1056 | ||
1015 | static int acpi_processor_handle_eject(struct acpi_processor *pr) | 1057 | static int acpi_processor_handle_eject(struct acpi_processor *pr) |
1016 | { | 1058 | { |
1017 | if (cpu_online(pr->id)) { | 1059 | if (cpu_online(pr->id)) |
1018 | return (-EINVAL); | 1060 | cpu_down(pr->id); |
1019 | } | 1061 | |
1020 | arch_unregister_cpu(pr->id); | 1062 | arch_unregister_cpu(pr->id); |
1021 | acpi_unmap_lsapic(pr->id); | 1063 | acpi_unmap_lsapic(pr->id); |
1022 | return (0); | 1064 | return (0); |
@@ -1068,8 +1110,6 @@ static int __init acpi_processor_init(void) | |||
1068 | { | 1110 | { |
1069 | int result = 0; | 1111 | int result = 0; |
1070 | 1112 | ||
1071 | |||
1072 | memset(&processors, 0, sizeof(processors)); | ||
1073 | memset(&errata, 0, sizeof(errata)); | 1113 | memset(&errata, 0, sizeof(errata)); |
1074 | 1114 | ||
1075 | #ifdef CONFIG_SMP | 1115 | #ifdef CONFIG_SMP |
@@ -1083,6 +1123,11 @@ static int __init acpi_processor_init(void) | |||
1083 | return -ENOMEM; | 1123 | return -ENOMEM; |
1084 | acpi_processor_dir->owner = THIS_MODULE; | 1124 | acpi_processor_dir->owner = THIS_MODULE; |
1085 | 1125 | ||
1126 | /* | ||
1127 | * Check whether the system is DMI table. If yes, OSPM | ||
1128 | * should not use mwait for CPU-states. | ||
1129 | */ | ||
1130 | dmi_check_system(processor_idle_dmi_table); | ||
1086 | result = cpuidle_register_driver(&acpi_idle_driver); | 1131 | result = cpuidle_register_driver(&acpi_idle_driver); |
1087 | if (result < 0) | 1132 | if (result < 0) |
1088 | goto out_proc; | 1133 | goto out_proc; |
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index 4976e5db2b3f..d592dbb1d12a 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <linux/pm_qos_params.h> | 41 | #include <linux/pm_qos_params.h> |
42 | #include <linux/clockchips.h> | 42 | #include <linux/clockchips.h> |
43 | #include <linux/cpuidle.h> | 43 | #include <linux/cpuidle.h> |
44 | #include <linux/cpuidle.h> | ||
44 | 45 | ||
45 | /* | 46 | /* |
46 | * Include the apic definitions for x86 to have the APIC timer related defines | 47 | * Include the apic definitions for x86 to have the APIC timer related defines |
@@ -57,6 +58,7 @@ | |||
57 | 58 | ||
58 | #include <acpi/acpi_bus.h> | 59 | #include <acpi/acpi_bus.h> |
59 | #include <acpi/processor.h> | 60 | #include <acpi/processor.h> |
61 | #include <asm/processor.h> | ||
60 | 62 | ||
61 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 | 63 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
62 | #define ACPI_PROCESSOR_CLASS "processor" | 64 | #define ACPI_PROCESSOR_CLASS "processor" |
@@ -401,7 +403,7 @@ static void acpi_processor_idle(void) | |||
401 | */ | 403 | */ |
402 | local_irq_disable(); | 404 | local_irq_disable(); |
403 | 405 | ||
404 | pr = processors[smp_processor_id()]; | 406 | pr = __get_cpu_var(processors); |
405 | if (!pr) { | 407 | if (!pr) { |
406 | local_irq_enable(); | 408 | local_irq_enable(); |
407 | return; | 409 | return; |
@@ -955,6 +957,21 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr) | |||
955 | } else { | 957 | } else { |
956 | continue; | 958 | continue; |
957 | } | 959 | } |
960 | if (cx.type == ACPI_STATE_C1 && | ||
961 | (idle_halt || idle_nomwait)) { | ||
962 | /* | ||
963 | * In most cases the C1 space_id obtained from | ||
964 | * _CST object is FIXED_HARDWARE access mode. | ||
965 | * But when the option of idle=halt is added, | ||
966 | * the entry_method type should be changed from | ||
967 | * CSTATE_FFH to CSTATE_HALT. | ||
968 | * When the option of idle=nomwait is added, | ||
969 | * the C1 entry_method type should be | ||
970 | * CSTATE_HALT. | ||
971 | */ | ||
972 | cx.entry_method = ACPI_CSTATE_HALT; | ||
973 | snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI HLT"); | ||
974 | } | ||
958 | } else { | 975 | } else { |
959 | snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", | 976 | snprintf(cx.desc, ACPI_CX_DESC_LEN, "ACPI IOPORT 0x%x", |
960 | cx.address); | 977 | cx.address); |
@@ -1431,7 +1448,7 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev, | |||
1431 | struct acpi_processor *pr; | 1448 | struct acpi_processor *pr; |
1432 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); | 1449 | struct acpi_processor_cx *cx = cpuidle_get_statedata(state); |
1433 | 1450 | ||
1434 | pr = processors[smp_processor_id()]; | 1451 | pr = __get_cpu_var(processors); |
1435 | 1452 | ||
1436 | if (unlikely(!pr)) | 1453 | if (unlikely(!pr)) |
1437 | return 0; | 1454 | return 0; |
@@ -1471,7 +1488,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev, | |||
1471 | u32 t1, t2; | 1488 | u32 t1, t2; |
1472 | int sleep_ticks = 0; | 1489 | int sleep_ticks = 0; |
1473 | 1490 | ||
1474 | pr = processors[smp_processor_id()]; | 1491 | pr = __get_cpu_var(processors); |
1475 | 1492 | ||
1476 | if (unlikely(!pr)) | 1493 | if (unlikely(!pr)) |
1477 | return 0; | 1494 | return 0; |
@@ -1549,7 +1566,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev, | |||
1549 | u32 t1, t2; | 1566 | u32 t1, t2; |
1550 | int sleep_ticks = 0; | 1567 | int sleep_ticks = 0; |
1551 | 1568 | ||
1552 | pr = processors[smp_processor_id()]; | 1569 | pr = __get_cpu_var(processors); |
1553 | 1570 | ||
1554 | if (unlikely(!pr)) | 1571 | if (unlikely(!pr)) |
1555 | return 0; | 1572 | return 0; |
@@ -1780,6 +1797,15 @@ int __cpuinit acpi_processor_power_init(struct acpi_processor *pr, | |||
1780 | return 0; | 1797 | return 0; |
1781 | 1798 | ||
1782 | if (!first_run) { | 1799 | if (!first_run) { |
1800 | if (idle_halt) { | ||
1801 | /* | ||
1802 | * When the boot option of "idle=halt" is added, halt | ||
1803 | * is used for CPU IDLE. | ||
1804 | * In such case C2/C3 is meaningless. So the max_cstate | ||
1805 | * is set to one. | ||
1806 | */ | ||
1807 | max_cstate = 1; | ||
1808 | } | ||
1783 | dmi_check_system(processor_power_dmi_table); | 1809 | dmi_check_system(processor_power_dmi_table); |
1784 | max_cstate = acpi_processor_cstate_check(max_cstate); | 1810 | max_cstate = acpi_processor_cstate_check(max_cstate); |
1785 | if (max_cstate < ACPI_C_STATES_MAX) | 1811 | if (max_cstate < ACPI_C_STATES_MAX) |
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c index d80b2d1441af..b4749969c6b4 100644 --- a/drivers/acpi/processor_perflib.c +++ b/drivers/acpi/processor_perflib.c | |||
@@ -89,7 +89,7 @@ static int acpi_processor_ppc_notifier(struct notifier_block *nb, | |||
89 | if (event != CPUFREQ_INCOMPATIBLE) | 89 | if (event != CPUFREQ_INCOMPATIBLE) |
90 | goto out; | 90 | goto out; |
91 | 91 | ||
92 | pr = processors[policy->cpu]; | 92 | pr = per_cpu(processors, policy->cpu); |
93 | if (!pr || !pr->performance) | 93 | if (!pr || !pr->performance) |
94 | goto out; | 94 | goto out; |
95 | 95 | ||
@@ -572,7 +572,7 @@ int acpi_processor_preregister_performance( | |||
572 | 572 | ||
573 | /* Call _PSD for all CPUs */ | 573 | /* Call _PSD for all CPUs */ |
574 | for_each_possible_cpu(i) { | 574 | for_each_possible_cpu(i) { |
575 | pr = processors[i]; | 575 | pr = per_cpu(processors, i); |
576 | if (!pr) { | 576 | if (!pr) { |
577 | /* Look only at processors in ACPI namespace */ | 577 | /* Look only at processors in ACPI namespace */ |
578 | continue; | 578 | continue; |
@@ -603,7 +603,7 @@ int acpi_processor_preregister_performance( | |||
603 | * domain info. | 603 | * domain info. |
604 | */ | 604 | */ |
605 | for_each_possible_cpu(i) { | 605 | for_each_possible_cpu(i) { |
606 | pr = processors[i]; | 606 | pr = per_cpu(processors, i); |
607 | if (!pr) | 607 | if (!pr) |
608 | continue; | 608 | continue; |
609 | 609 | ||
@@ -624,7 +624,7 @@ int acpi_processor_preregister_performance( | |||
624 | 624 | ||
625 | cpus_clear(covered_cpus); | 625 | cpus_clear(covered_cpus); |
626 | for_each_possible_cpu(i) { | 626 | for_each_possible_cpu(i) { |
627 | pr = processors[i]; | 627 | pr = per_cpu(processors, i); |
628 | if (!pr) | 628 | if (!pr) |
629 | continue; | 629 | continue; |
630 | 630 | ||
@@ -651,7 +651,7 @@ int acpi_processor_preregister_performance( | |||
651 | if (i == j) | 651 | if (i == j) |
652 | continue; | 652 | continue; |
653 | 653 | ||
654 | match_pr = processors[j]; | 654 | match_pr = per_cpu(processors, j); |
655 | if (!match_pr) | 655 | if (!match_pr) |
656 | continue; | 656 | continue; |
657 | 657 | ||
@@ -680,7 +680,7 @@ int acpi_processor_preregister_performance( | |||
680 | if (i == j) | 680 | if (i == j) |
681 | continue; | 681 | continue; |
682 | 682 | ||
683 | match_pr = processors[j]; | 683 | match_pr = per_cpu(processors, j); |
684 | if (!match_pr) | 684 | if (!match_pr) |
685 | continue; | 685 | continue; |
686 | 686 | ||
@@ -697,7 +697,7 @@ int acpi_processor_preregister_performance( | |||
697 | 697 | ||
698 | err_ret: | 698 | err_ret: |
699 | for_each_possible_cpu(i) { | 699 | for_each_possible_cpu(i) { |
700 | pr = processors[i]; | 700 | pr = per_cpu(processors, i); |
701 | if (!pr || !pr->performance) | 701 | if (!pr || !pr->performance) |
702 | continue; | 702 | continue; |
703 | 703 | ||
@@ -728,7 +728,7 @@ acpi_processor_register_performance(struct acpi_processor_performance | |||
728 | 728 | ||
729 | mutex_lock(&performance_mutex); | 729 | mutex_lock(&performance_mutex); |
730 | 730 | ||
731 | pr = processors[cpu]; | 731 | pr = per_cpu(processors, cpu); |
732 | if (!pr) { | 732 | if (!pr) { |
733 | mutex_unlock(&performance_mutex); | 733 | mutex_unlock(&performance_mutex); |
734 | return -ENODEV; | 734 | return -ENODEV; |
@@ -766,7 +766,7 @@ acpi_processor_unregister_performance(struct acpi_processor_performance | |||
766 | 766 | ||
767 | mutex_lock(&performance_mutex); | 767 | mutex_lock(&performance_mutex); |
768 | 768 | ||
769 | pr = processors[cpu]; | 769 | pr = per_cpu(processors, cpu); |
770 | if (!pr) { | 770 | if (!pr) { |
771 | mutex_unlock(&performance_mutex); | 771 | mutex_unlock(&performance_mutex); |
772 | return; | 772 | return; |
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index bb06738860c4..0622ace05220 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c | |||
@@ -71,7 +71,7 @@ static int acpi_processor_update_tsd_coord(void) | |||
71 | * coordination between all CPUs. | 71 | * coordination between all CPUs. |
72 | */ | 72 | */ |
73 | for_each_possible_cpu(i) { | 73 | for_each_possible_cpu(i) { |
74 | pr = processors[i]; | 74 | pr = per_cpu(processors, i); |
75 | if (!pr) | 75 | if (!pr) |
76 | continue; | 76 | continue; |
77 | 77 | ||
@@ -93,7 +93,7 @@ static int acpi_processor_update_tsd_coord(void) | |||
93 | 93 | ||
94 | cpus_clear(covered_cpus); | 94 | cpus_clear(covered_cpus); |
95 | for_each_possible_cpu(i) { | 95 | for_each_possible_cpu(i) { |
96 | pr = processors[i]; | 96 | pr = per_cpu(processors, i); |
97 | if (!pr) | 97 | if (!pr) |
98 | continue; | 98 | continue; |
99 | 99 | ||
@@ -119,7 +119,7 @@ static int acpi_processor_update_tsd_coord(void) | |||
119 | if (i == j) | 119 | if (i == j) |
120 | continue; | 120 | continue; |
121 | 121 | ||
122 | match_pr = processors[j]; | 122 | match_pr = per_cpu(processors, j); |
123 | if (!match_pr) | 123 | if (!match_pr) |
124 | continue; | 124 | continue; |
125 | 125 | ||
@@ -152,7 +152,7 @@ static int acpi_processor_update_tsd_coord(void) | |||
152 | if (i == j) | 152 | if (i == j) |
153 | continue; | 153 | continue; |
154 | 154 | ||
155 | match_pr = processors[j]; | 155 | match_pr = per_cpu(processors, j); |
156 | if (!match_pr) | 156 | if (!match_pr) |
157 | continue; | 157 | continue; |
158 | 158 | ||
@@ -172,7 +172,7 @@ static int acpi_processor_update_tsd_coord(void) | |||
172 | 172 | ||
173 | err_ret: | 173 | err_ret: |
174 | for_each_possible_cpu(i) { | 174 | for_each_possible_cpu(i) { |
175 | pr = processors[i]; | 175 | pr = per_cpu(processors, i); |
176 | if (!pr) | 176 | if (!pr) |
177 | continue; | 177 | continue; |
178 | 178 | ||
@@ -214,7 +214,7 @@ static int acpi_processor_throttling_notifier(unsigned long event, void *data) | |||
214 | struct acpi_processor_throttling *p_throttling; | 214 | struct acpi_processor_throttling *p_throttling; |
215 | 215 | ||
216 | cpu = p_tstate->cpu; | 216 | cpu = p_tstate->cpu; |
217 | pr = processors[cpu]; | 217 | pr = per_cpu(processors, cpu); |
218 | if (!pr) { | 218 | if (!pr) { |
219 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n")); | 219 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n")); |
220 | return 0; | 220 | return 0; |
@@ -1035,7 +1035,7 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state) | |||
1035 | * cpus. | 1035 | * cpus. |
1036 | */ | 1036 | */ |
1037 | for_each_cpu_mask(i, online_throttling_cpus) { | 1037 | for_each_cpu_mask(i, online_throttling_cpus) { |
1038 | match_pr = processors[i]; | 1038 | match_pr = per_cpu(processors, i); |
1039 | /* | 1039 | /* |
1040 | * If the pointer is invalid, we will report the | 1040 | * If the pointer is invalid, we will report the |
1041 | * error message and continue. | 1041 | * error message and continue. |
@@ -1232,7 +1232,10 @@ static ssize_t acpi_processor_write_throttling(struct file *file, | |||
1232 | int result = 0; | 1232 | int result = 0; |
1233 | struct seq_file *m = file->private_data; | 1233 | struct seq_file *m = file->private_data; |
1234 | struct acpi_processor *pr = m->private; | 1234 | struct acpi_processor *pr = m->private; |
1235 | char state_string[12] = { '\0' }; | 1235 | char state_string[5] = ""; |
1236 | char *charp = NULL; | ||
1237 | size_t state_val = 0; | ||
1238 | char tmpbuf[5] = ""; | ||
1236 | 1239 | ||
1237 | if (!pr || (count > sizeof(state_string) - 1)) | 1240 | if (!pr || (count > sizeof(state_string) - 1)) |
1238 | return -EINVAL; | 1241 | return -EINVAL; |
@@ -1241,10 +1244,23 @@ static ssize_t acpi_processor_write_throttling(struct file *file, | |||
1241 | return -EFAULT; | 1244 | return -EFAULT; |
1242 | 1245 | ||
1243 | state_string[count] = '\0'; | 1246 | state_string[count] = '\0'; |
1247 | if ((count > 0) && (state_string[count-1] == '\n')) | ||
1248 | state_string[count-1] = '\0'; | ||
1244 | 1249 | ||
1245 | result = acpi_processor_set_throttling(pr, | 1250 | charp = state_string; |
1246 | simple_strtoul(state_string, | 1251 | if ((state_string[0] == 't') || (state_string[0] == 'T')) |
1247 | NULL, 0)); | 1252 | charp++; |
1253 | |||
1254 | state_val = simple_strtoul(charp, NULL, 0); | ||
1255 | if (state_val >= pr->throttling.state_count) | ||
1256 | return -EINVAL; | ||
1257 | |||
1258 | snprintf(tmpbuf, 5, "%zu", state_val); | ||
1259 | |||
1260 | if (strcmp(tmpbuf, charp) != 0) | ||
1261 | return -EINVAL; | ||
1262 | |||
1263 | result = acpi_processor_set_throttling(pr, state_val); | ||
1248 | if (result) | 1264 | if (result) |
1249 | return result; | 1265 | return result; |
1250 | 1266 | ||
diff --git a/drivers/acpi/reboot.c b/drivers/acpi/reboot.c new file mode 100644 index 000000000000..a6b662c00b67 --- /dev/null +++ b/drivers/acpi/reboot.c | |||
@@ -0,0 +1,50 @@ | |||
1 | |||
2 | #include <linux/pci.h> | ||
3 | #include <linux/acpi.h> | ||
4 | #include <acpi/reboot.h> | ||
5 | |||
6 | void acpi_reboot(void) | ||
7 | { | ||
8 | struct acpi_generic_address *rr; | ||
9 | struct pci_bus *bus0; | ||
10 | u8 reset_value; | ||
11 | unsigned int devfn; | ||
12 | |||
13 | if (acpi_disabled) | ||
14 | return; | ||
15 | |||
16 | rr = &acpi_gbl_FADT.reset_register; | ||
17 | |||
18 | /* Is the reset register supported? */ | ||
19 | if (!(acpi_gbl_FADT.flags & ACPI_FADT_RESET_REGISTER) || | ||
20 | rr->bit_width != 8 || rr->bit_offset != 0) | ||
21 | return; | ||
22 | |||
23 | reset_value = acpi_gbl_FADT.reset_value; | ||
24 | |||
25 | /* The reset register can only exist in I/O, Memory or PCI config space | ||
26 | * on a device on bus 0. */ | ||
27 | switch (rr->space_id) { | ||
28 | case ACPI_ADR_SPACE_PCI_CONFIG: | ||
29 | /* The reset register can only live on bus 0. */ | ||
30 | bus0 = pci_find_bus(0, 0); | ||
31 | if (!bus0) | ||
32 | return; | ||
33 | /* Form PCI device/function pair. */ | ||
34 | devfn = PCI_DEVFN((rr->address >> 32) & 0xffff, | ||
35 | (rr->address >> 16) & 0xffff); | ||
36 | printk(KERN_DEBUG "Resetting with ACPI PCI RESET_REG."); | ||
37 | /* Write the value that resets us. */ | ||
38 | pci_bus_write_config_byte(bus0, devfn, | ||
39 | (rr->address & 0xffff), reset_value); | ||
40 | break; | ||
41 | |||
42 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | ||
43 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
44 | printk(KERN_DEBUG "ACPI MEMORY or I/O RESET_REG.\n"); | ||
45 | acpi_hw_low_level_write(8, reset_value, rr); | ||
46 | break; | ||
47 | } | ||
48 | /* Wait ten seconds */ | ||
49 | acpi_os_stall(10000000); | ||
50 | } | ||
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c index 8a112d11d491..f61ebc679e66 100644 --- a/drivers/acpi/resources/rscalc.c +++ b/drivers/acpi/resources/rscalc.c | |||
@@ -73,7 +73,7 @@ acpi_rs_stream_option_length(u32 resource_length, u32 minimum_total_length); | |||
73 | 73 | ||
74 | static u8 acpi_rs_count_set_bits(u16 bit_field) | 74 | static u8 acpi_rs_count_set_bits(u16 bit_field) |
75 | { | 75 | { |
76 | acpi_native_uint bits_set; | 76 | u8 bits_set; |
77 | 77 | ||
78 | ACPI_FUNCTION_ENTRY(); | 78 | ACPI_FUNCTION_ENTRY(); |
79 | 79 | ||
@@ -84,7 +84,7 @@ static u8 acpi_rs_count_set_bits(u16 bit_field) | |||
84 | bit_field &= (u16) (bit_field - 1); | 84 | bit_field &= (u16) (bit_field - 1); |
85 | } | 85 | } |
86 | 86 | ||
87 | return ((u8) bits_set); | 87 | return bits_set; |
88 | } | 88 | } |
89 | 89 | ||
90 | /******************************************************************************* | 90 | /******************************************************************************* |
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c index faddaee1bc07..7804a8c40e7a 100644 --- a/drivers/acpi/resources/rscreate.c +++ b/drivers/acpi/resources/rscreate.c | |||
@@ -181,9 +181,9 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, | |||
181 | } | 181 | } |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * Loop through the ACPI_INTERNAL_OBJECTS - Each object | 184 | * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a |
185 | * should be a package that in turn contains an | 185 | * package that in turn contains an acpi_integer Address, a u8 Pin, |
186 | * acpi_integer Address, a u8 Pin, a Name and a u8 source_index. | 186 | * a Name, and a u8 source_index. |
187 | */ | 187 | */ |
188 | top_object_list = package_object->package.elements; | 188 | top_object_list = package_object->package.elements; |
189 | number_of_elements = package_object->package.count; | 189 | number_of_elements = package_object->package.count; |
@@ -240,9 +240,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, | |||
240 | /* 1) First subobject: Dereference the PRT.Address */ | 240 | /* 1) First subobject: Dereference the PRT.Address */ |
241 | 241 | ||
242 | obj_desc = sub_object_list[0]; | 242 | obj_desc = sub_object_list[0]; |
243 | if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { | 243 | if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { |
244 | user_prt->address = obj_desc->integer.value; | ||
245 | } else { | ||
246 | ACPI_ERROR((AE_INFO, | 244 | ACPI_ERROR((AE_INFO, |
247 | "(PRT[%X].Address) Need Integer, found %s", | 245 | "(PRT[%X].Address) Need Integer, found %s", |
248 | index, | 246 | index, |
@@ -250,12 +248,12 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, | |||
250 | return_ACPI_STATUS(AE_BAD_DATA); | 248 | return_ACPI_STATUS(AE_BAD_DATA); |
251 | } | 249 | } |
252 | 250 | ||
251 | user_prt->address = obj_desc->integer.value; | ||
252 | |||
253 | /* 2) Second subobject: Dereference the PRT.Pin */ | 253 | /* 2) Second subobject: Dereference the PRT.Pin */ |
254 | 254 | ||
255 | obj_desc = sub_object_list[1]; | 255 | obj_desc = sub_object_list[1]; |
256 | if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { | 256 | if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { |
257 | user_prt->pin = (u32) obj_desc->integer.value; | ||
258 | } else { | ||
259 | ACPI_ERROR((AE_INFO, | 257 | ACPI_ERROR((AE_INFO, |
260 | "(PRT[%X].Pin) Need Integer, found %s", | 258 | "(PRT[%X].Pin) Need Integer, found %s", |
261 | index, | 259 | index, |
@@ -284,6 +282,25 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, | |||
284 | } | 282 | } |
285 | } | 283 | } |
286 | 284 | ||
285 | user_prt->pin = (u32) obj_desc->integer.value; | ||
286 | |||
287 | /* | ||
288 | * If the BIOS has erroneously reversed the _PRT source_name (index 2) | ||
289 | * and the source_index (index 3), fix it. _PRT is important enough to | ||
290 | * workaround this BIOS error. This also provides compatibility with | ||
291 | * other ACPI implementations. | ||
292 | */ | ||
293 | obj_desc = sub_object_list[3]; | ||
294 | if (!obj_desc | ||
295 | || (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER)) { | ||
296 | sub_object_list[3] = sub_object_list[2]; | ||
297 | sub_object_list[2] = obj_desc; | ||
298 | |||
299 | ACPI_WARNING((AE_INFO, | ||
300 | "(PRT[%X].Source) SourceName and SourceIndex are reversed, fixed", | ||
301 | index)); | ||
302 | } | ||
303 | |||
287 | /* | 304 | /* |
288 | * 3) Third subobject: Dereference the PRT.source_name | 305 | * 3) Third subobject: Dereference the PRT.source_name |
289 | * The name may be unresolved (slack mode), so allow a null object | 306 | * The name may be unresolved (slack mode), so allow a null object |
@@ -364,9 +381,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, | |||
364 | /* 4) Fourth subobject: Dereference the PRT.source_index */ | 381 | /* 4) Fourth subobject: Dereference the PRT.source_index */ |
365 | 382 | ||
366 | obj_desc = sub_object_list[source_index_index]; | 383 | obj_desc = sub_object_list[source_index_index]; |
367 | if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) { | 384 | if (ACPI_GET_OBJECT_TYPE(obj_desc) != ACPI_TYPE_INTEGER) { |
368 | user_prt->source_index = (u32) obj_desc->integer.value; | ||
369 | } else { | ||
370 | ACPI_ERROR((AE_INFO, | 385 | ACPI_ERROR((AE_INFO, |
371 | "(PRT[%X].SourceIndex) Need Integer, found %s", | 386 | "(PRT[%X].SourceIndex) Need Integer, found %s", |
372 | index, | 387 | index, |
@@ -374,6 +389,8 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object, | |||
374 | return_ACPI_STATUS(AE_BAD_DATA); | 389 | return_ACPI_STATUS(AE_BAD_DATA); |
375 | } | 390 | } |
376 | 391 | ||
392 | user_prt->source_index = (u32) obj_desc->integer.value; | ||
393 | |||
377 | /* Point to the next union acpi_operand_object in the top level package */ | 394 | /* Point to the next union acpi_operand_object in the top level package */ |
378 | 395 | ||
379 | top_object_list++; | 396 | top_object_list++; |
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c index de1ac3881b22..96a6c0353255 100644 --- a/drivers/acpi/resources/rsmisc.c +++ b/drivers/acpi/resources/rsmisc.c | |||
@@ -82,7 +82,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource, | |||
82 | 82 | ||
83 | ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource); | 83 | ACPI_FUNCTION_TRACE(rs_convert_aml_to_resource); |
84 | 84 | ||
85 | if (((acpi_native_uint) resource) & 0x3) { | 85 | if (((acpi_size) resource) & 0x3) { |
86 | 86 | ||
87 | /* Each internal resource struct is expected to be 32-bit aligned */ | 87 | /* Each internal resource struct is expected to be 32-bit aligned */ |
88 | 88 | ||
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c index befe2302f41b..f7b3bcd59ba7 100644 --- a/drivers/acpi/resources/rsutils.c +++ b/drivers/acpi/resources/rsutils.c | |||
@@ -62,7 +62,7 @@ ACPI_MODULE_NAME("rsutils") | |||
62 | ******************************************************************************/ | 62 | ******************************************************************************/ |
63 | u8 acpi_rs_decode_bitmask(u16 mask, u8 * list) | 63 | u8 acpi_rs_decode_bitmask(u16 mask, u8 * list) |
64 | { | 64 | { |
65 | acpi_native_uint i; | 65 | u8 i; |
66 | u8 bit_count; | 66 | u8 bit_count; |
67 | 67 | ||
68 | ACPI_FUNCTION_ENTRY(); | 68 | ACPI_FUNCTION_ENTRY(); |
@@ -71,7 +71,7 @@ u8 acpi_rs_decode_bitmask(u16 mask, u8 * list) | |||
71 | 71 | ||
72 | for (i = 0, bit_count = 0; mask; i++) { | 72 | for (i = 0, bit_count = 0; mask; i++) { |
73 | if (mask & 0x0001) { | 73 | if (mask & 0x0001) { |
74 | list[bit_count] = (u8) i; | 74 | list[bit_count] = i; |
75 | bit_count++; | 75 | bit_count++; |
76 | } | 76 | } |
77 | 77 | ||
@@ -96,8 +96,8 @@ u8 acpi_rs_decode_bitmask(u16 mask, u8 * list) | |||
96 | 96 | ||
97 | u16 acpi_rs_encode_bitmask(u8 * list, u8 count) | 97 | u16 acpi_rs_encode_bitmask(u8 * list, u8 count) |
98 | { | 98 | { |
99 | acpi_native_uint i; | 99 | u32 i; |
100 | acpi_native_uint mask; | 100 | u16 mask; |
101 | 101 | ||
102 | ACPI_FUNCTION_ENTRY(); | 102 | ACPI_FUNCTION_ENTRY(); |
103 | 103 | ||
@@ -107,7 +107,7 @@ u16 acpi_rs_encode_bitmask(u8 * list, u8 count) | |||
107 | mask |= (0x1 << list[i]); | 107 | mask |= (0x1 << list[i]); |
108 | } | 108 | } |
109 | 109 | ||
110 | return ((u16) mask); | 110 | return mask; |
111 | } | 111 | } |
112 | 112 | ||
113 | /******************************************************************************* | 113 | /******************************************************************************* |
@@ -130,7 +130,7 @@ u16 acpi_rs_encode_bitmask(u8 * list, u8 count) | |||
130 | void | 130 | void |
131 | acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type) | 131 | acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type) |
132 | { | 132 | { |
133 | acpi_native_uint i; | 133 | u32 i; |
134 | 134 | ||
135 | ACPI_FUNCTION_ENTRY(); | 135 | ACPI_FUNCTION_ENTRY(); |
136 | 136 | ||
@@ -679,7 +679,6 @@ acpi_rs_set_srs_method_data(struct acpi_namespace_node *node, | |||
679 | info->prefix_node = node; | 679 | info->prefix_node = node; |
680 | info->pathname = METHOD_NAME__SRS; | 680 | info->pathname = METHOD_NAME__SRS; |
681 | info->parameters = args; | 681 | info->parameters = args; |
682 | info->parameter_type = ACPI_PARAM_ARGS; | ||
683 | info->flags = ACPI_IGNORE_RETURN_VALUE; | 682 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
684 | 683 | ||
685 | /* | 684 | /* |
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 6d85289f1c12..f3132aa47a69 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -6,6 +6,8 @@ | |||
6 | #include <linux/init.h> | 6 | #include <linux/init.h> |
7 | #include <linux/kernel.h> | 7 | #include <linux/kernel.h> |
8 | #include <linux/acpi.h> | 8 | #include <linux/acpi.h> |
9 | #include <linux/signal.h> | ||
10 | #include <linux/kthread.h> | ||
9 | 11 | ||
10 | #include <acpi/acpi_drivers.h> | 12 | #include <acpi/acpi_drivers.h> |
11 | #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ | 13 | #include <acpi/acinterp.h> /* for acpi_ex_eisa_id_to_string() */ |
@@ -92,17 +94,37 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha | |||
92 | } | 94 | } |
93 | static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); | 95 | static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); |
94 | 96 | ||
95 | static int acpi_eject_operation(acpi_handle handle, int lockable) | 97 | static int acpi_bus_hot_remove_device(void *context) |
96 | { | 98 | { |
99 | struct acpi_device *device; | ||
100 | acpi_handle handle = context; | ||
97 | struct acpi_object_list arg_list; | 101 | struct acpi_object_list arg_list; |
98 | union acpi_object arg; | 102 | union acpi_object arg; |
99 | acpi_status status = AE_OK; | 103 | acpi_status status = AE_OK; |
100 | 104 | ||
101 | /* | 105 | if (acpi_bus_get_device(handle, &device)) |
102 | * TBD: evaluate _PS3? | 106 | return 0; |
103 | */ | 107 | |
108 | if (!device) | ||
109 | return 0; | ||
110 | |||
111 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
112 | "Hot-removing device %s...\n", device->dev.bus_id)); | ||
113 | |||
104 | 114 | ||
105 | if (lockable) { | 115 | if (acpi_bus_trim(device, 1)) { |
116 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
117 | "Removing device failed\n")); | ||
118 | return -1; | ||
119 | } | ||
120 | |||
121 | /* power off device */ | ||
122 | status = acpi_evaluate_object(handle, "_PS3", NULL, NULL); | ||
123 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) | ||
124 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, | ||
125 | "Power-off device failed\n")); | ||
126 | |||
127 | if (device->flags.lockable) { | ||
106 | arg_list.count = 1; | 128 | arg_list.count = 1; |
107 | arg_list.pointer = &arg; | 129 | arg_list.pointer = &arg; |
108 | arg.type = ACPI_TYPE_INTEGER; | 130 | arg.type = ACPI_TYPE_INTEGER; |
@@ -118,26 +140,22 @@ static int acpi_eject_operation(acpi_handle handle, int lockable) | |||
118 | /* | 140 | /* |
119 | * TBD: _EJD support. | 141 | * TBD: _EJD support. |
120 | */ | 142 | */ |
121 | |||
122 | status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); | 143 | status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); |
123 | if (ACPI_FAILURE(status)) { | 144 | if (ACPI_FAILURE(status)) |
124 | return (-ENODEV); | 145 | return -ENODEV; |
125 | } | ||
126 | 146 | ||
127 | return (0); | 147 | return 0; |
128 | } | 148 | } |
129 | 149 | ||
130 | static ssize_t | 150 | static ssize_t |
131 | acpi_eject_store(struct device *d, struct device_attribute *attr, | 151 | acpi_eject_store(struct device *d, struct device_attribute *attr, |
132 | const char *buf, size_t count) | 152 | const char *buf, size_t count) |
133 | { | 153 | { |
134 | int result; | ||
135 | int ret = count; | 154 | int ret = count; |
136 | int islockable; | ||
137 | acpi_status status; | 155 | acpi_status status; |
138 | acpi_handle handle; | ||
139 | acpi_object_type type = 0; | 156 | acpi_object_type type = 0; |
140 | struct acpi_device *acpi_device = to_acpi_device(d); | 157 | struct acpi_device *acpi_device = to_acpi_device(d); |
158 | struct task_struct *task; | ||
141 | 159 | ||
142 | if ((!count) || (buf[0] != '1')) { | 160 | if ((!count) || (buf[0] != '1')) { |
143 | return -EINVAL; | 161 | return -EINVAL; |
@@ -154,18 +172,12 @@ acpi_eject_store(struct device *d, struct device_attribute *attr, | |||
154 | goto err; | 172 | goto err; |
155 | } | 173 | } |
156 | 174 | ||
157 | islockable = acpi_device->flags.lockable; | 175 | /* remove the device in another thread to fix the deadlock issue */ |
158 | handle = acpi_device->handle; | 176 | task = kthread_run(acpi_bus_hot_remove_device, |
159 | 177 | acpi_device->handle, "acpi_hot_remove_device"); | |
160 | result = acpi_bus_trim(acpi_device, 1); | 178 | if (IS_ERR(task)) |
161 | 179 | ret = PTR_ERR(task); | |
162 | if (!result) | 180 | err: |
163 | result = acpi_eject_operation(handle, islockable); | ||
164 | |||
165 | if (result) { | ||
166 | ret = -EBUSY; | ||
167 | } | ||
168 | err: | ||
169 | return ret; | 181 | return ret; |
170 | } | 182 | } |
171 | 183 | ||
@@ -691,9 +703,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
691 | acpi_status status = 0; | 703 | acpi_status status = 0; |
692 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | 704 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
693 | union acpi_object *package = NULL; | 705 | union acpi_object *package = NULL; |
694 | union acpi_object in_arg[3]; | 706 | int psw_error; |
695 | struct acpi_object_list arg_list = { 3, in_arg }; | ||
696 | acpi_status psw_status = AE_OK; | ||
697 | 707 | ||
698 | struct acpi_device_id button_device_ids[] = { | 708 | struct acpi_device_id button_device_ids[] = { |
699 | {"PNP0C0D", 0}, | 709 | {"PNP0C0D", 0}, |
@@ -725,39 +735,11 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
725 | * So it is necessary to call _DSW object first. Only when it is not | 735 | * So it is necessary to call _DSW object first. Only when it is not |
726 | * present will the _PSW object used. | 736 | * present will the _PSW object used. |
727 | */ | 737 | */ |
728 | /* | 738 | psw_error = acpi_device_sleep_wake(device, 0, 0, 0); |
729 | * Three agruments are needed for the _DSW object. | 739 | if (psw_error) |
730 | * Argument 0: enable/disable the wake capabilities | 740 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
731 | * When _DSW object is called to disable the wake capabilities, maybe | 741 | "error in _DSW or _PSW evaluation\n")); |
732 | * the first argument is filled. The value of the other two agruments | 742 | |
733 | * is meaningless. | ||
734 | */ | ||
735 | in_arg[0].type = ACPI_TYPE_INTEGER; | ||
736 | in_arg[0].integer.value = 0; | ||
737 | in_arg[1].type = ACPI_TYPE_INTEGER; | ||
738 | in_arg[1].integer.value = 0; | ||
739 | in_arg[2].type = ACPI_TYPE_INTEGER; | ||
740 | in_arg[2].integer.value = 0; | ||
741 | psw_status = acpi_evaluate_object(device->handle, "_DSW", | ||
742 | &arg_list, NULL); | ||
743 | if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND)) | ||
744 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in evaluate _DSW\n")); | ||
745 | /* | ||
746 | * When the _DSW object is not present, OSPM will call _PSW object. | ||
747 | */ | ||
748 | if (psw_status == AE_NOT_FOUND) { | ||
749 | /* | ||
750 | * Only one agruments is required for the _PSW object. | ||
751 | * agrument 0: enable/disable the wake capabilities | ||
752 | */ | ||
753 | arg_list.count = 1; | ||
754 | in_arg[0].integer.value = 0; | ||
755 | psw_status = acpi_evaluate_object(device->handle, "_PSW", | ||
756 | &arg_list, NULL); | ||
757 | if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND)) | ||
758 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in " | ||
759 | "evaluate _PSW\n")); | ||
760 | } | ||
761 | /* Power button, Lid switch always enable wakeup */ | 743 | /* Power button, Lid switch always enable wakeup */ |
762 | if (!acpi_match_device_ids(device, button_device_ids)) | 744 | if (!acpi_match_device_ids(device, button_device_ids)) |
763 | device->wakeup.flags.run_wake = 1; | 745 | device->wakeup.flags.run_wake = 1; |
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c index 495c63a3e0af..0489a7d1d42c 100644 --- a/drivers/acpi/sleep/main.c +++ b/drivers/acpi/sleep/main.c | |||
@@ -24,10 +24,6 @@ | |||
24 | 24 | ||
25 | u8 sleep_states[ACPI_S_STATE_COUNT]; | 25 | u8 sleep_states[ACPI_S_STATE_COUNT]; |
26 | 26 | ||
27 | #ifdef CONFIG_PM_SLEEP | ||
28 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; | ||
29 | #endif | ||
30 | |||
31 | static int acpi_sleep_prepare(u32 acpi_state) | 27 | static int acpi_sleep_prepare(u32 acpi_state) |
32 | { | 28 | { |
33 | #ifdef CONFIG_ACPI_SLEEP | 29 | #ifdef CONFIG_ACPI_SLEEP |
@@ -49,9 +45,96 @@ static int acpi_sleep_prepare(u32 acpi_state) | |||
49 | return 0; | 45 | return 0; |
50 | } | 46 | } |
51 | 47 | ||
52 | #ifdef CONFIG_SUSPEND | 48 | #ifdef CONFIG_PM_SLEEP |
53 | static struct platform_suspend_ops acpi_suspend_ops; | 49 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; |
50 | |||
51 | /* | ||
52 | * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the | ||
53 | * user to request that behavior by using the 'acpi_old_suspend_ordering' | ||
54 | * kernel command line option that causes the following variable to be set. | ||
55 | */ | ||
56 | static bool old_suspend_ordering; | ||
54 | 57 | ||
58 | void __init acpi_old_suspend_ordering(void) | ||
59 | { | ||
60 | old_suspend_ordering = true; | ||
61 | } | ||
62 | |||
63 | /** | ||
64 | * acpi_pm_disable_gpes - Disable the GPEs. | ||
65 | */ | ||
66 | static int acpi_pm_disable_gpes(void) | ||
67 | { | ||
68 | acpi_hw_disable_all_gpes(); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * __acpi_pm_prepare - Prepare the platform to enter the target state. | ||
74 | * | ||
75 | * If necessary, set the firmware waking vector and do arch-specific | ||
76 | * nastiness to get the wakeup code to the waking vector. | ||
77 | */ | ||
78 | static int __acpi_pm_prepare(void) | ||
79 | { | ||
80 | int error = acpi_sleep_prepare(acpi_target_sleep_state); | ||
81 | |||
82 | if (error) | ||
83 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
84 | return error; | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * acpi_pm_prepare - Prepare the platform to enter the target sleep | ||
89 | * state and disable the GPEs. | ||
90 | */ | ||
91 | static int acpi_pm_prepare(void) | ||
92 | { | ||
93 | int error = __acpi_pm_prepare(); | ||
94 | |||
95 | if (!error) | ||
96 | acpi_hw_disable_all_gpes(); | ||
97 | return error; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * acpi_pm_finish - Instruct the platform to leave a sleep state. | ||
102 | * | ||
103 | * This is called after we wake back up (or if entering the sleep state | ||
104 | * failed). | ||
105 | */ | ||
106 | static void acpi_pm_finish(void) | ||
107 | { | ||
108 | u32 acpi_state = acpi_target_sleep_state; | ||
109 | |||
110 | if (acpi_state == ACPI_STATE_S0) | ||
111 | return; | ||
112 | |||
113 | printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", | ||
114 | acpi_state); | ||
115 | acpi_disable_wakeup_device(acpi_state); | ||
116 | acpi_leave_sleep_state(acpi_state); | ||
117 | |||
118 | /* reset firmware waking vector */ | ||
119 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
120 | |||
121 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * acpi_pm_end - Finish up suspend sequence. | ||
126 | */ | ||
127 | static void acpi_pm_end(void) | ||
128 | { | ||
129 | /* | ||
130 | * This is necessary in case acpi_pm_finish() is not called during a | ||
131 | * failing transition to a sleep state. | ||
132 | */ | ||
133 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
134 | } | ||
135 | #endif /* CONFIG_PM_SLEEP */ | ||
136 | |||
137 | #ifdef CONFIG_SUSPEND | ||
55 | extern void do_suspend_lowlevel(void); | 138 | extern void do_suspend_lowlevel(void); |
56 | 139 | ||
57 | static u32 acpi_suspend_states[] = { | 140 | static u32 acpi_suspend_states[] = { |
@@ -61,13 +144,10 @@ static u32 acpi_suspend_states[] = { | |||
61 | [PM_SUSPEND_MAX] = ACPI_STATE_S5 | 144 | [PM_SUSPEND_MAX] = ACPI_STATE_S5 |
62 | }; | 145 | }; |
63 | 146 | ||
64 | static int init_8259A_after_S1; | ||
65 | |||
66 | /** | 147 | /** |
67 | * acpi_suspend_begin - Set the target system sleep state to the state | 148 | * acpi_suspend_begin - Set the target system sleep state to the state |
68 | * associated with given @pm_state, if supported. | 149 | * associated with given @pm_state, if supported. |
69 | */ | 150 | */ |
70 | |||
71 | static int acpi_suspend_begin(suspend_state_t pm_state) | 151 | static int acpi_suspend_begin(suspend_state_t pm_state) |
72 | { | 152 | { |
73 | u32 acpi_state = acpi_suspend_states[pm_state]; | 153 | u32 acpi_state = acpi_suspend_states[pm_state]; |
@@ -84,25 +164,6 @@ static int acpi_suspend_begin(suspend_state_t pm_state) | |||
84 | } | 164 | } |
85 | 165 | ||
86 | /** | 166 | /** |
87 | * acpi_suspend_prepare - Do preliminary suspend work. | ||
88 | * | ||
89 | * If necessary, set the firmware waking vector and do arch-specific | ||
90 | * nastiness to get the wakeup code to the waking vector. | ||
91 | */ | ||
92 | |||
93 | static int acpi_suspend_prepare(void) | ||
94 | { | ||
95 | int error = acpi_sleep_prepare(acpi_target_sleep_state); | ||
96 | |||
97 | if (error) { | ||
98 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
99 | return error; | ||
100 | } | ||
101 | |||
102 | return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; | ||
103 | } | ||
104 | |||
105 | /** | ||
106 | * acpi_suspend_enter - Actually enter a sleep state. | 167 | * acpi_suspend_enter - Actually enter a sleep state. |
107 | * @pm_state: ignored | 168 | * @pm_state: ignored |
108 | * | 169 | * |
@@ -110,7 +171,6 @@ static int acpi_suspend_prepare(void) | |||
110 | * assembly, which in turn call acpi_enter_sleep_state(). | 171 | * assembly, which in turn call acpi_enter_sleep_state(). |
111 | * It's unfortunate, but it works. Please fix if you're feeling frisky. | 172 | * It's unfortunate, but it works. Please fix if you're feeling frisky. |
112 | */ | 173 | */ |
113 | |||
114 | static int acpi_suspend_enter(suspend_state_t pm_state) | 174 | static int acpi_suspend_enter(suspend_state_t pm_state) |
115 | { | 175 | { |
116 | acpi_status status = AE_OK; | 176 | acpi_status status = AE_OK; |
@@ -167,46 +227,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state) | |||
167 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | 227 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; |
168 | } | 228 | } |
169 | 229 | ||
170 | /** | ||
171 | * acpi_suspend_finish - Instruct the platform to leave a sleep state. | ||
172 | * | ||
173 | * This is called after we wake back up (or if entering the sleep state | ||
174 | * failed). | ||
175 | */ | ||
176 | |||
177 | static void acpi_suspend_finish(void) | ||
178 | { | ||
179 | u32 acpi_state = acpi_target_sleep_state; | ||
180 | |||
181 | acpi_disable_wakeup_device(acpi_state); | ||
182 | acpi_leave_sleep_state(acpi_state); | ||
183 | |||
184 | /* reset firmware waking vector */ | ||
185 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
186 | |||
187 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
188 | |||
189 | #ifdef CONFIG_X86 | ||
190 | if (init_8259A_after_S1) { | ||
191 | printk("Broken toshiba laptop -> kicking interrupts\n"); | ||
192 | init_8259A(0); | ||
193 | } | ||
194 | #endif | ||
195 | } | ||
196 | |||
197 | /** | ||
198 | * acpi_suspend_end - Finish up suspend sequence. | ||
199 | */ | ||
200 | |||
201 | static void acpi_suspend_end(void) | ||
202 | { | ||
203 | /* | ||
204 | * This is necessary in case acpi_suspend_finish() is not called during a | ||
205 | * failing transition to a sleep state. | ||
206 | */ | ||
207 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
208 | } | ||
209 | |||
210 | static int acpi_suspend_state_valid(suspend_state_t pm_state) | 230 | static int acpi_suspend_state_valid(suspend_state_t pm_state) |
211 | { | 231 | { |
212 | u32 acpi_state; | 232 | u32 acpi_state; |
@@ -226,30 +246,39 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state) | |||
226 | static struct platform_suspend_ops acpi_suspend_ops = { | 246 | static struct platform_suspend_ops acpi_suspend_ops = { |
227 | .valid = acpi_suspend_state_valid, | 247 | .valid = acpi_suspend_state_valid, |
228 | .begin = acpi_suspend_begin, | 248 | .begin = acpi_suspend_begin, |
229 | .prepare = acpi_suspend_prepare, | 249 | .prepare = acpi_pm_prepare, |
230 | .enter = acpi_suspend_enter, | 250 | .enter = acpi_suspend_enter, |
231 | .finish = acpi_suspend_finish, | 251 | .finish = acpi_pm_finish, |
232 | .end = acpi_suspend_end, | 252 | .end = acpi_pm_end, |
233 | }; | 253 | }; |
234 | 254 | ||
235 | /* | 255 | /** |
236 | * Toshiba fails to preserve interrupts over S1, reinitialization | 256 | * acpi_suspend_begin_old - Set the target system sleep state to the |
237 | * of 8259 is needed after S1 resume. | 257 | * state associated with given @pm_state, if supported, and |
258 | * execute the _PTS control method. This function is used if the | ||
259 | * pre-ACPI 2.0 suspend ordering has been requested. | ||
238 | */ | 260 | */ |
239 | static int __init init_ints_after_s1(const struct dmi_system_id *d) | 261 | static int acpi_suspend_begin_old(suspend_state_t pm_state) |
240 | { | 262 | { |
241 | printk(KERN_WARNING "%s with broken S1 detected.\n", d->ident); | 263 | int error = acpi_suspend_begin(pm_state); |
242 | init_8259A_after_S1 = 1; | 264 | |
243 | return 0; | 265 | if (!error) |
266 | error = __acpi_pm_prepare(); | ||
267 | return error; | ||
244 | } | 268 | } |
245 | 269 | ||
246 | static struct dmi_system_id __initdata acpisleep_dmi_table[] = { | 270 | /* |
247 | { | 271 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has |
248 | .callback = init_ints_after_s1, | 272 | * been requested. |
249 | .ident = "Toshiba Satellite 4030cdt", | 273 | */ |
250 | .matches = {DMI_MATCH(DMI_PRODUCT_NAME, "S4030CDT/4.3"),}, | 274 | static struct platform_suspend_ops acpi_suspend_ops_old = { |
251 | }, | 275 | .valid = acpi_suspend_state_valid, |
252 | {}, | 276 | .begin = acpi_suspend_begin_old, |
277 | .prepare = acpi_pm_disable_gpes, | ||
278 | .enter = acpi_suspend_enter, | ||
279 | .finish = acpi_pm_finish, | ||
280 | .end = acpi_pm_end, | ||
281 | .recover = acpi_pm_finish, | ||
253 | }; | 282 | }; |
254 | #endif /* CONFIG_SUSPEND */ | 283 | #endif /* CONFIG_SUSPEND */ |
255 | 284 | ||
@@ -257,22 +286,9 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = { | |||
257 | static int acpi_hibernation_begin(void) | 286 | static int acpi_hibernation_begin(void) |
258 | { | 287 | { |
259 | acpi_target_sleep_state = ACPI_STATE_S4; | 288 | acpi_target_sleep_state = ACPI_STATE_S4; |
260 | |||
261 | return 0; | 289 | return 0; |
262 | } | 290 | } |
263 | 291 | ||
264 | static int acpi_hibernation_prepare(void) | ||
265 | { | ||
266 | int error = acpi_sleep_prepare(ACPI_STATE_S4); | ||
267 | |||
268 | if (error) { | ||
269 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
270 | return error; | ||
271 | } | ||
272 | |||
273 | return ACPI_SUCCESS(acpi_hw_disable_all_gpes()) ? 0 : -EFAULT; | ||
274 | } | ||
275 | |||
276 | static int acpi_hibernation_enter(void) | 292 | static int acpi_hibernation_enter(void) |
277 | { | 293 | { |
278 | acpi_status status = AE_OK; | 294 | acpi_status status = AE_OK; |
@@ -302,52 +318,55 @@ static void acpi_hibernation_leave(void) | |||
302 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); | 318 | acpi_leave_sleep_state_prep(ACPI_STATE_S4); |
303 | } | 319 | } |
304 | 320 | ||
305 | static void acpi_hibernation_finish(void) | 321 | static void acpi_pm_enable_gpes(void) |
306 | { | 322 | { |
307 | acpi_disable_wakeup_device(ACPI_STATE_S4); | 323 | acpi_hw_enable_all_runtime_gpes(); |
308 | acpi_leave_sleep_state(ACPI_STATE_S4); | ||
309 | |||
310 | /* reset firmware waking vector */ | ||
311 | acpi_set_firmware_waking_vector((acpi_physical_address) 0); | ||
312 | |||
313 | acpi_target_sleep_state = ACPI_STATE_S0; | ||
314 | } | 324 | } |
315 | 325 | ||
316 | static void acpi_hibernation_end(void) | 326 | static struct platform_hibernation_ops acpi_hibernation_ops = { |
317 | { | 327 | .begin = acpi_hibernation_begin, |
318 | /* | 328 | .end = acpi_pm_end, |
319 | * This is necessary in case acpi_hibernation_finish() is not called | 329 | .pre_snapshot = acpi_pm_prepare, |
320 | * during a failing transition to the sleep state. | 330 | .finish = acpi_pm_finish, |
321 | */ | 331 | .prepare = acpi_pm_prepare, |
322 | acpi_target_sleep_state = ACPI_STATE_S0; | 332 | .enter = acpi_hibernation_enter, |
323 | } | 333 | .leave = acpi_hibernation_leave, |
334 | .pre_restore = acpi_pm_disable_gpes, | ||
335 | .restore_cleanup = acpi_pm_enable_gpes, | ||
336 | }; | ||
324 | 337 | ||
325 | static int acpi_hibernation_pre_restore(void) | 338 | /** |
339 | * acpi_hibernation_begin_old - Set the target system sleep state to | ||
340 | * ACPI_STATE_S4 and execute the _PTS control method. This | ||
341 | * function is used if the pre-ACPI 2.0 suspend ordering has been | ||
342 | * requested. | ||
343 | */ | ||
344 | static int acpi_hibernation_begin_old(void) | ||
326 | { | 345 | { |
327 | acpi_status status; | 346 | int error = acpi_sleep_prepare(ACPI_STATE_S4); |
328 | |||
329 | status = acpi_hw_disable_all_gpes(); | ||
330 | |||
331 | return ACPI_SUCCESS(status) ? 0 : -EFAULT; | ||
332 | } | ||
333 | 347 | ||
334 | static void acpi_hibernation_restore_cleanup(void) | 348 | if (!error) |
335 | { | 349 | acpi_target_sleep_state = ACPI_STATE_S4; |
336 | acpi_hw_enable_all_runtime_gpes(); | 350 | return error; |
337 | } | 351 | } |
338 | 352 | ||
339 | static struct platform_hibernation_ops acpi_hibernation_ops = { | 353 | /* |
340 | .begin = acpi_hibernation_begin, | 354 | * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has |
341 | .end = acpi_hibernation_end, | 355 | * been requested. |
342 | .pre_snapshot = acpi_hibernation_prepare, | 356 | */ |
343 | .finish = acpi_hibernation_finish, | 357 | static struct platform_hibernation_ops acpi_hibernation_ops_old = { |
344 | .prepare = acpi_hibernation_prepare, | 358 | .begin = acpi_hibernation_begin_old, |
359 | .end = acpi_pm_end, | ||
360 | .pre_snapshot = acpi_pm_disable_gpes, | ||
361 | .finish = acpi_pm_finish, | ||
362 | .prepare = acpi_pm_disable_gpes, | ||
345 | .enter = acpi_hibernation_enter, | 363 | .enter = acpi_hibernation_enter, |
346 | .leave = acpi_hibernation_leave, | 364 | .leave = acpi_hibernation_leave, |
347 | .pre_restore = acpi_hibernation_pre_restore, | 365 | .pre_restore = acpi_pm_disable_gpes, |
348 | .restore_cleanup = acpi_hibernation_restore_cleanup, | 366 | .restore_cleanup = acpi_pm_enable_gpes, |
367 | .recover = acpi_pm_finish, | ||
349 | }; | 368 | }; |
350 | #endif /* CONFIG_HIBERNATION */ | 369 | #endif /* CONFIG_HIBERNATION */ |
351 | 370 | ||
352 | int acpi_suspend(u32 acpi_state) | 371 | int acpi_suspend(u32 acpi_state) |
353 | { | 372 | { |
@@ -368,8 +387,8 @@ int acpi_suspend(u32 acpi_state) | |||
368 | /** | 387 | /** |
369 | * acpi_pm_device_sleep_state - return preferred power state of ACPI device | 388 | * acpi_pm_device_sleep_state - return preferred power state of ACPI device |
370 | * in the system sleep state given by %acpi_target_sleep_state | 389 | * in the system sleep state given by %acpi_target_sleep_state |
371 | * @dev: device to examine | 390 | * @dev: device to examine; its driver model wakeup flags control |
372 | * @wake: if set, the device should be able to wake up the system | 391 | * whether it should be able to wake up the system |
373 | * @d_min_p: used to store the upper limit of allowed states range | 392 | * @d_min_p: used to store the upper limit of allowed states range |
374 | * Return value: preferred power state of the device on success, -ENODEV on | 393 | * Return value: preferred power state of the device on success, -ENODEV on |
375 | * failure (ie. if there's no 'struct acpi_device' for @dev) | 394 | * failure (ie. if there's no 'struct acpi_device' for @dev) |
@@ -387,7 +406,7 @@ int acpi_suspend(u32 acpi_state) | |||
387 | * via @wake. | 406 | * via @wake. |
388 | */ | 407 | */ |
389 | 408 | ||
390 | int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p) | 409 | int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) |
391 | { | 410 | { |
392 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); | 411 | acpi_handle handle = DEVICE_ACPI_HANDLE(dev); |
393 | struct acpi_device *adev; | 412 | struct acpi_device *adev; |
@@ -426,7 +445,7 @@ int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p) | |||
426 | * can wake the system. _S0W may be valid, too. | 445 | * can wake the system. _S0W may be valid, too. |
427 | */ | 446 | */ |
428 | if (acpi_target_sleep_state == ACPI_STATE_S0 || | 447 | if (acpi_target_sleep_state == ACPI_STATE_S0 || |
429 | (wake && adev->wakeup.state.enabled && | 448 | (device_may_wakeup(dev) && adev->wakeup.state.enabled && |
430 | adev->wakeup.sleep_state <= acpi_target_sleep_state)) { | 449 | adev->wakeup.sleep_state <= acpi_target_sleep_state)) { |
431 | acpi_status status; | 450 | acpi_status status; |
432 | 451 | ||
@@ -448,6 +467,31 @@ int acpi_pm_device_sleep_state(struct device *dev, int wake, int *d_min_p) | |||
448 | *d_min_p = d_min; | 467 | *d_min_p = d_min; |
449 | return d_max; | 468 | return d_max; |
450 | } | 469 | } |
470 | |||
471 | /** | ||
472 | * acpi_pm_device_sleep_wake - enable or disable the system wake-up | ||
473 | * capability of given device | ||
474 | * @dev: device to handle | ||
475 | * @enable: 'true' - enable, 'false' - disable the wake-up capability | ||
476 | */ | ||
477 | int acpi_pm_device_sleep_wake(struct device *dev, bool enable) | ||
478 | { | ||
479 | acpi_handle handle; | ||
480 | struct acpi_device *adev; | ||
481 | |||
482 | if (!device_may_wakeup(dev)) | ||
483 | return -EINVAL; | ||
484 | |||
485 | handle = DEVICE_ACPI_HANDLE(dev); | ||
486 | if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | ||
487 | printk(KERN_DEBUG "ACPI handle has no context!\n"); | ||
488 | return -ENODEV; | ||
489 | } | ||
490 | |||
491 | return enable ? | ||
492 | acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : | ||
493 | acpi_disable_wakeup_device_power(adev); | ||
494 | } | ||
451 | #endif | 495 | #endif |
452 | 496 | ||
453 | static void acpi_power_off_prepare(void) | 497 | static void acpi_power_off_prepare(void) |
@@ -472,8 +516,6 @@ int __init acpi_sleep_init(void) | |||
472 | u8 type_a, type_b; | 516 | u8 type_a, type_b; |
473 | #ifdef CONFIG_SUSPEND | 517 | #ifdef CONFIG_SUSPEND |
474 | int i = 0; | 518 | int i = 0; |
475 | |||
476 | dmi_check_system(acpisleep_dmi_table); | ||
477 | #endif | 519 | #endif |
478 | 520 | ||
479 | if (acpi_disabled) | 521 | if (acpi_disabled) |
@@ -491,13 +533,15 @@ int __init acpi_sleep_init(void) | |||
491 | } | 533 | } |
492 | } | 534 | } |
493 | 535 | ||
494 | suspend_set_ops(&acpi_suspend_ops); | 536 | suspend_set_ops(old_suspend_ordering ? |
537 | &acpi_suspend_ops_old : &acpi_suspend_ops); | ||
495 | #endif | 538 | #endif |
496 | 539 | ||
497 | #ifdef CONFIG_HIBERNATION | 540 | #ifdef CONFIG_HIBERNATION |
498 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); | 541 | status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); |
499 | if (ACPI_SUCCESS(status)) { | 542 | if (ACPI_SUCCESS(status)) { |
500 | hibernation_set_ops(&acpi_hibernation_ops); | 543 | hibernation_set_ops(old_suspend_ordering ? |
544 | &acpi_hibernation_ops_old : &acpi_hibernation_ops); | ||
501 | sleep_states[ACPI_STATE_S4] = 1; | 545 | sleep_states[ACPI_STATE_S4] = 1; |
502 | printk(" S4"); | 546 | printk(" S4"); |
503 | } | 547 | } |
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c index ed8e41becf0c..38655eb132dc 100644 --- a/drivers/acpi/sleep/wakeup.c +++ b/drivers/acpi/sleep/wakeup.c | |||
@@ -42,7 +42,7 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state) | |||
42 | continue; | 42 | continue; |
43 | 43 | ||
44 | spin_unlock(&acpi_device_lock); | 44 | spin_unlock(&acpi_device_lock); |
45 | acpi_enable_wakeup_device_power(dev); | 45 | acpi_enable_wakeup_device_power(dev, sleep_state); |
46 | spin_lock(&acpi_device_lock); | 46 | spin_lock(&acpi_device_lock); |
47 | } | 47 | } |
48 | spin_unlock(&acpi_device_lock); | 48 | spin_unlock(&acpi_device_lock); |
@@ -66,13 +66,15 @@ void acpi_enable_wakeup_device(u8 sleep_state) | |||
66 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { | 66 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
67 | struct acpi_device *dev = | 67 | struct acpi_device *dev = |
68 | container_of(node, struct acpi_device, wakeup_list); | 68 | container_of(node, struct acpi_device, wakeup_list); |
69 | |||
69 | if (!dev->wakeup.flags.valid) | 70 | if (!dev->wakeup.flags.valid) |
70 | continue; | 71 | continue; |
72 | |||
71 | /* If users want to disable run-wake GPE, | 73 | /* If users want to disable run-wake GPE, |
72 | * we only disable it for wake and leave it for runtime | 74 | * we only disable it for wake and leave it for runtime |
73 | */ | 75 | */ |
74 | if (!dev->wakeup.state.enabled || | 76 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
75 | sleep_state > (u32) dev->wakeup.sleep_state) { | 77 | || sleep_state > (u32) dev->wakeup.sleep_state) { |
76 | if (dev->wakeup.flags.run_wake) { | 78 | if (dev->wakeup.flags.run_wake) { |
77 | spin_unlock(&acpi_device_lock); | 79 | spin_unlock(&acpi_device_lock); |
78 | /* set_gpe_type will disable GPE, leave it like that */ | 80 | /* set_gpe_type will disable GPE, leave it like that */ |
@@ -110,8 +112,9 @@ void acpi_disable_wakeup_device(u8 sleep_state) | |||
110 | 112 | ||
111 | if (!dev->wakeup.flags.valid) | 113 | if (!dev->wakeup.flags.valid) |
112 | continue; | 114 | continue; |
113 | if (!dev->wakeup.state.enabled || | 115 | |
114 | sleep_state > (u32) dev->wakeup.sleep_state) { | 116 | if ((!dev->wakeup.state.enabled && !dev->wakeup.flags.prepared) |
117 | || sleep_state > (u32) dev->wakeup.sleep_state) { | ||
115 | if (dev->wakeup.flags.run_wake) { | 118 | if (dev->wakeup.flags.run_wake) { |
116 | spin_unlock(&acpi_device_lock); | 119 | spin_unlock(&acpi_device_lock); |
117 | acpi_set_gpe_type(dev->wakeup.gpe_device, | 120 | acpi_set_gpe_type(dev->wakeup.gpe_device, |
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c index 5bd2dec9a7ac..d8e3f153b295 100644 --- a/drivers/acpi/system.c +++ b/drivers/acpi/system.c | |||
@@ -167,7 +167,13 @@ static int acpi_system_sysfs_init(void) | |||
167 | #define COUNT_ERROR 2 /* other */ | 167 | #define COUNT_ERROR 2 /* other */ |
168 | #define NUM_COUNTERS_EXTRA 3 | 168 | #define NUM_COUNTERS_EXTRA 3 |
169 | 169 | ||
170 | static u32 *all_counters; | 170 | #define ACPI_EVENT_VALID 0x01 |
171 | struct event_counter { | ||
172 | u32 count; | ||
173 | u32 flags; | ||
174 | }; | ||
175 | |||
176 | static struct event_counter *all_counters; | ||
171 | static u32 num_gpes; | 177 | static u32 num_gpes; |
172 | static u32 num_counters; | 178 | static u32 num_counters; |
173 | static struct attribute **all_attrs; | 179 | static struct attribute **all_attrs; |
@@ -202,9 +208,44 @@ static int count_num_gpes(void) | |||
202 | return count; | 208 | return count; |
203 | } | 209 | } |
204 | 210 | ||
211 | static int get_gpe_device(int index, acpi_handle *handle) | ||
212 | { | ||
213 | struct acpi_gpe_xrupt_info *gpe_xrupt_info; | ||
214 | struct acpi_gpe_block_info *gpe_block; | ||
215 | acpi_cpu_flags flags; | ||
216 | struct acpi_namespace_node *node; | ||
217 | |||
218 | flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); | ||
219 | |||
220 | gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head; | ||
221 | while (gpe_xrupt_info) { | ||
222 | gpe_block = gpe_xrupt_info->gpe_block_list_head; | ||
223 | node = gpe_block->node; | ||
224 | while (gpe_block) { | ||
225 | index -= gpe_block->register_count * | ||
226 | ACPI_GPE_REGISTER_WIDTH; | ||
227 | if (index < 0) { | ||
228 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | ||
229 | /* return NULL if it's FADT GPE */ | ||
230 | if (node->type != ACPI_TYPE_DEVICE) | ||
231 | *handle = NULL; | ||
232 | else | ||
233 | *handle = node; | ||
234 | return 0; | ||
235 | } | ||
236 | node = gpe_block->node; | ||
237 | gpe_block = gpe_block->next; | ||
238 | } | ||
239 | gpe_xrupt_info = gpe_xrupt_info->next; | ||
240 | } | ||
241 | acpi_os_release_lock(acpi_gbl_gpe_lock, flags); | ||
242 | |||
243 | return -ENODEV; | ||
244 | } | ||
245 | |||
205 | static void delete_gpe_attr_array(void) | 246 | static void delete_gpe_attr_array(void) |
206 | { | 247 | { |
207 | u32 *tmp = all_counters; | 248 | struct event_counter *tmp = all_counters; |
208 | 249 | ||
209 | all_counters = NULL; | 250 | all_counters = NULL; |
210 | kfree(tmp); | 251 | kfree(tmp); |
@@ -230,9 +271,10 @@ void acpi_os_gpe_count(u32 gpe_number) | |||
230 | return; | 271 | return; |
231 | 272 | ||
232 | if (gpe_number < num_gpes) | 273 | if (gpe_number < num_gpes) |
233 | all_counters[gpe_number]++; | 274 | all_counters[gpe_number].count++; |
234 | else | 275 | else |
235 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++; | 276 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]. |
277 | count++; | ||
236 | 278 | ||
237 | return; | 279 | return; |
238 | } | 280 | } |
@@ -243,44 +285,144 @@ void acpi_os_fixed_event_count(u32 event_number) | |||
243 | return; | 285 | return; |
244 | 286 | ||
245 | if (event_number < ACPI_NUM_FIXED_EVENTS) | 287 | if (event_number < ACPI_NUM_FIXED_EVENTS) |
246 | all_counters[num_gpes + event_number]++; | 288 | all_counters[num_gpes + event_number].count++; |
247 | else | 289 | else |
248 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]++; | 290 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_ERROR]. |
291 | count++; | ||
249 | 292 | ||
250 | return; | 293 | return; |
251 | } | 294 | } |
252 | 295 | ||
296 | static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle) | ||
297 | { | ||
298 | int result = 0; | ||
299 | |||
300 | if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) | ||
301 | goto end; | ||
302 | |||
303 | if (index < num_gpes) { | ||
304 | result = get_gpe_device(index, handle); | ||
305 | if (result) { | ||
306 | ACPI_EXCEPTION((AE_INFO, AE_NOT_FOUND, | ||
307 | "Invalid GPE 0x%x\n", index)); | ||
308 | goto end; | ||
309 | } | ||
310 | result = acpi_get_gpe_status(*handle, index, | ||
311 | ACPI_NOT_ISR, status); | ||
312 | } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS)) | ||
313 | result = acpi_get_event_status(index - num_gpes, status); | ||
314 | |||
315 | /* | ||
316 | * sleep/power button GPE/Fixed Event is enabled after acpi_system_init, | ||
317 | * check the status at runtime and mark it as valid once it's enabled | ||
318 | */ | ||
319 | if (!result && (*status & ACPI_EVENT_FLAG_ENABLED)) | ||
320 | all_counters[index].flags |= ACPI_EVENT_VALID; | ||
321 | end: | ||
322 | return result; | ||
323 | } | ||
324 | |||
253 | static ssize_t counter_show(struct kobject *kobj, | 325 | static ssize_t counter_show(struct kobject *kobj, |
254 | struct kobj_attribute *attr, char *buf) | 326 | struct kobj_attribute *attr, char *buf) |
255 | { | 327 | { |
256 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI] = | 328 | int index = attr - counter_attrs; |
329 | int size; | ||
330 | acpi_handle handle; | ||
331 | acpi_event_status status; | ||
332 | int result = 0; | ||
333 | |||
334 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI].count = | ||
257 | acpi_irq_handled; | 335 | acpi_irq_handled; |
258 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE] = | 336 | all_counters[num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_GPE].count = |
259 | acpi_gpe_count; | 337 | acpi_gpe_count; |
260 | 338 | ||
261 | return sprintf(buf, "%d\n", all_counters[attr - counter_attrs]); | 339 | size = sprintf(buf, "%8d", all_counters[index].count); |
340 | |||
341 | /* "gpe_all" or "sci" */ | ||
342 | if (index >= num_gpes + ACPI_NUM_FIXED_EVENTS) | ||
343 | goto end; | ||
344 | |||
345 | result = get_status(index, &status, &handle); | ||
346 | if (result) | ||
347 | goto end; | ||
348 | |||
349 | if (!(all_counters[index].flags & ACPI_EVENT_VALID)) | ||
350 | size += sprintf(buf + size, " invalid"); | ||
351 | else if (status & ACPI_EVENT_FLAG_ENABLED) | ||
352 | size += sprintf(buf + size, " enable"); | ||
353 | else | ||
354 | size += sprintf(buf + size, " disable"); | ||
355 | |||
356 | end: | ||
357 | size += sprintf(buf + size, "\n"); | ||
358 | return result ? result : size; | ||
262 | } | 359 | } |
263 | 360 | ||
264 | /* | 361 | /* |
265 | * counter_set() sets the specified counter. | 362 | * counter_set() sets the specified counter. |
266 | * setting the total "sci" file to any value clears all counters. | 363 | * setting the total "sci" file to any value clears all counters. |
364 | * enable/disable/clear a gpe/fixed event in user space. | ||
267 | */ | 365 | */ |
268 | static ssize_t counter_set(struct kobject *kobj, | 366 | static ssize_t counter_set(struct kobject *kobj, |
269 | struct kobj_attribute *attr, const char *buf, size_t size) | 367 | struct kobj_attribute *attr, const char *buf, size_t size) |
270 | { | 368 | { |
271 | int index = attr - counter_attrs; | 369 | int index = attr - counter_attrs; |
370 | acpi_event_status status; | ||
371 | acpi_handle handle; | ||
372 | int result = 0; | ||
272 | 373 | ||
273 | if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { | 374 | if (index == num_gpes + ACPI_NUM_FIXED_EVENTS + COUNT_SCI) { |
274 | int i; | 375 | int i; |
275 | for (i = 0; i < num_counters; ++i) | 376 | for (i = 0; i < num_counters; ++i) |
276 | all_counters[i] = 0; | 377 | all_counters[i].count = 0; |
277 | acpi_gpe_count = 0; | 378 | acpi_gpe_count = 0; |
278 | acpi_irq_handled = 0; | 379 | acpi_irq_handled = 0; |
380 | goto end; | ||
381 | } | ||
279 | 382 | ||
383 | /* show the event status for both GPEs and Fixed Events */ | ||
384 | result = get_status(index, &status, &handle); | ||
385 | if (result) | ||
386 | goto end; | ||
387 | |||
388 | if (!(all_counters[index].flags & ACPI_EVENT_VALID)) { | ||
389 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, | ||
390 | "Can not change Invalid GPE/Fixed Event status\n")); | ||
391 | return -EINVAL; | ||
392 | } | ||
393 | |||
394 | if (index < num_gpes) { | ||
395 | if (!strcmp(buf, "disable\n") && | ||
396 | (status & ACPI_EVENT_FLAG_ENABLED)) | ||
397 | result = acpi_disable_gpe(handle, index, ACPI_NOT_ISR); | ||
398 | else if (!strcmp(buf, "enable\n") && | ||
399 | !(status & ACPI_EVENT_FLAG_ENABLED)) | ||
400 | result = acpi_enable_gpe(handle, index, ACPI_NOT_ISR); | ||
401 | else if (!strcmp(buf, "clear\n") && | ||
402 | (status & ACPI_EVENT_FLAG_SET)) | ||
403 | result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR); | ||
404 | else | ||
405 | all_counters[index].count = strtoul(buf, NULL, 0); | ||
406 | } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) { | ||
407 | int event = index - num_gpes; | ||
408 | if (!strcmp(buf, "disable\n") && | ||
409 | (status & ACPI_EVENT_FLAG_ENABLED)) | ||
410 | result = acpi_disable_event(event, ACPI_NOT_ISR); | ||
411 | else if (!strcmp(buf, "enable\n") && | ||
412 | !(status & ACPI_EVENT_FLAG_ENABLED)) | ||
413 | result = acpi_enable_event(event, ACPI_NOT_ISR); | ||
414 | else if (!strcmp(buf, "clear\n") && | ||
415 | (status & ACPI_EVENT_FLAG_SET)) | ||
416 | result = acpi_clear_event(event); | ||
417 | else | ||
418 | all_counters[index].count = strtoul(buf, NULL, 0); | ||
280 | } else | 419 | } else |
281 | all_counters[index] = strtoul(buf, NULL, 0); | 420 | all_counters[index].count = strtoul(buf, NULL, 0); |
282 | 421 | ||
283 | return size; | 422 | if (ACPI_FAILURE(result)) |
423 | result = -EINVAL; | ||
424 | end: | ||
425 | return result ? result : size; | ||
284 | } | 426 | } |
285 | 427 | ||
286 | void acpi_irq_stats_init(void) | 428 | void acpi_irq_stats_init(void) |
@@ -298,7 +440,8 @@ void acpi_irq_stats_init(void) | |||
298 | if (all_attrs == NULL) | 440 | if (all_attrs == NULL) |
299 | return; | 441 | return; |
300 | 442 | ||
301 | all_counters = kzalloc(sizeof(u32) * (num_counters), GFP_KERNEL); | 443 | all_counters = kzalloc(sizeof(struct event_counter) * (num_counters), |
444 | GFP_KERNEL); | ||
302 | if (all_counters == NULL) | 445 | if (all_counters == NULL) |
303 | goto fail; | 446 | goto fail; |
304 | 447 | ||
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c index 949d4114eb9f..ccb5b64bbef3 100644 --- a/drivers/acpi/tables/tbfadt.c +++ b/drivers/acpi/tables/tbfadt.c | |||
@@ -124,7 +124,7 @@ static struct acpi_fadt_info fadt_info_table[] = { | |||
124 | 124 | ||
125 | static void inline | 125 | static void inline |
126 | acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, | 126 | acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, |
127 | u8 bit_width, u64 address) | 127 | u8 byte_width, u64 address) |
128 | { | 128 | { |
129 | 129 | ||
130 | /* | 130 | /* |
@@ -136,7 +136,7 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, | |||
136 | /* All other fields are byte-wide */ | 136 | /* All other fields are byte-wide */ |
137 | 137 | ||
138 | generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO; | 138 | generic_address->space_id = ACPI_ADR_SPACE_SYSTEM_IO; |
139 | generic_address->bit_width = bit_width; | 139 | generic_address->bit_width = byte_width << 3; |
140 | generic_address->bit_offset = 0; | 140 | generic_address->bit_offset = 0; |
141 | generic_address->access_width = 0; | 141 | generic_address->access_width = 0; |
142 | } | 142 | } |
@@ -155,7 +155,7 @@ acpi_tb_init_generic_address(struct acpi_generic_address *generic_address, | |||
155 | * | 155 | * |
156 | ******************************************************************************/ | 156 | ******************************************************************************/ |
157 | 157 | ||
158 | void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags) | 158 | void acpi_tb_parse_fadt(u32 table_index, u8 flags) |
159 | { | 159 | { |
160 | u32 length; | 160 | u32 length; |
161 | struct acpi_table_header *table; | 161 | struct acpi_table_header *table; |
@@ -280,7 +280,7 @@ static void acpi_tb_convert_fadt(void) | |||
280 | { | 280 | { |
281 | u8 pm1_register_length; | 281 | u8 pm1_register_length; |
282 | struct acpi_generic_address *target; | 282 | struct acpi_generic_address *target; |
283 | acpi_native_uint i; | 283 | u32 i; |
284 | 284 | ||
285 | /* Update the local FADT table header length */ | 285 | /* Update the local FADT table header length */ |
286 | 286 | ||
@@ -343,9 +343,11 @@ static void acpi_tb_convert_fadt(void) | |||
343 | * | 343 | * |
344 | * The PM event blocks are split into two register blocks, first is the | 344 | * The PM event blocks are split into two register blocks, first is the |
345 | * PM Status Register block, followed immediately by the PM Enable Register | 345 | * PM Status Register block, followed immediately by the PM Enable Register |
346 | * block. Each is of length (pm1_event_length/2) | 346 | * block. Each is of length (xpm1x_event_block.bit_width/2) |
347 | */ | 347 | */ |
348 | pm1_register_length = (u8) ACPI_DIV_2(acpi_gbl_FADT.pm1_event_length); | 348 | WARN_ON(ACPI_MOD_16(acpi_gbl_FADT.xpm1a_event_block.bit_width)); |
349 | pm1_register_length = (u8) ACPI_DIV_16(acpi_gbl_FADT | ||
350 | .xpm1a_event_block.bit_width); | ||
349 | 351 | ||
350 | /* The PM1A register block is required */ | 352 | /* The PM1A register block is required */ |
351 | 353 | ||
@@ -360,14 +362,17 @@ static void acpi_tb_convert_fadt(void) | |||
360 | /* The PM1B register block is optional, ignore if not present */ | 362 | /* The PM1B register block is optional, ignore if not present */ |
361 | 363 | ||
362 | if (acpi_gbl_FADT.xpm1b_event_block.address) { | 364 | if (acpi_gbl_FADT.xpm1b_event_block.address) { |
365 | WARN_ON(ACPI_MOD_16(acpi_gbl_FADT.xpm1b_event_block.bit_width)); | ||
366 | pm1_register_length = (u8) ACPI_DIV_16(acpi_gbl_FADT | ||
367 | .xpm1b_event_block | ||
368 | .bit_width); | ||
363 | acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, | 369 | acpi_tb_init_generic_address(&acpi_gbl_xpm1b_enable, |
364 | pm1_register_length, | 370 | pm1_register_length, |
365 | (acpi_gbl_FADT.xpm1b_event_block. | 371 | (acpi_gbl_FADT.xpm1b_event_block. |
366 | address + pm1_register_length)); | 372 | address + pm1_register_length)); |
367 | /* Don't forget to copy space_id of the GAS */ | 373 | /* Don't forget to copy space_id of the GAS */ |
368 | acpi_gbl_xpm1b_enable.space_id = | 374 | acpi_gbl_xpm1b_enable.space_id = |
369 | acpi_gbl_FADT.xpm1a_event_block.space_id; | 375 | acpi_gbl_FADT.xpm1b_event_block.space_id; |
370 | |||
371 | } | 376 | } |
372 | } | 377 | } |
373 | 378 | ||
@@ -396,7 +401,7 @@ static void acpi_tb_validate_fadt(void) | |||
396 | u32 *address32; | 401 | u32 *address32; |
397 | struct acpi_generic_address *address64; | 402 | struct acpi_generic_address *address64; |
398 | u8 length; | 403 | u8 length; |
399 | acpi_native_uint i; | 404 | u32 i; |
400 | 405 | ||
401 | /* Examine all of the 64-bit extended address fields (X fields) */ | 406 | /* Examine all of the 64-bit extended address fields (X fields) */ |
402 | 407 | ||
diff --git a/drivers/acpi/tables/tbfind.c b/drivers/acpi/tables/tbfind.c index 9ca3afc98c80..531584defbb8 100644 --- a/drivers/acpi/tables/tbfind.c +++ b/drivers/acpi/tables/tbfind.c | |||
@@ -65,10 +65,9 @@ ACPI_MODULE_NAME("tbfind") | |||
65 | ******************************************************************************/ | 65 | ******************************************************************************/ |
66 | acpi_status | 66 | acpi_status |
67 | acpi_tb_find_table(char *signature, | 67 | acpi_tb_find_table(char *signature, |
68 | char *oem_id, | 68 | char *oem_id, char *oem_table_id, u32 *table_index) |
69 | char *oem_table_id, acpi_native_uint * table_index) | ||
70 | { | 69 | { |
71 | acpi_native_uint i; | 70 | u32 i; |
72 | acpi_status status; | 71 | acpi_status status; |
73 | struct acpi_table_header header; | 72 | struct acpi_table_header header; |
74 | 73 | ||
diff --git a/drivers/acpi/tables/tbinstal.c b/drivers/acpi/tables/tbinstal.c index 5336ce88f89f..b22185f55a16 100644 --- a/drivers/acpi/tables/tbinstal.c +++ b/drivers/acpi/tables/tbinstal.c | |||
@@ -107,11 +107,10 @@ acpi_status acpi_tb_verify_table(struct acpi_table_desc *table_desc) | |||
107 | ******************************************************************************/ | 107 | ******************************************************************************/ |
108 | 108 | ||
109 | acpi_status | 109 | acpi_status |
110 | acpi_tb_add_table(struct acpi_table_desc *table_desc, | 110 | acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index) |
111 | acpi_native_uint * table_index) | ||
112 | { | 111 | { |
113 | acpi_native_uint i; | 112 | u32 i; |
114 | acpi_native_uint length; | 113 | u32 length; |
115 | acpi_status status = AE_OK; | 114 | acpi_status status = AE_OK; |
116 | 115 | ||
117 | ACPI_FUNCTION_TRACE(tb_add_table); | 116 | ACPI_FUNCTION_TRACE(tb_add_table); |
@@ -207,8 +206,8 @@ acpi_status acpi_tb_resize_root_table_list(void) | |||
207 | 206 | ||
208 | /* Increase the Table Array size */ | 207 | /* Increase the Table Array size */ |
209 | 208 | ||
210 | tables = ACPI_ALLOCATE_ZEROED((acpi_gbl_root_table_list.size + | 209 | tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list. |
211 | ACPI_ROOT_TABLE_SIZE_INCREMENT) | 210 | size + ACPI_ROOT_TABLE_SIZE_INCREMENT) |
212 | * sizeof(struct acpi_table_desc)); | 211 | * sizeof(struct acpi_table_desc)); |
213 | if (!tables) { | 212 | if (!tables) { |
214 | ACPI_ERROR((AE_INFO, | 213 | ACPI_ERROR((AE_INFO, |
@@ -220,7 +219,7 @@ acpi_status acpi_tb_resize_root_table_list(void) | |||
220 | 219 | ||
221 | if (acpi_gbl_root_table_list.tables) { | 220 | if (acpi_gbl_root_table_list.tables) { |
222 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, | 221 | ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, |
223 | acpi_gbl_root_table_list.size * | 222 | (acpi_size) acpi_gbl_root_table_list.size * |
224 | sizeof(struct acpi_table_desc)); | 223 | sizeof(struct acpi_table_desc)); |
225 | 224 | ||
226 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { | 225 | if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) { |
@@ -253,7 +252,7 @@ acpi_status acpi_tb_resize_root_table_list(void) | |||
253 | acpi_status | 252 | acpi_status |
254 | acpi_tb_store_table(acpi_physical_address address, | 253 | acpi_tb_store_table(acpi_physical_address address, |
255 | struct acpi_table_header *table, | 254 | struct acpi_table_header *table, |
256 | u32 length, u8 flags, acpi_native_uint * table_index) | 255 | u32 length, u8 flags, u32 *table_index) |
257 | { | 256 | { |
258 | acpi_status status = AE_OK; | 257 | acpi_status status = AE_OK; |
259 | 258 | ||
@@ -334,7 +333,7 @@ void acpi_tb_delete_table(struct acpi_table_desc *table_desc) | |||
334 | 333 | ||
335 | void acpi_tb_terminate(void) | 334 | void acpi_tb_terminate(void) |
336 | { | 335 | { |
337 | acpi_native_uint i; | 336 | u32 i; |
338 | 337 | ||
339 | ACPI_FUNCTION_TRACE(tb_terminate); | 338 | ACPI_FUNCTION_TRACE(tb_terminate); |
340 | 339 | ||
@@ -374,7 +373,7 @@ void acpi_tb_terminate(void) | |||
374 | * | 373 | * |
375 | ******************************************************************************/ | 374 | ******************************************************************************/ |
376 | 375 | ||
377 | void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index) | 376 | void acpi_tb_delete_namespace_by_owner(u32 table_index) |
378 | { | 377 | { |
379 | acpi_owner_id owner_id; | 378 | acpi_owner_id owner_id; |
380 | 379 | ||
@@ -403,7 +402,7 @@ void acpi_tb_delete_namespace_by_owner(acpi_native_uint table_index) | |||
403 | * | 402 | * |
404 | ******************************************************************************/ | 403 | ******************************************************************************/ |
405 | 404 | ||
406 | acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index) | 405 | acpi_status acpi_tb_allocate_owner_id(u32 table_index) |
407 | { | 406 | { |
408 | acpi_status status = AE_BAD_PARAMETER; | 407 | acpi_status status = AE_BAD_PARAMETER; |
409 | 408 | ||
@@ -431,7 +430,7 @@ acpi_status acpi_tb_allocate_owner_id(acpi_native_uint table_index) | |||
431 | * | 430 | * |
432 | ******************************************************************************/ | 431 | ******************************************************************************/ |
433 | 432 | ||
434 | acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index) | 433 | acpi_status acpi_tb_release_owner_id(u32 table_index) |
435 | { | 434 | { |
436 | acpi_status status = AE_BAD_PARAMETER; | 435 | acpi_status status = AE_BAD_PARAMETER; |
437 | 436 | ||
@@ -462,8 +461,7 @@ acpi_status acpi_tb_release_owner_id(acpi_native_uint table_index) | |||
462 | * | 461 | * |
463 | ******************************************************************************/ | 462 | ******************************************************************************/ |
464 | 463 | ||
465 | acpi_status | 464 | acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id) |
466 | acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id) | ||
467 | { | 465 | { |
468 | acpi_status status = AE_BAD_PARAMETER; | 466 | acpi_status status = AE_BAD_PARAMETER; |
469 | 467 | ||
@@ -490,7 +488,7 @@ acpi_tb_get_owner_id(acpi_native_uint table_index, acpi_owner_id * owner_id) | |||
490 | * | 488 | * |
491 | ******************************************************************************/ | 489 | ******************************************************************************/ |
492 | 490 | ||
493 | u8 acpi_tb_is_table_loaded(acpi_native_uint table_index) | 491 | u8 acpi_tb_is_table_loaded(u32 table_index) |
494 | { | 492 | { |
495 | u8 is_loaded = FALSE; | 493 | u8 is_loaded = FALSE; |
496 | 494 | ||
@@ -518,7 +516,7 @@ u8 acpi_tb_is_table_loaded(acpi_native_uint table_index) | |||
518 | * | 516 | * |
519 | ******************************************************************************/ | 517 | ******************************************************************************/ |
520 | 518 | ||
521 | void acpi_tb_set_table_loaded_flag(acpi_native_uint table_index, u8 is_loaded) | 519 | void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded) |
522 | { | 520 | { |
523 | 521 | ||
524 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); | 522 | (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES); |
diff --git a/drivers/acpi/tables/tbutils.c b/drivers/acpi/tables/tbutils.c index bc019b9b6a68..0cc92ef5236f 100644 --- a/drivers/acpi/tables/tbutils.c +++ b/drivers/acpi/tables/tbutils.c | |||
@@ -49,8 +49,8 @@ ACPI_MODULE_NAME("tbutils") | |||
49 | 49 | ||
50 | /* Local prototypes */ | 50 | /* Local prototypes */ |
51 | static acpi_physical_address | 51 | static acpi_physical_address |
52 | acpi_tb_get_root_table_entry(u8 * table_entry, | 52 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size); |
53 | acpi_native_uint table_entry_size); | 53 | |
54 | /******************************************************************************* | 54 | /******************************************************************************* |
55 | * | 55 | * |
56 | * FUNCTION: acpi_tb_check_xsdt | 56 | * FUNCTION: acpi_tb_check_xsdt |
@@ -238,7 +238,7 @@ acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length) | |||
238 | * | 238 | * |
239 | ******************************************************************************/ | 239 | ******************************************************************************/ |
240 | 240 | ||
241 | u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length) | 241 | u8 acpi_tb_checksum(u8 *buffer, u32 length) |
242 | { | 242 | { |
243 | u8 sum = 0; | 243 | u8 sum = 0; |
244 | u8 *end = buffer + length; | 244 | u8 *end = buffer + length; |
@@ -268,7 +268,7 @@ u8 acpi_tb_checksum(u8 * buffer, acpi_native_uint length) | |||
268 | 268 | ||
269 | void | 269 | void |
270 | acpi_tb_install_table(acpi_physical_address address, | 270 | acpi_tb_install_table(acpi_physical_address address, |
271 | u8 flags, char *signature, acpi_native_uint table_index) | 271 | u8 flags, char *signature, u32 table_index) |
272 | { | 272 | { |
273 | struct acpi_table_header *table; | 273 | struct acpi_table_header *table; |
274 | 274 | ||
@@ -336,8 +336,7 @@ acpi_tb_install_table(acpi_physical_address address, | |||
336 | ******************************************************************************/ | 336 | ******************************************************************************/ |
337 | 337 | ||
338 | static acpi_physical_address | 338 | static acpi_physical_address |
339 | acpi_tb_get_root_table_entry(u8 * table_entry, | 339 | acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size) |
340 | acpi_native_uint table_entry_size) | ||
341 | { | 340 | { |
342 | u64 address64; | 341 | u64 address64; |
343 | 342 | ||
@@ -395,8 +394,8 @@ acpi_status __init | |||
395 | acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags) | 394 | acpi_tb_parse_root_table(acpi_physical_address rsdp_address, u8 flags) |
396 | { | 395 | { |
397 | struct acpi_table_rsdp *rsdp; | 396 | struct acpi_table_rsdp *rsdp; |
398 | acpi_native_uint table_entry_size; | 397 | u32 table_entry_size; |
399 | acpi_native_uint i; | 398 | u32 i; |
400 | u32 table_count; | 399 | u32 table_count; |
401 | struct acpi_table_header *table; | 400 | struct acpi_table_header *table; |
402 | acpi_physical_address address; | 401 | acpi_physical_address address; |
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c index 0e319604d3e7..fd7770aa1061 100644 --- a/drivers/acpi/tables/tbxface.c +++ b/drivers/acpi/tables/tbxface.c | |||
@@ -125,7 +125,7 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array, | |||
125 | /* Root Table Array has been statically allocated by the host */ | 125 | /* Root Table Array has been statically allocated by the host */ |
126 | 126 | ||
127 | ACPI_MEMSET(initial_table_array, 0, | 127 | ACPI_MEMSET(initial_table_array, 0, |
128 | initial_table_count * | 128 | (acpi_size) initial_table_count * |
129 | sizeof(struct acpi_table_desc)); | 129 | sizeof(struct acpi_table_desc)); |
130 | 130 | ||
131 | acpi_gbl_root_table_list.tables = initial_table_array; | 131 | acpi_gbl_root_table_list.tables = initial_table_array; |
@@ -183,9 +183,9 @@ acpi_status acpi_reallocate_root_table(void) | |||
183 | return_ACPI_STATUS(AE_SUPPORT); | 183 | return_ACPI_STATUS(AE_SUPPORT); |
184 | } | 184 | } |
185 | 185 | ||
186 | new_size = | 186 | new_size = ((acpi_size) acpi_gbl_root_table_list.count + |
187 | (acpi_gbl_root_table_list.count + | 187 | ACPI_ROOT_TABLE_SIZE_INCREMENT) * |
188 | ACPI_ROOT_TABLE_SIZE_INCREMENT) * sizeof(struct acpi_table_desc); | 188 | sizeof(struct acpi_table_desc); |
189 | 189 | ||
190 | /* Create new array and copy the old array */ | 190 | /* Create new array and copy the old array */ |
191 | 191 | ||
@@ -222,7 +222,7 @@ acpi_status acpi_reallocate_root_table(void) | |||
222 | acpi_status acpi_load_table(struct acpi_table_header *table_ptr) | 222 | acpi_status acpi_load_table(struct acpi_table_header *table_ptr) |
223 | { | 223 | { |
224 | acpi_status status; | 224 | acpi_status status; |
225 | acpi_native_uint table_index; | 225 | u32 table_index; |
226 | struct acpi_table_desc table_desc; | 226 | struct acpi_table_desc table_desc; |
227 | 227 | ||
228 | if (!table_ptr) | 228 | if (!table_ptr) |
@@ -264,11 +264,10 @@ ACPI_EXPORT_SYMBOL(acpi_load_table) | |||
264 | *****************************************************************************/ | 264 | *****************************************************************************/ |
265 | acpi_status | 265 | acpi_status |
266 | acpi_get_table_header(char *signature, | 266 | acpi_get_table_header(char *signature, |
267 | acpi_native_uint instance, | 267 | u32 instance, struct acpi_table_header *out_table_header) |
268 | struct acpi_table_header * out_table_header) | ||
269 | { | 268 | { |
270 | acpi_native_uint i; | 269 | u32 i; |
271 | acpi_native_uint j; | 270 | u32 j; |
272 | struct acpi_table_header *header; | 271 | struct acpi_table_header *header; |
273 | 272 | ||
274 | /* Parameter validation */ | 273 | /* Parameter validation */ |
@@ -378,10 +377,10 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id) | |||
378 | *****************************************************************************/ | 377 | *****************************************************************************/ |
379 | acpi_status | 378 | acpi_status |
380 | acpi_get_table(char *signature, | 379 | acpi_get_table(char *signature, |
381 | acpi_native_uint instance, struct acpi_table_header **out_table) | 380 | u32 instance, struct acpi_table_header **out_table) |
382 | { | 381 | { |
383 | acpi_native_uint i; | 382 | u32 i; |
384 | acpi_native_uint j; | 383 | u32 j; |
385 | acpi_status status; | 384 | acpi_status status; |
386 | 385 | ||
387 | /* Parameter validation */ | 386 | /* Parameter validation */ |
@@ -435,8 +434,7 @@ ACPI_EXPORT_SYMBOL(acpi_get_table) | |||
435 | * | 434 | * |
436 | ******************************************************************************/ | 435 | ******************************************************************************/ |
437 | acpi_status | 436 | acpi_status |
438 | acpi_get_table_by_index(acpi_native_uint table_index, | 437 | acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table) |
439 | struct acpi_table_header ** table) | ||
440 | { | 438 | { |
441 | acpi_status status; | 439 | acpi_status status; |
442 | 440 | ||
@@ -493,7 +491,7 @@ static acpi_status acpi_tb_load_namespace(void) | |||
493 | { | 491 | { |
494 | acpi_status status; | 492 | acpi_status status; |
495 | struct acpi_table_header *table; | 493 | struct acpi_table_header *table; |
496 | acpi_native_uint i; | 494 | u32 i; |
497 | 495 | ||
498 | ACPI_FUNCTION_TRACE(tb_load_namespace); | 496 | ACPI_FUNCTION_TRACE(tb_load_namespace); |
499 | 497 | ||
diff --git a/drivers/acpi/tables/tbxfroot.c b/drivers/acpi/tables/tbxfroot.c index b8c0dfa084f6..2d157e0f98d2 100644 --- a/drivers/acpi/tables/tbxfroot.c +++ b/drivers/acpi/tables/tbxfroot.c | |||
@@ -118,7 +118,7 @@ static acpi_status acpi_tb_validate_rsdp(struct acpi_table_rsdp *rsdp) | |||
118 | * | 118 | * |
119 | ******************************************************************************/ | 119 | ******************************************************************************/ |
120 | 120 | ||
121 | acpi_status acpi_find_root_pointer(acpi_native_uint * table_address) | 121 | acpi_status acpi_find_root_pointer(acpi_size *table_address) |
122 | { | 122 | { |
123 | u8 *table_ptr; | 123 | u8 *table_ptr; |
124 | u8 *mem_rover; | 124 | u8 *mem_rover; |
@@ -153,7 +153,7 @@ acpi_status acpi_find_root_pointer(acpi_native_uint * table_address) | |||
153 | * 1b) Search EBDA paragraphs (EBDA is required to be a | 153 | * 1b) Search EBDA paragraphs (EBDA is required to be a |
154 | * minimum of 1_k length) | 154 | * minimum of 1_k length) |
155 | */ | 155 | */ |
156 | table_ptr = acpi_os_map_memory((acpi_native_uint) | 156 | table_ptr = acpi_os_map_memory((acpi_physical_address) |
157 | physical_address, | 157 | physical_address, |
158 | ACPI_EBDA_WINDOW_SIZE); | 158 | ACPI_EBDA_WINDOW_SIZE); |
159 | if (!table_ptr) { | 159 | if (!table_ptr) { |
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c index ede084829a70..3dfb8a442b26 100644 --- a/drivers/acpi/utilities/utalloc.c +++ b/drivers/acpi/utilities/utalloc.c | |||
@@ -309,7 +309,8 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer, | |||
309 | * | 309 | * |
310 | ******************************************************************************/ | 310 | ******************************************************************************/ |
311 | 311 | ||
312 | void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line) | 312 | void *acpi_ut_allocate(acpi_size size, |
313 | u32 component, const char *module, u32 line) | ||
313 | { | 314 | { |
314 | void *allocation; | 315 | void *allocation; |
315 | 316 | ||
@@ -353,7 +354,7 @@ void *acpi_ut_allocate(acpi_size size, u32 component, char *module, u32 line) | |||
353 | ******************************************************************************/ | 354 | ******************************************************************************/ |
354 | 355 | ||
355 | void *acpi_ut_allocate_zeroed(acpi_size size, | 356 | void *acpi_ut_allocate_zeroed(acpi_size size, |
356 | u32 component, char *module, u32 line) | 357 | u32 component, const char *module, u32 line) |
357 | { | 358 | { |
358 | void *allocation; | 359 | void *allocation; |
359 | 360 | ||
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c index 655c290aca7b..53499ac90988 100644 --- a/drivers/acpi/utilities/utcopy.c +++ b/drivers/acpi/utilities/utcopy.c | |||
@@ -572,7 +572,7 @@ acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object, | |||
572 | acpi_status status = AE_OK; | 572 | acpi_status status = AE_OK; |
573 | union acpi_operand_object *package_object; | 573 | union acpi_operand_object *package_object; |
574 | union acpi_operand_object **package_elements; | 574 | union acpi_operand_object **package_elements; |
575 | acpi_native_uint i; | 575 | u32 i; |
576 | 576 | ||
577 | ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage); | 577 | ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage); |
578 | 578 | ||
@@ -599,7 +599,7 @@ acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object, | |||
599 | 599 | ||
600 | /* Truncate package and delete it */ | 600 | /* Truncate package and delete it */ |
601 | 601 | ||
602 | package_object->package.count = (u32) i; | 602 | package_object->package.count = i; |
603 | package_elements[i] = NULL; | 603 | package_elements[i] = NULL; |
604 | acpi_ut_remove_reference(package_object); | 604 | acpi_ut_remove_reference(package_object); |
605 | return_ACPI_STATUS(status); | 605 | return_ACPI_STATUS(status); |
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c index f938f465efa4..fd66ecb6741e 100644 --- a/drivers/acpi/utilities/utdebug.c +++ b/drivers/acpi/utilities/utdebug.c | |||
@@ -157,7 +157,8 @@ void ACPI_INTERNAL_VAR_XFACE | |||
157 | acpi_ut_debug_print(u32 requested_debug_level, | 157 | acpi_ut_debug_print(u32 requested_debug_level, |
158 | u32 line_number, | 158 | u32 line_number, |
159 | const char *function_name, | 159 | const char *function_name, |
160 | char *module_name, u32 component_id, char *format, ...) | 160 | const char *module_name, |
161 | u32 component_id, const char *format, ...) | ||
161 | { | 162 | { |
162 | acpi_thread_id thread_id; | 163 | acpi_thread_id thread_id; |
163 | va_list args; | 164 | va_list args; |
@@ -228,7 +229,8 @@ void ACPI_INTERNAL_VAR_XFACE | |||
228 | acpi_ut_debug_print_raw(u32 requested_debug_level, | 229 | acpi_ut_debug_print_raw(u32 requested_debug_level, |
229 | u32 line_number, | 230 | u32 line_number, |
230 | const char *function_name, | 231 | const char *function_name, |
231 | char *module_name, u32 component_id, char *format, ...) | 232 | const char *module_name, |
233 | u32 component_id, const char *format, ...) | ||
232 | { | 234 | { |
233 | va_list args; | 235 | va_list args; |
234 | 236 | ||
@@ -261,7 +263,8 @@ ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw) | |||
261 | ******************************************************************************/ | 263 | ******************************************************************************/ |
262 | void | 264 | void |
263 | acpi_ut_trace(u32 line_number, | 265 | acpi_ut_trace(u32 line_number, |
264 | const char *function_name, char *module_name, u32 component_id) | 266 | const char *function_name, |
267 | const char *module_name, u32 component_id) | ||
265 | { | 268 | { |
266 | 269 | ||
267 | acpi_gbl_nesting_level++; | 270 | acpi_gbl_nesting_level++; |
@@ -293,7 +296,7 @@ ACPI_EXPORT_SYMBOL(acpi_ut_trace) | |||
293 | void | 296 | void |
294 | acpi_ut_trace_ptr(u32 line_number, | 297 | acpi_ut_trace_ptr(u32 line_number, |
295 | const char *function_name, | 298 | const char *function_name, |
296 | char *module_name, u32 component_id, void *pointer) | 299 | const char *module_name, u32 component_id, void *pointer) |
297 | { | 300 | { |
298 | acpi_gbl_nesting_level++; | 301 | acpi_gbl_nesting_level++; |
299 | acpi_ut_track_stack_ptr(); | 302 | acpi_ut_track_stack_ptr(); |
@@ -324,7 +327,7 @@ acpi_ut_trace_ptr(u32 line_number, | |||
324 | void | 327 | void |
325 | acpi_ut_trace_str(u32 line_number, | 328 | acpi_ut_trace_str(u32 line_number, |
326 | const char *function_name, | 329 | const char *function_name, |
327 | char *module_name, u32 component_id, char *string) | 330 | const char *module_name, u32 component_id, char *string) |
328 | { | 331 | { |
329 | 332 | ||
330 | acpi_gbl_nesting_level++; | 333 | acpi_gbl_nesting_level++; |
@@ -356,7 +359,7 @@ acpi_ut_trace_str(u32 line_number, | |||
356 | void | 359 | void |
357 | acpi_ut_trace_u32(u32 line_number, | 360 | acpi_ut_trace_u32(u32 line_number, |
358 | const char *function_name, | 361 | const char *function_name, |
359 | char *module_name, u32 component_id, u32 integer) | 362 | const char *module_name, u32 component_id, u32 integer) |
360 | { | 363 | { |
361 | 364 | ||
362 | acpi_gbl_nesting_level++; | 365 | acpi_gbl_nesting_level++; |
@@ -386,7 +389,8 @@ acpi_ut_trace_u32(u32 line_number, | |||
386 | 389 | ||
387 | void | 390 | void |
388 | acpi_ut_exit(u32 line_number, | 391 | acpi_ut_exit(u32 line_number, |
389 | const char *function_name, char *module_name, u32 component_id) | 392 | const char *function_name, |
393 | const char *module_name, u32 component_id) | ||
390 | { | 394 | { |
391 | 395 | ||
392 | acpi_ut_debug_print(ACPI_LV_FUNCTIONS, | 396 | acpi_ut_debug_print(ACPI_LV_FUNCTIONS, |
@@ -417,7 +421,8 @@ ACPI_EXPORT_SYMBOL(acpi_ut_exit) | |||
417 | void | 421 | void |
418 | acpi_ut_status_exit(u32 line_number, | 422 | acpi_ut_status_exit(u32 line_number, |
419 | const char *function_name, | 423 | const char *function_name, |
420 | char *module_name, u32 component_id, acpi_status status) | 424 | const char *module_name, |
425 | u32 component_id, acpi_status status) | ||
421 | { | 426 | { |
422 | 427 | ||
423 | if (ACPI_SUCCESS(status)) { | 428 | if (ACPI_SUCCESS(status)) { |
@@ -458,7 +463,8 @@ ACPI_EXPORT_SYMBOL(acpi_ut_status_exit) | |||
458 | void | 463 | void |
459 | acpi_ut_value_exit(u32 line_number, | 464 | acpi_ut_value_exit(u32 line_number, |
460 | const char *function_name, | 465 | const char *function_name, |
461 | char *module_name, u32 component_id, acpi_integer value) | 466 | const char *module_name, |
467 | u32 component_id, acpi_integer value) | ||
462 | { | 468 | { |
463 | 469 | ||
464 | acpi_ut_debug_print(ACPI_LV_FUNCTIONS, | 470 | acpi_ut_debug_print(ACPI_LV_FUNCTIONS, |
@@ -490,7 +496,7 @@ ACPI_EXPORT_SYMBOL(acpi_ut_value_exit) | |||
490 | void | 496 | void |
491 | acpi_ut_ptr_exit(u32 line_number, | 497 | acpi_ut_ptr_exit(u32 line_number, |
492 | const char *function_name, | 498 | const char *function_name, |
493 | char *module_name, u32 component_id, u8 * ptr) | 499 | const char *module_name, u32 component_id, u8 *ptr) |
494 | { | 500 | { |
495 | 501 | ||
496 | acpi_ut_debug_print(ACPI_LV_FUNCTIONS, | 502 | acpi_ut_debug_print(ACPI_LV_FUNCTIONS, |
@@ -519,8 +525,8 @@ acpi_ut_ptr_exit(u32 line_number, | |||
519 | 525 | ||
520 | void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) | 526 | void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) |
521 | { | 527 | { |
522 | acpi_native_uint i = 0; | 528 | u32 i = 0; |
523 | acpi_native_uint j; | 529 | u32 j; |
524 | u32 temp32; | 530 | u32 temp32; |
525 | u8 buf_char; | 531 | u8 buf_char; |
526 | 532 | ||
@@ -539,7 +545,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) | |||
539 | 545 | ||
540 | /* Print current offset */ | 546 | /* Print current offset */ |
541 | 547 | ||
542 | acpi_os_printf("%6.4X: ", (u32) i); | 548 | acpi_os_printf("%6.4X: ", i); |
543 | 549 | ||
544 | /* Print 16 hex chars */ | 550 | /* Print 16 hex chars */ |
545 | 551 | ||
@@ -549,7 +555,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) | |||
549 | /* Dump fill spaces */ | 555 | /* Dump fill spaces */ |
550 | 556 | ||
551 | acpi_os_printf("%*s", ((display * 2) + 1), " "); | 557 | acpi_os_printf("%*s", ((display * 2) + 1), " "); |
552 | j += (acpi_native_uint) display; | 558 | j += display; |
553 | continue; | 559 | continue; |
554 | } | 560 | } |
555 | 561 | ||
@@ -557,32 +563,38 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) | |||
557 | case DB_BYTE_DISPLAY: | 563 | case DB_BYTE_DISPLAY: |
558 | default: /* Default is BYTE display */ | 564 | default: /* Default is BYTE display */ |
559 | 565 | ||
560 | acpi_os_printf("%02X ", buffer[i + j]); | 566 | acpi_os_printf("%02X ", |
567 | buffer[(acpi_size) i + j]); | ||
561 | break; | 568 | break; |
562 | 569 | ||
563 | case DB_WORD_DISPLAY: | 570 | case DB_WORD_DISPLAY: |
564 | 571 | ||
565 | ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]); | 572 | ACPI_MOVE_16_TO_32(&temp32, |
573 | &buffer[(acpi_size) i + j]); | ||
566 | acpi_os_printf("%04X ", temp32); | 574 | acpi_os_printf("%04X ", temp32); |
567 | break; | 575 | break; |
568 | 576 | ||
569 | case DB_DWORD_DISPLAY: | 577 | case DB_DWORD_DISPLAY: |
570 | 578 | ||
571 | ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]); | 579 | ACPI_MOVE_32_TO_32(&temp32, |
580 | &buffer[(acpi_size) i + j]); | ||
572 | acpi_os_printf("%08X ", temp32); | 581 | acpi_os_printf("%08X ", temp32); |
573 | break; | 582 | break; |
574 | 583 | ||
575 | case DB_QWORD_DISPLAY: | 584 | case DB_QWORD_DISPLAY: |
576 | 585 | ||
577 | ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]); | 586 | ACPI_MOVE_32_TO_32(&temp32, |
587 | &buffer[(acpi_size) i + j]); | ||
578 | acpi_os_printf("%08X", temp32); | 588 | acpi_os_printf("%08X", temp32); |
579 | 589 | ||
580 | ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]); | 590 | ACPI_MOVE_32_TO_32(&temp32, |
591 | &buffer[(acpi_size) i + j + | ||
592 | 4]); | ||
581 | acpi_os_printf("%08X ", temp32); | 593 | acpi_os_printf("%08X ", temp32); |
582 | break; | 594 | break; |
583 | } | 595 | } |
584 | 596 | ||
585 | j += (acpi_native_uint) display; | 597 | j += display; |
586 | } | 598 | } |
587 | 599 | ||
588 | /* | 600 | /* |
@@ -596,7 +608,7 @@ void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display) | |||
596 | return; | 608 | return; |
597 | } | 609 | } |
598 | 610 | ||
599 | buf_char = buffer[i + j]; | 611 | buf_char = buffer[(acpi_size) i + j]; |
600 | if (ACPI_IS_PRINT(buf_char)) { | 612 | if (ACPI_IS_PRINT(buf_char)) { |
601 | acpi_os_printf("%c", buf_char); | 613 | acpi_os_printf("%c", buf_char); |
602 | } else { | 614 | } else { |
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c index 1fbc35139e84..c5c791a575c9 100644 --- a/drivers/acpi/utilities/utdelete.c +++ b/drivers/acpi/utilities/utdelete.c | |||
@@ -442,7 +442,7 @@ acpi_ut_update_object_reference(union acpi_operand_object *object, u16 action) | |||
442 | union acpi_generic_state *state_list = NULL; | 442 | union acpi_generic_state *state_list = NULL; |
443 | union acpi_operand_object *next_object = NULL; | 443 | union acpi_operand_object *next_object = NULL; |
444 | union acpi_generic_state *state; | 444 | union acpi_generic_state *state; |
445 | acpi_native_uint i; | 445 | u32 i; |
446 | 446 | ||
447 | ACPI_FUNCTION_TRACE_PTR(ut_update_object_reference, object); | 447 | ACPI_FUNCTION_TRACE_PTR(ut_update_object_reference, object); |
448 | 448 | ||
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c index 05e61be267d5..352747e49c7a 100644 --- a/drivers/acpi/utilities/uteval.c +++ b/drivers/acpi/utilities/uteval.c | |||
@@ -97,7 +97,7 @@ acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state) | |||
97 | acpi_status status; | 97 | acpi_status status; |
98 | union acpi_operand_object *string_desc; | 98 | union acpi_operand_object *string_desc; |
99 | union acpi_operand_object *return_desc; | 99 | union acpi_operand_object *return_desc; |
100 | acpi_native_uint i; | 100 | u32 i; |
101 | 101 | ||
102 | ACPI_FUNCTION_TRACE(ut_osi_implementation); | 102 | ACPI_FUNCTION_TRACE(ut_osi_implementation); |
103 | 103 | ||
@@ -217,7 +217,6 @@ acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node, | |||
217 | 217 | ||
218 | info->prefix_node = prefix_node; | 218 | info->prefix_node = prefix_node; |
219 | info->pathname = path; | 219 | info->pathname = path; |
220 | info->parameter_type = ACPI_PARAM_ARGS; | ||
221 | 220 | ||
222 | /* Evaluate the object/method */ | 221 | /* Evaluate the object/method */ |
223 | 222 | ||
@@ -514,7 +513,7 @@ acpi_ut_execute_CID(struct acpi_namespace_node * device_node, | |||
514 | u32 count; | 513 | u32 count; |
515 | u32 size; | 514 | u32 size; |
516 | struct acpi_compatible_id_list *cid_list; | 515 | struct acpi_compatible_id_list *cid_list; |
517 | acpi_native_uint i; | 516 | u32 i; |
518 | 517 | ||
519 | ACPI_FUNCTION_TRACE(ut_execute_CID); | 518 | ACPI_FUNCTION_TRACE(ut_execute_CID); |
520 | 519 | ||
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c index 1f057b71db1a..f34be6773556 100644 --- a/drivers/acpi/utilities/utmisc.c +++ b/drivers/acpi/utilities/utmisc.c | |||
@@ -64,7 +64,7 @@ ACPI_MODULE_NAME("utmisc") | |||
64 | ******************************************************************************/ | 64 | ******************************************************************************/ |
65 | const char *acpi_ut_validate_exception(acpi_status status) | 65 | const char *acpi_ut_validate_exception(acpi_status status) |
66 | { | 66 | { |
67 | acpi_status sub_status; | 67 | u32 sub_status; |
68 | const char *exception = NULL; | 68 | const char *exception = NULL; |
69 | 69 | ||
70 | ACPI_FUNCTION_ENTRY(); | 70 | ACPI_FUNCTION_ENTRY(); |
@@ -85,32 +85,28 @@ const char *acpi_ut_validate_exception(acpi_status status) | |||
85 | case AE_CODE_PROGRAMMER: | 85 | case AE_CODE_PROGRAMMER: |
86 | 86 | ||
87 | if (sub_status <= AE_CODE_PGM_MAX) { | 87 | if (sub_status <= AE_CODE_PGM_MAX) { |
88 | exception = | 88 | exception = acpi_gbl_exception_names_pgm[sub_status]; |
89 | acpi_gbl_exception_names_pgm[sub_status - 1]; | ||
90 | } | 89 | } |
91 | break; | 90 | break; |
92 | 91 | ||
93 | case AE_CODE_ACPI_TABLES: | 92 | case AE_CODE_ACPI_TABLES: |
94 | 93 | ||
95 | if (sub_status <= AE_CODE_TBL_MAX) { | 94 | if (sub_status <= AE_CODE_TBL_MAX) { |
96 | exception = | 95 | exception = acpi_gbl_exception_names_tbl[sub_status]; |
97 | acpi_gbl_exception_names_tbl[sub_status - 1]; | ||
98 | } | 96 | } |
99 | break; | 97 | break; |
100 | 98 | ||
101 | case AE_CODE_AML: | 99 | case AE_CODE_AML: |
102 | 100 | ||
103 | if (sub_status <= AE_CODE_AML_MAX) { | 101 | if (sub_status <= AE_CODE_AML_MAX) { |
104 | exception = | 102 | exception = acpi_gbl_exception_names_aml[sub_status]; |
105 | acpi_gbl_exception_names_aml[sub_status - 1]; | ||
106 | } | 103 | } |
107 | break; | 104 | break; |
108 | 105 | ||
109 | case AE_CODE_CONTROL: | 106 | case AE_CODE_CONTROL: |
110 | 107 | ||
111 | if (sub_status <= AE_CODE_CTRL_MAX) { | 108 | if (sub_status <= AE_CODE_CTRL_MAX) { |
112 | exception = | 109 | exception = acpi_gbl_exception_names_ctrl[sub_status]; |
113 | acpi_gbl_exception_names_ctrl[sub_status - 1]; | ||
114 | } | 110 | } |
115 | break; | 111 | break; |
116 | 112 | ||
@@ -165,9 +161,9 @@ u8 acpi_ut_is_aml_table(struct acpi_table_header *table) | |||
165 | 161 | ||
166 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) | 162 | acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id) |
167 | { | 163 | { |
168 | acpi_native_uint i; | 164 | u32 i; |
169 | acpi_native_uint j; | 165 | u32 j; |
170 | acpi_native_uint k; | 166 | u32 k; |
171 | acpi_status status; | 167 | acpi_status status; |
172 | 168 | ||
173 | ACPI_FUNCTION_TRACE(ut_allocate_owner_id); | 169 | ACPI_FUNCTION_TRACE(ut_allocate_owner_id); |
@@ -273,7 +269,7 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr) | |||
273 | { | 269 | { |
274 | acpi_owner_id owner_id = *owner_id_ptr; | 270 | acpi_owner_id owner_id = *owner_id_ptr; |
275 | acpi_status status; | 271 | acpi_status status; |
276 | acpi_native_uint index; | 272 | u32 index; |
277 | u32 bit; | 273 | u32 bit; |
278 | 274 | ||
279 | ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id); | 275 | ACPI_FUNCTION_TRACE_U32(ut_release_owner_id, owner_id); |
@@ -593,7 +589,7 @@ acpi_ut_display_init_pathname(u8 type, | |||
593 | * | 589 | * |
594 | ******************************************************************************/ | 590 | ******************************************************************************/ |
595 | 591 | ||
596 | u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position) | 592 | u8 acpi_ut_valid_acpi_char(char character, u32 position) |
597 | { | 593 | { |
598 | 594 | ||
599 | if (!((character >= 'A' && character <= 'Z') || | 595 | if (!((character >= 'A' && character <= 'Z') || |
@@ -628,7 +624,7 @@ u8 acpi_ut_valid_acpi_char(char character, acpi_native_uint position) | |||
628 | 624 | ||
629 | u8 acpi_ut_valid_acpi_name(u32 name) | 625 | u8 acpi_ut_valid_acpi_name(u32 name) |
630 | { | 626 | { |
631 | acpi_native_uint i; | 627 | u32 i; |
632 | 628 | ||
633 | ACPI_FUNCTION_ENTRY(); | 629 | ACPI_FUNCTION_ENTRY(); |
634 | 630 | ||
@@ -657,7 +653,7 @@ u8 acpi_ut_valid_acpi_name(u32 name) | |||
657 | 653 | ||
658 | acpi_name acpi_ut_repair_name(char *name) | 654 | acpi_name acpi_ut_repair_name(char *name) |
659 | { | 655 | { |
660 | acpi_native_uint i; | 656 | u32 i; |
661 | char new_name[ACPI_NAME_SIZE]; | 657 | char new_name[ACPI_NAME_SIZE]; |
662 | 658 | ||
663 | for (i = 0; i < ACPI_NAME_SIZE; i++) { | 659 | for (i = 0; i < ACPI_NAME_SIZE; i++) { |
@@ -1024,7 +1020,7 @@ acpi_ut_walk_package_tree(union acpi_operand_object * source_object, | |||
1024 | ******************************************************************************/ | 1020 | ******************************************************************************/ |
1025 | 1021 | ||
1026 | void ACPI_INTERNAL_VAR_XFACE | 1022 | void ACPI_INTERNAL_VAR_XFACE |
1027 | acpi_ut_error(char *module_name, u32 line_number, char *format, ...) | 1023 | acpi_ut_error(const char *module_name, u32 line_number, const char *format, ...) |
1028 | { | 1024 | { |
1029 | va_list args; | 1025 | va_list args; |
1030 | 1026 | ||
@@ -1037,8 +1033,8 @@ acpi_ut_error(char *module_name, u32 line_number, char *format, ...) | |||
1037 | } | 1033 | } |
1038 | 1034 | ||
1039 | void ACPI_INTERNAL_VAR_XFACE | 1035 | void ACPI_INTERNAL_VAR_XFACE |
1040 | acpi_ut_exception(char *module_name, | 1036 | acpi_ut_exception(const char *module_name, |
1041 | u32 line_number, acpi_status status, char *format, ...) | 1037 | u32 line_number, acpi_status status, const char *format, ...) |
1042 | { | 1038 | { |
1043 | va_list args; | 1039 | va_list args; |
1044 | 1040 | ||
@@ -1054,7 +1050,8 @@ acpi_ut_exception(char *module_name, | |||
1054 | EXPORT_SYMBOL(acpi_ut_exception); | 1050 | EXPORT_SYMBOL(acpi_ut_exception); |
1055 | 1051 | ||
1056 | void ACPI_INTERNAL_VAR_XFACE | 1052 | void ACPI_INTERNAL_VAR_XFACE |
1057 | acpi_ut_warning(char *module_name, u32 line_number, char *format, ...) | 1053 | acpi_ut_warning(const char *module_name, |
1054 | u32 line_number, const char *format, ...) | ||
1058 | { | 1055 | { |
1059 | va_list args; | 1056 | va_list args; |
1060 | 1057 | ||
@@ -1067,7 +1064,7 @@ acpi_ut_warning(char *module_name, u32 line_number, char *format, ...) | |||
1067 | } | 1064 | } |
1068 | 1065 | ||
1069 | void ACPI_INTERNAL_VAR_XFACE | 1066 | void ACPI_INTERNAL_VAR_XFACE |
1070 | acpi_ut_info(char *module_name, u32 line_number, char *format, ...) | 1067 | acpi_ut_info(const char *module_name, u32 line_number, const char *format, ...) |
1071 | { | 1068 | { |
1072 | va_list args; | 1069 | va_list args; |
1073 | 1070 | ||
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c index f7d602b1a894..7331dde9e1b3 100644 --- a/drivers/acpi/utilities/utmutex.c +++ b/drivers/acpi/utilities/utmutex.c | |||
@@ -218,7 +218,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id) | |||
218 | * the mutex ordering rule. This indicates a coding error somewhere in | 218 | * the mutex ordering rule. This indicates a coding error somewhere in |
219 | * the ACPI subsystem code. | 219 | * the ACPI subsystem code. |
220 | */ | 220 | */ |
221 | for (i = mutex_id; i < ACPI_MAX_MUTEX; i++) { | 221 | for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) { |
222 | if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { | 222 | if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { |
223 | if (i == mutex_id) { | 223 | if (i == mutex_id) { |
224 | ACPI_ERROR((AE_INFO, | 224 | ACPI_ERROR((AE_INFO, |
@@ -315,7 +315,7 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id) | |||
315 | * ordering rule. This indicates a coding error somewhere in | 315 | * ordering rule. This indicates a coding error somewhere in |
316 | * the ACPI subsystem code. | 316 | * the ACPI subsystem code. |
317 | */ | 317 | */ |
318 | for (i = mutex_id; i < ACPI_MAX_MUTEX; i++) { | 318 | for (i = mutex_id; i < ACPI_NUM_MUTEX; i++) { |
319 | if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { | 319 | if (acpi_gbl_mutex_info[i].thread_id == this_thread_id) { |
320 | if (i == mutex_id) { | 320 | if (i == mutex_id) { |
321 | continue; | 321 | continue; |
diff --git a/drivers/acpi/utilities/utobject.c b/drivers/acpi/utilities/utobject.c index e68466de8044..e25484495e65 100644 --- a/drivers/acpi/utilities/utobject.c +++ b/drivers/acpi/utilities/utobject.c | |||
@@ -83,7 +83,8 @@ acpi_ut_get_element_length(u8 object_type, | |||
83 | * | 83 | * |
84 | ******************************************************************************/ | 84 | ******************************************************************************/ |
85 | 85 | ||
86 | union acpi_operand_object *acpi_ut_create_internal_object_dbg(char *module_name, | 86 | union acpi_operand_object *acpi_ut_create_internal_object_dbg(const char |
87 | *module_name, | ||
87 | u32 line_number, | 88 | u32 line_number, |
88 | u32 component_id, | 89 | u32 component_id, |
89 | acpi_object_type | 90 | acpi_object_type |
@@ -175,8 +176,8 @@ union acpi_operand_object *acpi_ut_create_package_object(u32 count) | |||
175 | * Create the element array. Count+1 allows the array to be null | 176 | * Create the element array. Count+1 allows the array to be null |
176 | * terminated. | 177 | * terminated. |
177 | */ | 178 | */ |
178 | package_elements = ACPI_ALLOCATE_ZEROED((acpi_size) | 179 | package_elements = ACPI_ALLOCATE_ZEROED(((acpi_size) count + |
179 | (count + 1) * sizeof(void *)); | 180 | 1) * sizeof(void *)); |
180 | if (!package_elements) { | 181 | if (!package_elements) { |
181 | acpi_ut_remove_reference(package_desc); | 182 | acpi_ut_remove_reference(package_desc); |
182 | return_PTR(NULL); | 183 | return_PTR(NULL); |
@@ -347,7 +348,7 @@ u8 acpi_ut_valid_internal_object(void *object) | |||
347 | * | 348 | * |
348 | ******************************************************************************/ | 349 | ******************************************************************************/ |
349 | 350 | ||
350 | void *acpi_ut_allocate_object_desc_dbg(char *module_name, | 351 | void *acpi_ut_allocate_object_desc_dbg(const char *module_name, |
351 | u32 line_number, u32 component_id) | 352 | u32 line_number, u32 component_id) |
352 | { | 353 | { |
353 | union acpi_operand_object *object; | 354 | union acpi_operand_object *object; |
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index d089c4519d45..64c889331f3b 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -631,6 +631,76 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) | |||
631 | * device : video output device (LCD, CRT, ..) | 631 | * device : video output device (LCD, CRT, ..) |
632 | * | 632 | * |
633 | * Return Value: | 633 | * Return Value: |
634 | * Maximum brightness level | ||
635 | * | ||
636 | * Allocate and initialize device->brightness. | ||
637 | */ | ||
638 | |||
639 | static int | ||
640 | acpi_video_init_brightness(struct acpi_video_device *device) | ||
641 | { | ||
642 | union acpi_object *obj = NULL; | ||
643 | int i, max_level = 0, count = 0; | ||
644 | union acpi_object *o; | ||
645 | struct acpi_video_device_brightness *br = NULL; | ||
646 | |||
647 | if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { | ||
648 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " | ||
649 | "LCD brightness level\n")); | ||
650 | goto out; | ||
651 | } | ||
652 | |||
653 | if (obj->package.count < 2) | ||
654 | goto out; | ||
655 | |||
656 | br = kzalloc(sizeof(*br), GFP_KERNEL); | ||
657 | if (!br) { | ||
658 | printk(KERN_ERR "can't allocate memory\n"); | ||
659 | goto out; | ||
660 | } | ||
661 | |||
662 | br->levels = kmalloc(obj->package.count * sizeof *(br->levels), | ||
663 | GFP_KERNEL); | ||
664 | if (!br->levels) | ||
665 | goto out_free; | ||
666 | |||
667 | for (i = 0; i < obj->package.count; i++) { | ||
668 | o = (union acpi_object *)&obj->package.elements[i]; | ||
669 | if (o->type != ACPI_TYPE_INTEGER) { | ||
670 | printk(KERN_ERR PREFIX "Invalid data\n"); | ||
671 | continue; | ||
672 | } | ||
673 | br->levels[count] = (u32) o->integer.value; | ||
674 | |||
675 | if (br->levels[count] > max_level) | ||
676 | max_level = br->levels[count]; | ||
677 | count++; | ||
678 | } | ||
679 | |||
680 | if (count < 2) | ||
681 | goto out_free_levels; | ||
682 | |||
683 | br->count = count; | ||
684 | device->brightness = br; | ||
685 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count)); | ||
686 | kfree(obj); | ||
687 | return max_level; | ||
688 | |||
689 | out_free_levels: | ||
690 | kfree(br->levels); | ||
691 | out_free: | ||
692 | kfree(br); | ||
693 | out: | ||
694 | device->brightness = NULL; | ||
695 | kfree(obj); | ||
696 | return 0; | ||
697 | } | ||
698 | |||
699 | /* | ||
700 | * Arg: | ||
701 | * device : video output device (LCD, CRT, ..) | ||
702 | * | ||
703 | * Return Value: | ||
634 | * None | 704 | * None |
635 | * | 705 | * |
636 | * Find out all required AML methods defined under the output | 706 | * Find out all required AML methods defined under the output |
@@ -640,10 +710,7 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) | |||
640 | static void acpi_video_device_find_cap(struct acpi_video_device *device) | 710 | static void acpi_video_device_find_cap(struct acpi_video_device *device) |
641 | { | 711 | { |
642 | acpi_handle h_dummy1; | 712 | acpi_handle h_dummy1; |
643 | int i; | ||
644 | u32 max_level = 0; | 713 | u32 max_level = 0; |
645 | union acpi_object *obj = NULL; | ||
646 | struct acpi_video_device_brightness *br = NULL; | ||
647 | 714 | ||
648 | 715 | ||
649 | memset(&device->cap, 0, sizeof(device->cap)); | 716 | memset(&device->cap, 0, sizeof(device->cap)); |
@@ -672,53 +739,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device) | |||
672 | device->cap._DSS = 1; | 739 | device->cap._DSS = 1; |
673 | } | 740 | } |
674 | 741 | ||
675 | if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { | 742 | max_level = acpi_video_init_brightness(device); |
676 | |||
677 | if (obj->package.count >= 2) { | ||
678 | int count = 0; | ||
679 | union acpi_object *o; | ||
680 | |||
681 | br = kzalloc(sizeof(*br), GFP_KERNEL); | ||
682 | if (!br) { | ||
683 | printk(KERN_ERR "can't allocate memory\n"); | ||
684 | } else { | ||
685 | br->levels = kmalloc(obj->package.count * | ||
686 | sizeof *(br->levels), GFP_KERNEL); | ||
687 | if (!br->levels) | ||
688 | goto out; | ||
689 | |||
690 | for (i = 0; i < obj->package.count; i++) { | ||
691 | o = (union acpi_object *)&obj->package. | ||
692 | elements[i]; | ||
693 | if (o->type != ACPI_TYPE_INTEGER) { | ||
694 | printk(KERN_ERR PREFIX "Invalid data\n"); | ||
695 | continue; | ||
696 | } | ||
697 | br->levels[count] = (u32) o->integer.value; | ||
698 | |||
699 | if (br->levels[count] > max_level) | ||
700 | max_level = br->levels[count]; | ||
701 | count++; | ||
702 | } | ||
703 | out: | ||
704 | if (count < 2) { | ||
705 | kfree(br->levels); | ||
706 | kfree(br); | ||
707 | } else { | ||
708 | br->count = count; | ||
709 | device->brightness = br; | ||
710 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | ||
711 | "found %d brightness levels\n", | ||
712 | count)); | ||
713 | } | ||
714 | } | ||
715 | } | ||
716 | |||
717 | } else { | ||
718 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n")); | ||
719 | } | ||
720 | |||
721 | kfree(obj); | ||
722 | 743 | ||
723 | if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){ | 744 | if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){ |
724 | int result; | 745 | int result; |
@@ -1695,6 +1716,8 @@ static void | |||
1695 | acpi_video_switch_brightness(struct acpi_video_device *device, int event) | 1716 | acpi_video_switch_brightness(struct acpi_video_device *device, int event) |
1696 | { | 1717 | { |
1697 | unsigned long level_current, level_next; | 1718 | unsigned long level_current, level_next; |
1719 | if (!device->brightness) | ||
1720 | return; | ||
1698 | acpi_video_device_lcd_get_level_current(device, &level_current); | 1721 | acpi_video_device_lcd_get_level_current(device, &level_current); |
1699 | level_next = acpi_video_get_next_level(device, level_current, event); | 1722 | level_next = acpi_video_get_next_level(device, level_current, event); |
1700 | acpi_video_device_lcd_set_level(device, level_next); | 1723 | acpi_video_device_lcd_set_level(device, level_next); |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 911ec600fe71..3f940393d6c7 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -453,6 +453,8 @@ int platform_driver_register(struct platform_driver *drv) | |||
453 | drv->driver.suspend = platform_drv_suspend; | 453 | drv->driver.suspend = platform_drv_suspend; |
454 | if (drv->resume) | 454 | if (drv->resume) |
455 | drv->driver.resume = platform_drv_resume; | 455 | drv->driver.resume = platform_drv_resume; |
456 | if (drv->pm) | ||
457 | drv->driver.pm = &drv->pm->base; | ||
456 | return driver_register(&drv->driver); | 458 | return driver_register(&drv->driver); |
457 | } | 459 | } |
458 | EXPORT_SYMBOL_GPL(platform_driver_register); | 460 | EXPORT_SYMBOL_GPL(platform_driver_register); |
@@ -560,7 +562,9 @@ static int platform_match(struct device *dev, struct device_driver *drv) | |||
560 | return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); | 562 | return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); |
561 | } | 563 | } |
562 | 564 | ||
563 | static int platform_suspend(struct device *dev, pm_message_t mesg) | 565 | #ifdef CONFIG_PM_SLEEP |
566 | |||
567 | static int platform_legacy_suspend(struct device *dev, pm_message_t mesg) | ||
564 | { | 568 | { |
565 | int ret = 0; | 569 | int ret = 0; |
566 | 570 | ||
@@ -570,7 +574,7 @@ static int platform_suspend(struct device *dev, pm_message_t mesg) | |||
570 | return ret; | 574 | return ret; |
571 | } | 575 | } |
572 | 576 | ||
573 | static int platform_suspend_late(struct device *dev, pm_message_t mesg) | 577 | static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg) |
574 | { | 578 | { |
575 | struct platform_driver *drv = to_platform_driver(dev->driver); | 579 | struct platform_driver *drv = to_platform_driver(dev->driver); |
576 | struct platform_device *pdev; | 580 | struct platform_device *pdev; |
@@ -583,7 +587,7 @@ static int platform_suspend_late(struct device *dev, pm_message_t mesg) | |||
583 | return ret; | 587 | return ret; |
584 | } | 588 | } |
585 | 589 | ||
586 | static int platform_resume_early(struct device *dev) | 590 | static int platform_legacy_resume_early(struct device *dev) |
587 | { | 591 | { |
588 | struct platform_driver *drv = to_platform_driver(dev->driver); | 592 | struct platform_driver *drv = to_platform_driver(dev->driver); |
589 | struct platform_device *pdev; | 593 | struct platform_device *pdev; |
@@ -596,7 +600,7 @@ static int platform_resume_early(struct device *dev) | |||
596 | return ret; | 600 | return ret; |
597 | } | 601 | } |
598 | 602 | ||
599 | static int platform_resume(struct device *dev) | 603 | static int platform_legacy_resume(struct device *dev) |
600 | { | 604 | { |
601 | int ret = 0; | 605 | int ret = 0; |
602 | 606 | ||
@@ -606,15 +610,291 @@ static int platform_resume(struct device *dev) | |||
606 | return ret; | 610 | return ret; |
607 | } | 611 | } |
608 | 612 | ||
613 | static int platform_pm_prepare(struct device *dev) | ||
614 | { | ||
615 | struct device_driver *drv = dev->driver; | ||
616 | int ret = 0; | ||
617 | |||
618 | if (drv && drv->pm && drv->pm->prepare) | ||
619 | ret = drv->pm->prepare(dev); | ||
620 | |||
621 | return ret; | ||
622 | } | ||
623 | |||
624 | static void platform_pm_complete(struct device *dev) | ||
625 | { | ||
626 | struct device_driver *drv = dev->driver; | ||
627 | |||
628 | if (drv && drv->pm && drv->pm->complete) | ||
629 | drv->pm->complete(dev); | ||
630 | } | ||
631 | |||
632 | #ifdef CONFIG_SUSPEND | ||
633 | |||
634 | static int platform_pm_suspend(struct device *dev) | ||
635 | { | ||
636 | struct device_driver *drv = dev->driver; | ||
637 | int ret = 0; | ||
638 | |||
639 | if (drv && drv->pm) { | ||
640 | if (drv->pm->suspend) | ||
641 | ret = drv->pm->suspend(dev); | ||
642 | } else { | ||
643 | ret = platform_legacy_suspend(dev, PMSG_SUSPEND); | ||
644 | } | ||
645 | |||
646 | return ret; | ||
647 | } | ||
648 | |||
649 | static int platform_pm_suspend_noirq(struct device *dev) | ||
650 | { | ||
651 | struct platform_driver *pdrv; | ||
652 | int ret = 0; | ||
653 | |||
654 | if (!dev->driver) | ||
655 | return 0; | ||
656 | |||
657 | pdrv = to_platform_driver(dev->driver); | ||
658 | if (pdrv->pm) { | ||
659 | if (pdrv->pm->suspend_noirq) | ||
660 | ret = pdrv->pm->suspend_noirq(dev); | ||
661 | } else { | ||
662 | ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND); | ||
663 | } | ||
664 | |||
665 | return ret; | ||
666 | } | ||
667 | |||
668 | static int platform_pm_resume(struct device *dev) | ||
669 | { | ||
670 | struct device_driver *drv = dev->driver; | ||
671 | int ret = 0; | ||
672 | |||
673 | if (drv && drv->pm) { | ||
674 | if (drv->pm->resume) | ||
675 | ret = drv->pm->resume(dev); | ||
676 | } else { | ||
677 | ret = platform_legacy_resume(dev); | ||
678 | } | ||
679 | |||
680 | return ret; | ||
681 | } | ||
682 | |||
683 | static int platform_pm_resume_noirq(struct device *dev) | ||
684 | { | ||
685 | struct platform_driver *pdrv; | ||
686 | int ret = 0; | ||
687 | |||
688 | if (!dev->driver) | ||
689 | return 0; | ||
690 | |||
691 | pdrv = to_platform_driver(dev->driver); | ||
692 | if (pdrv->pm) { | ||
693 | if (pdrv->pm->resume_noirq) | ||
694 | ret = pdrv->pm->resume_noirq(dev); | ||
695 | } else { | ||
696 | ret = platform_legacy_resume_early(dev); | ||
697 | } | ||
698 | |||
699 | return ret; | ||
700 | } | ||
701 | |||
702 | #else /* !CONFIG_SUSPEND */ | ||
703 | |||
704 | #define platform_pm_suspend NULL | ||
705 | #define platform_pm_resume NULL | ||
706 | #define platform_pm_suspend_noirq NULL | ||
707 | #define platform_pm_resume_noirq NULL | ||
708 | |||
709 | #endif /* !CONFIG_SUSPEND */ | ||
710 | |||
711 | #ifdef CONFIG_HIBERNATION | ||
712 | |||
713 | static int platform_pm_freeze(struct device *dev) | ||
714 | { | ||
715 | struct device_driver *drv = dev->driver; | ||
716 | int ret = 0; | ||
717 | |||
718 | if (!drv) | ||
719 | return 0; | ||
720 | |||
721 | if (drv->pm) { | ||
722 | if (drv->pm->freeze) | ||
723 | ret = drv->pm->freeze(dev); | ||
724 | } else { | ||
725 | ret = platform_legacy_suspend(dev, PMSG_FREEZE); | ||
726 | } | ||
727 | |||
728 | return ret; | ||
729 | } | ||
730 | |||
731 | static int platform_pm_freeze_noirq(struct device *dev) | ||
732 | { | ||
733 | struct platform_driver *pdrv; | ||
734 | int ret = 0; | ||
735 | |||
736 | if (!dev->driver) | ||
737 | return 0; | ||
738 | |||
739 | pdrv = to_platform_driver(dev->driver); | ||
740 | if (pdrv->pm) { | ||
741 | if (pdrv->pm->freeze_noirq) | ||
742 | ret = pdrv->pm->freeze_noirq(dev); | ||
743 | } else { | ||
744 | ret = platform_legacy_suspend_late(dev, PMSG_FREEZE); | ||
745 | } | ||
746 | |||
747 | return ret; | ||
748 | } | ||
749 | |||
750 | static int platform_pm_thaw(struct device *dev) | ||
751 | { | ||
752 | struct device_driver *drv = dev->driver; | ||
753 | int ret = 0; | ||
754 | |||
755 | if (drv && drv->pm) { | ||
756 | if (drv->pm->thaw) | ||
757 | ret = drv->pm->thaw(dev); | ||
758 | } else { | ||
759 | ret = platform_legacy_resume(dev); | ||
760 | } | ||
761 | |||
762 | return ret; | ||
763 | } | ||
764 | |||
765 | static int platform_pm_thaw_noirq(struct device *dev) | ||
766 | { | ||
767 | struct platform_driver *pdrv; | ||
768 | int ret = 0; | ||
769 | |||
770 | if (!dev->driver) | ||
771 | return 0; | ||
772 | |||
773 | pdrv = to_platform_driver(dev->driver); | ||
774 | if (pdrv->pm) { | ||
775 | if (pdrv->pm->thaw_noirq) | ||
776 | ret = pdrv->pm->thaw_noirq(dev); | ||
777 | } else { | ||
778 | ret = platform_legacy_resume_early(dev); | ||
779 | } | ||
780 | |||
781 | return ret; | ||
782 | } | ||
783 | |||
784 | static int platform_pm_poweroff(struct device *dev) | ||
785 | { | ||
786 | struct device_driver *drv = dev->driver; | ||
787 | int ret = 0; | ||
788 | |||
789 | if (drv && drv->pm) { | ||
790 | if (drv->pm->poweroff) | ||
791 | ret = drv->pm->poweroff(dev); | ||
792 | } else { | ||
793 | ret = platform_legacy_suspend(dev, PMSG_HIBERNATE); | ||
794 | } | ||
795 | |||
796 | return ret; | ||
797 | } | ||
798 | |||
799 | static int platform_pm_poweroff_noirq(struct device *dev) | ||
800 | { | ||
801 | struct platform_driver *pdrv; | ||
802 | int ret = 0; | ||
803 | |||
804 | if (!dev->driver) | ||
805 | return 0; | ||
806 | |||
807 | pdrv = to_platform_driver(dev->driver); | ||
808 | if (pdrv->pm) { | ||
809 | if (pdrv->pm->poweroff_noirq) | ||
810 | ret = pdrv->pm->poweroff_noirq(dev); | ||
811 | } else { | ||
812 | ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE); | ||
813 | } | ||
814 | |||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | static int platform_pm_restore(struct device *dev) | ||
819 | { | ||
820 | struct device_driver *drv = dev->driver; | ||
821 | int ret = 0; | ||
822 | |||
823 | if (drv && drv->pm) { | ||
824 | if (drv->pm->restore) | ||
825 | ret = drv->pm->restore(dev); | ||
826 | } else { | ||
827 | ret = platform_legacy_resume(dev); | ||
828 | } | ||
829 | |||
830 | return ret; | ||
831 | } | ||
832 | |||
833 | static int platform_pm_restore_noirq(struct device *dev) | ||
834 | { | ||
835 | struct platform_driver *pdrv; | ||
836 | int ret = 0; | ||
837 | |||
838 | if (!dev->driver) | ||
839 | return 0; | ||
840 | |||
841 | pdrv = to_platform_driver(dev->driver); | ||
842 | if (pdrv->pm) { | ||
843 | if (pdrv->pm->restore_noirq) | ||
844 | ret = pdrv->pm->restore_noirq(dev); | ||
845 | } else { | ||
846 | ret = platform_legacy_resume_early(dev); | ||
847 | } | ||
848 | |||
849 | return ret; | ||
850 | } | ||
851 | |||
852 | #else /* !CONFIG_HIBERNATION */ | ||
853 | |||
854 | #define platform_pm_freeze NULL | ||
855 | #define platform_pm_thaw NULL | ||
856 | #define platform_pm_poweroff NULL | ||
857 | #define platform_pm_restore NULL | ||
858 | #define platform_pm_freeze_noirq NULL | ||
859 | #define platform_pm_thaw_noirq NULL | ||
860 | #define platform_pm_poweroff_noirq NULL | ||
861 | #define platform_pm_restore_noirq NULL | ||
862 | |||
863 | #endif /* !CONFIG_HIBERNATION */ | ||
864 | |||
865 | struct pm_ext_ops platform_pm_ops = { | ||
866 | .base = { | ||
867 | .prepare = platform_pm_prepare, | ||
868 | .complete = platform_pm_complete, | ||
869 | .suspend = platform_pm_suspend, | ||
870 | .resume = platform_pm_resume, | ||
871 | .freeze = platform_pm_freeze, | ||
872 | .thaw = platform_pm_thaw, | ||
873 | .poweroff = platform_pm_poweroff, | ||
874 | .restore = platform_pm_restore, | ||
875 | }, | ||
876 | .suspend_noirq = platform_pm_suspend_noirq, | ||
877 | .resume_noirq = platform_pm_resume_noirq, | ||
878 | .freeze_noirq = platform_pm_freeze_noirq, | ||
879 | .thaw_noirq = platform_pm_thaw_noirq, | ||
880 | .poweroff_noirq = platform_pm_poweroff_noirq, | ||
881 | .restore_noirq = platform_pm_restore_noirq, | ||
882 | }; | ||
883 | |||
884 | #define PLATFORM_PM_OPS_PTR &platform_pm_ops | ||
885 | |||
886 | #else /* !CONFIG_PM_SLEEP */ | ||
887 | |||
888 | #define PLATFORM_PM_OPS_PTR NULL | ||
889 | |||
890 | #endif /* !CONFIG_PM_SLEEP */ | ||
891 | |||
609 | struct bus_type platform_bus_type = { | 892 | struct bus_type platform_bus_type = { |
610 | .name = "platform", | 893 | .name = "platform", |
611 | .dev_attrs = platform_dev_attrs, | 894 | .dev_attrs = platform_dev_attrs, |
612 | .match = platform_match, | 895 | .match = platform_match, |
613 | .uevent = platform_uevent, | 896 | .uevent = platform_uevent, |
614 | .suspend = platform_suspend, | 897 | .pm = PLATFORM_PM_OPS_PTR, |
615 | .suspend_late = platform_suspend_late, | ||
616 | .resume_early = platform_resume_early, | ||
617 | .resume = platform_resume, | ||
618 | }; | 898 | }; |
619 | EXPORT_SYMBOL_GPL(platform_bus_type); | 899 | EXPORT_SYMBOL_GPL(platform_bus_type); |
620 | 900 | ||
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index 45cc3d9eacb8..3250c5257b74 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -12,11 +12,9 @@ | |||
12 | * and add it to the list of power-controlled devices. sysfs entries for | 12 | * and add it to the list of power-controlled devices. sysfs entries for |
13 | * controlling device power management will also be added. | 13 | * controlling device power management will also be added. |
14 | * | 14 | * |
15 | * A different set of lists than the global subsystem list are used to | 15 | * A separate list is used for keeping track of power info, because the power |
16 | * keep track of power info because we use different lists to hold | 16 | * domain dependencies may differ from the ancestral dependencies that the |
17 | * devices based on what stage of the power management process they | 17 | * subsystem list maintains. |
18 | * are in. The power domain dependencies may also differ from the | ||
19 | * ancestral dependencies that the subsystem list maintains. | ||
20 | */ | 18 | */ |
21 | 19 | ||
22 | #include <linux/device.h> | 20 | #include <linux/device.h> |
@@ -30,31 +28,40 @@ | |||
30 | #include "power.h" | 28 | #include "power.h" |
31 | 29 | ||
32 | /* | 30 | /* |
33 | * The entries in the dpm_active list are in a depth first order, simply | 31 | * The entries in the dpm_list list are in a depth first order, simply |
34 | * because children are guaranteed to be discovered after parents, and | 32 | * because children are guaranteed to be discovered after parents, and |
35 | * are inserted at the back of the list on discovery. | 33 | * are inserted at the back of the list on discovery. |
36 | * | 34 | * |
37 | * All the other lists are kept in the same order, for consistency. | ||
38 | * However the lists aren't always traversed in the same order. | ||
39 | * Semaphores must be acquired from the top (i.e., front) down | ||
40 | * and released in the opposite order. Devices must be suspended | ||
41 | * from the bottom (i.e., end) up and resumed in the opposite order. | ||
42 | * That way no parent will be suspended while it still has an active | ||
43 | * child. | ||
44 | * | ||
45 | * Since device_pm_add() may be called with a device semaphore held, | 35 | * Since device_pm_add() may be called with a device semaphore held, |
46 | * we must never try to acquire a device semaphore while holding | 36 | * we must never try to acquire a device semaphore while holding |
47 | * dpm_list_mutex. | 37 | * dpm_list_mutex. |
48 | */ | 38 | */ |
49 | 39 | ||
50 | LIST_HEAD(dpm_active); | 40 | LIST_HEAD(dpm_list); |
51 | static LIST_HEAD(dpm_off); | ||
52 | static LIST_HEAD(dpm_off_irq); | ||
53 | 41 | ||
54 | static DEFINE_MUTEX(dpm_list_mtx); | 42 | static DEFINE_MUTEX(dpm_list_mtx); |
55 | 43 | ||
56 | /* 'true' if all devices have been suspended, protected by dpm_list_mtx */ | 44 | /* |
57 | static bool all_sleeping; | 45 | * Set once the preparation of devices for a PM transition has started, reset |
46 | * before starting to resume devices. Protected by dpm_list_mtx. | ||
47 | */ | ||
48 | static bool transition_started; | ||
49 | |||
50 | /** | ||
51 | * device_pm_lock - lock the list of active devices used by the PM core | ||
52 | */ | ||
53 | void device_pm_lock(void) | ||
54 | { | ||
55 | mutex_lock(&dpm_list_mtx); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | * device_pm_unlock - unlock the list of active devices used by the PM core | ||
60 | */ | ||
61 | void device_pm_unlock(void) | ||
62 | { | ||
63 | mutex_unlock(&dpm_list_mtx); | ||
64 | } | ||
58 | 65 | ||
59 | /** | 66 | /** |
60 | * device_pm_add - add a device to the list of active devices | 67 | * device_pm_add - add a device to the list of active devices |
@@ -68,17 +75,25 @@ int device_pm_add(struct device *dev) | |||
68 | dev->bus ? dev->bus->name : "No Bus", | 75 | dev->bus ? dev->bus->name : "No Bus", |
69 | kobject_name(&dev->kobj)); | 76 | kobject_name(&dev->kobj)); |
70 | mutex_lock(&dpm_list_mtx); | 77 | mutex_lock(&dpm_list_mtx); |
71 | if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) { | 78 | if (dev->parent) { |
72 | if (dev->parent->power.sleeping) | 79 | if (dev->parent->power.status >= DPM_SUSPENDING) { |
73 | dev_warn(dev, "parent %s is sleeping\n", | 80 | dev_warn(dev, "parent %s is sleeping, will not add\n", |
74 | dev->parent->bus_id); | 81 | dev->parent->bus_id); |
75 | else | 82 | WARN_ON(true); |
76 | dev_warn(dev, "all devices are sleeping\n"); | 83 | } |
84 | } else if (transition_started) { | ||
85 | /* | ||
86 | * We refuse to register parentless devices while a PM | ||
87 | * transition is in progress in order to avoid leaving them | ||
88 | * unhandled down the road | ||
89 | */ | ||
77 | WARN_ON(true); | 90 | WARN_ON(true); |
78 | } | 91 | } |
79 | error = dpm_sysfs_add(dev); | 92 | error = dpm_sysfs_add(dev); |
80 | if (!error) | 93 | if (!error) { |
81 | list_add_tail(&dev->power.entry, &dpm_active); | 94 | dev->power.status = DPM_ON; |
95 | list_add_tail(&dev->power.entry, &dpm_list); | ||
96 | } | ||
82 | mutex_unlock(&dpm_list_mtx); | 97 | mutex_unlock(&dpm_list_mtx); |
83 | return error; | 98 | return error; |
84 | } | 99 | } |
@@ -100,73 +115,243 @@ void device_pm_remove(struct device *dev) | |||
100 | mutex_unlock(&dpm_list_mtx); | 115 | mutex_unlock(&dpm_list_mtx); |
101 | } | 116 | } |
102 | 117 | ||
118 | /** | ||
119 | * pm_op - execute the PM operation appropiate for given PM event | ||
120 | * @dev: Device. | ||
121 | * @ops: PM operations to choose from. | ||
122 | * @state: PM transition of the system being carried out. | ||
123 | */ | ||
124 | static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state) | ||
125 | { | ||
126 | int error = 0; | ||
127 | |||
128 | switch (state.event) { | ||
129 | #ifdef CONFIG_SUSPEND | ||
130 | case PM_EVENT_SUSPEND: | ||
131 | if (ops->suspend) { | ||
132 | error = ops->suspend(dev); | ||
133 | suspend_report_result(ops->suspend, error); | ||
134 | } | ||
135 | break; | ||
136 | case PM_EVENT_RESUME: | ||
137 | if (ops->resume) { | ||
138 | error = ops->resume(dev); | ||
139 | suspend_report_result(ops->resume, error); | ||
140 | } | ||
141 | break; | ||
142 | #endif /* CONFIG_SUSPEND */ | ||
143 | #ifdef CONFIG_HIBERNATION | ||
144 | case PM_EVENT_FREEZE: | ||
145 | case PM_EVENT_QUIESCE: | ||
146 | if (ops->freeze) { | ||
147 | error = ops->freeze(dev); | ||
148 | suspend_report_result(ops->freeze, error); | ||
149 | } | ||
150 | break; | ||
151 | case PM_EVENT_HIBERNATE: | ||
152 | if (ops->poweroff) { | ||
153 | error = ops->poweroff(dev); | ||
154 | suspend_report_result(ops->poweroff, error); | ||
155 | } | ||
156 | break; | ||
157 | case PM_EVENT_THAW: | ||
158 | case PM_EVENT_RECOVER: | ||
159 | if (ops->thaw) { | ||
160 | error = ops->thaw(dev); | ||
161 | suspend_report_result(ops->thaw, error); | ||
162 | } | ||
163 | break; | ||
164 | case PM_EVENT_RESTORE: | ||
165 | if (ops->restore) { | ||
166 | error = ops->restore(dev); | ||
167 | suspend_report_result(ops->restore, error); | ||
168 | } | ||
169 | break; | ||
170 | #endif /* CONFIG_HIBERNATION */ | ||
171 | default: | ||
172 | error = -EINVAL; | ||
173 | } | ||
174 | return error; | ||
175 | } | ||
176 | |||
177 | /** | ||
178 | * pm_noirq_op - execute the PM operation appropiate for given PM event | ||
179 | * @dev: Device. | ||
180 | * @ops: PM operations to choose from. | ||
181 | * @state: PM transition of the system being carried out. | ||
182 | * | ||
183 | * The operation is executed with interrupts disabled by the only remaining | ||
184 | * functional CPU in the system. | ||
185 | */ | ||
186 | static int pm_noirq_op(struct device *dev, struct pm_ext_ops *ops, | ||
187 | pm_message_t state) | ||
188 | { | ||
189 | int error = 0; | ||
190 | |||
191 | switch (state.event) { | ||
192 | #ifdef CONFIG_SUSPEND | ||
193 | case PM_EVENT_SUSPEND: | ||
194 | if (ops->suspend_noirq) { | ||
195 | error = ops->suspend_noirq(dev); | ||
196 | suspend_report_result(ops->suspend_noirq, error); | ||
197 | } | ||
198 | break; | ||
199 | case PM_EVENT_RESUME: | ||
200 | if (ops->resume_noirq) { | ||
201 | error = ops->resume_noirq(dev); | ||
202 | suspend_report_result(ops->resume_noirq, error); | ||
203 | } | ||
204 | break; | ||
205 | #endif /* CONFIG_SUSPEND */ | ||
206 | #ifdef CONFIG_HIBERNATION | ||
207 | case PM_EVENT_FREEZE: | ||
208 | case PM_EVENT_QUIESCE: | ||
209 | if (ops->freeze_noirq) { | ||
210 | error = ops->freeze_noirq(dev); | ||
211 | suspend_report_result(ops->freeze_noirq, error); | ||
212 | } | ||
213 | break; | ||
214 | case PM_EVENT_HIBERNATE: | ||
215 | if (ops->poweroff_noirq) { | ||
216 | error = ops->poweroff_noirq(dev); | ||
217 | suspend_report_result(ops->poweroff_noirq, error); | ||
218 | } | ||
219 | break; | ||
220 | case PM_EVENT_THAW: | ||
221 | case PM_EVENT_RECOVER: | ||
222 | if (ops->thaw_noirq) { | ||
223 | error = ops->thaw_noirq(dev); | ||
224 | suspend_report_result(ops->thaw_noirq, error); | ||
225 | } | ||
226 | break; | ||
227 | case PM_EVENT_RESTORE: | ||
228 | if (ops->restore_noirq) { | ||
229 | error = ops->restore_noirq(dev); | ||
230 | suspend_report_result(ops->restore_noirq, error); | ||
231 | } | ||
232 | break; | ||
233 | #endif /* CONFIG_HIBERNATION */ | ||
234 | default: | ||
235 | error = -EINVAL; | ||
236 | } | ||
237 | return error; | ||
238 | } | ||
239 | |||
240 | static char *pm_verb(int event) | ||
241 | { | ||
242 | switch (event) { | ||
243 | case PM_EVENT_SUSPEND: | ||
244 | return "suspend"; | ||
245 | case PM_EVENT_RESUME: | ||
246 | return "resume"; | ||
247 | case PM_EVENT_FREEZE: | ||
248 | return "freeze"; | ||
249 | case PM_EVENT_QUIESCE: | ||
250 | return "quiesce"; | ||
251 | case PM_EVENT_HIBERNATE: | ||
252 | return "hibernate"; | ||
253 | case PM_EVENT_THAW: | ||
254 | return "thaw"; | ||
255 | case PM_EVENT_RESTORE: | ||
256 | return "restore"; | ||
257 | case PM_EVENT_RECOVER: | ||
258 | return "recover"; | ||
259 | default: | ||
260 | return "(unknown PM event)"; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | static void pm_dev_dbg(struct device *dev, pm_message_t state, char *info) | ||
265 | { | ||
266 | dev_dbg(dev, "%s%s%s\n", info, pm_verb(state.event), | ||
267 | ((state.event & PM_EVENT_SLEEP) && device_may_wakeup(dev)) ? | ||
268 | ", may wakeup" : ""); | ||
269 | } | ||
270 | |||
271 | static void pm_dev_err(struct device *dev, pm_message_t state, char *info, | ||
272 | int error) | ||
273 | { | ||
274 | printk(KERN_ERR "PM: Device %s failed to %s%s: error %d\n", | ||
275 | kobject_name(&dev->kobj), pm_verb(state.event), info, error); | ||
276 | } | ||
277 | |||
103 | /*------------------------- Resume routines -------------------------*/ | 278 | /*------------------------- Resume routines -------------------------*/ |
104 | 279 | ||
105 | /** | 280 | /** |
106 | * resume_device_early - Power on one device (early resume). | 281 | * resume_device_noirq - Power on one device (early resume). |
107 | * @dev: Device. | 282 | * @dev: Device. |
283 | * @state: PM transition of the system being carried out. | ||
108 | * | 284 | * |
109 | * Must be called with interrupts disabled. | 285 | * Must be called with interrupts disabled. |
110 | */ | 286 | */ |
111 | static int resume_device_early(struct device *dev) | 287 | static int resume_device_noirq(struct device *dev, pm_message_t state) |
112 | { | 288 | { |
113 | int error = 0; | 289 | int error = 0; |
114 | 290 | ||
115 | TRACE_DEVICE(dev); | 291 | TRACE_DEVICE(dev); |
116 | TRACE_RESUME(0); | 292 | TRACE_RESUME(0); |
117 | 293 | ||
118 | if (dev->bus && dev->bus->resume_early) { | 294 | if (!dev->bus) |
119 | dev_dbg(dev, "EARLY resume\n"); | 295 | goto End; |
296 | |||
297 | if (dev->bus->pm) { | ||
298 | pm_dev_dbg(dev, state, "EARLY "); | ||
299 | error = pm_noirq_op(dev, dev->bus->pm, state); | ||
300 | } else if (dev->bus->resume_early) { | ||
301 | pm_dev_dbg(dev, state, "legacy EARLY "); | ||
120 | error = dev->bus->resume_early(dev); | 302 | error = dev->bus->resume_early(dev); |
121 | } | 303 | } |
122 | 304 | End: | |
123 | TRACE_RESUME(error); | 305 | TRACE_RESUME(error); |
124 | return error; | 306 | return error; |
125 | } | 307 | } |
126 | 308 | ||
127 | /** | 309 | /** |
128 | * dpm_power_up - Power on all regular (non-sysdev) devices. | 310 | * dpm_power_up - Power on all regular (non-sysdev) devices. |
311 | * @state: PM transition of the system being carried out. | ||
129 | * | 312 | * |
130 | * Walk the dpm_off_irq list and power each device up. This | 313 | * Execute the appropriate "noirq resume" callback for all devices marked |
131 | * is used for devices that required they be powered down with | 314 | * as DPM_OFF_IRQ. |
132 | * interrupts disabled. As devices are powered on, they are moved | ||
133 | * to the dpm_off list. | ||
134 | * | 315 | * |
135 | * Must be called with interrupts disabled and only one CPU running. | 316 | * Must be called with interrupts disabled and only one CPU running. |
136 | */ | 317 | */ |
137 | static void dpm_power_up(void) | 318 | static void dpm_power_up(pm_message_t state) |
138 | { | 319 | { |
320 | struct device *dev; | ||
139 | 321 | ||
140 | while (!list_empty(&dpm_off_irq)) { | 322 | list_for_each_entry(dev, &dpm_list, power.entry) |
141 | struct list_head *entry = dpm_off_irq.next; | 323 | if (dev->power.status > DPM_OFF) { |
142 | struct device *dev = to_device(entry); | 324 | int error; |
143 | 325 | ||
144 | list_move_tail(entry, &dpm_off); | 326 | dev->power.status = DPM_OFF; |
145 | resume_device_early(dev); | 327 | error = resume_device_noirq(dev, state); |
146 | } | 328 | if (error) |
329 | pm_dev_err(dev, state, " early", error); | ||
330 | } | ||
147 | } | 331 | } |
148 | 332 | ||
149 | /** | 333 | /** |
150 | * device_power_up - Turn on all devices that need special attention. | 334 | * device_power_up - Turn on all devices that need special attention. |
335 | * @state: PM transition of the system being carried out. | ||
151 | * | 336 | * |
152 | * Power on system devices, then devices that required we shut them down | 337 | * Power on system devices, then devices that required we shut them down |
153 | * with interrupts disabled. | 338 | * with interrupts disabled. |
154 | * | 339 | * |
155 | * Must be called with interrupts disabled. | 340 | * Must be called with interrupts disabled. |
156 | */ | 341 | */ |
157 | void device_power_up(void) | 342 | void device_power_up(pm_message_t state) |
158 | { | 343 | { |
159 | sysdev_resume(); | 344 | sysdev_resume(); |
160 | dpm_power_up(); | 345 | dpm_power_up(state); |
161 | } | 346 | } |
162 | EXPORT_SYMBOL_GPL(device_power_up); | 347 | EXPORT_SYMBOL_GPL(device_power_up); |
163 | 348 | ||
164 | /** | 349 | /** |
165 | * resume_device - Restore state for one device. | 350 | * resume_device - Restore state for one device. |
166 | * @dev: Device. | 351 | * @dev: Device. |
167 | * | 352 | * @state: PM transition of the system being carried out. |
168 | */ | 353 | */ |
169 | static int resume_device(struct device *dev) | 354 | static int resume_device(struct device *dev, pm_message_t state) |
170 | { | 355 | { |
171 | int error = 0; | 356 | int error = 0; |
172 | 357 | ||
@@ -175,21 +360,40 @@ static int resume_device(struct device *dev) | |||
175 | 360 | ||
176 | down(&dev->sem); | 361 | down(&dev->sem); |
177 | 362 | ||
178 | if (dev->bus && dev->bus->resume) { | 363 | if (dev->bus) { |
179 | dev_dbg(dev,"resuming\n"); | 364 | if (dev->bus->pm) { |
180 | error = dev->bus->resume(dev); | 365 | pm_dev_dbg(dev, state, ""); |
366 | error = pm_op(dev, &dev->bus->pm->base, state); | ||
367 | } else if (dev->bus->resume) { | ||
368 | pm_dev_dbg(dev, state, "legacy "); | ||
369 | error = dev->bus->resume(dev); | ||
370 | } | ||
371 | if (error) | ||
372 | goto End; | ||
181 | } | 373 | } |
182 | 374 | ||
183 | if (!error && dev->type && dev->type->resume) { | 375 | if (dev->type) { |
184 | dev_dbg(dev,"resuming\n"); | 376 | if (dev->type->pm) { |
185 | error = dev->type->resume(dev); | 377 | pm_dev_dbg(dev, state, "type "); |
378 | error = pm_op(dev, dev->type->pm, state); | ||
379 | } else if (dev->type->resume) { | ||
380 | pm_dev_dbg(dev, state, "legacy type "); | ||
381 | error = dev->type->resume(dev); | ||
382 | } | ||
383 | if (error) | ||
384 | goto End; | ||
186 | } | 385 | } |
187 | 386 | ||
188 | if (!error && dev->class && dev->class->resume) { | 387 | if (dev->class) { |
189 | dev_dbg(dev,"class resume\n"); | 388 | if (dev->class->pm) { |
190 | error = dev->class->resume(dev); | 389 | pm_dev_dbg(dev, state, "class "); |
390 | error = pm_op(dev, dev->class->pm, state); | ||
391 | } else if (dev->class->resume) { | ||
392 | pm_dev_dbg(dev, state, "legacy class "); | ||
393 | error = dev->class->resume(dev); | ||
394 | } | ||
191 | } | 395 | } |
192 | 396 | End: | |
193 | up(&dev->sem); | 397 | up(&dev->sem); |
194 | 398 | ||
195 | TRACE_RESUME(error); | 399 | TRACE_RESUME(error); |
@@ -198,78 +402,161 @@ static int resume_device(struct device *dev) | |||
198 | 402 | ||
199 | /** | 403 | /** |
200 | * dpm_resume - Resume every device. | 404 | * dpm_resume - Resume every device. |
405 | * @state: PM transition of the system being carried out. | ||
201 | * | 406 | * |
202 | * Resume the devices that have either not gone through | 407 | * Execute the appropriate "resume" callback for all devices the status of |
203 | * the late suspend, or that did go through it but also | 408 | * which indicates that they are inactive. |
204 | * went through the early resume. | 409 | */ |
410 | static void dpm_resume(pm_message_t state) | ||
411 | { | ||
412 | struct list_head list; | ||
413 | |||
414 | INIT_LIST_HEAD(&list); | ||
415 | mutex_lock(&dpm_list_mtx); | ||
416 | transition_started = false; | ||
417 | while (!list_empty(&dpm_list)) { | ||
418 | struct device *dev = to_device(dpm_list.next); | ||
419 | |||
420 | get_device(dev); | ||
421 | if (dev->power.status >= DPM_OFF) { | ||
422 | int error; | ||
423 | |||
424 | dev->power.status = DPM_RESUMING; | ||
425 | mutex_unlock(&dpm_list_mtx); | ||
426 | |||
427 | error = resume_device(dev, state); | ||
428 | |||
429 | mutex_lock(&dpm_list_mtx); | ||
430 | if (error) | ||
431 | pm_dev_err(dev, state, "", error); | ||
432 | } else if (dev->power.status == DPM_SUSPENDING) { | ||
433 | /* Allow new children of the device to be registered */ | ||
434 | dev->power.status = DPM_RESUMING; | ||
435 | } | ||
436 | if (!list_empty(&dev->power.entry)) | ||
437 | list_move_tail(&dev->power.entry, &list); | ||
438 | put_device(dev); | ||
439 | } | ||
440 | list_splice(&list, &dpm_list); | ||
441 | mutex_unlock(&dpm_list_mtx); | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * complete_device - Complete a PM transition for given device | ||
446 | * @dev: Device. | ||
447 | * @state: PM transition of the system being carried out. | ||
448 | */ | ||
449 | static void complete_device(struct device *dev, pm_message_t state) | ||
450 | { | ||
451 | down(&dev->sem); | ||
452 | |||
453 | if (dev->class && dev->class->pm && dev->class->pm->complete) { | ||
454 | pm_dev_dbg(dev, state, "completing class "); | ||
455 | dev->class->pm->complete(dev); | ||
456 | } | ||
457 | |||
458 | if (dev->type && dev->type->pm && dev->type->pm->complete) { | ||
459 | pm_dev_dbg(dev, state, "completing type "); | ||
460 | dev->type->pm->complete(dev); | ||
461 | } | ||
462 | |||
463 | if (dev->bus && dev->bus->pm && dev->bus->pm->base.complete) { | ||
464 | pm_dev_dbg(dev, state, "completing "); | ||
465 | dev->bus->pm->base.complete(dev); | ||
466 | } | ||
467 | |||
468 | up(&dev->sem); | ||
469 | } | ||
470 | |||
471 | /** | ||
472 | * dpm_complete - Complete a PM transition for all devices. | ||
473 | * @state: PM transition of the system being carried out. | ||
205 | * | 474 | * |
206 | * Take devices from the dpm_off_list, resume them, | 475 | * Execute the ->complete() callbacks for all devices that are not marked |
207 | * and put them on the dpm_locked list. | 476 | * as DPM_ON. |
208 | */ | 477 | */ |
209 | static void dpm_resume(void) | 478 | static void dpm_complete(pm_message_t state) |
210 | { | 479 | { |
480 | struct list_head list; | ||
481 | |||
482 | INIT_LIST_HEAD(&list); | ||
211 | mutex_lock(&dpm_list_mtx); | 483 | mutex_lock(&dpm_list_mtx); |
212 | all_sleeping = false; | 484 | while (!list_empty(&dpm_list)) { |
213 | while(!list_empty(&dpm_off)) { | 485 | struct device *dev = to_device(dpm_list.prev); |
214 | struct list_head *entry = dpm_off.next; | ||
215 | struct device *dev = to_device(entry); | ||
216 | 486 | ||
217 | list_move_tail(entry, &dpm_active); | 487 | get_device(dev); |
218 | dev->power.sleeping = false; | 488 | if (dev->power.status > DPM_ON) { |
219 | mutex_unlock(&dpm_list_mtx); | 489 | dev->power.status = DPM_ON; |
220 | resume_device(dev); | 490 | mutex_unlock(&dpm_list_mtx); |
221 | mutex_lock(&dpm_list_mtx); | 491 | |
492 | complete_device(dev, state); | ||
493 | |||
494 | mutex_lock(&dpm_list_mtx); | ||
495 | } | ||
496 | if (!list_empty(&dev->power.entry)) | ||
497 | list_move(&dev->power.entry, &list); | ||
498 | put_device(dev); | ||
222 | } | 499 | } |
500 | list_splice(&list, &dpm_list); | ||
223 | mutex_unlock(&dpm_list_mtx); | 501 | mutex_unlock(&dpm_list_mtx); |
224 | } | 502 | } |
225 | 503 | ||
226 | /** | 504 | /** |
227 | * device_resume - Restore state of each device in system. | 505 | * device_resume - Restore state of each device in system. |
506 | * @state: PM transition of the system being carried out. | ||
228 | * | 507 | * |
229 | * Resume all the devices, unlock them all, and allow new | 508 | * Resume all the devices, unlock them all, and allow new |
230 | * devices to be registered once again. | 509 | * devices to be registered once again. |
231 | */ | 510 | */ |
232 | void device_resume(void) | 511 | void device_resume(pm_message_t state) |
233 | { | 512 | { |
234 | might_sleep(); | 513 | might_sleep(); |
235 | dpm_resume(); | 514 | dpm_resume(state); |
515 | dpm_complete(state); | ||
236 | } | 516 | } |
237 | EXPORT_SYMBOL_GPL(device_resume); | 517 | EXPORT_SYMBOL_GPL(device_resume); |
238 | 518 | ||
239 | 519 | ||
240 | /*------------------------- Suspend routines -------------------------*/ | 520 | /*------------------------- Suspend routines -------------------------*/ |
241 | 521 | ||
242 | static inline char *suspend_verb(u32 event) | 522 | /** |
523 | * resume_event - return a PM message representing the resume event | ||
524 | * corresponding to given sleep state. | ||
525 | * @sleep_state: PM message representing a sleep state. | ||
526 | */ | ||
527 | static pm_message_t resume_event(pm_message_t sleep_state) | ||
243 | { | 528 | { |
244 | switch (event) { | 529 | switch (sleep_state.event) { |
245 | case PM_EVENT_SUSPEND: return "suspend"; | 530 | case PM_EVENT_SUSPEND: |
246 | case PM_EVENT_FREEZE: return "freeze"; | 531 | return PMSG_RESUME; |
247 | case PM_EVENT_PRETHAW: return "prethaw"; | 532 | case PM_EVENT_FREEZE: |
248 | default: return "(unknown suspend event)"; | 533 | case PM_EVENT_QUIESCE: |
534 | return PMSG_RECOVER; | ||
535 | case PM_EVENT_HIBERNATE: | ||
536 | return PMSG_RESTORE; | ||
249 | } | 537 | } |
250 | } | 538 | return PMSG_ON; |
251 | |||
252 | static void | ||
253 | suspend_device_dbg(struct device *dev, pm_message_t state, char *info) | ||
254 | { | ||
255 | dev_dbg(dev, "%s%s%s\n", info, suspend_verb(state.event), | ||
256 | ((state.event == PM_EVENT_SUSPEND) && device_may_wakeup(dev)) ? | ||
257 | ", may wakeup" : ""); | ||
258 | } | 539 | } |
259 | 540 | ||
260 | /** | 541 | /** |
261 | * suspend_device_late - Shut down one device (late suspend). | 542 | * suspend_device_noirq - Shut down one device (late suspend). |
262 | * @dev: Device. | 543 | * @dev: Device. |
263 | * @state: Power state device is entering. | 544 | * @state: PM transition of the system being carried out. |
264 | * | 545 | * |
265 | * This is called with interrupts off and only a single CPU running. | 546 | * This is called with interrupts off and only a single CPU running. |
266 | */ | 547 | */ |
267 | static int suspend_device_late(struct device *dev, pm_message_t state) | 548 | static int suspend_device_noirq(struct device *dev, pm_message_t state) |
268 | { | 549 | { |
269 | int error = 0; | 550 | int error = 0; |
270 | 551 | ||
271 | if (dev->bus && dev->bus->suspend_late) { | 552 | if (!dev->bus) |
272 | suspend_device_dbg(dev, state, "LATE "); | 553 | return 0; |
554 | |||
555 | if (dev->bus->pm) { | ||
556 | pm_dev_dbg(dev, state, "LATE "); | ||
557 | error = pm_noirq_op(dev, dev->bus->pm, state); | ||
558 | } else if (dev->bus->suspend_late) { | ||
559 | pm_dev_dbg(dev, state, "legacy LATE "); | ||
273 | error = dev->bus->suspend_late(dev, state); | 560 | error = dev->bus->suspend_late(dev, state); |
274 | suspend_report_result(dev->bus->suspend_late, error); | 561 | suspend_report_result(dev->bus->suspend_late, error); |
275 | } | 562 | } |
@@ -278,37 +565,30 @@ static int suspend_device_late(struct device *dev, pm_message_t state) | |||
278 | 565 | ||
279 | /** | 566 | /** |
280 | * device_power_down - Shut down special devices. | 567 | * device_power_down - Shut down special devices. |
281 | * @state: Power state to enter. | 568 | * @state: PM transition of the system being carried out. |
282 | * | 569 | * |
283 | * Power down devices that require interrupts to be disabled | 570 | * Power down devices that require interrupts to be disabled. |
284 | * and move them from the dpm_off list to the dpm_off_irq list. | ||
285 | * Then power down system devices. | 571 | * Then power down system devices. |
286 | * | 572 | * |
287 | * Must be called with interrupts disabled and only one CPU running. | 573 | * Must be called with interrupts disabled and only one CPU running. |
288 | */ | 574 | */ |
289 | int device_power_down(pm_message_t state) | 575 | int device_power_down(pm_message_t state) |
290 | { | 576 | { |
577 | struct device *dev; | ||
291 | int error = 0; | 578 | int error = 0; |
292 | 579 | ||
293 | while (!list_empty(&dpm_off)) { | 580 | list_for_each_entry_reverse(dev, &dpm_list, power.entry) { |
294 | struct list_head *entry = dpm_off.prev; | 581 | error = suspend_device_noirq(dev, state); |
295 | struct device *dev = to_device(entry); | ||
296 | |||
297 | error = suspend_device_late(dev, state); | ||
298 | if (error) { | 582 | if (error) { |
299 | printk(KERN_ERR "Could not power down device %s: " | 583 | pm_dev_err(dev, state, " late", error); |
300 | "error %d\n", | ||
301 | kobject_name(&dev->kobj), error); | ||
302 | break; | 584 | break; |
303 | } | 585 | } |
304 | if (!list_empty(&dev->power.entry)) | 586 | dev->power.status = DPM_OFF_IRQ; |
305 | list_move(&dev->power.entry, &dpm_off_irq); | ||
306 | } | 587 | } |
307 | |||
308 | if (!error) | 588 | if (!error) |
309 | error = sysdev_suspend(state); | 589 | error = sysdev_suspend(state); |
310 | if (error) | 590 | if (error) |
311 | dpm_power_up(); | 591 | dpm_power_up(resume_event(state)); |
312 | return error; | 592 | return error; |
313 | } | 593 | } |
314 | EXPORT_SYMBOL_GPL(device_power_down); | 594 | EXPORT_SYMBOL_GPL(device_power_down); |
@@ -316,7 +596,7 @@ EXPORT_SYMBOL_GPL(device_power_down); | |||
316 | /** | 596 | /** |
317 | * suspend_device - Save state of one device. | 597 | * suspend_device - Save state of one device. |
318 | * @dev: Device. | 598 | * @dev: Device. |
319 | * @state: Power state device is entering. | 599 | * @state: PM transition of the system being carried out. |
320 | */ | 600 | */ |
321 | static int suspend_device(struct device *dev, pm_message_t state) | 601 | static int suspend_device(struct device *dev, pm_message_t state) |
322 | { | 602 | { |
@@ -324,24 +604,43 @@ static int suspend_device(struct device *dev, pm_message_t state) | |||
324 | 604 | ||
325 | down(&dev->sem); | 605 | down(&dev->sem); |
326 | 606 | ||
327 | if (dev->class && dev->class->suspend) { | 607 | if (dev->class) { |
328 | suspend_device_dbg(dev, state, "class "); | 608 | if (dev->class->pm) { |
329 | error = dev->class->suspend(dev, state); | 609 | pm_dev_dbg(dev, state, "class "); |
330 | suspend_report_result(dev->class->suspend, error); | 610 | error = pm_op(dev, dev->class->pm, state); |
611 | } else if (dev->class->suspend) { | ||
612 | pm_dev_dbg(dev, state, "legacy class "); | ||
613 | error = dev->class->suspend(dev, state); | ||
614 | suspend_report_result(dev->class->suspend, error); | ||
615 | } | ||
616 | if (error) | ||
617 | goto End; | ||
331 | } | 618 | } |
332 | 619 | ||
333 | if (!error && dev->type && dev->type->suspend) { | 620 | if (dev->type) { |
334 | suspend_device_dbg(dev, state, "type "); | 621 | if (dev->type->pm) { |
335 | error = dev->type->suspend(dev, state); | 622 | pm_dev_dbg(dev, state, "type "); |
336 | suspend_report_result(dev->type->suspend, error); | 623 | error = pm_op(dev, dev->type->pm, state); |
624 | } else if (dev->type->suspend) { | ||
625 | pm_dev_dbg(dev, state, "legacy type "); | ||
626 | error = dev->type->suspend(dev, state); | ||
627 | suspend_report_result(dev->type->suspend, error); | ||
628 | } | ||
629 | if (error) | ||
630 | goto End; | ||
337 | } | 631 | } |
338 | 632 | ||
339 | if (!error && dev->bus && dev->bus->suspend) { | 633 | if (dev->bus) { |
340 | suspend_device_dbg(dev, state, ""); | 634 | if (dev->bus->pm) { |
341 | error = dev->bus->suspend(dev, state); | 635 | pm_dev_dbg(dev, state, ""); |
342 | suspend_report_result(dev->bus->suspend, error); | 636 | error = pm_op(dev, &dev->bus->pm->base, state); |
637 | } else if (dev->bus->suspend) { | ||
638 | pm_dev_dbg(dev, state, "legacy "); | ||
639 | error = dev->bus->suspend(dev, state); | ||
640 | suspend_report_result(dev->bus->suspend, error); | ||
641 | } | ||
343 | } | 642 | } |
344 | 643 | End: | |
345 | up(&dev->sem); | 644 | up(&dev->sem); |
346 | 645 | ||
347 | return error; | 646 | return error; |
@@ -349,67 +648,139 @@ static int suspend_device(struct device *dev, pm_message_t state) | |||
349 | 648 | ||
350 | /** | 649 | /** |
351 | * dpm_suspend - Suspend every device. | 650 | * dpm_suspend - Suspend every device. |
352 | * @state: Power state to put each device in. | 651 | * @state: PM transition of the system being carried out. |
353 | * | ||
354 | * Walk the dpm_locked list. Suspend each device and move it | ||
355 | * to the dpm_off list. | ||
356 | * | 652 | * |
357 | * (For historical reasons, if it returns -EAGAIN, that used to mean | 653 | * Execute the appropriate "suspend" callbacks for all devices. |
358 | * that the device would be called again with interrupts disabled. | ||
359 | * These days, we use the "suspend_late()" callback for that, so we | ||
360 | * print a warning and consider it an error). | ||
361 | */ | 654 | */ |
362 | static int dpm_suspend(pm_message_t state) | 655 | static int dpm_suspend(pm_message_t state) |
363 | { | 656 | { |
657 | struct list_head list; | ||
364 | int error = 0; | 658 | int error = 0; |
365 | 659 | ||
660 | INIT_LIST_HEAD(&list); | ||
366 | mutex_lock(&dpm_list_mtx); | 661 | mutex_lock(&dpm_list_mtx); |
367 | while (!list_empty(&dpm_active)) { | 662 | while (!list_empty(&dpm_list)) { |
368 | struct list_head *entry = dpm_active.prev; | 663 | struct device *dev = to_device(dpm_list.prev); |
369 | struct device *dev = to_device(entry); | ||
370 | 664 | ||
371 | WARN_ON(dev->parent && dev->parent->power.sleeping); | 665 | get_device(dev); |
372 | |||
373 | dev->power.sleeping = true; | ||
374 | mutex_unlock(&dpm_list_mtx); | 666 | mutex_unlock(&dpm_list_mtx); |
667 | |||
375 | error = suspend_device(dev, state); | 668 | error = suspend_device(dev, state); |
669 | |||
376 | mutex_lock(&dpm_list_mtx); | 670 | mutex_lock(&dpm_list_mtx); |
377 | if (error) { | 671 | if (error) { |
378 | printk(KERN_ERR "Could not suspend device %s: " | 672 | pm_dev_err(dev, state, "", error); |
379 | "error %d%s\n", | 673 | put_device(dev); |
380 | kobject_name(&dev->kobj), | ||
381 | error, | ||
382 | (error == -EAGAIN ? | ||
383 | " (please convert to suspend_late)" : | ||
384 | "")); | ||
385 | dev->power.sleeping = false; | ||
386 | break; | 674 | break; |
387 | } | 675 | } |
676 | dev->power.status = DPM_OFF; | ||
388 | if (!list_empty(&dev->power.entry)) | 677 | if (!list_empty(&dev->power.entry)) |
389 | list_move(&dev->power.entry, &dpm_off); | 678 | list_move(&dev->power.entry, &list); |
679 | put_device(dev); | ||
390 | } | 680 | } |
391 | if (!error) | 681 | list_splice(&list, dpm_list.prev); |
392 | all_sleeping = true; | ||
393 | mutex_unlock(&dpm_list_mtx); | 682 | mutex_unlock(&dpm_list_mtx); |
683 | return error; | ||
684 | } | ||
685 | |||
686 | /** | ||
687 | * prepare_device - Execute the ->prepare() callback(s) for given device. | ||
688 | * @dev: Device. | ||
689 | * @state: PM transition of the system being carried out. | ||
690 | */ | ||
691 | static int prepare_device(struct device *dev, pm_message_t state) | ||
692 | { | ||
693 | int error = 0; | ||
694 | |||
695 | down(&dev->sem); | ||
696 | |||
697 | if (dev->bus && dev->bus->pm && dev->bus->pm->base.prepare) { | ||
698 | pm_dev_dbg(dev, state, "preparing "); | ||
699 | error = dev->bus->pm->base.prepare(dev); | ||
700 | suspend_report_result(dev->bus->pm->base.prepare, error); | ||
701 | if (error) | ||
702 | goto End; | ||
703 | } | ||
704 | |||
705 | if (dev->type && dev->type->pm && dev->type->pm->prepare) { | ||
706 | pm_dev_dbg(dev, state, "preparing type "); | ||
707 | error = dev->type->pm->prepare(dev); | ||
708 | suspend_report_result(dev->type->pm->prepare, error); | ||
709 | if (error) | ||
710 | goto End; | ||
711 | } | ||
712 | |||
713 | if (dev->class && dev->class->pm && dev->class->pm->prepare) { | ||
714 | pm_dev_dbg(dev, state, "preparing class "); | ||
715 | error = dev->class->pm->prepare(dev); | ||
716 | suspend_report_result(dev->class->pm->prepare, error); | ||
717 | } | ||
718 | End: | ||
719 | up(&dev->sem); | ||
720 | |||
721 | return error; | ||
722 | } | ||
723 | |||
724 | /** | ||
725 | * dpm_prepare - Prepare all devices for a PM transition. | ||
726 | * @state: PM transition of the system being carried out. | ||
727 | * | ||
728 | * Execute the ->prepare() callback for all devices. | ||
729 | */ | ||
730 | static int dpm_prepare(pm_message_t state) | ||
731 | { | ||
732 | struct list_head list; | ||
733 | int error = 0; | ||
734 | |||
735 | INIT_LIST_HEAD(&list); | ||
736 | mutex_lock(&dpm_list_mtx); | ||
737 | transition_started = true; | ||
738 | while (!list_empty(&dpm_list)) { | ||
739 | struct device *dev = to_device(dpm_list.next); | ||
740 | |||
741 | get_device(dev); | ||
742 | dev->power.status = DPM_PREPARING; | ||
743 | mutex_unlock(&dpm_list_mtx); | ||
394 | 744 | ||
745 | error = prepare_device(dev, state); | ||
746 | |||
747 | mutex_lock(&dpm_list_mtx); | ||
748 | if (error) { | ||
749 | dev->power.status = DPM_ON; | ||
750 | if (error == -EAGAIN) { | ||
751 | put_device(dev); | ||
752 | continue; | ||
753 | } | ||
754 | printk(KERN_ERR "PM: Failed to prepare device %s " | ||
755 | "for power transition: error %d\n", | ||
756 | kobject_name(&dev->kobj), error); | ||
757 | put_device(dev); | ||
758 | break; | ||
759 | } | ||
760 | dev->power.status = DPM_SUSPENDING; | ||
761 | if (!list_empty(&dev->power.entry)) | ||
762 | list_move_tail(&dev->power.entry, &list); | ||
763 | put_device(dev); | ||
764 | } | ||
765 | list_splice(&list, &dpm_list); | ||
766 | mutex_unlock(&dpm_list_mtx); | ||
395 | return error; | 767 | return error; |
396 | } | 768 | } |
397 | 769 | ||
398 | /** | 770 | /** |
399 | * device_suspend - Save state and stop all devices in system. | 771 | * device_suspend - Save state and stop all devices in system. |
400 | * @state: new power management state | 772 | * @state: PM transition of the system being carried out. |
401 | * | 773 | * |
402 | * Prevent new devices from being registered, then lock all devices | 774 | * Prepare and suspend all devices. |
403 | * and suspend them. | ||
404 | */ | 775 | */ |
405 | int device_suspend(pm_message_t state) | 776 | int device_suspend(pm_message_t state) |
406 | { | 777 | { |
407 | int error; | 778 | int error; |
408 | 779 | ||
409 | might_sleep(); | 780 | might_sleep(); |
410 | error = dpm_suspend(state); | 781 | error = dpm_prepare(state); |
411 | if (error) | 782 | if (!error) |
412 | device_resume(); | 783 | error = dpm_suspend(state); |
413 | return error; | 784 | return error; |
414 | } | 785 | } |
415 | EXPORT_SYMBOL_GPL(device_suspend); | 786 | EXPORT_SYMBOL_GPL(device_suspend); |
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h index a6894f2a4b99..a3252c0e2887 100644 --- a/drivers/base/power/power.h +++ b/drivers/base/power/power.h | |||
@@ -4,7 +4,7 @@ | |||
4 | * main.c | 4 | * main.c |
5 | */ | 5 | */ |
6 | 6 | ||
7 | extern struct list_head dpm_active; /* The active device list */ | 7 | extern struct list_head dpm_list; /* The active device list */ |
8 | 8 | ||
9 | static inline struct device *to_device(struct list_head *entry) | 9 | static inline struct device *to_device(struct list_head *entry) |
10 | { | 10 | { |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index d11f74b038db..596aeecfdffe 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -6,9 +6,6 @@ | |||
6 | #include <linux/string.h> | 6 | #include <linux/string.h> |
7 | #include "power.h" | 7 | #include "power.h" |
8 | 8 | ||
9 | int (*platform_enable_wakeup)(struct device *dev, int is_on); | ||
10 | |||
11 | |||
12 | /* | 9 | /* |
13 | * wakeup - Report/change current wakeup option for device | 10 | * wakeup - Report/change current wakeup option for device |
14 | * | 11 | * |
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c index 87a7f1d02578..9b1b20b59e0a 100644 --- a/drivers/base/power/trace.c +++ b/drivers/base/power/trace.c | |||
@@ -188,9 +188,9 @@ static int show_file_hash(unsigned int value) | |||
188 | static int show_dev_hash(unsigned int value) | 188 | static int show_dev_hash(unsigned int value) |
189 | { | 189 | { |
190 | int match = 0; | 190 | int match = 0; |
191 | struct list_head * entry = dpm_active.prev; | 191 | struct list_head *entry = dpm_list.prev; |
192 | 192 | ||
193 | while (entry != &dpm_active) { | 193 | while (entry != &dpm_list) { |
194 | struct device * dev = to_device(entry); | 194 | struct device * dev = to_device(entry); |
195 | unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); | 195 | unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); |
196 | if (hash == value) { | 196 | if (hash == value) { |
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig index 0d1d2133d9bc..61ad8d639ba3 100644 --- a/drivers/block/Kconfig +++ b/drivers/block/Kconfig | |||
@@ -433,4 +433,16 @@ config VIRTIO_BLK | |||
433 | This is the virtual block driver for virtio. It can be used with | 433 | This is the virtual block driver for virtio. It can be used with |
434 | lguest or QEMU based VMMs (like KVM or Xen). Say Y or M. | 434 | lguest or QEMU based VMMs (like KVM or Xen). Say Y or M. |
435 | 435 | ||
436 | config BLK_DEV_HD | ||
437 | bool "Very old hard disk (MFM/RLL/IDE) driver" | ||
438 | depends on HAVE_IDE | ||
439 | depends on !ARM || ARCH_RPC || ARCH_SHARK || BROKEN | ||
440 | help | ||
441 | This is a very old hard disk driver that lacks the enhanced | ||
442 | functionality of the newer ones. | ||
443 | |||
444 | It is required for systems with ancient MFM/RLL/ESDI drives. | ||
445 | |||
446 | If unsure, say N. | ||
447 | |||
436 | endif # BLK_DEV | 448 | endif # BLK_DEV |
diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 5e584306be99..204332b29578 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile | |||
@@ -29,5 +29,6 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o | |||
29 | obj-$(CONFIG_VIODASD) += viodasd.o | 29 | obj-$(CONFIG_VIODASD) += viodasd.o |
30 | obj-$(CONFIG_BLK_DEV_SX8) += sx8.o | 30 | obj-$(CONFIG_BLK_DEV_SX8) += sx8.o |
31 | obj-$(CONFIG_BLK_DEV_UB) += ub.o | 31 | obj-$(CONFIG_BLK_DEV_UB) += ub.o |
32 | obj-$(CONFIG_BLK_DEV_HD) += hd.o | ||
32 | 33 | ||
33 | obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o | 34 | obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o |
diff --git a/drivers/ide/legacy/hd.c b/drivers/block/hd.c index abdedf56643e..682243bf2e46 100644 --- a/drivers/ide/legacy/hd.c +++ b/drivers/block/hd.c | |||
@@ -37,7 +37,6 @@ | |||
37 | #include <linux/slab.h> | 37 | #include <linux/slab.h> |
38 | #include <linux/string.h> | 38 | #include <linux/string.h> |
39 | #include <linux/ioport.h> | 39 | #include <linux/ioport.h> |
40 | #include <linux/mc146818rtc.h> /* CMOS defines */ | ||
41 | #include <linux/init.h> | 40 | #include <linux/init.h> |
42 | #include <linux/blkpg.h> | 41 | #include <linux/blkpg.h> |
43 | #include <linux/hdreg.h> | 42 | #include <linux/hdreg.h> |
@@ -812,4 +811,4 @@ static int __init parse_hd_setup(char *line) | |||
812 | } | 811 | } |
813 | __setup("hd=", parse_hd_setup); | 812 | __setup("hd=", parse_hd_setup); |
814 | 813 | ||
815 | module_init(hd_init); | 814 | late_initcall(hd_init); |
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c index da8a1658a273..aaca40283be9 100644 --- a/drivers/char/apm-emulation.c +++ b/drivers/char/apm-emulation.c | |||
@@ -59,6 +59,55 @@ struct apm_queue { | |||
59 | }; | 59 | }; |
60 | 60 | ||
61 | /* | 61 | /* |
62 | * thread states (for threads using a writable /dev/apm_bios fd): | ||
63 | * | ||
64 | * SUSPEND_NONE: nothing happening | ||
65 | * SUSPEND_PENDING: suspend event queued for thread and pending to be read | ||
66 | * SUSPEND_READ: suspend event read, pending acknowledgement | ||
67 | * SUSPEND_ACKED: acknowledgement received from thread (via ioctl), | ||
68 | * waiting for resume | ||
69 | * SUSPEND_ACKTO: acknowledgement timeout | ||
70 | * SUSPEND_DONE: thread had acked suspend and is now notified of | ||
71 | * resume | ||
72 | * | ||
73 | * SUSPEND_WAIT: this thread invoked suspend and is waiting for resume | ||
74 | * | ||
75 | * A thread migrates in one of three paths: | ||
76 | * NONE -1-> PENDING -2-> READ -3-> ACKED -4-> DONE -5-> NONE | ||
77 | * -6-> ACKTO -7-> NONE | ||
78 | * NONE -8-> WAIT -9-> NONE | ||
79 | * | ||
80 | * While in PENDING or READ, the thread is accounted for in the | ||
81 | * suspend_acks_pending counter. | ||
82 | * | ||
83 | * The transitions are invoked as follows: | ||
84 | * 1: suspend event is signalled from the core PM code | ||
85 | * 2: the suspend event is read from the fd by the userspace thread | ||
86 | * 3: userspace thread issues the APM_IOC_SUSPEND ioctl (as ack) | ||
87 | * 4: core PM code signals that we have resumed | ||
88 | * 5: APM_IOC_SUSPEND ioctl returns | ||
89 | * | ||
90 | * 6: the notifier invoked from the core PM code timed out waiting | ||
91 | * for all relevant threds to enter ACKED state and puts those | ||
92 | * that haven't into ACKTO | ||
93 | * 7: those threads issue APM_IOC_SUSPEND ioctl too late, | ||
94 | * get an error | ||
95 | * | ||
96 | * 8: userspace thread issues the APM_IOC_SUSPEND ioctl (to suspend), | ||
97 | * ioctl code invokes pm_suspend() | ||
98 | * 9: pm_suspend() returns indicating resume | ||
99 | */ | ||
100 | enum apm_suspend_state { | ||
101 | SUSPEND_NONE, | ||
102 | SUSPEND_PENDING, | ||
103 | SUSPEND_READ, | ||
104 | SUSPEND_ACKED, | ||
105 | SUSPEND_ACKTO, | ||
106 | SUSPEND_WAIT, | ||
107 | SUSPEND_DONE, | ||
108 | }; | ||
109 | |||
110 | /* | ||
62 | * The per-file APM data | 111 | * The per-file APM data |
63 | */ | 112 | */ |
64 | struct apm_user { | 113 | struct apm_user { |
@@ -69,13 +118,7 @@ struct apm_user { | |||
69 | unsigned int reader: 1; | 118 | unsigned int reader: 1; |
70 | 119 | ||
71 | int suspend_result; | 120 | int suspend_result; |
72 | unsigned int suspend_state; | 121 | enum apm_suspend_state suspend_state; |
73 | #define SUSPEND_NONE 0 /* no suspend pending */ | ||
74 | #define SUSPEND_PENDING 1 /* suspend pending read */ | ||
75 | #define SUSPEND_READ 2 /* suspend read, pending ack */ | ||
76 | #define SUSPEND_ACKED 3 /* suspend acked */ | ||
77 | #define SUSPEND_WAIT 4 /* waiting for suspend */ | ||
78 | #define SUSPEND_DONE 5 /* suspend completed */ | ||
79 | 122 | ||
80 | struct apm_queue queue; | 123 | struct apm_queue queue; |
81 | }; | 124 | }; |
@@ -83,7 +126,8 @@ struct apm_user { | |||
83 | /* | 126 | /* |
84 | * Local variables | 127 | * Local variables |
85 | */ | 128 | */ |
86 | static int suspends_pending; | 129 | static atomic_t suspend_acks_pending = ATOMIC_INIT(0); |
130 | static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0); | ||
87 | static int apm_disabled; | 131 | static int apm_disabled; |
88 | static struct task_struct *kapmd_tsk; | 132 | static struct task_struct *kapmd_tsk; |
89 | 133 | ||
@@ -166,78 +210,6 @@ static void queue_event(apm_event_t event) | |||
166 | wake_up_interruptible(&apm_waitqueue); | 210 | wake_up_interruptible(&apm_waitqueue); |
167 | } | 211 | } |
168 | 212 | ||
169 | /* | ||
170 | * queue_suspend_event - queue an APM suspend event. | ||
171 | * | ||
172 | * Check that we're in a state where we can suspend. If not, | ||
173 | * return -EBUSY. Otherwise, queue an event to all "writer" | ||
174 | * users. If there are no "writer" users, return '1' to | ||
175 | * indicate that we can immediately suspend. | ||
176 | */ | ||
177 | static int queue_suspend_event(apm_event_t event, struct apm_user *sender) | ||
178 | { | ||
179 | struct apm_user *as; | ||
180 | int ret = 1; | ||
181 | |||
182 | mutex_lock(&state_lock); | ||
183 | down_read(&user_list_lock); | ||
184 | |||
185 | /* | ||
186 | * If a thread is still processing, we can't suspend, so reject | ||
187 | * the request. | ||
188 | */ | ||
189 | list_for_each_entry(as, &apm_user_list, list) { | ||
190 | if (as != sender && as->reader && as->writer && as->suser && | ||
191 | as->suspend_state != SUSPEND_NONE) { | ||
192 | ret = -EBUSY; | ||
193 | goto out; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | list_for_each_entry(as, &apm_user_list, list) { | ||
198 | if (as != sender && as->reader && as->writer && as->suser) { | ||
199 | as->suspend_state = SUSPEND_PENDING; | ||
200 | suspends_pending++; | ||
201 | queue_add_event(&as->queue, event); | ||
202 | ret = 0; | ||
203 | } | ||
204 | } | ||
205 | out: | ||
206 | up_read(&user_list_lock); | ||
207 | mutex_unlock(&state_lock); | ||
208 | wake_up_interruptible(&apm_waitqueue); | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | static void apm_suspend(void) | ||
213 | { | ||
214 | struct apm_user *as; | ||
215 | int err = pm_suspend(PM_SUSPEND_MEM); | ||
216 | |||
217 | /* | ||
218 | * Anyone on the APM queues will think we're still suspended. | ||
219 | * Send a message so everyone knows we're now awake again. | ||
220 | */ | ||
221 | queue_event(APM_NORMAL_RESUME); | ||
222 | |||
223 | /* | ||
224 | * Finally, wake up anyone who is sleeping on the suspend. | ||
225 | */ | ||
226 | mutex_lock(&state_lock); | ||
227 | down_read(&user_list_lock); | ||
228 | list_for_each_entry(as, &apm_user_list, list) { | ||
229 | if (as->suspend_state == SUSPEND_WAIT || | ||
230 | as->suspend_state == SUSPEND_ACKED) { | ||
231 | as->suspend_result = err; | ||
232 | as->suspend_state = SUSPEND_DONE; | ||
233 | } | ||
234 | } | ||
235 | up_read(&user_list_lock); | ||
236 | mutex_unlock(&state_lock); | ||
237 | |||
238 | wake_up(&apm_suspend_waitqueue); | ||
239 | } | ||
240 | |||
241 | static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos) | 213 | static ssize_t apm_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos) |
242 | { | 214 | { |
243 | struct apm_user *as = fp->private_data; | 215 | struct apm_user *as = fp->private_data; |
@@ -308,25 +280,22 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) | |||
308 | 280 | ||
309 | as->suspend_result = -EINTR; | 281 | as->suspend_result = -EINTR; |
310 | 282 | ||
311 | if (as->suspend_state == SUSPEND_READ) { | 283 | switch (as->suspend_state) { |
312 | int pending; | 284 | case SUSPEND_READ: |
313 | |||
314 | /* | 285 | /* |
315 | * If we read a suspend command from /dev/apm_bios, | 286 | * If we read a suspend command from /dev/apm_bios, |
316 | * then the corresponding APM_IOC_SUSPEND ioctl is | 287 | * then the corresponding APM_IOC_SUSPEND ioctl is |
317 | * interpreted as an acknowledge. | 288 | * interpreted as an acknowledge. |
318 | */ | 289 | */ |
319 | as->suspend_state = SUSPEND_ACKED; | 290 | as->suspend_state = SUSPEND_ACKED; |
320 | suspends_pending--; | 291 | atomic_dec(&suspend_acks_pending); |
321 | pending = suspends_pending == 0; | ||
322 | mutex_unlock(&state_lock); | 292 | mutex_unlock(&state_lock); |
323 | 293 | ||
324 | /* | 294 | /* |
325 | * If there are no further acknowledges required, | 295 | * suspend_acks_pending changed, the notifier needs to |
326 | * suspend the system. | 296 | * be woken up for this |
327 | */ | 297 | */ |
328 | if (pending) | 298 | wake_up(&apm_suspend_waitqueue); |
329 | apm_suspend(); | ||
330 | 299 | ||
331 | /* | 300 | /* |
332 | * Wait for the suspend/resume to complete. If there | 301 | * Wait for the suspend/resume to complete. If there |
@@ -342,35 +311,21 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) | |||
342 | * try_to_freeze() in freezer_count() will not trigger | 311 | * try_to_freeze() in freezer_count() will not trigger |
343 | */ | 312 | */ |
344 | freezer_count(); | 313 | freezer_count(); |
345 | } else { | 314 | break; |
315 | case SUSPEND_ACKTO: | ||
316 | as->suspend_result = -ETIMEDOUT; | ||
317 | mutex_unlock(&state_lock); | ||
318 | break; | ||
319 | default: | ||
346 | as->suspend_state = SUSPEND_WAIT; | 320 | as->suspend_state = SUSPEND_WAIT; |
347 | mutex_unlock(&state_lock); | 321 | mutex_unlock(&state_lock); |
348 | 322 | ||
349 | /* | 323 | /* |
350 | * Otherwise it is a request to suspend the system. | 324 | * Otherwise it is a request to suspend the system. |
351 | * Queue an event for all readers, and expect an | 325 | * Just invoke pm_suspend(), we'll handle it from |
352 | * acknowledge from all writers who haven't already | 326 | * there via the notifier. |
353 | * acknowledged. | ||
354 | */ | ||
355 | err = queue_suspend_event(APM_USER_SUSPEND, as); | ||
356 | if (err < 0) { | ||
357 | /* | ||
358 | * Avoid taking the lock here - this | ||
359 | * should be fine. | ||
360 | */ | ||
361 | as->suspend_state = SUSPEND_NONE; | ||
362 | break; | ||
363 | } | ||
364 | |||
365 | if (err > 0) | ||
366 | apm_suspend(); | ||
367 | |||
368 | /* | ||
369 | * Wait for the suspend/resume to complete. If there | ||
370 | * are pending acknowledges, we wait here for them. | ||
371 | */ | 327 | */ |
372 | wait_event_freezable(apm_suspend_waitqueue, | 328 | as->suspend_result = pm_suspend(PM_SUSPEND_MEM); |
373 | as->suspend_state == SUSPEND_DONE); | ||
374 | } | 329 | } |
375 | 330 | ||
376 | mutex_lock(&state_lock); | 331 | mutex_lock(&state_lock); |
@@ -386,7 +341,6 @@ apm_ioctl(struct inode * inode, struct file *filp, u_int cmd, u_long arg) | |||
386 | static int apm_release(struct inode * inode, struct file * filp) | 341 | static int apm_release(struct inode * inode, struct file * filp) |
387 | { | 342 | { |
388 | struct apm_user *as = filp->private_data; | 343 | struct apm_user *as = filp->private_data; |
389 | int pending = 0; | ||
390 | 344 | ||
391 | filp->private_data = NULL; | 345 | filp->private_data = NULL; |
392 | 346 | ||
@@ -396,18 +350,15 @@ static int apm_release(struct inode * inode, struct file * filp) | |||
396 | 350 | ||
397 | /* | 351 | /* |
398 | * We are now unhooked from the chain. As far as new | 352 | * We are now unhooked from the chain. As far as new |
399 | * events are concerned, we no longer exist. However, we | 353 | * events are concerned, we no longer exist. |
400 | * need to balance suspends_pending, which means the | ||
401 | * possibility of sleeping. | ||
402 | */ | 354 | */ |
403 | mutex_lock(&state_lock); | 355 | mutex_lock(&state_lock); |
404 | if (as->suspend_state != SUSPEND_NONE) { | 356 | if (as->suspend_state == SUSPEND_PENDING || |
405 | suspends_pending -= 1; | 357 | as->suspend_state == SUSPEND_READ) |
406 | pending = suspends_pending == 0; | 358 | atomic_dec(&suspend_acks_pending); |
407 | } | ||
408 | mutex_unlock(&state_lock); | 359 | mutex_unlock(&state_lock); |
409 | if (pending) | 360 | |
410 | apm_suspend(); | 361 | wake_up(&apm_suspend_waitqueue); |
411 | 362 | ||
412 | kfree(as); | 363 | kfree(as); |
413 | return 0; | 364 | return 0; |
@@ -545,7 +496,6 @@ static int kapmd(void *arg) | |||
545 | { | 496 | { |
546 | do { | 497 | do { |
547 | apm_event_t event; | 498 | apm_event_t event; |
548 | int ret; | ||
549 | 499 | ||
550 | wait_event_interruptible(kapmd_wait, | 500 | wait_event_interruptible(kapmd_wait, |
551 | !queue_empty(&kapmd_queue) || kthread_should_stop()); | 501 | !queue_empty(&kapmd_queue) || kthread_should_stop()); |
@@ -570,20 +520,13 @@ static int kapmd(void *arg) | |||
570 | 520 | ||
571 | case APM_USER_SUSPEND: | 521 | case APM_USER_SUSPEND: |
572 | case APM_SYS_SUSPEND: | 522 | case APM_SYS_SUSPEND: |
573 | ret = queue_suspend_event(event, NULL); | 523 | pm_suspend(PM_SUSPEND_MEM); |
574 | if (ret < 0) { | ||
575 | /* | ||
576 | * We were busy. Try again in 50ms. | ||
577 | */ | ||
578 | queue_add_event(&kapmd_queue, event); | ||
579 | msleep(50); | ||
580 | } | ||
581 | if (ret > 0) | ||
582 | apm_suspend(); | ||
583 | break; | 524 | break; |
584 | 525 | ||
585 | case APM_CRITICAL_SUSPEND: | 526 | case APM_CRITICAL_SUSPEND: |
586 | apm_suspend(); | 527 | atomic_inc(&userspace_notification_inhibit); |
528 | pm_suspend(PM_SUSPEND_MEM); | ||
529 | atomic_dec(&userspace_notification_inhibit); | ||
587 | break; | 530 | break; |
588 | } | 531 | } |
589 | } while (1); | 532 | } while (1); |
@@ -591,6 +534,120 @@ static int kapmd(void *arg) | |||
591 | return 0; | 534 | return 0; |
592 | } | 535 | } |
593 | 536 | ||
537 | static int apm_suspend_notifier(struct notifier_block *nb, | ||
538 | unsigned long event, | ||
539 | void *dummy) | ||
540 | { | ||
541 | struct apm_user *as; | ||
542 | int err; | ||
543 | |||
544 | /* short-cut emergency suspends */ | ||
545 | if (atomic_read(&userspace_notification_inhibit)) | ||
546 | return NOTIFY_DONE; | ||
547 | |||
548 | switch (event) { | ||
549 | case PM_SUSPEND_PREPARE: | ||
550 | /* | ||
551 | * Queue an event to all "writer" users that we want | ||
552 | * to suspend and need their ack. | ||
553 | */ | ||
554 | mutex_lock(&state_lock); | ||
555 | down_read(&user_list_lock); | ||
556 | |||
557 | list_for_each_entry(as, &apm_user_list, list) { | ||
558 | if (as->suspend_state != SUSPEND_WAIT && as->reader && | ||
559 | as->writer && as->suser) { | ||
560 | as->suspend_state = SUSPEND_PENDING; | ||
561 | atomic_inc(&suspend_acks_pending); | ||
562 | queue_add_event(&as->queue, APM_USER_SUSPEND); | ||
563 | } | ||
564 | } | ||
565 | |||
566 | up_read(&user_list_lock); | ||
567 | mutex_unlock(&state_lock); | ||
568 | wake_up_interruptible(&apm_waitqueue); | ||
569 | |||
570 | /* | ||
571 | * Wait for the the suspend_acks_pending variable to drop to | ||
572 | * zero, meaning everybody acked the suspend event (or the | ||
573 | * process was killed.) | ||
574 | * | ||
575 | * If the app won't answer within a short while we assume it | ||
576 | * locked up and ignore it. | ||
577 | */ | ||
578 | err = wait_event_interruptible_timeout( | ||
579 | apm_suspend_waitqueue, | ||
580 | atomic_read(&suspend_acks_pending) == 0, | ||
581 | 5*HZ); | ||
582 | |||
583 | /* timed out */ | ||
584 | if (err == 0) { | ||
585 | /* | ||
586 | * Move anybody who timed out to "ack timeout" state. | ||
587 | * | ||
588 | * We could time out and the userspace does the ACK | ||
589 | * right after we time out but before we enter the | ||
590 | * locked section here, but that's fine. | ||
591 | */ | ||
592 | mutex_lock(&state_lock); | ||
593 | down_read(&user_list_lock); | ||
594 | list_for_each_entry(as, &apm_user_list, list) { | ||
595 | if (as->suspend_state == SUSPEND_PENDING || | ||
596 | as->suspend_state == SUSPEND_READ) { | ||
597 | as->suspend_state = SUSPEND_ACKTO; | ||
598 | atomic_dec(&suspend_acks_pending); | ||
599 | } | ||
600 | } | ||
601 | up_read(&user_list_lock); | ||
602 | mutex_unlock(&state_lock); | ||
603 | } | ||
604 | |||
605 | /* let suspend proceed */ | ||
606 | if (err >= 0) | ||
607 | return NOTIFY_OK; | ||
608 | |||
609 | /* interrupted by signal */ | ||
610 | return NOTIFY_BAD; | ||
611 | |||
612 | case PM_POST_SUSPEND: | ||
613 | /* | ||
614 | * Anyone on the APM queues will think we're still suspended. | ||
615 | * Send a message so everyone knows we're now awake again. | ||
616 | */ | ||
617 | queue_event(APM_NORMAL_RESUME); | ||
618 | |||
619 | /* | ||
620 | * Finally, wake up anyone who is sleeping on the suspend. | ||
621 | */ | ||
622 | mutex_lock(&state_lock); | ||
623 | down_read(&user_list_lock); | ||
624 | list_for_each_entry(as, &apm_user_list, list) { | ||
625 | if (as->suspend_state == SUSPEND_ACKED) { | ||
626 | /* | ||
627 | * TODO: maybe grab error code, needs core | ||
628 | * changes to push the error to the notifier | ||
629 | * chain (could use the second parameter if | ||
630 | * implemented) | ||
631 | */ | ||
632 | as->suspend_result = 0; | ||
633 | as->suspend_state = SUSPEND_DONE; | ||
634 | } | ||
635 | } | ||
636 | up_read(&user_list_lock); | ||
637 | mutex_unlock(&state_lock); | ||
638 | |||
639 | wake_up(&apm_suspend_waitqueue); | ||
640 | return NOTIFY_OK; | ||
641 | |||
642 | default: | ||
643 | return NOTIFY_DONE; | ||
644 | } | ||
645 | } | ||
646 | |||
647 | static struct notifier_block apm_notif_block = { | ||
648 | .notifier_call = apm_suspend_notifier, | ||
649 | }; | ||
650 | |||
594 | static int __init apm_init(void) | 651 | static int __init apm_init(void) |
595 | { | 652 | { |
596 | int ret; | 653 | int ret; |
@@ -604,7 +661,7 @@ static int __init apm_init(void) | |||
604 | if (IS_ERR(kapmd_tsk)) { | 661 | if (IS_ERR(kapmd_tsk)) { |
605 | ret = PTR_ERR(kapmd_tsk); | 662 | ret = PTR_ERR(kapmd_tsk); |
606 | kapmd_tsk = NULL; | 663 | kapmd_tsk = NULL; |
607 | return ret; | 664 | goto out; |
608 | } | 665 | } |
609 | wake_up_process(kapmd_tsk); | 666 | wake_up_process(kapmd_tsk); |
610 | 667 | ||
@@ -613,16 +670,27 @@ static int __init apm_init(void) | |||
613 | #endif | 670 | #endif |
614 | 671 | ||
615 | ret = misc_register(&apm_device); | 672 | ret = misc_register(&apm_device); |
616 | if (ret != 0) { | 673 | if (ret) |
617 | remove_proc_entry("apm", NULL); | 674 | goto out_stop; |
618 | kthread_stop(kapmd_tsk); | ||
619 | } | ||
620 | 675 | ||
676 | ret = register_pm_notifier(&apm_notif_block); | ||
677 | if (ret) | ||
678 | goto out_unregister; | ||
679 | |||
680 | return 0; | ||
681 | |||
682 | out_unregister: | ||
683 | misc_deregister(&apm_device); | ||
684 | out_stop: | ||
685 | remove_proc_entry("apm", NULL); | ||
686 | kthread_stop(kapmd_tsk); | ||
687 | out: | ||
621 | return ret; | 688 | return ret; |
622 | } | 689 | } |
623 | 690 | ||
624 | static void __exit apm_exit(void) | 691 | static void __exit apm_exit(void) |
625 | { | 692 | { |
693 | unregister_pm_notifier(&apm_notif_block); | ||
626 | misc_deregister(&apm_device); | 694 | misc_deregister(&apm_device); |
627 | remove_proc_entry("apm", NULL); | 695 | remove_proc_entry("apm", NULL); |
628 | 696 | ||
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 59ca35156d81..e4a4fbd37d7a 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c | |||
@@ -1439,7 +1439,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) | |||
1439 | DEBUGP(4, dev, "CMM_ABSENT flag set\n"); | 1439 | DEBUGP(4, dev, "CMM_ABSENT flag set\n"); |
1440 | goto out; | 1440 | goto out; |
1441 | } | 1441 | } |
1442 | rc = EINVAL; | 1442 | rc = -EINVAL; |
1443 | 1443 | ||
1444 | if (_IOC_TYPE(cmd) != CM_IOC_MAGIC) { | 1444 | if (_IOC_TYPE(cmd) != CM_IOC_MAGIC) { |
1445 | DEBUGP(4, dev, "ioctype mismatch\n"); | 1445 | DEBUGP(4, dev, "ioctype mismatch\n"); |
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig index cf707c8f08d4..15b09b89588a 100644 --- a/drivers/ide/Kconfig +++ b/drivers/ide/Kconfig | |||
@@ -98,6 +98,9 @@ if BLK_DEV_IDE | |||
98 | 98 | ||
99 | comment "Please see Documentation/ide/ide.txt for help/info on IDE drives" | 99 | comment "Please see Documentation/ide/ide.txt for help/info on IDE drives" |
100 | 100 | ||
101 | config IDE_TIMINGS | ||
102 | bool | ||
103 | |||
101 | config IDE_ATAPI | 104 | config IDE_ATAPI |
102 | bool | 105 | bool |
103 | 106 | ||
@@ -326,6 +329,7 @@ config BLK_DEV_PLATFORM | |||
326 | config BLK_DEV_CMD640 | 329 | config BLK_DEV_CMD640 |
327 | tristate "CMD640 chipset bugfix/support" | 330 | tristate "CMD640 chipset bugfix/support" |
328 | depends on X86 | 331 | depends on X86 |
332 | select IDE_TIMINGS | ||
329 | ---help--- | 333 | ---help--- |
330 | The CMD-Technologies CMD640 IDE chip is used on many common 486 and | 334 | The CMD-Technologies CMD640 IDE chip is used on many common 486 and |
331 | Pentium motherboards, usually in combination with a "Neptune" or | 335 | Pentium motherboards, usually in combination with a "Neptune" or |
@@ -455,6 +459,7 @@ config BLK_DEV_AEC62XX | |||
455 | 459 | ||
456 | config BLK_DEV_ALI15X3 | 460 | config BLK_DEV_ALI15X3 |
457 | tristate "ALI M15x3 chipset support" | 461 | tristate "ALI M15x3 chipset support" |
462 | select IDE_TIMINGS | ||
458 | select BLK_DEV_IDEDMA_PCI | 463 | select BLK_DEV_IDEDMA_PCI |
459 | help | 464 | help |
460 | This driver ensures (U)DMA support for ALI 1533, 1543 and 1543C | 465 | This driver ensures (U)DMA support for ALI 1533, 1543 and 1543C |
@@ -469,6 +474,7 @@ config BLK_DEV_ALI15X3 | |||
469 | config BLK_DEV_AMD74XX | 474 | config BLK_DEV_AMD74XX |
470 | tristate "AMD and nVidia IDE support" | 475 | tristate "AMD and nVidia IDE support" |
471 | depends on !ARM | 476 | depends on !ARM |
477 | select IDE_TIMINGS | ||
472 | select BLK_DEV_IDEDMA_PCI | 478 | select BLK_DEV_IDEDMA_PCI |
473 | help | 479 | help |
474 | This driver adds explicit support for AMD-7xx and AMD-8111 chips | 480 | This driver adds explicit support for AMD-7xx and AMD-8111 chips |
@@ -489,6 +495,7 @@ config BLK_DEV_ATIIXP | |||
489 | 495 | ||
490 | config BLK_DEV_CMD64X | 496 | config BLK_DEV_CMD64X |
491 | tristate "CMD64{3|6|8|9} chipset support" | 497 | tristate "CMD64{3|6|8|9} chipset support" |
498 | select IDE_TIMINGS | ||
492 | select BLK_DEV_IDEDMA_PCI | 499 | select BLK_DEV_IDEDMA_PCI |
493 | help | 500 | help |
494 | Say Y here if you have an IDE controller which uses any of these | 501 | Say Y here if you have an IDE controller which uses any of these |
@@ -503,6 +510,7 @@ config BLK_DEV_TRIFLEX | |||
503 | 510 | ||
504 | config BLK_DEV_CY82C693 | 511 | config BLK_DEV_CY82C693 |
505 | tristate "CY82C693 chipset support" | 512 | tristate "CY82C693 chipset support" |
513 | select IDE_TIMINGS | ||
506 | select BLK_DEV_IDEDMA_PCI | 514 | select BLK_DEV_IDEDMA_PCI |
507 | help | 515 | help |
508 | This driver adds detection and support for the CY82C693 chipset | 516 | This driver adds detection and support for the CY82C693 chipset |
@@ -695,6 +703,7 @@ config BLK_DEV_SIS5513 | |||
695 | config BLK_DEV_SL82C105 | 703 | config BLK_DEV_SL82C105 |
696 | tristate "Winbond SL82c105 support" | 704 | tristate "Winbond SL82c105 support" |
697 | depends on (PPC || ARM) | 705 | depends on (PPC || ARM) |
706 | select IDE_TIMINGS | ||
698 | select BLK_DEV_IDEDMA_PCI | 707 | select BLK_DEV_IDEDMA_PCI |
699 | help | 708 | help |
700 | If you have a Winbond SL82c105 IDE controller, say Y here to enable | 709 | If you have a Winbond SL82c105 IDE controller, say Y here to enable |
@@ -725,6 +734,7 @@ config BLK_DEV_TRM290 | |||
725 | 734 | ||
726 | config BLK_DEV_VIA82CXXX | 735 | config BLK_DEV_VIA82CXXX |
727 | tristate "VIA82CXXX chipset support" | 736 | tristate "VIA82CXXX chipset support" |
737 | select IDE_TIMINGS | ||
728 | select BLK_DEV_IDEDMA_PCI | 738 | select BLK_DEV_IDEDMA_PCI |
729 | help | 739 | help |
730 | This driver adds explicit support for VIA BusMastering IDE chips. | 740 | This driver adds explicit support for VIA BusMastering IDE chips. |
@@ -751,6 +761,7 @@ endif | |||
751 | config BLK_DEV_IDE_PMAC | 761 | config BLK_DEV_IDE_PMAC |
752 | tristate "PowerMac on-board IDE support" | 762 | tristate "PowerMac on-board IDE support" |
753 | depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y | 763 | depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y |
764 | select IDE_TIMINGS | ||
754 | help | 765 | help |
755 | This driver provides support for the on-board IDE controller on | 766 | This driver provides support for the on-board IDE controller on |
756 | most of the recent Apple Power Macintoshes and PowerBooks. | 767 | most of the recent Apple Power Macintoshes and PowerBooks. |
@@ -829,13 +840,6 @@ config BLK_DEV_IDE_RAPIDE | |||
829 | Say Y here if you want to support the Yellowstone RapIDE controller | 840 | Say Y here if you want to support the Yellowstone RapIDE controller |
830 | manufactured for use with Acorn computers. | 841 | manufactured for use with Acorn computers. |
831 | 842 | ||
832 | config BLK_DEV_IDE_BAST | ||
833 | tristate "Simtec BAST / Thorcom VR1000 IDE support" | ||
834 | depends on ARM && (ARCH_BAST || MACH_VR1000) | ||
835 | help | ||
836 | Say Y here if you want to support the onboard IDE channels on the | ||
837 | Simtec BAST or the Thorcom VR1000 | ||
838 | |||
839 | config IDE_H8300 | 843 | config IDE_H8300 |
840 | tristate "H8300 IDE support" | 844 | tristate "H8300 IDE support" |
841 | depends on H8300 | 845 | depends on H8300 |
@@ -919,51 +923,12 @@ config BLK_DEV_Q40IDE | |||
919 | config BLK_DEV_PALMCHIP_BK3710 | 923 | config BLK_DEV_PALMCHIP_BK3710 |
920 | tristate "Palmchip bk3710 IDE controller support" | 924 | tristate "Palmchip bk3710 IDE controller support" |
921 | depends on ARCH_DAVINCI | 925 | depends on ARCH_DAVINCI |
926 | select IDE_TIMINGS | ||
922 | select BLK_DEV_IDEDMA_SFF | 927 | select BLK_DEV_IDEDMA_SFF |
923 | help | 928 | help |
924 | Say Y here if you want to support the onchip IDE controller on the | 929 | Say Y here if you want to support the onchip IDE controller on the |
925 | TI DaVinci SoC | 930 | TI DaVinci SoC |
926 | 931 | ||
927 | |||
928 | config BLK_DEV_MPC8xx_IDE | ||
929 | tristate "MPC8xx IDE support" | ||
930 | depends on 8xx && (LWMON || IVMS8 || IVML24 || TQM8xxL) && IDE=y && BLK_DEV_IDE=y && !PPC_MERGE | ||
931 | help | ||
932 | This option provides support for IDE on Motorola MPC8xx Systems. | ||
933 | Please see 'Type of MPC8xx IDE interface' for details. | ||
934 | |||
935 | If unsure, say N. | ||
936 | |||
937 | choice | ||
938 | prompt "Type of MPC8xx IDE interface" | ||
939 | depends on BLK_DEV_MPC8xx_IDE | ||
940 | default IDE_8xx_PCCARD | ||
941 | |||
942 | config IDE_8xx_PCCARD | ||
943 | bool "8xx_PCCARD" | ||
944 | ---help--- | ||
945 | Select how the IDE devices are connected to the MPC8xx system: | ||
946 | |||
947 | 8xx_PCCARD uses the 8xx internal PCMCIA interface in combination | ||
948 | with a PC Card (e.g. ARGOSY portable Hard Disk Adapter), | ||
949 | ATA PC Card HDDs or ATA PC Flash Cards (example: TQM8xxL | ||
950 | systems) | ||
951 | |||
952 | 8xx_DIRECT is used for directly connected IDE devices using the 8xx | ||
953 | internal PCMCIA interface (example: IVMS8 systems) | ||
954 | |||
955 | EXT_DIRECT is used for IDE devices directly connected to the 8xx | ||
956 | bus using some glue logic, but _not_ the 8xx internal | ||
957 | PCMCIA interface (example: IDIF860 systems) | ||
958 | |||
959 | config IDE_8xx_DIRECT | ||
960 | bool "8xx_DIRECT" | ||
961 | |||
962 | config IDE_EXT_DIRECT | ||
963 | bool "EXT_DIRECT" | ||
964 | |||
965 | endchoice | ||
966 | |||
967 | # no isa -> no vlb | 932 | # no isa -> no vlb |
968 | if ISA && (ALPHA || X86 || MIPS) | 933 | if ISA && (ALPHA || X86 || MIPS) |
969 | 934 | ||
@@ -981,6 +946,7 @@ config BLK_DEV_4DRIVES | |||
981 | 946 | ||
982 | config BLK_DEV_ALI14XX | 947 | config BLK_DEV_ALI14XX |
983 | tristate "ALI M14xx support" | 948 | tristate "ALI M14xx support" |
949 | select IDE_TIMINGS | ||
984 | help | 950 | help |
985 | This driver is enabled at runtime using the "ali14xx.probe" kernel | 951 | This driver is enabled at runtime using the "ali14xx.probe" kernel |
986 | boot parameter. It enables support for the secondary IDE interface | 952 | boot parameter. It enables support for the secondary IDE interface |
@@ -1000,6 +966,7 @@ config BLK_DEV_DTC2278 | |||
1000 | 966 | ||
1001 | config BLK_DEV_HT6560B | 967 | config BLK_DEV_HT6560B |
1002 | tristate "Holtek HT6560B support" | 968 | tristate "Holtek HT6560B support" |
969 | select IDE_TIMINGS | ||
1003 | help | 970 | help |
1004 | This driver is enabled at runtime using the "ht6560b.probe" kernel | 971 | This driver is enabled at runtime using the "ht6560b.probe" kernel |
1005 | boot parameter. It enables support for the secondary IDE interface | 972 | boot parameter. It enables support for the secondary IDE interface |
@@ -1009,6 +976,7 @@ config BLK_DEV_HT6560B | |||
1009 | 976 | ||
1010 | config BLK_DEV_QD65XX | 977 | config BLK_DEV_QD65XX |
1011 | tristate "QDI QD65xx support" | 978 | tristate "QDI QD65xx support" |
979 | select IDE_TIMINGS | ||
1012 | help | 980 | help |
1013 | This driver is enabled at runtime using the "qd65xx.probe" kernel | 981 | This driver is enabled at runtime using the "qd65xx.probe" kernel |
1014 | boot parameter. It permits faster I/O speeds to be set. See the | 982 | boot parameter. It permits faster I/O speeds to be set. See the |
@@ -1032,30 +1000,4 @@ config BLK_DEV_IDEDMA | |||
1032 | 1000 | ||
1033 | endif | 1001 | endif |
1034 | 1002 | ||
1035 | config BLK_DEV_HD_ONLY | ||
1036 | bool "Old hard disk (MFM/RLL/IDE) driver" | ||
1037 | depends on !ARM || ARCH_RPC || ARCH_SHARK || BROKEN | ||
1038 | help | ||
1039 | There are two drivers for MFM/RLL/IDE hard disks. Most people use | ||
1040 | the newer enhanced driver, but this old one is still around for two | ||
1041 | reasons. Some older systems have strange timing problems and seem to | ||
1042 | work only with the old driver (which itself does not work with some | ||
1043 | newer systems). The other reason is that the old driver is smaller, | ||
1044 | since it lacks the enhanced functionality of the new one. This makes | ||
1045 | it a good choice for systems with very tight memory restrictions, or | ||
1046 | for systems with only older MFM/RLL/ESDI drives. Choosing the old | ||
1047 | driver can save 13 KB or so of kernel memory. | ||
1048 | |||
1049 | If you want to use this driver together with the new one you have | ||
1050 | to use "hda=noprobe hdb=noprobe" kernel parameters to prevent the new | ||
1051 | driver from probing the primary interface. | ||
1052 | |||
1053 | If you are unsure, then just choose the Enhanced IDE/MFM/RLL driver | ||
1054 | instead of this one. For more detailed information, read the | ||
1055 | Disk-HOWTO, available from | ||
1056 | <http://www.tldp.org/docs.html#howto>. | ||
1057 | |||
1058 | config BLK_DEV_HD | ||
1059 | def_bool BLK_DEV_HD_ONLY | ||
1060 | |||
1061 | endif # IDE | 1003 | endif # IDE |
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile index a2b3f84d710d..5d414e301a5a 100644 --- a/drivers/ide/Makefile +++ b/drivers/ide/Makefile | |||
@@ -11,9 +11,11 @@ | |||
11 | 11 | ||
12 | EXTRA_CFLAGS += -Idrivers/ide | 12 | EXTRA_CFLAGS += -Idrivers/ide |
13 | 13 | ||
14 | ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o | 14 | ide-core-y += ide.o ide-io.o ide-iops.o ide-lib.o ide-probe.o ide-taskfile.o \ |
15 | ide-pio-blacklist.o | ||
15 | 16 | ||
16 | # core IDE code | 17 | # core IDE code |
18 | ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o | ||
17 | ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o | 19 | ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o |
18 | ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o | 20 | ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o |
19 | ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o | 21 | ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o |
@@ -59,9 +61,3 @@ ifeq ($(CONFIG_BLK_DEV_PLATFORM), y) | |||
59 | endif | 61 | endif |
60 | 62 | ||
61 | obj-$(CONFIG_BLK_DEV_IDE) += arm/ mips/ | 63 | obj-$(CONFIG_BLK_DEV_IDE) += arm/ mips/ |
62 | |||
63 | # old hd driver must be last | ||
64 | ifeq ($(CONFIG_BLK_DEV_HD), y) | ||
65 | hd-core-y += legacy/hd.o | ||
66 | obj-y += hd-core.o | ||
67 | endif | ||
diff --git a/drivers/ide/arm/Makefile b/drivers/ide/arm/Makefile index 936e7b0237f5..5bc26053afa6 100644 --- a/drivers/ide/arm/Makefile +++ b/drivers/ide/arm/Makefile | |||
@@ -1,7 +1,6 @@ | |||
1 | 1 | ||
2 | obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o | 2 | obj-$(CONFIG_BLK_DEV_IDE_ICSIDE) += icside.o |
3 | obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o | 3 | obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapide.o |
4 | obj-$(CONFIG_BLK_DEV_IDE_BAST) += bast-ide.o | ||
5 | obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o | 4 | obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o |
6 | 5 | ||
7 | ifeq ($(CONFIG_IDE_ARM), m) | 6 | ifeq ($(CONFIG_IDE_ARM), m) |
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c deleted file mode 100644 index 8e8c28104b45..000000000000 --- a/drivers/ide/arm/bast-ide.c +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2003-2004 Simtec Electronics | ||
3 | * Ben Dooks <ben@simtec.co.uk> | ||
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 version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/errno.h> | ||
13 | #include <linux/ide.h> | ||
14 | #include <linux/init.h> | ||
15 | |||
16 | #include <asm/mach-types.h> | ||
17 | |||
18 | #include <asm/io.h> | ||
19 | #include <asm/irq.h> | ||
20 | #include <asm/arch/map.h> | ||
21 | #include <asm/arch/bast-map.h> | ||
22 | #include <asm/arch/bast-irq.h> | ||
23 | |||
24 | #define DRV_NAME "bast-ide" | ||
25 | |||
26 | static int __init bastide_register(unsigned int base, unsigned int aux, int irq) | ||
27 | { | ||
28 | ide_hwif_t *hwif; | ||
29 | hw_regs_t hw; | ||
30 | int i; | ||
31 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | ||
32 | |||
33 | memset(&hw, 0, sizeof(hw)); | ||
34 | |||
35 | base += BAST_IDE_CS; | ||
36 | aux += BAST_IDE_CS; | ||
37 | |||
38 | for (i = 0; i <= 7; i++) { | ||
39 | hw.io_ports_array[i] = (unsigned long)base; | ||
40 | base += 0x20; | ||
41 | } | ||
42 | |||
43 | hw.io_ports.ctl_addr = aux + (6 * 0x20); | ||
44 | hw.irq = irq; | ||
45 | hw.chipset = ide_generic; | ||
46 | |||
47 | hwif = ide_find_port(); | ||
48 | if (hwif == NULL) | ||
49 | goto out; | ||
50 | |||
51 | i = hwif->index; | ||
52 | |||
53 | ide_init_port_data(hwif, i); | ||
54 | ide_init_port_hw(hwif, &hw); | ||
55 | hwif->port_ops = NULL; | ||
56 | |||
57 | idx[0] = i; | ||
58 | |||
59 | ide_device_add(idx, NULL); | ||
60 | out: | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | static int __init bastide_init(void) | ||
65 | { | ||
66 | unsigned long base = BAST_VA_IDEPRI + BAST_IDE_CS; | ||
67 | |||
68 | /* we can treat the VR1000 and the BAST the same */ | ||
69 | |||
70 | if (!(machine_is_bast() || machine_is_vr1000())) | ||
71 | return 0; | ||
72 | |||
73 | printk("BAST: IDE driver, (c) 2003-2004 Simtec Electronics\n"); | ||
74 | |||
75 | if (!request_mem_region(base, 0x400000, DRV_NAME)) { | ||
76 | printk(KERN_ERR "%s: resources busy\n", DRV_NAME); | ||
77 | return -EBUSY; | ||
78 | } | ||
79 | |||
80 | bastide_register(BAST_VA_IDEPRI, BAST_VA_IDEPRIAUX, IRQ_IDE0); | ||
81 | bastide_register(BAST_VA_IDESEC, BAST_VA_IDESECAUX, IRQ_IDE1); | ||
82 | |||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | module_init(bastide_init); | ||
87 | |||
88 | MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); | ||
89 | MODULE_LICENSE("GPL"); | ||
90 | MODULE_DESCRIPTION("Simtec BAST / Thorcom VR1000 IDE driver"); | ||
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c index 061456914ca3..52f58c885783 100644 --- a/drivers/ide/arm/icside.c +++ b/drivers/ide/arm/icside.c | |||
@@ -21,6 +21,8 @@ | |||
21 | #include <asm/dma.h> | 21 | #include <asm/dma.h> |
22 | #include <asm/ecard.h> | 22 | #include <asm/ecard.h> |
23 | 23 | ||
24 | #define DRV_NAME "icside" | ||
25 | |||
24 | #define ICS_IDENT_OFFSET 0x2280 | 26 | #define ICS_IDENT_OFFSET 0x2280 |
25 | 27 | ||
26 | #define ICS_ARCIN_V5_INTRSTAT 0x0000 | 28 | #define ICS_ARCIN_V5_INTRSTAT 0x0000 |
@@ -68,6 +70,7 @@ struct icside_state { | |||
68 | unsigned int enabled; | 70 | unsigned int enabled; |
69 | void __iomem *irq_port; | 71 | void __iomem *irq_port; |
70 | void __iomem *ioc_base; | 72 | void __iomem *ioc_base; |
73 | unsigned int sel; | ||
71 | unsigned int type; | 74 | unsigned int type; |
72 | ide_hwif_t *hwif[2]; | 75 | ide_hwif_t *hwif[2]; |
73 | }; | 76 | }; |
@@ -165,7 +168,8 @@ static const expansioncard_ops_t icside_ops_arcin_v6 = { | |||
165 | static void icside_maskproc(ide_drive_t *drive, int mask) | 168 | static void icside_maskproc(ide_drive_t *drive, int mask) |
166 | { | 169 | { |
167 | ide_hwif_t *hwif = HWIF(drive); | 170 | ide_hwif_t *hwif = HWIF(drive); |
168 | struct icside_state *state = hwif->hwif_data; | 171 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
172 | struct icside_state *state = ecard_get_drvdata(ec); | ||
169 | unsigned long flags; | 173 | unsigned long flags; |
170 | 174 | ||
171 | local_irq_save(flags); | 175 | local_irq_save(flags); |
@@ -308,6 +312,7 @@ static int icside_dma_setup(ide_drive_t *drive) | |||
308 | { | 312 | { |
309 | ide_hwif_t *hwif = HWIF(drive); | 313 | ide_hwif_t *hwif = HWIF(drive); |
310 | struct expansion_card *ec = ECARD_DEV(hwif->dev); | 314 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
315 | struct icside_state *state = ecard_get_drvdata(ec); | ||
311 | struct request *rq = hwif->hwgroup->rq; | 316 | struct request *rq = hwif->hwgroup->rq; |
312 | unsigned int dma_mode; | 317 | unsigned int dma_mode; |
313 | 318 | ||
@@ -331,7 +336,7 @@ static int icside_dma_setup(ide_drive_t *drive) | |||
331 | /* | 336 | /* |
332 | * Route the DMA signals to the correct interface. | 337 | * Route the DMA signals to the correct interface. |
333 | */ | 338 | */ |
334 | writeb(hwif->select_data, hwif->config_data); | 339 | writeb(state->sel | hwif->channel, state->ioc_base); |
335 | 340 | ||
336 | /* | 341 | /* |
337 | * Select the correct timing for this drive. | 342 | * Select the correct timing for this drive. |
@@ -359,7 +364,8 @@ static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd) | |||
359 | static int icside_dma_test_irq(ide_drive_t *drive) | 364 | static int icside_dma_test_irq(ide_drive_t *drive) |
360 | { | 365 | { |
361 | ide_hwif_t *hwif = HWIF(drive); | 366 | ide_hwif_t *hwif = HWIF(drive); |
362 | struct icside_state *state = hwif->hwif_data; | 367 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
368 | struct icside_state *state = ecard_get_drvdata(ec); | ||
363 | 369 | ||
364 | return readb(state->irq_port + | 370 | return readb(state->irq_port + |
365 | (hwif->channel ? | 371 | (hwif->channel ? |
@@ -411,36 +417,24 @@ static int icside_dma_off_init(ide_hwif_t *hwif, const struct ide_port_info *d) | |||
411 | return -EOPNOTSUPP; | 417 | return -EOPNOTSUPP; |
412 | } | 418 | } |
413 | 419 | ||
414 | static ide_hwif_t * | 420 | static void icside_setup_ports(hw_regs_t *hw, void __iomem *base, |
415 | icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *ec) | 421 | struct cardinfo *info, struct expansion_card *ec) |
416 | { | 422 | { |
417 | unsigned long port = (unsigned long)base + info->dataoffset; | 423 | unsigned long port = (unsigned long)base + info->dataoffset; |
418 | ide_hwif_t *hwif; | ||
419 | 424 | ||
420 | hwif = ide_find_port(); | 425 | hw->io_ports.data_addr = port; |
421 | if (hwif) { | 426 | hw->io_ports.error_addr = port + (1 << info->stepping); |
422 | /* | 427 | hw->io_ports.nsect_addr = port + (2 << info->stepping); |
423 | * Ensure we're using MMIO | 428 | hw->io_ports.lbal_addr = port + (3 << info->stepping); |
424 | */ | 429 | hw->io_ports.lbam_addr = port + (4 << info->stepping); |
425 | default_hwif_mmiops(hwif); | 430 | hw->io_ports.lbah_addr = port + (5 << info->stepping); |
426 | 431 | hw->io_ports.device_addr = port + (6 << info->stepping); | |
427 | hwif->io_ports.data_addr = port; | 432 | hw->io_ports.status_addr = port + (7 << info->stepping); |
428 | hwif->io_ports.error_addr = port + (1 << info->stepping); | 433 | hw->io_ports.ctl_addr = (unsigned long)base + info->ctrloffset; |
429 | hwif->io_ports.nsect_addr = port + (2 << info->stepping); | 434 | |
430 | hwif->io_ports.lbal_addr = port + (3 << info->stepping); | 435 | hw->irq = ec->irq; |
431 | hwif->io_ports.lbam_addr = port + (4 << info->stepping); | 436 | hw->dev = &ec->dev; |
432 | hwif->io_ports.lbah_addr = port + (5 << info->stepping); | 437 | hw->chipset = ide_acorn; |
433 | hwif->io_ports.device_addr = port + (6 << info->stepping); | ||
434 | hwif->io_ports.status_addr = port + (7 << info->stepping); | ||
435 | hwif->io_ports.ctl_addr = | ||
436 | (unsigned long)base + info->ctrloffset; | ||
437 | hwif->irq = ec->irq; | ||
438 | hwif->chipset = ide_acorn; | ||
439 | hwif->gendev.parent = &ec->dev; | ||
440 | hwif->dev = &ec->dev; | ||
441 | } | ||
442 | |||
443 | return hwif; | ||
444 | } | 438 | } |
445 | 439 | ||
446 | static int __init | 440 | static int __init |
@@ -449,6 +443,7 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec) | |||
449 | ide_hwif_t *hwif; | 443 | ide_hwif_t *hwif; |
450 | void __iomem *base; | 444 | void __iomem *base; |
451 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | 445 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
446 | hw_regs_t hw; | ||
452 | 447 | ||
453 | base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); | 448 | base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); |
454 | if (!base) | 449 | if (!base) |
@@ -466,12 +461,19 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec) | |||
466 | */ | 461 | */ |
467 | icside_irqdisable_arcin_v5(ec, 0); | 462 | icside_irqdisable_arcin_v5(ec, 0); |
468 | 463 | ||
469 | hwif = icside_setup(base, &icside_cardinfo_v5, ec); | 464 | icside_setup_ports(&hw, base, &icside_cardinfo_v5, ec); |
465 | |||
466 | hwif = ide_find_port(); | ||
470 | if (!hwif) | 467 | if (!hwif) |
471 | return -ENODEV; | 468 | return -ENODEV; |
472 | 469 | ||
470 | ide_init_port_hw(hwif, &hw); | ||
471 | default_hwif_mmiops(hwif); | ||
472 | |||
473 | state->hwif[0] = hwif; | 473 | state->hwif[0] = hwif; |
474 | 474 | ||
475 | ecard_set_drvdata(ec, state); | ||
476 | |||
475 | idx[0] = hwif->index; | 477 | idx[0] = hwif->index; |
476 | 478 | ||
477 | ide_device_add(idx, NULL); | 479 | ide_device_add(idx, NULL); |
@@ -497,6 +499,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec) | |||
497 | int ret; | 499 | int ret; |
498 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | 500 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
499 | struct ide_port_info d = icside_v6_port_info; | 501 | struct ide_port_info d = icside_v6_port_info; |
502 | hw_regs_t hw[2]; | ||
500 | 503 | ||
501 | ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); | 504 | ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); |
502 | if (!ioc_base) { | 505 | if (!ioc_base) { |
@@ -525,43 +528,47 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec) | |||
525 | 528 | ||
526 | state->irq_port = easi_base; | 529 | state->irq_port = easi_base; |
527 | state->ioc_base = ioc_base; | 530 | state->ioc_base = ioc_base; |
531 | state->sel = sel; | ||
528 | 532 | ||
529 | /* | 533 | /* |
530 | * Be on the safe side - disable interrupts | 534 | * Be on the safe side - disable interrupts |
531 | */ | 535 | */ |
532 | icside_irqdisable_arcin_v6(ec, 0); | 536 | icside_irqdisable_arcin_v6(ec, 0); |
533 | 537 | ||
538 | icside_setup_ports(&hw[0], easi_base, &icside_cardinfo_v6_1, ec); | ||
539 | icside_setup_ports(&hw[1], easi_base, &icside_cardinfo_v6_2, ec); | ||
540 | |||
534 | /* | 541 | /* |
535 | * Find and register the interfaces. | 542 | * Find and register the interfaces. |
536 | */ | 543 | */ |
537 | hwif = icside_setup(easi_base, &icside_cardinfo_v6_1, ec); | 544 | hwif = ide_find_port(); |
538 | mate = icside_setup(easi_base, &icside_cardinfo_v6_2, ec); | 545 | if (hwif == NULL) |
546 | return -ENODEV; | ||
539 | 547 | ||
540 | if (!hwif || !mate) { | 548 | ide_init_port_hw(hwif, &hw[0]); |
541 | ret = -ENODEV; | 549 | default_hwif_mmiops(hwif); |
542 | goto out; | 550 | |
551 | idx[0] = hwif->index; | ||
552 | |||
553 | mate = ide_find_port(); | ||
554 | if (mate) { | ||
555 | ide_init_port_hw(mate, &hw[1]); | ||
556 | default_hwif_mmiops(mate); | ||
557 | |||
558 | idx[1] = mate->index; | ||
543 | } | 559 | } |
544 | 560 | ||
545 | state->hwif[0] = hwif; | 561 | state->hwif[0] = hwif; |
546 | state->hwif[1] = mate; | 562 | state->hwif[1] = mate; |
547 | 563 | ||
548 | hwif->hwif_data = state; | 564 | ecard_set_drvdata(ec, state); |
549 | hwif->config_data = (unsigned long)ioc_base; | ||
550 | hwif->select_data = sel; | ||
551 | |||
552 | mate->hwif_data = state; | ||
553 | mate->config_data = (unsigned long)ioc_base; | ||
554 | mate->select_data = sel | 1; | ||
555 | 565 | ||
556 | if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) { | 566 | if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) { |
557 | d.init_dma = icside_dma_init; | 567 | d.init_dma = icside_dma_init; |
558 | d.port_ops = &icside_v6_port_ops; | 568 | d.port_ops = &icside_v6_port_ops; |
559 | d.dma_ops = NULL; | 569 | d.dma_ops = NULL; |
560 | } | 570 | } |
561 | 571 | ||
562 | idx[0] = hwif->index; | ||
563 | idx[1] = mate->index; | ||
564 | |||
565 | ide_device_add(idx, &d); | 572 | ide_device_add(idx, &d); |
566 | 573 | ||
567 | return 0; | 574 | return 0; |
@@ -627,10 +634,8 @@ icside_probe(struct expansion_card *ec, const struct ecard_id *id) | |||
627 | break; | 634 | break; |
628 | } | 635 | } |
629 | 636 | ||
630 | if (ret == 0) { | 637 | if (ret == 0) |
631 | ecard_set_drvdata(ec, state); | ||
632 | goto out; | 638 | goto out; |
633 | } | ||
634 | 639 | ||
635 | kfree(state); | 640 | kfree(state); |
636 | release: | 641 | release: |
diff --git a/drivers/ide/arm/palm_bk3710.c b/drivers/ide/arm/palm_bk3710.c index 3839f5722985..c79b85b6e4a3 100644 --- a/drivers/ide/arm/palm_bk3710.c +++ b/drivers/ide/arm/palm_bk3710.c | |||
@@ -74,8 +74,6 @@ struct palm_bk3710_udmatiming { | |||
74 | #define BK3710_IORDYTMP 0x78 | 74 | #define BK3710_IORDYTMP 0x78 |
75 | #define BK3710_IORDYTMS 0x7C | 75 | #define BK3710_IORDYTMS 0x7C |
76 | 76 | ||
77 | #include "../ide-timing.h" | ||
78 | |||
79 | static unsigned ideclk_period; /* in nanoseconds */ | 77 | static unsigned ideclk_period; /* in nanoseconds */ |
80 | 78 | ||
81 | static const struct palm_bk3710_udmatiming palm_bk3710_udmatimings[6] = { | 79 | static const struct palm_bk3710_udmatiming palm_bk3710_udmatimings[6] = { |
@@ -402,7 +400,6 @@ static int __devinit palm_bk3710_probe(struct platform_device *pdev) | |||
402 | 400 | ||
403 | i = hwif->index; | 401 | i = hwif->index; |
404 | 402 | ||
405 | ide_init_port_data(hwif, i); | ||
406 | ide_init_port_hw(hwif, &hw); | 403 | ide_init_port_hw(hwif, &hw); |
407 | 404 | ||
408 | default_hwif_mmiops(hwif); | 405 | default_hwif_mmiops(hwif); |
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c index 1747b2358775..43057e0303c8 100644 --- a/drivers/ide/arm/rapide.c +++ b/drivers/ide/arm/rapide.c | |||
@@ -11,6 +11,10 @@ | |||
11 | 11 | ||
12 | #include <asm/ecard.h> | 12 | #include <asm/ecard.h> |
13 | 13 | ||
14 | static struct const ide_port_info rapide_port_info = { | ||
15 | .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, | ||
16 | }; | ||
17 | |||
14 | static void rapide_setup_ports(hw_regs_t *hw, void __iomem *base, | 18 | static void rapide_setup_ports(hw_regs_t *hw, void __iomem *base, |
15 | void __iomem *ctrl, unsigned int sz, int irq) | 19 | void __iomem *ctrl, unsigned int sz, int irq) |
16 | { | 20 | { |
@@ -44,25 +48,26 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id) | |||
44 | goto release; | 48 | goto release; |
45 | } | 49 | } |
46 | 50 | ||
47 | hwif = ide_find_port(); | 51 | memset(&hw, 0, sizeof(hw)); |
48 | if (hwif) { | 52 | rapide_setup_ports(&hw, base, base + 0x818, 1 << 6, ec->irq); |
49 | memset(&hw, 0, sizeof(hw)); | 53 | hw.chipset = ide_generic; |
50 | rapide_setup_ports(&hw, base, base + 0x818, 1 << 6, ec->irq); | 54 | hw.dev = &ec->dev; |
51 | hw.chipset = ide_generic; | ||
52 | hw.dev = &ec->dev; | ||
53 | 55 | ||
54 | ide_init_port_hw(hwif, &hw); | 56 | hwif = ide_find_port(); |
57 | if (hwif == NULL) { | ||
58 | ret = -ENOENT; | ||
59 | goto release; | ||
60 | } | ||
55 | 61 | ||
56 | hwif->host_flags = IDE_HFLAG_MMIO; | 62 | ide_init_port_hw(hwif, &hw); |
57 | default_hwif_mmiops(hwif); | 63 | default_hwif_mmiops(hwif); |
58 | 64 | ||
59 | idx[0] = hwif->index; | 65 | idx[0] = hwif->index; |
60 | 66 | ||
61 | ide_device_add(idx, NULL); | 67 | ide_device_add(idx, &rapide_port_info); |
62 | 68 | ||
63 | ecard_set_drvdata(ec, hwif); | 69 | ecard_set_drvdata(ec, hwif); |
64 | goto out; | 70 | goto out; |
65 | } | ||
66 | 71 | ||
67 | release: | 72 | release: |
68 | ecard_release_resources(ec); | 73 | ecard_release_resources(ec); |
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c index ae37ee58bae2..20fad6d542cc 100644 --- a/drivers/ide/h8300/ide-h8300.c +++ b/drivers/ide/h8300/ide-h8300.c | |||
@@ -8,6 +8,8 @@ | |||
8 | #include <asm/io.h> | 8 | #include <asm/io.h> |
9 | #include <asm/irq.h> | 9 | #include <asm/irq.h> |
10 | 10 | ||
11 | #define DRV_NAME "ide-h8300" | ||
12 | |||
11 | #define bswap(d) \ | 13 | #define bswap(d) \ |
12 | ({ \ | 14 | ({ \ |
13 | u16 r; \ | 15 | u16 r; \ |
@@ -176,6 +178,10 @@ static inline void hwif_setup(ide_hwif_t *hwif) | |||
176 | hwif->output_data = h8300_output_data; | 178 | hwif->output_data = h8300_output_data; |
177 | } | 179 | } |
178 | 180 | ||
181 | static const struct ide_port_info h8300_port_info = { | ||
182 | .host_flags = IDE_HFLAG_NO_IO_32BIT | IDE_HFLAG_NO_DMA, | ||
183 | }; | ||
184 | |||
179 | static int __init h8300_ide_init(void) | 185 | static int __init h8300_ide_init(void) |
180 | { | 186 | { |
181 | hw_regs_t hw; | 187 | hw_regs_t hw; |
@@ -183,6 +189,8 @@ static int __init h8300_ide_init(void) | |||
183 | int index; | 189 | int index; |
184 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | 190 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
185 | 191 | ||
192 | printk(KERN_INFO DRV_NAME ": H8/300 generic IDE interface\n"); | ||
193 | |||
186 | if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300")) | 194 | if (!request_region(CONFIG_H8300_IDE_BASE, H8300_IDE_GAP*8, "ide-h8300")) |
187 | goto out_busy; | 195 | goto out_busy; |
188 | if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) { | 196 | if (!request_region(CONFIG_H8300_IDE_ALT, H8300_IDE_GAP, "ide-h8300")) { |
@@ -192,22 +200,17 @@ static int __init h8300_ide_init(void) | |||
192 | 200 | ||
193 | hw_setup(&hw); | 201 | hw_setup(&hw); |
194 | 202 | ||
195 | hwif = ide_find_port(); | 203 | hwif = ide_find_port_slot(&h8300_port_info); |
196 | if (hwif == NULL) { | 204 | if (hwif == NULL) |
197 | printk(KERN_ERR "ide-h8300: IDE I/F register failed\n"); | ||
198 | return -ENOENT; | 205 | return -ENOENT; |
199 | } | ||
200 | 206 | ||
201 | index = hwif->index; | 207 | index = hwif->index; |
202 | ide_init_port_data(hwif, index); | ||
203 | ide_init_port_hw(hwif, &hw); | 208 | ide_init_port_hw(hwif, &hw); |
204 | hwif_setup(hwif); | 209 | hwif_setup(hwif); |
205 | hwif->host_flags = IDE_HFLAG_NO_IO_32BIT; | ||
206 | printk(KERN_INFO "ide%d: H8/300 generic IDE interface\n", index); | ||
207 | 210 | ||
208 | idx[0] = index; | 211 | idx[0] = index; |
209 | 212 | ||
210 | ide_device_add(idx, NULL); | 213 | ide_device_add(idx, &h8300_port_info); |
211 | 214 | ||
212 | return 0; | 215 | return 0; |
213 | 216 | ||
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index d99847157186..6e29dd532090 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c | |||
@@ -517,14 +517,9 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | |||
517 | int xferlen, | 517 | int xferlen, |
518 | ide_handler_t *handler) | 518 | ide_handler_t *handler) |
519 | { | 519 | { |
520 | ide_startstop_t startstop; | ||
521 | struct cdrom_info *info = drive->driver_data; | 520 | struct cdrom_info *info = drive->driver_data; |
522 | ide_hwif_t *hwif = drive->hwif; | 521 | ide_hwif_t *hwif = drive->hwif; |
523 | 522 | ||
524 | /* wait for the controller to be idle */ | ||
525 | if (ide_wait_stat(&startstop, drive, 0, BUSY_STAT, WAIT_READY)) | ||
526 | return startstop; | ||
527 | |||
528 | /* FIXME: for Virtual DMA we must check harder */ | 523 | /* FIXME: for Virtual DMA we must check harder */ |
529 | if (info->dma) | 524 | if (info->dma) |
530 | info->dma = !hwif->dma_ops->dma_setup(drive); | 525 | info->dma = !hwif->dma_ops->dma_setup(drive); |
@@ -604,28 +599,6 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, | |||
604 | } | 599 | } |
605 | 600 | ||
606 | /* | 601 | /* |
607 | * Block read functions. | ||
608 | */ | ||
609 | static void ide_cd_pad_transfer(ide_drive_t *drive, xfer_func_t *xf, int len) | ||
610 | { | ||
611 | while (len > 0) { | ||
612 | int dum = 0; | ||
613 | xf(drive, NULL, &dum, sizeof(dum)); | ||
614 | len -= sizeof(dum); | ||
615 | } | ||
616 | } | ||
617 | |||
618 | static void ide_cd_drain_data(ide_drive_t *drive, int nsects) | ||
619 | { | ||
620 | while (nsects > 0) { | ||
621 | static char dum[SECTOR_SIZE]; | ||
622 | |||
623 | drive->hwif->input_data(drive, NULL, dum, sizeof(dum)); | ||
624 | nsects--; | ||
625 | } | ||
626 | } | ||
627 | |||
628 | /* | ||
629 | * Check the contents of the interrupt reason register from the cdrom | 602 | * Check the contents of the interrupt reason register from the cdrom |
630 | * and attempt to recover if there are problems. Returns 0 if everything's | 603 | * and attempt to recover if there are problems. Returns 0 if everything's |
631 | * ok; nonzero if the request has been terminated. | 604 | * ok; nonzero if the request has been terminated. |
@@ -640,15 +613,12 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq, | |||
640 | if (ireason == (!rw << 1)) | 613 | if (ireason == (!rw << 1)) |
641 | return 0; | 614 | return 0; |
642 | else if (ireason == (rw << 1)) { | 615 | else if (ireason == (rw << 1)) { |
643 | ide_hwif_t *hwif = drive->hwif; | ||
644 | xfer_func_t *xf; | ||
645 | 616 | ||
646 | /* whoops... */ | 617 | /* whoops... */ |
647 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", | 618 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", |
648 | drive->name, __func__); | 619 | drive->name, __func__); |
649 | 620 | ||
650 | xf = rw ? hwif->output_data : hwif->input_data; | 621 | ide_pad_transfer(drive, rw, len); |
651 | ide_cd_pad_transfer(drive, xf, len); | ||
652 | } else if (rw == 0 && ireason == 1) { | 622 | } else if (rw == 0 && ireason == 1) { |
653 | /* | 623 | /* |
654 | * Some drives (ASUS) seem to tell us that status info is | 624 | * Some drives (ASUS) seem to tell us that status info is |
@@ -696,16 +666,9 @@ static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) | |||
696 | 666 | ||
697 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); | 667 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); |
698 | 668 | ||
699 | /* | 669 | static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, |
700 | * Routine to send a read/write packet command to the drive. This is usually | 670 | struct request *rq) |
701 | * called directly from cdrom_start_{read,write}(). However, for drq_interrupt | ||
702 | * devices, it is called from an interrupt when the drive is ready to accept | ||
703 | * the command. | ||
704 | */ | ||
705 | static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | ||
706 | { | 671 | { |
707 | struct request *rq = HWGROUP(drive)->rq; | ||
708 | |||
709 | if (rq_data_dir(rq) == READ) { | 672 | if (rq_data_dir(rq) == READ) { |
710 | unsigned short sectors_per_frame = | 673 | unsigned short sectors_per_frame = |
711 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; | 674 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; |
@@ -742,6 +705,19 @@ static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | |||
742 | /* set up the command */ | 705 | /* set up the command */ |
743 | rq->timeout = ATAPI_WAIT_PC; | 706 | rq->timeout = ATAPI_WAIT_PC; |
744 | 707 | ||
708 | return ide_started; | ||
709 | } | ||
710 | |||
711 | /* | ||
712 | * Routine to send a read/write packet command to the drive. This is usually | ||
713 | * called directly from cdrom_start_{read,write}(). However, for drq_interrupt | ||
714 | * devices, it is called from an interrupt when the drive is ready to accept | ||
715 | * the command. | ||
716 | */ | ||
717 | static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | ||
718 | { | ||
719 | struct request *rq = drive->hwif->hwgroup->rq; | ||
720 | |||
745 | /* send the command to the drive and return */ | 721 | /* send the command to the drive and return */ |
746 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); | 722 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); |
747 | } | 723 | } |
@@ -768,9 +744,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive) | |||
768 | return ide_stopped; | 744 | return ide_stopped; |
769 | } | 745 | } |
770 | 746 | ||
771 | static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive) | 747 | static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq) |
772 | { | 748 | { |
773 | struct request *rq = HWGROUP(drive)->rq; | ||
774 | sector_t frame = rq->sector; | 749 | sector_t frame = rq->sector; |
775 | 750 | ||
776 | sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); | 751 | sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); |
@@ -780,17 +755,13 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive) | |||
780 | put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]); | 755 | put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]); |
781 | 756 | ||
782 | rq->timeout = ATAPI_WAIT_PC; | 757 | rq->timeout = ATAPI_WAIT_PC; |
783 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); | ||
784 | } | 758 | } |
785 | 759 | ||
786 | static ide_startstop_t cdrom_start_seek(ide_drive_t *drive, unsigned int block) | 760 | static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive) |
787 | { | 761 | { |
788 | struct cdrom_info *info = drive->driver_data; | 762 | struct request *rq = drive->hwif->hwgroup->rq; |
789 | 763 | ||
790 | info->dma = 0; | 764 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); |
791 | info->start_seek = jiffies; | ||
792 | return cdrom_start_packet_command(drive, 0, | ||
793 | cdrom_start_seek_continuation); | ||
794 | } | 765 | } |
795 | 766 | ||
796 | /* | 767 | /* |
@@ -1011,7 +982,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
1011 | - bio_cur_sectors(rq->bio), | 982 | - bio_cur_sectors(rq->bio), |
1012 | thislen >> 9); | 983 | thislen >> 9); |
1013 | if (nskip > 0) { | 984 | if (nskip > 0) { |
1014 | ide_cd_drain_data(drive, nskip); | 985 | ide_pad_transfer(drive, write, nskip << 9); |
1015 | rq->current_nr_sectors -= nskip; | 986 | rq->current_nr_sectors -= nskip; |
1016 | thislen -= (nskip << 9); | 987 | thislen -= (nskip << 9); |
1017 | } | 988 | } |
@@ -1048,7 +1019,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
1048 | * If the buffers are full, pipe the rest into | 1019 | * If the buffers are full, pipe the rest into |
1049 | * oblivion. | 1020 | * oblivion. |
1050 | */ | 1021 | */ |
1051 | ide_cd_drain_data(drive, thislen >> 9); | 1022 | ide_pad_transfer(drive, 0, thislen); |
1052 | else { | 1023 | else { |
1053 | printk(KERN_ERR "%s: confused, missing data\n", | 1024 | printk(KERN_ERR "%s: confused, missing data\n", |
1054 | drive->name); | 1025 | drive->name); |
@@ -1096,7 +1067,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | |||
1096 | 1067 | ||
1097 | /* pad, if necessary */ | 1068 | /* pad, if necessary */ |
1098 | if (!blk_fs_request(rq) && len > 0) | 1069 | if (!blk_fs_request(rq) && len > 0) |
1099 | ide_cd_pad_transfer(drive, xferfunc, len); | 1070 | ide_pad_transfer(drive, write, len); |
1100 | 1071 | ||
1101 | if (blk_pc_request(rq)) { | 1072 | if (blk_pc_request(rq)) { |
1102 | timeout = rq->timeout; | 1073 | timeout = rq->timeout; |
@@ -1165,21 +1136,17 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | |||
1165 | if (write) | 1136 | if (write) |
1166 | cd->devinfo.media_written = 1; | 1137 | cd->devinfo.media_written = 1; |
1167 | 1138 | ||
1168 | /* start sending the read/write request to the drive */ | 1139 | return ide_started; |
1169 | return cdrom_start_packet_command(drive, 32768, cdrom_start_rw_cont); | ||
1170 | } | 1140 | } |
1171 | 1141 | ||
1172 | static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive) | 1142 | static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive) |
1173 | { | 1143 | { |
1174 | struct request *rq = HWGROUP(drive)->rq; | 1144 | struct request *rq = HWGROUP(drive)->rq; |
1175 | 1145 | ||
1176 | if (!rq->timeout) | ||
1177 | rq->timeout = ATAPI_WAIT_PC; | ||
1178 | |||
1179 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); | 1146 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); |
1180 | } | 1147 | } |
1181 | 1148 | ||
1182 | static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | 1149 | static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) |
1183 | { | 1150 | { |
1184 | struct cdrom_info *info = drive->driver_data; | 1151 | struct cdrom_info *info = drive->driver_data; |
1185 | 1152 | ||
@@ -1191,10 +1158,16 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | |||
1191 | info->dma = 0; | 1158 | info->dma = 0; |
1192 | 1159 | ||
1193 | /* sg request */ | 1160 | /* sg request */ |
1194 | if (rq->bio) { | 1161 | if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { |
1195 | int mask = drive->queue->dma_alignment; | 1162 | struct request_queue *q = drive->queue; |
1196 | unsigned long addr = | 1163 | unsigned int alignment; |
1197 | (unsigned long)page_address(bio_page(rq->bio)); | 1164 | unsigned long addr; |
1165 | unsigned long stack_mask = ~(THREAD_SIZE - 1); | ||
1166 | |||
1167 | if (rq->bio) | ||
1168 | addr = (unsigned long)bio_data(rq->bio); | ||
1169 | else | ||
1170 | addr = (unsigned long)rq->data; | ||
1198 | 1171 | ||
1199 | info->dma = drive->using_dma; | 1172 | info->dma = drive->using_dma; |
1200 | 1173 | ||
@@ -1204,23 +1177,25 @@ static ide_startstop_t cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | |||
1204 | * NOTE! The "len" and "addr" checks should possibly have | 1177 | * NOTE! The "len" and "addr" checks should possibly have |
1205 | * separate masks. | 1178 | * separate masks. |
1206 | */ | 1179 | */ |
1207 | if ((rq->data_len & 15) || (addr & mask)) | 1180 | alignment = queue_dma_alignment(q) | q->dma_pad_mask; |
1181 | if (addr & alignment || rq->data_len & alignment) | ||
1208 | info->dma = 0; | 1182 | info->dma = 0; |
1209 | } | ||
1210 | 1183 | ||
1211 | /* start sending the command to the drive */ | 1184 | if (!((addr & stack_mask) ^ |
1212 | return cdrom_start_packet_command(drive, rq->data_len, | 1185 | ((unsigned long)current->stack & stack_mask))) |
1213 | cdrom_do_newpc_cont); | 1186 | info->dma = 0; |
1187 | } | ||
1214 | } | 1188 | } |
1215 | 1189 | ||
1216 | /* | 1190 | /* |
1217 | * cdrom driver request routine. | 1191 | * cdrom driver request routine. |
1218 | */ | 1192 | */ |
1219 | static ide_startstop_t ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, | 1193 | static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq, |
1220 | sector_t block) | 1194 | sector_t block) |
1221 | { | 1195 | { |
1222 | ide_startstop_t action; | ||
1223 | struct cdrom_info *info = drive->driver_data; | 1196 | struct cdrom_info *info = drive->driver_data; |
1197 | ide_handler_t *fn; | ||
1198 | int xferlen; | ||
1224 | 1199 | ||
1225 | if (blk_fs_request(rq)) { | 1200 | if (blk_fs_request(rq)) { |
1226 | if (info->cd_flags & IDE_CD_FLAG_SEEKING) { | 1201 | if (info->cd_flags & IDE_CD_FLAG_SEEKING) { |
@@ -1240,29 +1215,48 @@ static ide_startstop_t ide_do_rw_cdrom(ide_drive_t *drive, struct request *rq, | |||
1240 | } | 1215 | } |
1241 | if (rq_data_dir(rq) == READ && | 1216 | if (rq_data_dir(rq) == READ && |
1242 | IDE_LARGE_SEEK(info->last_block, block, | 1217 | IDE_LARGE_SEEK(info->last_block, block, |
1243 | IDECD_SEEK_THRESHOLD) && | 1218 | IDECD_SEEK_THRESHOLD) && |
1244 | drive->dsc_overlap) | 1219 | drive->dsc_overlap) { |
1245 | action = cdrom_start_seek(drive, block); | 1220 | xferlen = 0; |
1246 | else | 1221 | fn = cdrom_start_seek_continuation; |
1247 | action = cdrom_start_rw(drive, rq); | 1222 | |
1223 | info->dma = 0; | ||
1224 | info->start_seek = jiffies; | ||
1225 | |||
1226 | ide_cd_prepare_seek_request(drive, rq); | ||
1227 | } else { | ||
1228 | xferlen = 32768; | ||
1229 | fn = cdrom_start_rw_cont; | ||
1230 | |||
1231 | if (cdrom_start_rw(drive, rq) == ide_stopped) | ||
1232 | return ide_stopped; | ||
1233 | |||
1234 | if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped) | ||
1235 | return ide_stopped; | ||
1236 | } | ||
1248 | info->last_block = block; | 1237 | info->last_block = block; |
1249 | return action; | ||
1250 | } else if (blk_sense_request(rq) || blk_pc_request(rq) || | 1238 | } else if (blk_sense_request(rq) || blk_pc_request(rq) || |
1251 | rq->cmd_type == REQ_TYPE_ATA_PC) { | 1239 | rq->cmd_type == REQ_TYPE_ATA_PC) { |
1252 | return cdrom_do_block_pc(drive, rq); | 1240 | xferlen = rq->data_len; |
1241 | fn = cdrom_do_newpc_cont; | ||
1242 | |||
1243 | if (!rq->timeout) | ||
1244 | rq->timeout = ATAPI_WAIT_PC; | ||
1245 | |||
1246 | cdrom_do_block_pc(drive, rq); | ||
1253 | } else if (blk_special_request(rq)) { | 1247 | } else if (blk_special_request(rq)) { |
1254 | /* right now this can only be a reset... */ | 1248 | /* right now this can only be a reset... */ |
1255 | cdrom_end_request(drive, 1); | 1249 | cdrom_end_request(drive, 1); |
1256 | return ide_stopped; | 1250 | return ide_stopped; |
1251 | } else { | ||
1252 | blk_dump_rq_flags(rq, "ide-cd bad flags"); | ||
1253 | cdrom_end_request(drive, 0); | ||
1254 | return ide_stopped; | ||
1257 | } | 1255 | } |
1258 | 1256 | ||
1259 | blk_dump_rq_flags(rq, "ide-cd bad flags"); | 1257 | return cdrom_start_packet_command(drive, xferlen, fn); |
1260 | cdrom_end_request(drive, 0); | ||
1261 | return ide_stopped; | ||
1262 | } | 1258 | } |
1263 | 1259 | ||
1264 | |||
1265 | |||
1266 | /* | 1260 | /* |
1267 | * Ioctl handling. | 1261 | * Ioctl handling. |
1268 | * | 1262 | * |
@@ -1872,6 +1866,7 @@ static int ide_cdrom_setup(ide_drive_t *drive) | |||
1872 | 1866 | ||
1873 | blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); | 1867 | blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); |
1874 | blk_queue_dma_alignment(drive->queue, 31); | 1868 | blk_queue_dma_alignment(drive->queue, 31); |
1869 | blk_queue_update_dma_pad(drive->queue, 15); | ||
1875 | drive->queue->unplug_delay = (1 * HZ) / 1000; | 1870 | drive->queue->unplug_delay = (1 * HZ) / 1000; |
1876 | if (!drive->queue->unplug_delay) | 1871 | if (!drive->queue->unplug_delay) |
1877 | drive->queue->unplug_delay = 1; | 1872 | drive->queue->unplug_delay = 1; |
@@ -1954,10 +1949,9 @@ static ide_driver_t ide_cdrom_driver = { | |||
1954 | .version = IDECD_VERSION, | 1949 | .version = IDECD_VERSION, |
1955 | .media = ide_cdrom, | 1950 | .media = ide_cdrom, |
1956 | .supports_dsc_overlap = 1, | 1951 | .supports_dsc_overlap = 1, |
1957 | .do_request = ide_do_rw_cdrom, | 1952 | .do_request = ide_cd_do_request, |
1958 | .end_request = ide_end_request, | 1953 | .end_request = ide_end_request, |
1959 | .error = __ide_error, | 1954 | .error = __ide_error, |
1960 | .abort = __ide_abort, | ||
1961 | #ifdef CONFIG_IDE_PROC_FS | 1955 | #ifdef CONFIG_IDE_PROC_FS |
1962 | .proc = idecd_proc, | 1956 | .proc = idecd_proc, |
1963 | #endif | 1957 | #endif |
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c index 5f49a4ae9dd8..3a2e80237c10 100644 --- a/drivers/ide/ide-disk.c +++ b/drivers/ide/ide-disk.c | |||
@@ -985,7 +985,6 @@ static ide_driver_t idedisk_driver = { | |||
985 | .do_request = ide_do_rw_disk, | 985 | .do_request = ide_do_rw_disk, |
986 | .end_request = ide_end_request, | 986 | .end_request = ide_end_request, |
987 | .error = __ide_error, | 987 | .error = __ide_error, |
988 | .abort = __ide_abort, | ||
989 | #ifdef CONFIG_IDE_PROC_FS | 988 | #ifdef CONFIG_IDE_PROC_FS |
990 | .proc = idedisk_proc, | 989 | .proc = idedisk_proc, |
991 | #endif | 990 | #endif |
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index b3689437269f..011d72011cc4 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c | |||
@@ -351,10 +351,7 @@ static void ide_floppy_callback(ide_drive_t *drive) | |||
351 | 351 | ||
352 | static void idefloppy_init_pc(struct ide_atapi_pc *pc) | 352 | static void idefloppy_init_pc(struct ide_atapi_pc *pc) |
353 | { | 353 | { |
354 | memset(pc->c, 0, 12); | 354 | memset(pc, 0, sizeof(*pc)); |
355 | pc->retries = 0; | ||
356 | pc->flags = 0; | ||
357 | pc->req_xfer = 0; | ||
358 | pc->buf = pc->pc_buf; | 355 | pc->buf = pc->pc_buf; |
359 | pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE; | 356 | pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE; |
360 | pc->callback = ide_floppy_callback; | 357 | pc->callback = ide_floppy_callback; |
@@ -561,12 +558,6 @@ static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start) | |||
561 | pc->c[4] = start; | 558 | pc->c[4] = start; |
562 | } | 559 | } |
563 | 560 | ||
564 | static void idefloppy_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) | ||
565 | { | ||
566 | idefloppy_init_pc(pc); | ||
567 | pc->c[0] = GPCMD_TEST_UNIT_READY; | ||
568 | } | ||
569 | |||
570 | static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, | 561 | static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, |
571 | struct ide_atapi_pc *pc, struct request *rq, | 562 | struct ide_atapi_pc *pc, struct request *rq, |
572 | unsigned long sector) | 563 | unsigned long sector) |
@@ -711,10 +702,10 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) | |||
711 | set_disk_ro(floppy->disk, floppy->wp); | 702 | set_disk_ro(floppy->disk, floppy->wp); |
712 | page = &pc.buf[8]; | 703 | page = &pc.buf[8]; |
713 | 704 | ||
714 | transfer_rate = be16_to_cpu(*(u16 *)&pc.buf[8 + 2]); | 705 | transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); |
715 | sector_size = be16_to_cpu(*(u16 *)&pc.buf[8 + 6]); | 706 | sector_size = be16_to_cpup((__be16 *)&pc.buf[8 + 6]); |
716 | cyls = be16_to_cpu(*(u16 *)&pc.buf[8 + 8]); | 707 | cyls = be16_to_cpup((__be16 *)&pc.buf[8 + 8]); |
717 | rpm = be16_to_cpu(*(u16 *)&pc.buf[8 + 28]); | 708 | rpm = be16_to_cpup((__be16 *)&pc.buf[8 + 28]); |
718 | heads = pc.buf[8 + 4]; | 709 | heads = pc.buf[8 + 4]; |
719 | sectors = pc.buf[8 + 5]; | 710 | sectors = pc.buf[8 + 5]; |
720 | 711 | ||
@@ -789,8 +780,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive) | |||
789 | for (i = 0; i < desc_cnt; i++) { | 780 | for (i = 0; i < desc_cnt; i++) { |
790 | unsigned int desc_start = 4 + i*8; | 781 | unsigned int desc_start = 4 + i*8; |
791 | 782 | ||
792 | blocks = be32_to_cpu(*(u32 *)&pc.buf[desc_start]); | 783 | blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); |
793 | length = be16_to_cpu(*(u16 *)&pc.buf[desc_start + 6]); | 784 | length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); |
794 | 785 | ||
795 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", | 786 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", |
796 | i, blocks * length / 1024, blocks, length); | 787 | i, blocks * length / 1024, blocks, length); |
@@ -911,8 +902,8 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg) | |||
911 | if (u_index >= u_array_size) | 902 | if (u_index >= u_array_size) |
912 | break; /* User-supplied buffer too small */ | 903 | break; /* User-supplied buffer too small */ |
913 | 904 | ||
914 | blocks = be32_to_cpu(*(u32 *)&pc.buf[desc_start]); | 905 | blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); |
915 | length = be16_to_cpu(*(u16 *)&pc.buf[desc_start + 6]); | 906 | length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); |
916 | 907 | ||
917 | if (put_user(blocks, argp)) | 908 | if (put_user(blocks, argp)) |
918 | return(-EFAULT); | 909 | return(-EFAULT); |
@@ -1138,7 +1129,6 @@ static ide_driver_t idefloppy_driver = { | |||
1138 | .do_request = idefloppy_do_request, | 1129 | .do_request = idefloppy_do_request, |
1139 | .end_request = idefloppy_end_request, | 1130 | .end_request = idefloppy_end_request, |
1140 | .error = __ide_error, | 1131 | .error = __ide_error, |
1141 | .abort = __ide_abort, | ||
1142 | #ifdef CONFIG_IDE_PROC_FS | 1132 | #ifdef CONFIG_IDE_PROC_FS |
1143 | .proc = idefloppy_proc, | 1133 | .proc = idefloppy_proc, |
1144 | #endif | 1134 | #endif |
@@ -1166,7 +1156,9 @@ static int idefloppy_open(struct inode *inode, struct file *filp) | |||
1166 | floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; | 1156 | floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; |
1167 | /* Just in case */ | 1157 | /* Just in case */ |
1168 | 1158 | ||
1169 | idefloppy_create_test_unit_ready_cmd(&pc); | 1159 | idefloppy_init_pc(&pc); |
1160 | pc.c[0] = GPCMD_TEST_UNIT_READY; | ||
1161 | |||
1170 | if (idefloppy_queue_pc_tail(drive, &pc)) { | 1162 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
1171 | idefloppy_create_start_stop_cmd(&pc, 1); | 1163 | idefloppy_create_start_stop_cmd(&pc, 1); |
1172 | (void) idefloppy_queue_pc_tail(drive, &pc); | 1164 | (void) idefloppy_queue_pc_tail(drive, &pc); |
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index 28057747c1f8..661b75a89d4d 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c | |||
@@ -504,55 +504,6 @@ ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat) | |||
504 | 504 | ||
505 | EXPORT_SYMBOL_GPL(ide_error); | 505 | EXPORT_SYMBOL_GPL(ide_error); |
506 | 506 | ||
507 | ide_startstop_t __ide_abort(ide_drive_t *drive, struct request *rq) | ||
508 | { | ||
509 | if (drive->media != ide_disk) | ||
510 | rq->errors |= ERROR_RESET; | ||
511 | |||
512 | ide_kill_rq(drive, rq); | ||
513 | |||
514 | return ide_stopped; | ||
515 | } | ||
516 | |||
517 | EXPORT_SYMBOL_GPL(__ide_abort); | ||
518 | |||
519 | /** | ||
520 | * ide_abort - abort pending IDE operations | ||
521 | * @drive: drive the error occurred on | ||
522 | * @msg: message to report | ||
523 | * | ||
524 | * ide_abort kills and cleans up when we are about to do a | ||
525 | * host initiated reset on active commands. Longer term we | ||
526 | * want handlers to have sensible abort handling themselves | ||
527 | * | ||
528 | * This differs fundamentally from ide_error because in | ||
529 | * this case the command is doing just fine when we | ||
530 | * blow it away. | ||
531 | */ | ||
532 | |||
533 | ide_startstop_t ide_abort(ide_drive_t *drive, const char *msg) | ||
534 | { | ||
535 | struct request *rq; | ||
536 | |||
537 | if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL) | ||
538 | return ide_stopped; | ||
539 | |||
540 | /* retry only "normal" I/O: */ | ||
541 | if (!blk_fs_request(rq)) { | ||
542 | rq->errors = 1; | ||
543 | ide_end_drive_cmd(drive, BUSY_STAT, 0); | ||
544 | return ide_stopped; | ||
545 | } | ||
546 | |||
547 | if (rq->rq_disk) { | ||
548 | ide_driver_t *drv; | ||
549 | |||
550 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | ||
551 | return drv->abort(drive, rq); | ||
552 | } else | ||
553 | return __ide_abort(drive, rq); | ||
554 | } | ||
555 | |||
556 | static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf) | 507 | static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf) |
557 | { | 508 | { |
558 | tf->nsect = drive->sect; | 509 | tf->nsect = drive->sect; |
@@ -766,6 +717,18 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive, | |||
766 | return ide_stopped; | 717 | return ide_stopped; |
767 | } | 718 | } |
768 | 719 | ||
720 | static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) | ||
721 | { | ||
722 | switch (rq->cmd[0]) { | ||
723 | case REQ_DRIVE_RESET: | ||
724 | return ide_do_reset(drive); | ||
725 | default: | ||
726 | blk_dump_rq_flags(rq, "ide_special_rq - bad request"); | ||
727 | ide_end_request(drive, 0, 0); | ||
728 | return ide_stopped; | ||
729 | } | ||
730 | } | ||
731 | |||
769 | static void ide_check_pm_state(ide_drive_t *drive, struct request *rq) | 732 | static void ide_check_pm_state(ide_drive_t *drive, struct request *rq) |
770 | { | 733 | { |
771 | struct request_pm_state *pm = rq->data; | 734 | struct request_pm_state *pm = rq->data; |
@@ -869,7 +832,16 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq) | |||
869 | pm->pm_step == ide_pm_state_completed) | 832 | pm->pm_step == ide_pm_state_completed) |
870 | ide_complete_pm_request(drive, rq); | 833 | ide_complete_pm_request(drive, rq); |
871 | return startstop; | 834 | return startstop; |
872 | } | 835 | } else if (!rq->rq_disk && blk_special_request(rq)) |
836 | /* | ||
837 | * TODO: Once all ULDs have been modified to | ||
838 | * check for specific op codes rather than | ||
839 | * blindly accepting any special request, the | ||
840 | * check for ->rq_disk above may be replaced | ||
841 | * by a more suitable mechanism or even | ||
842 | * dropped entirely. | ||
843 | */ | ||
844 | return ide_special_rq(drive, rq); | ||
873 | 845 | ||
874 | drv = *(ide_driver_t **)rq->rq_disk->private_data; | 846 | drv = *(ide_driver_t **)rq->rq_disk->private_data; |
875 | return drv->do_request(drive, rq, block); | 847 | return drv->do_request(drive, rq, block); |
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c index 80ad4f234f3f..44aaec256a30 100644 --- a/drivers/ide/ide-iops.c +++ b/drivers/ide/ide-iops.c | |||
@@ -905,6 +905,14 @@ void ide_execute_pkt_cmd(ide_drive_t *drive) | |||
905 | } | 905 | } |
906 | EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd); | 906 | EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd); |
907 | 907 | ||
908 | static inline void ide_complete_drive_reset(ide_drive_t *drive, int err) | ||
909 | { | ||
910 | struct request *rq = drive->hwif->hwgroup->rq; | ||
911 | |||
912 | if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET) | ||
913 | ide_end_request(drive, err ? err : 1, 0); | ||
914 | } | ||
915 | |||
908 | /* needed below */ | 916 | /* needed below */ |
909 | static ide_startstop_t do_reset1 (ide_drive_t *, int); | 917 | static ide_startstop_t do_reset1 (ide_drive_t *, int); |
910 | 918 | ||
@@ -940,7 +948,7 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive) | |||
940 | } | 948 | } |
941 | /* done polling */ | 949 | /* done polling */ |
942 | hwgroup->polling = 0; | 950 | hwgroup->polling = 0; |
943 | hwgroup->resetting = 0; | 951 | ide_complete_drive_reset(drive, 0); |
944 | return ide_stopped; | 952 | return ide_stopped; |
945 | } | 953 | } |
946 | 954 | ||
@@ -956,12 +964,14 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive) | |||
956 | ide_hwif_t *hwif = HWIF(drive); | 964 | ide_hwif_t *hwif = HWIF(drive); |
957 | const struct ide_port_ops *port_ops = hwif->port_ops; | 965 | const struct ide_port_ops *port_ops = hwif->port_ops; |
958 | u8 tmp; | 966 | u8 tmp; |
967 | int err = 0; | ||
959 | 968 | ||
960 | if (port_ops && port_ops->reset_poll) { | 969 | if (port_ops && port_ops->reset_poll) { |
961 | if (port_ops->reset_poll(drive)) { | 970 | err = port_ops->reset_poll(drive); |
971 | if (err) { | ||
962 | printk(KERN_ERR "%s: host reset_poll failure for %s.\n", | 972 | printk(KERN_ERR "%s: host reset_poll failure for %s.\n", |
963 | hwif->name, drive->name); | 973 | hwif->name, drive->name); |
964 | return ide_stopped; | 974 | goto out; |
965 | } | 975 | } |
966 | } | 976 | } |
967 | 977 | ||
@@ -975,6 +985,7 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive) | |||
975 | } | 985 | } |
976 | printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp); | 986 | printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp); |
977 | drive->failures++; | 987 | drive->failures++; |
988 | err = -EIO; | ||
978 | } else { | 989 | } else { |
979 | printk("%s: reset: ", hwif->name); | 990 | printk("%s: reset: ", hwif->name); |
980 | tmp = ide_read_error(drive); | 991 | tmp = ide_read_error(drive); |
@@ -1001,10 +1012,12 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive) | |||
1001 | if (tmp & 0x80) | 1012 | if (tmp & 0x80) |
1002 | printk("; slave: failed"); | 1013 | printk("; slave: failed"); |
1003 | printk("\n"); | 1014 | printk("\n"); |
1015 | err = -EIO; | ||
1004 | } | 1016 | } |
1005 | } | 1017 | } |
1018 | out: | ||
1006 | hwgroup->polling = 0; /* done polling */ | 1019 | hwgroup->polling = 0; /* done polling */ |
1007 | hwgroup->resetting = 0; /* done reset attempt */ | 1020 | ide_complete_drive_reset(drive, err); |
1008 | return ide_stopped; | 1021 | return ide_stopped; |
1009 | } | 1022 | } |
1010 | 1023 | ||
@@ -1090,7 +1103,6 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | |||
1090 | 1103 | ||
1091 | /* For an ATAPI device, first try an ATAPI SRST. */ | 1104 | /* For an ATAPI device, first try an ATAPI SRST. */ |
1092 | if (drive->media != ide_disk && !do_not_try_atapi) { | 1105 | if (drive->media != ide_disk && !do_not_try_atapi) { |
1093 | hwgroup->resetting = 1; | ||
1094 | pre_reset(drive); | 1106 | pre_reset(drive); |
1095 | SELECT_DRIVE(drive); | 1107 | SELECT_DRIVE(drive); |
1096 | udelay (20); | 1108 | udelay (20); |
@@ -1112,10 +1124,10 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) | |||
1112 | 1124 | ||
1113 | if (io_ports->ctl_addr == 0) { | 1125 | if (io_ports->ctl_addr == 0) { |
1114 | spin_unlock_irqrestore(&ide_lock, flags); | 1126 | spin_unlock_irqrestore(&ide_lock, flags); |
1127 | ide_complete_drive_reset(drive, -ENXIO); | ||
1115 | return ide_stopped; | 1128 | return ide_stopped; |
1116 | } | 1129 | } |
1117 | 1130 | ||
1118 | hwgroup->resetting = 1; | ||
1119 | /* | 1131 | /* |
1120 | * Note that we also set nIEN while resetting the device, | 1132 | * Note that we also set nIEN while resetting the device, |
1121 | * to mask unwanted interrupts from the interface during the reset. | 1133 | * to mask unwanted interrupts from the interface during the reset. |
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c index 47af80df6872..13af72f09ec4 100644 --- a/drivers/ide/ide-lib.c +++ b/drivers/ide/ide-lib.c | |||
@@ -1,26 +1,11 @@ | |||
1 | #include <linux/module.h> | ||
2 | #include <linux/types.h> | 1 | #include <linux/types.h> |
3 | #include <linux/string.h> | 2 | #include <linux/string.h> |
4 | #include <linux/kernel.h> | 3 | #include <linux/kernel.h> |
5 | #include <linux/timer.h> | ||
6 | #include <linux/mm.h> | ||
7 | #include <linux/interrupt.h> | 4 | #include <linux/interrupt.h> |
8 | #include <linux/major.h> | ||
9 | #include <linux/errno.h> | ||
10 | #include <linux/genhd.h> | ||
11 | #include <linux/blkpg.h> | ||
12 | #include <linux/slab.h> | ||
13 | #include <linux/pci.h> | ||
14 | #include <linux/delay.h> | ||
15 | #include <linux/hdreg.h> | 5 | #include <linux/hdreg.h> |
16 | #include <linux/ide.h> | 6 | #include <linux/ide.h> |
17 | #include <linux/bitops.h> | 7 | #include <linux/bitops.h> |
18 | 8 | ||
19 | #include <asm/byteorder.h> | ||
20 | #include <asm/irq.h> | ||
21 | #include <asm/uaccess.h> | ||
22 | #include <asm/io.h> | ||
23 | |||
24 | static const char *udma_str[] = | 9 | static const char *udma_str[] = |
25 | { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44", | 10 | { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44", |
26 | "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" }; | 11 | "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" }; |
@@ -90,142 +75,6 @@ static u8 ide_rate_filter(ide_drive_t *drive, u8 speed) | |||
90 | return min(speed, mode); | 75 | return min(speed, mode); |
91 | } | 76 | } |
92 | 77 | ||
93 | /* | ||
94 | * Standard (generic) timings for PIO modes, from ATA2 specification. | ||
95 | * These timings are for access to the IDE data port register *only*. | ||
96 | * Some drives may specify a mode, while also specifying a different | ||
97 | * value for cycle_time (from drive identification data). | ||
98 | */ | ||
99 | const ide_pio_timings_t ide_pio_timings[6] = { | ||
100 | { 70, 165, 600 }, /* PIO Mode 0 */ | ||
101 | { 50, 125, 383 }, /* PIO Mode 1 */ | ||
102 | { 30, 100, 240 }, /* PIO Mode 2 */ | ||
103 | { 30, 80, 180 }, /* PIO Mode 3 with IORDY */ | ||
104 | { 25, 70, 120 }, /* PIO Mode 4 with IORDY */ | ||
105 | { 20, 50, 100 } /* PIO Mode 5 with IORDY (nonstandard) */ | ||
106 | }; | ||
107 | |||
108 | EXPORT_SYMBOL_GPL(ide_pio_timings); | ||
109 | |||
110 | /* | ||
111 | * Shared data/functions for determining best PIO mode for an IDE drive. | ||
112 | * Most of this stuff originally lived in cmd640.c, and changes to the | ||
113 | * ide_pio_blacklist[] table should be made with EXTREME CAUTION to avoid | ||
114 | * breaking the fragile cmd640.c support. | ||
115 | */ | ||
116 | |||
117 | /* | ||
118 | * Black list. Some drives incorrectly report their maximal PIO mode, | ||
119 | * at least in respect to CMD640. Here we keep info on some known drives. | ||
120 | */ | ||
121 | static struct ide_pio_info { | ||
122 | const char *name; | ||
123 | int pio; | ||
124 | } ide_pio_blacklist [] = { | ||
125 | { "Conner Peripherals 540MB - CFS540A", 3 }, | ||
126 | |||
127 | { "WDC AC2700", 3 }, | ||
128 | { "WDC AC2540", 3 }, | ||
129 | { "WDC AC2420", 3 }, | ||
130 | { "WDC AC2340", 3 }, | ||
131 | { "WDC AC2250", 0 }, | ||
132 | { "WDC AC2200", 0 }, | ||
133 | { "WDC AC21200", 4 }, | ||
134 | { "WDC AC2120", 0 }, | ||
135 | { "WDC AC2850", 3 }, | ||
136 | { "WDC AC1270", 3 }, | ||
137 | { "WDC AC1170", 1 }, | ||
138 | { "WDC AC1210", 1 }, | ||
139 | { "WDC AC280", 0 }, | ||
140 | { "WDC AC31000", 3 }, | ||
141 | { "WDC AC31200", 3 }, | ||
142 | |||
143 | { "Maxtor 7131 AT", 1 }, | ||
144 | { "Maxtor 7171 AT", 1 }, | ||
145 | { "Maxtor 7213 AT", 1 }, | ||
146 | { "Maxtor 7245 AT", 1 }, | ||
147 | { "Maxtor 7345 AT", 1 }, | ||
148 | { "Maxtor 7546 AT", 3 }, | ||
149 | { "Maxtor 7540 AV", 3 }, | ||
150 | |||
151 | { "SAMSUNG SHD-3121A", 1 }, | ||
152 | { "SAMSUNG SHD-3122A", 1 }, | ||
153 | { "SAMSUNG SHD-3172A", 1 }, | ||
154 | |||
155 | { "ST5660A", 3 }, | ||
156 | { "ST3660A", 3 }, | ||
157 | { "ST3630A", 3 }, | ||
158 | { "ST3655A", 3 }, | ||
159 | { "ST3391A", 3 }, | ||
160 | { "ST3390A", 1 }, | ||
161 | { "ST3600A", 1 }, | ||
162 | { "ST3290A", 0 }, | ||
163 | { "ST3144A", 0 }, | ||
164 | { "ST3491A", 1 }, /* reports 3, should be 1 or 2 (depending on */ | ||
165 | /* drive) according to Seagates FIND-ATA program */ | ||
166 | |||
167 | { "QUANTUM ELS127A", 0 }, | ||
168 | { "QUANTUM ELS170A", 0 }, | ||
169 | { "QUANTUM LPS240A", 0 }, | ||
170 | { "QUANTUM LPS210A", 3 }, | ||
171 | { "QUANTUM LPS270A", 3 }, | ||
172 | { "QUANTUM LPS365A", 3 }, | ||
173 | { "QUANTUM LPS540A", 3 }, | ||
174 | { "QUANTUM LIGHTNING 540A", 3 }, | ||
175 | { "QUANTUM LIGHTNING 730A", 3 }, | ||
176 | |||
177 | { "QUANTUM FIREBALL_540", 3 }, /* Older Quantum Fireballs don't work */ | ||
178 | { "QUANTUM FIREBALL_640", 3 }, | ||
179 | { "QUANTUM FIREBALL_1080", 3 }, | ||
180 | { "QUANTUM FIREBALL_1280", 3 }, | ||
181 | { NULL, 0 } | ||
182 | }; | ||
183 | |||
184 | /** | ||
185 | * ide_scan_pio_blacklist - check for a blacklisted drive | ||
186 | * @model: Drive model string | ||
187 | * | ||
188 | * This routine searches the ide_pio_blacklist for an entry | ||
189 | * matching the start/whole of the supplied model name. | ||
190 | * | ||
191 | * Returns -1 if no match found. | ||
192 | * Otherwise returns the recommended PIO mode from ide_pio_blacklist[]. | ||
193 | */ | ||
194 | |||
195 | static int ide_scan_pio_blacklist (char *model) | ||
196 | { | ||
197 | struct ide_pio_info *p; | ||
198 | |||
199 | for (p = ide_pio_blacklist; p->name != NULL; p++) { | ||
200 | if (strncmp(p->name, model, strlen(p->name)) == 0) | ||
201 | return p->pio; | ||
202 | } | ||
203 | return -1; | ||
204 | } | ||
205 | |||
206 | unsigned int ide_pio_cycle_time(ide_drive_t *drive, u8 pio) | ||
207 | { | ||
208 | struct hd_driveid *id = drive->id; | ||
209 | int cycle_time = 0; | ||
210 | |||
211 | if (id->field_valid & 2) { | ||
212 | if (id->capability & 8) | ||
213 | cycle_time = id->eide_pio_iordy; | ||
214 | else | ||
215 | cycle_time = id->eide_pio; | ||
216 | } | ||
217 | |||
218 | /* conservative "downgrade" for all pre-ATA2 drives */ | ||
219 | if (pio < 3) { | ||
220 | if (cycle_time && cycle_time < ide_pio_timings[pio].cycle_time) | ||
221 | cycle_time = 0; /* use standard timing */ | ||
222 | } | ||
223 | |||
224 | return cycle_time ? cycle_time : ide_pio_timings[pio].cycle_time; | ||
225 | } | ||
226 | |||
227 | EXPORT_SYMBOL_GPL(ide_pio_cycle_time); | ||
228 | |||
229 | /** | 78 | /** |
230 | * ide_get_best_pio_mode - get PIO mode from drive | 79 | * ide_get_best_pio_mode - get PIO mode from drive |
231 | * @drive: drive to consider | 80 | * @drive: drive to consider |
diff --git a/drivers/ide/ide-pio-blacklist.c b/drivers/ide/ide-pio-blacklist.c new file mode 100644 index 000000000000..a8c2c8f8660a --- /dev/null +++ b/drivers/ide/ide-pio-blacklist.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * PIO blacklist. Some drives incorrectly report their maximal PIO mode, | ||
3 | * at least in respect to CMD640. Here we keep info on some known drives. | ||
4 | * | ||
5 | * Changes to the ide_pio_blacklist[] should be made with EXTREME CAUTION | ||
6 | * to avoid breaking the fragile cmd640.c support. | ||
7 | */ | ||
8 | |||
9 | #include <linux/string.h> | ||
10 | |||
11 | static struct ide_pio_info { | ||
12 | const char *name; | ||
13 | int pio; | ||
14 | } ide_pio_blacklist [] = { | ||
15 | { "Conner Peripherals 540MB - CFS540A", 3 }, | ||
16 | |||
17 | { "WDC AC2700", 3 }, | ||
18 | { "WDC AC2540", 3 }, | ||
19 | { "WDC AC2420", 3 }, | ||
20 | { "WDC AC2340", 3 }, | ||
21 | { "WDC AC2250", 0 }, | ||
22 | { "WDC AC2200", 0 }, | ||
23 | { "WDC AC21200", 4 }, | ||
24 | { "WDC AC2120", 0 }, | ||
25 | { "WDC AC2850", 3 }, | ||
26 | { "WDC AC1270", 3 }, | ||
27 | { "WDC AC1170", 1 }, | ||
28 | { "WDC AC1210", 1 }, | ||
29 | { "WDC AC280", 0 }, | ||
30 | { "WDC AC31000", 3 }, | ||
31 | { "WDC AC31200", 3 }, | ||
32 | |||
33 | { "Maxtor 7131 AT", 1 }, | ||
34 | { "Maxtor 7171 AT", 1 }, | ||
35 | { "Maxtor 7213 AT", 1 }, | ||
36 | { "Maxtor 7245 AT", 1 }, | ||
37 | { "Maxtor 7345 AT", 1 }, | ||
38 | { "Maxtor 7546 AT", 3 }, | ||
39 | { "Maxtor 7540 AV", 3 }, | ||
40 | |||
41 | { "SAMSUNG SHD-3121A", 1 }, | ||
42 | { "SAMSUNG SHD-3122A", 1 }, | ||
43 | { "SAMSUNG SHD-3172A", 1 }, | ||
44 | |||
45 | { "ST5660A", 3 }, | ||
46 | { "ST3660A", 3 }, | ||
47 | { "ST3630A", 3 }, | ||
48 | { "ST3655A", 3 }, | ||
49 | { "ST3391A", 3 }, | ||
50 | { "ST3390A", 1 }, | ||
51 | { "ST3600A", 1 }, | ||
52 | { "ST3290A", 0 }, | ||
53 | { "ST3144A", 0 }, | ||
54 | { "ST3491A", 1 }, /* reports 3, should be 1 or 2 (depending on drive) | ||
55 | according to Seagate's FIND-ATA program */ | ||
56 | |||
57 | { "QUANTUM ELS127A", 0 }, | ||
58 | { "QUANTUM ELS170A", 0 }, | ||
59 | { "QUANTUM LPS240A", 0 }, | ||
60 | { "QUANTUM LPS210A", 3 }, | ||
61 | { "QUANTUM LPS270A", 3 }, | ||
62 | { "QUANTUM LPS365A", 3 }, | ||
63 | { "QUANTUM LPS540A", 3 }, | ||
64 | { "QUANTUM LIGHTNING 540A", 3 }, | ||
65 | { "QUANTUM LIGHTNING 730A", 3 }, | ||
66 | |||
67 | { "QUANTUM FIREBALL_540", 3 }, /* Older Quantum Fireballs don't work */ | ||
68 | { "QUANTUM FIREBALL_640", 3 }, | ||
69 | { "QUANTUM FIREBALL_1080", 3 }, | ||
70 | { "QUANTUM FIREBALL_1280", 3 }, | ||
71 | { NULL, 0 } | ||
72 | }; | ||
73 | |||
74 | /** | ||
75 | * ide_scan_pio_blacklist - check for a blacklisted drive | ||
76 | * @model: Drive model string | ||
77 | * | ||
78 | * This routine searches the ide_pio_blacklist for an entry | ||
79 | * matching the start/whole of the supplied model name. | ||
80 | * | ||
81 | * Returns -1 if no match found. | ||
82 | * Otherwise returns the recommended PIO mode from ide_pio_blacklist[]. | ||
83 | */ | ||
84 | |||
85 | int ide_scan_pio_blacklist(char *model) | ||
86 | { | ||
87 | struct ide_pio_info *p; | ||
88 | |||
89 | for (p = ide_pio_blacklist; p->name != NULL; p++) { | ||
90 | if (strncmp(p->name, model, strlen(p->name)) == 0) | ||
91 | return p->pio; | ||
92 | } | ||
93 | return -1; | ||
94 | } | ||
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c index adbd01784162..03f2ef5470a3 100644 --- a/drivers/ide/ide-pnp.c +++ b/drivers/ide/ide-pnp.c | |||
@@ -33,6 +33,8 @@ static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) | |||
33 | ide_hwif_t *hwif; | 33 | ide_hwif_t *hwif; |
34 | unsigned long base, ctl; | 34 | unsigned long base, ctl; |
35 | 35 | ||
36 | printk(KERN_INFO DRV_NAME ": generic PnP IDE interface\n"); | ||
37 | |||
36 | if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && pnp_irq_valid(dev, 0))) | 38 | if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && pnp_irq_valid(dev, 0))) |
37 | return -1; | 39 | return -1; |
38 | 40 | ||
@@ -62,10 +64,8 @@ static int idepnp_probe(struct pnp_dev *dev, const struct pnp_device_id *dev_id) | |||
62 | u8 index = hwif->index; | 64 | u8 index = hwif->index; |
63 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; | 65 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; |
64 | 66 | ||
65 | ide_init_port_data(hwif, index); | ||
66 | ide_init_port_hw(hwif, &hw); | 67 | ide_init_port_hw(hwif, &hw); |
67 | 68 | ||
68 | printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index); | ||
69 | pnp_set_drvdata(dev, hwif); | 69 | pnp_set_drvdata(dev, hwif); |
70 | 70 | ||
71 | ide_device_add(idx, NULL); | 71 | ide_device_add(idx, NULL); |
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c index d21e51a02c3e..235ebdb29b28 100644 --- a/drivers/ide/ide-probe.c +++ b/drivers/ide/ide-probe.c | |||
@@ -39,6 +39,8 @@ | |||
39 | #include <asm/uaccess.h> | 39 | #include <asm/uaccess.h> |
40 | #include <asm/io.h> | 40 | #include <asm/io.h> |
41 | 41 | ||
42 | static ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */ | ||
43 | |||
42 | /** | 44 | /** |
43 | * generic_id - add a generic drive id | 45 | * generic_id - add a generic drive id |
44 | * @drive: drive to make an ID block for | 46 | * @drive: drive to make an ID block for |
@@ -1318,10 +1320,10 @@ static void ide_port_init_devices(ide_hwif_t *hwif) | |||
1318 | drive->unmask = 1; | 1320 | drive->unmask = 1; |
1319 | if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS) | 1321 | if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS) |
1320 | drive->no_unmask = 1; | 1322 | drive->no_unmask = 1; |
1321 | } | ||
1322 | 1323 | ||
1323 | if (port_ops && port_ops->port_init_devs) | 1324 | if (port_ops && port_ops->init_dev) |
1324 | port_ops->port_init_devs(hwif); | 1325 | port_ops->init_dev(drive); |
1326 | } | ||
1325 | } | 1327 | } |
1326 | 1328 | ||
1327 | static void ide_init_port(ide_hwif_t *hwif, unsigned int port, | 1329 | static void ide_init_port(ide_hwif_t *hwif, unsigned int port, |
@@ -1473,22 +1475,29 @@ ide_hwif_t *ide_find_port_slot(const struct ide_port_info *d) | |||
1473 | for (; i < MAX_HWIFS; i++) { | 1475 | for (; i < MAX_HWIFS; i++) { |
1474 | hwif = &ide_hwifs[i]; | 1476 | hwif = &ide_hwifs[i]; |
1475 | if (hwif->chipset == ide_unknown) | 1477 | if (hwif->chipset == ide_unknown) |
1476 | return hwif; | 1478 | goto out_found; |
1477 | } | 1479 | } |
1478 | } else { | 1480 | } else { |
1479 | for (i = 2; i < MAX_HWIFS; i++) { | 1481 | for (i = 2; i < MAX_HWIFS; i++) { |
1480 | hwif = &ide_hwifs[i]; | 1482 | hwif = &ide_hwifs[i]; |
1481 | if (hwif->chipset == ide_unknown) | 1483 | if (hwif->chipset == ide_unknown) |
1482 | return hwif; | 1484 | goto out_found; |
1483 | } | 1485 | } |
1484 | for (i = 0; i < 2 && i < MAX_HWIFS; i++) { | 1486 | for (i = 0; i < 2 && i < MAX_HWIFS; i++) { |
1485 | hwif = &ide_hwifs[i]; | 1487 | hwif = &ide_hwifs[i]; |
1486 | if (hwif->chipset == ide_unknown) | 1488 | if (hwif->chipset == ide_unknown) |
1487 | return hwif; | 1489 | goto out_found; |
1488 | } | 1490 | } |
1489 | } | 1491 | } |
1490 | 1492 | ||
1493 | printk(KERN_ERR "%s: no free slot for interface\n", | ||
1494 | d ? d->name : "ide"); | ||
1495 | |||
1491 | return NULL; | 1496 | return NULL; |
1497 | |||
1498 | out_found: | ||
1499 | ide_init_port_data(hwif, i); | ||
1500 | return hwif; | ||
1492 | } | 1501 | } |
1493 | EXPORT_SYMBOL_GPL(ide_find_port_slot); | 1502 | EXPORT_SYMBOL_GPL(ide_find_port_slot); |
1494 | 1503 | ||
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index f9cf1670e4e1..b711ab96e287 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c | |||
@@ -2591,7 +2591,6 @@ static ide_driver_t idetape_driver = { | |||
2591 | .do_request = idetape_do_request, | 2591 | .do_request = idetape_do_request, |
2592 | .end_request = idetape_end_request, | 2592 | .end_request = idetape_end_request, |
2593 | .error = __ide_error, | 2593 | .error = __ide_error, |
2594 | .abort = __ide_abort, | ||
2595 | #ifdef CONFIG_IDE_PROC_FS | 2594 | #ifdef CONFIG_IDE_PROC_FS |
2596 | .proc = idetape_proc, | 2595 | .proc = idetape_proc, |
2597 | #endif | 2596 | #endif |
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c index cf55a48a7dd2..1fbdb746dc88 100644 --- a/drivers/ide/ide-taskfile.c +++ b/drivers/ide/ide-taskfile.c | |||
@@ -8,28 +8,18 @@ | |||
8 | * The big the bad and the ugly. | 8 | * The big the bad and the ugly. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/types.h> | 11 | #include <linux/types.h> |
13 | #include <linux/string.h> | 12 | #include <linux/string.h> |
14 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
15 | #include <linux/timer.h> | ||
16 | #include <linux/mm.h> | ||
17 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
18 | #include <linux/interrupt.h> | 15 | #include <linux/interrupt.h> |
19 | #include <linux/major.h> | ||
20 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
21 | #include <linux/genhd.h> | ||
22 | #include <linux/blkpg.h> | ||
23 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
24 | #include <linux/pci.h> | ||
25 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
26 | #include <linux/hdreg.h> | 19 | #include <linux/hdreg.h> |
27 | #include <linux/ide.h> | 20 | #include <linux/ide.h> |
28 | #include <linux/bitops.h> | ||
29 | #include <linux/scatterlist.h> | 21 | #include <linux/scatterlist.h> |
30 | 22 | ||
31 | #include <asm/byteorder.h> | ||
32 | #include <asm/irq.h> | ||
33 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
34 | #include <asm/io.h> | 24 | #include <asm/io.h> |
35 | 25 | ||
@@ -62,25 +52,6 @@ int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf) | |||
62 | return ide_raw_taskfile(drive, &args, buf, 1); | 52 | return ide_raw_taskfile(drive, &args, buf, 1); |
63 | } | 53 | } |
64 | 54 | ||
65 | static int inline task_dma_ok(ide_task_t *task) | ||
66 | { | ||
67 | if (blk_fs_request(task->rq) || (task->tf_flags & IDE_TFLAG_FLAGGED)) | ||
68 | return 1; | ||
69 | |||
70 | switch (task->tf.command) { | ||
71 | case WIN_WRITEDMA_ONCE: | ||
72 | case WIN_WRITEDMA: | ||
73 | case WIN_WRITEDMA_EXT: | ||
74 | case WIN_READDMA_ONCE: | ||
75 | case WIN_READDMA: | ||
76 | case WIN_READDMA_EXT: | ||
77 | case WIN_IDENTIFY_DMA: | ||
78 | return 1; | ||
79 | } | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | static ide_startstop_t task_no_data_intr(ide_drive_t *); | 55 | static ide_startstop_t task_no_data_intr(ide_drive_t *); |
85 | static ide_startstop_t set_geometry_intr(ide_drive_t *); | 56 | static ide_startstop_t set_geometry_intr(ide_drive_t *); |
86 | static ide_startstop_t recal_intr(ide_drive_t *); | 57 | static ide_startstop_t recal_intr(ide_drive_t *); |
@@ -139,8 +110,7 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task) | |||
139 | WAIT_WORSTCASE, NULL); | 110 | WAIT_WORSTCASE, NULL); |
140 | return ide_started; | 111 | return ide_started; |
141 | default: | 112 | default: |
142 | if (task_dma_ok(task) == 0 || drive->using_dma == 0 || | 113 | if (drive->using_dma == 0 || dma_ops->dma_setup(drive)) |
143 | dma_ops->dma_setup(drive)) | ||
144 | return ide_stopped; | 114 | return ide_stopped; |
145 | dma_ops->dma_exec_cmd(drive, tf->command); | 115 | dma_ops->dma_exec_cmd(drive, tf->command); |
146 | dma_ops->dma_start(drive); | 116 | dma_ops->dma_start(drive); |
@@ -183,7 +153,6 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive) | |||
183 | if (stat & (ERR_STAT|DRQ_STAT)) | 153 | if (stat & (ERR_STAT|DRQ_STAT)) |
184 | return ide_error(drive, "set_geometry_intr", stat); | 154 | return ide_error(drive, "set_geometry_intr", stat); |
185 | 155 | ||
186 | BUG_ON(HWGROUP(drive)->handler != NULL); | ||
187 | ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); | 156 | ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); |
188 | return ide_started; | 157 | return ide_started; |
189 | } | 158 | } |
diff --git a/drivers/ide/ide-timing.h b/drivers/ide/ide-timings.c index 2e91c5870b4c..8c2f8327f487 100644 --- a/drivers/ide/ide-timing.h +++ b/drivers/ide/ide-timings.c | |||
@@ -1,11 +1,7 @@ | |||
1 | #ifndef _IDE_TIMING_H | ||
2 | #define _IDE_TIMING_H | ||
3 | |||
4 | /* | 1 | /* |
5 | * Copyright (c) 1999-2001 Vojtech Pavlik | 2 | * Copyright (c) 1999-2001 Vojtech Pavlik |
6 | */ | 3 | * Copyright (c) 2007-2008 Bartlomiej Zolnierkiewicz |
7 | 4 | * | |
8 | /* | ||
9 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or |
@@ -27,27 +23,14 @@ | |||
27 | 23 | ||
28 | #include <linux/kernel.h> | 24 | #include <linux/kernel.h> |
29 | #include <linux/hdreg.h> | 25 | #include <linux/hdreg.h> |
30 | 26 | #include <linux/ide.h> | |
31 | #define XFER_PIO_5 0x0d | 27 | #include <linux/module.h> |
32 | #define XFER_UDMA_SLOW 0x4f | ||
33 | |||
34 | struct ide_timing { | ||
35 | short mode; | ||
36 | short setup; /* t1 */ | ||
37 | short act8b; /* t2 for 8-bit io */ | ||
38 | short rec8b; /* t2i for 8-bit io */ | ||
39 | short cyc8b; /* t0 for 8-bit io */ | ||
40 | short active; /* t2 or tD */ | ||
41 | short recover; /* t2i or tK */ | ||
42 | short cycle; /* t0 */ | ||
43 | short udma; /* t2CYCTYP/2 */ | ||
44 | }; | ||
45 | 28 | ||
46 | /* | 29 | /* |
47 | * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). | 30 | * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). |
48 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except | 31 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except |
49 | * for PIO 5, which is a nonstandard extension and UDMA6, which | 32 | * for PIO 5, which is a nonstandard extension and UDMA6, which |
50 | * is currently supported only by Maxtor drives. | 33 | * is currently supported only by Maxtor drives. |
51 | */ | 34 | */ |
52 | 35 | ||
53 | static struct ide_timing ide_timing[] = { | 36 | static struct ide_timing ide_timing[] = { |
@@ -61,12 +44,10 @@ static struct ide_timing ide_timing[] = { | |||
61 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, | 44 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, |
62 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, | 45 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, |
63 | 46 | ||
64 | { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, | ||
65 | |||
66 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, | 47 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, |
67 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, | 48 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, |
68 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, | 49 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, |
69 | 50 | ||
70 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, | 51 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, |
71 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, | 52 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, |
72 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, | 53 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, |
@@ -81,29 +62,46 @@ static struct ide_timing ide_timing[] = { | |||
81 | 62 | ||
82 | { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, | 63 | { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, |
83 | 64 | ||
84 | { -1 } | 65 | { 0xff } |
85 | }; | 66 | }; |
86 | 67 | ||
87 | #define IDE_TIMING_SETUP 0x01 | 68 | struct ide_timing *ide_timing_find_mode(u8 speed) |
88 | #define IDE_TIMING_ACT8B 0x02 | 69 | { |
89 | #define IDE_TIMING_REC8B 0x04 | 70 | struct ide_timing *t; |
90 | #define IDE_TIMING_CYC8B 0x08 | 71 | |
91 | #define IDE_TIMING_8BIT 0x0e | 72 | for (t = ide_timing; t->mode != speed; t++) |
92 | #define IDE_TIMING_ACTIVE 0x10 | 73 | if (t->mode == 0xff) |
93 | #define IDE_TIMING_RECOVER 0x20 | 74 | return NULL; |
94 | #define IDE_TIMING_CYCLE 0x40 | 75 | return t; |
95 | #define IDE_TIMING_UDMA 0x80 | 76 | } |
96 | #define IDE_TIMING_ALL 0xff | 77 | EXPORT_SYMBOL_GPL(ide_timing_find_mode); |
97 | 78 | ||
98 | #define ENOUGH(v,unit) (((v)-1)/(unit)+1) | 79 | u16 ide_pio_cycle_time(ide_drive_t *drive, u8 pio) |
99 | #define EZ(v,unit) ((v)?ENOUGH(v,unit):0) | 80 | { |
100 | 81 | struct hd_driveid *id = drive->id; | |
101 | #define XFER_MODE 0xf0 | 82 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); |
102 | #define XFER_MWDMA 0x20 | 83 | u16 cycle = 0; |
103 | #define XFER_EPIO 0x01 | 84 | |
104 | #define XFER_PIO 0x00 | 85 | if (id->field_valid & 2) { |
105 | 86 | if (id->capability & 8) | |
106 | static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT) | 87 | cycle = id->eide_pio_iordy; |
88 | else | ||
89 | cycle = id->eide_pio; | ||
90 | |||
91 | /* conservative "downgrade" for all pre-ATA2 drives */ | ||
92 | if (pio < 3 && cycle < t->cycle) | ||
93 | cycle = 0; /* use standard timing */ | ||
94 | } | ||
95 | |||
96 | return cycle ? cycle : t->cycle; | ||
97 | } | ||
98 | EXPORT_SYMBOL_GPL(ide_pio_cycle_time); | ||
99 | |||
100 | #define ENOUGH(v, unit) (((v) - 1) / (unit) + 1) | ||
101 | #define EZ(v, unit) ((v) ? ENOUGH(v, unit) : 0) | ||
102 | |||
103 | static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, | ||
104 | int T, int UT) | ||
107 | { | 105 | { |
108 | q->setup = EZ(t->setup * 1000, T); | 106 | q->setup = EZ(t->setup * 1000, T); |
109 | q->act8b = EZ(t->act8b * 1000, T); | 107 | q->act8b = EZ(t->act8b * 1000, T); |
@@ -115,92 +113,83 @@ static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int | |||
115 | q->udma = EZ(t->udma * 1000, UT); | 113 | q->udma = EZ(t->udma * 1000, UT); |
116 | } | 114 | } |
117 | 115 | ||
118 | static void ide_timing_merge(struct ide_timing *a, struct ide_timing *b, struct ide_timing *m, unsigned int what) | 116 | void ide_timing_merge(struct ide_timing *a, struct ide_timing *b, |
119 | { | 117 | struct ide_timing *m, unsigned int what) |
120 | if (what & IDE_TIMING_SETUP ) m->setup = max(a->setup, b->setup); | ||
121 | if (what & IDE_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b); | ||
122 | if (what & IDE_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b); | ||
123 | if (what & IDE_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b); | ||
124 | if (what & IDE_TIMING_ACTIVE ) m->active = max(a->active, b->active); | ||
125 | if (what & IDE_TIMING_RECOVER) m->recover = max(a->recover, b->recover); | ||
126 | if (what & IDE_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle); | ||
127 | if (what & IDE_TIMING_UDMA ) m->udma = max(a->udma, b->udma); | ||
128 | } | ||
129 | |||
130 | static struct ide_timing* ide_timing_find_mode(short speed) | ||
131 | { | 118 | { |
132 | struct ide_timing *t; | 119 | if (what & IDE_TIMING_SETUP) |
133 | 120 | m->setup = max(a->setup, b->setup); | |
134 | for (t = ide_timing; t->mode != speed; t++) | 121 | if (what & IDE_TIMING_ACT8B) |
135 | if (t->mode < 0) | 122 | m->act8b = max(a->act8b, b->act8b); |
136 | return NULL; | 123 | if (what & IDE_TIMING_REC8B) |
137 | return t; | 124 | m->rec8b = max(a->rec8b, b->rec8b); |
125 | if (what & IDE_TIMING_CYC8B) | ||
126 | m->cyc8b = max(a->cyc8b, b->cyc8b); | ||
127 | if (what & IDE_TIMING_ACTIVE) | ||
128 | m->active = max(a->active, b->active); | ||
129 | if (what & IDE_TIMING_RECOVER) | ||
130 | m->recover = max(a->recover, b->recover); | ||
131 | if (what & IDE_TIMING_CYCLE) | ||
132 | m->cycle = max(a->cycle, b->cycle); | ||
133 | if (what & IDE_TIMING_UDMA) | ||
134 | m->udma = max(a->udma, b->udma); | ||
138 | } | 135 | } |
136 | EXPORT_SYMBOL_GPL(ide_timing_merge); | ||
139 | 137 | ||
140 | static int ide_timing_compute(ide_drive_t *drive, short speed, struct ide_timing *t, int T, int UT) | 138 | int ide_timing_compute(ide_drive_t *drive, u8 speed, |
139 | struct ide_timing *t, int T, int UT) | ||
141 | { | 140 | { |
142 | struct hd_driveid *id = drive->id; | 141 | struct hd_driveid *id = drive->id; |
143 | struct ide_timing *s, p; | 142 | struct ide_timing *s, p; |
144 | 143 | ||
145 | /* | 144 | /* |
146 | * Find the mode. | 145 | * Find the mode. |
147 | */ | 146 | */ |
148 | 147 | s = ide_timing_find_mode(speed); | |
149 | if (!(s = ide_timing_find_mode(speed))) | 148 | if (s == NULL) |
150 | return -EINVAL; | 149 | return -EINVAL; |
151 | 150 | ||
152 | /* | 151 | /* |
153 | * Copy the timing from the table. | 152 | * Copy the timing from the table. |
154 | */ | 153 | */ |
155 | |||
156 | *t = *s; | 154 | *t = *s; |
157 | 155 | ||
158 | /* | 156 | /* |
159 | * If the drive is an EIDE drive, it can tell us it needs extended | 157 | * If the drive is an EIDE drive, it can tell us it needs extended |
160 | * PIO/MWDMA cycle timing. | 158 | * PIO/MWDMA cycle timing. |
161 | */ | 159 | */ |
162 | |||
163 | if (id && id->field_valid & 2) { /* EIDE drive */ | 160 | if (id && id->field_valid & 2) { /* EIDE drive */ |
164 | 161 | ||
165 | memset(&p, 0, sizeof(p)); | 162 | memset(&p, 0, sizeof(p)); |
166 | 163 | ||
167 | switch (speed & XFER_MODE) { | 164 | if (speed <= XFER_PIO_2) |
168 | 165 | p.cycle = p.cyc8b = id->eide_pio; | |
169 | case XFER_PIO: | 166 | else if (speed <= XFER_PIO_5) |
170 | if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = id->eide_pio; | 167 | p.cycle = p.cyc8b = id->eide_pio_iordy; |
171 | else p.cycle = p.cyc8b = id->eide_pio_iordy; | 168 | else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) |
172 | break; | 169 | p.cycle = id->eide_dma_min; |
173 | |||
174 | case XFER_MWDMA: | ||
175 | p.cycle = id->eide_dma_min; | ||
176 | break; | ||
177 | } | ||
178 | 170 | ||
179 | ide_timing_merge(&p, t, t, IDE_TIMING_CYCLE | IDE_TIMING_CYC8B); | 171 | ide_timing_merge(&p, t, t, IDE_TIMING_CYCLE | IDE_TIMING_CYC8B); |
180 | } | 172 | } |
181 | 173 | ||
182 | /* | 174 | /* |
183 | * Convert the timing to bus clock counts. | 175 | * Convert the timing to bus clock counts. |
184 | */ | 176 | */ |
185 | |||
186 | ide_timing_quantize(t, t, T, UT); | 177 | ide_timing_quantize(t, t, T, UT); |
187 | 178 | ||
188 | /* | 179 | /* |
189 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, S.M.A.R.T | 180 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, |
190 | * and some other commands. We have to ensure that the DMA cycle timing is | 181 | * S.M.A.R.T and some other commands. We have to ensure that the |
191 | * slower/equal than the fastest PIO timing. | 182 | * DMA cycle timing is slower/equal than the fastest PIO timing. |
192 | */ | 183 | */ |
193 | 184 | if (speed >= XFER_SW_DMA_0) { | |
194 | if ((speed & XFER_MODE) != XFER_PIO) { | ||
195 | u8 pio = ide_get_best_pio_mode(drive, 255, 5); | 185 | u8 pio = ide_get_best_pio_mode(drive, 255, 5); |
196 | ide_timing_compute(drive, XFER_PIO_0 + pio, &p, T, UT); | 186 | ide_timing_compute(drive, XFER_PIO_0 + pio, &p, T, UT); |
197 | ide_timing_merge(&p, t, t, IDE_TIMING_ALL); | 187 | ide_timing_merge(&p, t, t, IDE_TIMING_ALL); |
198 | } | 188 | } |
199 | 189 | ||
200 | /* | 190 | /* |
201 | * Lengthen active & recovery time so that cycle time is correct. | 191 | * Lengthen active & recovery time so that cycle time is correct. |
202 | */ | 192 | */ |
203 | |||
204 | if (t->act8b + t->rec8b < t->cyc8b) { | 193 | if (t->act8b + t->rec8b < t->cyc8b) { |
205 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; | 194 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; |
206 | t->rec8b = t->cyc8b - t->act8b; | 195 | t->rec8b = t->cyc8b - t->act8b; |
@@ -213,5 +202,4 @@ static int ide_timing_compute(ide_drive_t *drive, short speed, struct ide_timing | |||
213 | 202 | ||
214 | return 0; | 203 | return 0; |
215 | } | 204 | } |
216 | 205 | EXPORT_SYMBOL_GPL(ide_timing_compute); | |
217 | #endif | ||
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index 2b8453510e09..d4a6b102a772 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -50,29 +50,16 @@ | |||
50 | #include <linux/types.h> | 50 | #include <linux/types.h> |
51 | #include <linux/string.h> | 51 | #include <linux/string.h> |
52 | #include <linux/kernel.h> | 52 | #include <linux/kernel.h> |
53 | #include <linux/timer.h> | ||
54 | #include <linux/mm.h> | ||
55 | #include <linux/interrupt.h> | 53 | #include <linux/interrupt.h> |
56 | #include <linux/major.h> | 54 | #include <linux/major.h> |
57 | #include <linux/errno.h> | 55 | #include <linux/errno.h> |
58 | #include <linux/genhd.h> | 56 | #include <linux/genhd.h> |
59 | #include <linux/blkpg.h> | ||
60 | #include <linux/slab.h> | 57 | #include <linux/slab.h> |
61 | #include <linux/init.h> | 58 | #include <linux/init.h> |
62 | #include <linux/pci.h> | 59 | #include <linux/pci.h> |
63 | #include <linux/delay.h> | ||
64 | #include <linux/ide.h> | 60 | #include <linux/ide.h> |
65 | #include <linux/completion.h> | 61 | #include <linux/completion.h> |
66 | #include <linux/reboot.h> | ||
67 | #include <linux/cdrom.h> | ||
68 | #include <linux/seq_file.h> | ||
69 | #include <linux/device.h> | 62 | #include <linux/device.h> |
70 | #include <linux/bitops.h> | ||
71 | |||
72 | #include <asm/byteorder.h> | ||
73 | #include <asm/irq.h> | ||
74 | #include <asm/uaccess.h> | ||
75 | #include <asm/io.h> | ||
76 | 63 | ||
77 | 64 | ||
78 | /* default maximum number of failures */ | 65 | /* default maximum number of failures */ |
@@ -91,8 +78,6 @@ DEFINE_MUTEX(ide_cfg_mtx); | |||
91 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock); | 78 | __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock); |
92 | EXPORT_SYMBOL(ide_lock); | 79 | EXPORT_SYMBOL(ide_lock); |
93 | 80 | ||
94 | ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */ | ||
95 | |||
96 | static void ide_port_init_devices_data(ide_hwif_t *); | 81 | static void ide_port_init_devices_data(ide_hwif_t *); |
97 | 82 | ||
98 | /* | 83 | /* |
@@ -121,7 +106,6 @@ void ide_init_port_data(ide_hwif_t *hwif, unsigned int index) | |||
121 | 106 | ||
122 | ide_port_init_devices_data(hwif); | 107 | ide_port_init_devices_data(hwif); |
123 | } | 108 | } |
124 | EXPORT_SYMBOL_GPL(ide_init_port_data); | ||
125 | 109 | ||
126 | static void ide_port_init_devices_data(ide_hwif_t *hwif) | 110 | static void ide_port_init_devices_data(ide_hwif_t *hwif) |
127 | { | 111 | { |
@@ -150,18 +134,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif) | |||
150 | } | 134 | } |
151 | } | 135 | } |
152 | 136 | ||
153 | static void __init init_ide_data (void) | ||
154 | { | ||
155 | unsigned int index; | ||
156 | |||
157 | /* Initialise all interface structures */ | ||
158 | for (index = 0; index < MAX_HWIFS; ++index) { | ||
159 | ide_hwif_t *hwif = &ide_hwifs[index]; | ||
160 | |||
161 | ide_init_port_data(hwif, index); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | void ide_remove_port_from_hwgroup(ide_hwif_t *hwif) | 137 | void ide_remove_port_from_hwgroup(ide_hwif_t *hwif) |
166 | { | 138 | { |
167 | ide_hwgroup_t *hwgroup = hwif->hwgroup; | 139 | ide_hwgroup_t *hwgroup = hwif->hwgroup; |
@@ -312,7 +284,8 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw) | |||
312 | memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports)); | 284 | memcpy(&hwif->io_ports, &hw->io_ports, sizeof(hwif->io_ports)); |
313 | hwif->irq = hw->irq; | 285 | hwif->irq = hw->irq; |
314 | hwif->chipset = hw->chipset; | 286 | hwif->chipset = hw->chipset; |
315 | hwif->gendev.parent = hw->dev; | 287 | hwif->dev = hw->dev; |
288 | hwif->gendev.parent = hw->parent ? hw->parent : hw->dev; | ||
316 | hwif->ack_intr = hw->ack_intr; | 289 | hwif->ack_intr = hw->ack_intr; |
317 | } | 290 | } |
318 | EXPORT_SYMBOL_GPL(ide_init_port_hw); | 291 | EXPORT_SYMBOL_GPL(ide_init_port_hw); |
@@ -556,6 +529,22 @@ static int generic_ide_resume(struct device *dev) | |||
556 | return err; | 529 | return err; |
557 | } | 530 | } |
558 | 531 | ||
532 | static int generic_drive_reset(ide_drive_t *drive) | ||
533 | { | ||
534 | struct request *rq; | ||
535 | int ret = 0; | ||
536 | |||
537 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); | ||
538 | rq->cmd_type = REQ_TYPE_SPECIAL; | ||
539 | rq->cmd_len = 1; | ||
540 | rq->cmd[0] = REQ_DRIVE_RESET; | ||
541 | rq->cmd_flags |= REQ_SOFTBARRIER; | ||
542 | if (blk_execute_rq(drive->queue, NULL, rq, 1)) | ||
543 | ret = rq->errors; | ||
544 | blk_put_request(rq); | ||
545 | return ret; | ||
546 | } | ||
547 | |||
559 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, | 548 | int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, |
560 | unsigned int cmd, unsigned long arg) | 549 | unsigned int cmd, unsigned long arg) |
561 | { | 550 | { |
@@ -630,33 +619,8 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device | |||
630 | if (!capable(CAP_SYS_ADMIN)) | 619 | if (!capable(CAP_SYS_ADMIN)) |
631 | return -EACCES; | 620 | return -EACCES; |
632 | 621 | ||
633 | /* | 622 | return generic_drive_reset(drive); |
634 | * Abort the current command on the | ||
635 | * group if there is one, taking | ||
636 | * care not to allow anything else | ||
637 | * to be queued and to die on the | ||
638 | * spot if we miss one somehow | ||
639 | */ | ||
640 | |||
641 | spin_lock_irqsave(&ide_lock, flags); | ||
642 | |||
643 | if (HWGROUP(drive)->resetting) { | ||
644 | spin_unlock_irqrestore(&ide_lock, flags); | ||
645 | return -EBUSY; | ||
646 | } | ||
647 | 623 | ||
648 | ide_abort(drive, "drive reset"); | ||
649 | |||
650 | BUG_ON(HWGROUP(drive)->handler); | ||
651 | |||
652 | /* Ensure nothing gets queued after we | ||
653 | drop the lock. Reset will clear the busy */ | ||
654 | |||
655 | HWGROUP(drive)->busy = 1; | ||
656 | spin_unlock_irqrestore(&ide_lock, flags); | ||
657 | (void) ide_do_reset(drive); | ||
658 | |||
659 | return 0; | ||
660 | case HDIO_GET_BUSSTATE: | 624 | case HDIO_GET_BUSSTATE: |
661 | if (!capable(CAP_SYS_ADMIN)) | 625 | if (!capable(CAP_SYS_ADMIN)) |
662 | return -EACCES; | 626 | return -EACCES; |
@@ -1021,8 +985,6 @@ static int __init ide_init(void) | |||
1021 | goto out_port_class; | 985 | goto out_port_class; |
1022 | } | 986 | } |
1023 | 987 | ||
1024 | init_ide_data(); | ||
1025 | |||
1026 | proc_ide_create(); | 988 | proc_ide_create(); |
1027 | 989 | ||
1028 | return 0; | 990 | return 0; |
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c index 052125fafcfa..4ec19737f3c5 100644 --- a/drivers/ide/legacy/ali14xx.c +++ b/drivers/ide/legacy/ali14xx.c | |||
@@ -117,10 +117,11 @@ static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
117 | u8 param1, param2, param3, param4; | 117 | u8 param1, param2, param3, param4; |
118 | unsigned long flags; | 118 | unsigned long flags; |
119 | int bus_speed = ide_vlb_clk ? ide_vlb_clk : 50; | 119 | int bus_speed = ide_vlb_clk ? ide_vlb_clk : 50; |
120 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
120 | 121 | ||
121 | /* calculate timing, according to PIO mode */ | 122 | /* calculate timing, according to PIO mode */ |
122 | time1 = ide_pio_cycle_time(drive, pio); | 123 | time1 = ide_pio_cycle_time(drive, pio); |
123 | time2 = ide_pio_timings[pio].active_time; | 124 | time2 = t->active; |
124 | param3 = param1 = (time2 * bus_speed + 999) / 1000; | 125 | param3 = param1 = (time2 * bus_speed + 999) / 1000; |
125 | param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1; | 126 | param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1; |
126 | if (pio < 3) { | 127 | if (pio < 3) { |
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c index 9a1d27ef3f8a..0497e7f85b09 100644 --- a/drivers/ide/legacy/buddha.c +++ b/drivers/ide/legacy/buddha.c | |||
@@ -227,7 +227,6 @@ fail_base2: | |||
227 | if (hwif) { | 227 | if (hwif) { |
228 | u8 index = hwif->index; | 228 | u8 index = hwif->index; |
229 | 229 | ||
230 | ide_init_port_data(hwif, index); | ||
231 | ide_init_port_hw(hwif, &hw); | 230 | ide_init_port_hw(hwif, &hw); |
232 | 231 | ||
233 | idx[i] = index; | 232 | idx[i] = index; |
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c index af11028b4794..129a812bb57f 100644 --- a/drivers/ide/legacy/falconide.c +++ b/drivers/ide/legacy/falconide.c | |||
@@ -111,7 +111,6 @@ static int __init falconide_init(void) | |||
111 | u8 index = hwif->index; | 111 | u8 index = hwif->index; |
112 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; | 112 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; |
113 | 113 | ||
114 | ide_init_port_data(hwif, index); | ||
115 | ide_init_port_hw(hwif, &hw); | 114 | ide_init_port_hw(hwif, &hw); |
116 | 115 | ||
117 | /* Atari has a byte-swapped IDE interface */ | 116 | /* Atari has a byte-swapped IDE interface */ |
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c index b78941680c32..7e74b20202df 100644 --- a/drivers/ide/legacy/gayle.c +++ b/drivers/ide/legacy/gayle.c | |||
@@ -185,7 +185,6 @@ found: | |||
185 | if (hwif) { | 185 | if (hwif) { |
186 | u8 index = hwif->index; | 186 | u8 index = hwif->index; |
187 | 187 | ||
188 | ide_init_port_data(hwif, index); | ||
189 | ide_init_port_hw(hwif, &hw); | 188 | ide_init_port_hw(hwif, &hw); |
190 | 189 | ||
191 | idx[i] = index; | 190 | idx[i] = index; |
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c index dd6dfb32e853..7bc8fd59ea9e 100644 --- a/drivers/ide/legacy/ht6560b.c +++ b/drivers/ide/legacy/ht6560b.c | |||
@@ -216,6 +216,7 @@ static u8 ht_pio2timings(ide_drive_t *drive, const u8 pio) | |||
216 | 216 | ||
217 | if (pio) { | 217 | if (pio) { |
218 | unsigned int cycle_time; | 218 | unsigned int cycle_time; |
219 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
219 | 220 | ||
220 | cycle_time = ide_pio_cycle_time(drive, pio); | 221 | cycle_time = ide_pio_cycle_time(drive, pio); |
221 | 222 | ||
@@ -224,10 +225,8 @@ static u8 ht_pio2timings(ide_drive_t *drive, const u8 pio) | |||
224 | * actual cycle time for recovery and activity | 225 | * actual cycle time for recovery and activity |
225 | * according system bus speed. | 226 | * according system bus speed. |
226 | */ | 227 | */ |
227 | active_time = ide_pio_timings[pio].active_time; | 228 | active_time = t->active; |
228 | recovery_time = cycle_time | 229 | recovery_time = cycle_time - active_time - t->setup; |
229 | - active_time | ||
230 | - ide_pio_timings[pio].setup_time; | ||
231 | /* | 230 | /* |
232 | * Cycle times should be Vesa bus cycles | 231 | * Cycle times should be Vesa bus cycles |
233 | */ | 232 | */ |
@@ -311,16 +310,16 @@ static void ht6560b_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
311 | #endif | 310 | #endif |
312 | } | 311 | } |
313 | 312 | ||
314 | static void __init ht6560b_port_init_devs(ide_hwif_t *hwif) | 313 | static void __init ht6560b_init_dev(ide_drive_t *drive) |
315 | { | 314 | { |
315 | ide_hwif_t *hwif = drive->hwif; | ||
316 | /* Setting default configurations for drives. */ | 316 | /* Setting default configurations for drives. */ |
317 | int t = (HT_CONFIG_DEFAULT << 8) | HT_TIMING_DEFAULT; | 317 | int t = (HT_CONFIG_DEFAULT << 8) | HT_TIMING_DEFAULT; |
318 | 318 | ||
319 | if (hwif->channel) | 319 | if (hwif->channel) |
320 | t |= (HT_SECONDARY_IF << 8); | 320 | t |= (HT_SECONDARY_IF << 8); |
321 | 321 | ||
322 | hwif->drives[0].drive_data = t; | 322 | drive->drive_data = t; |
323 | hwif->drives[1].drive_data = t; | ||
324 | } | 323 | } |
325 | 324 | ||
326 | static int probe_ht6560b; | 325 | static int probe_ht6560b; |
@@ -329,7 +328,7 @@ module_param_named(probe, probe_ht6560b, bool, 0); | |||
329 | MODULE_PARM_DESC(probe, "probe for HT6560B chipset"); | 328 | MODULE_PARM_DESC(probe, "probe for HT6560B chipset"); |
330 | 329 | ||
331 | static const struct ide_port_ops ht6560b_port_ops = { | 330 | static const struct ide_port_ops ht6560b_port_ops = { |
332 | .port_init_devs = ht6560b_port_init_devs, | 331 | .init_dev = ht6560b_init_dev, |
333 | .set_pio_mode = ht6560b_set_pio_mode, | 332 | .set_pio_mode = ht6560b_set_pio_mode, |
334 | .selectproc = ht6560b_selectproc, | 333 | .selectproc = ht6560b_selectproc, |
335 | }; | 334 | }; |
diff --git a/drivers/ide/legacy/ide-4drives.c b/drivers/ide/legacy/ide-4drives.c index ecae916a3385..89c8ff0a4d08 100644 --- a/drivers/ide/legacy/ide-4drives.c +++ b/drivers/ide/legacy/ide-4drives.c | |||
@@ -11,6 +11,21 @@ static int probe_4drives; | |||
11 | module_param_named(probe, probe_4drives, bool, 0); | 11 | module_param_named(probe, probe_4drives, bool, 0); |
12 | MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port"); | 12 | MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port"); |
13 | 13 | ||
14 | static void ide_4drives_init_dev(ide_drive_t *drive) | ||
15 | { | ||
16 | if (drive->hwif->channel) | ||
17 | drive->select.all ^= 0x20; | ||
18 | } | ||
19 | |||
20 | static const struct ide_port_ops ide_4drives_port_ops = { | ||
21 | .init_dev = ide_4drives_init_dev, | ||
22 | }; | ||
23 | |||
24 | static const struct ide_port_info ide_4drives_port_info = { | ||
25 | .port_ops = &ide_4drives_port_ops, | ||
26 | .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_NO_DMA, | ||
27 | }; | ||
28 | |||
14 | static int __init ide_4drives_init(void) | 29 | static int __init ide_4drives_init(void) |
15 | { | 30 | { |
16 | ide_hwif_t *hwif, *mate; | 31 | ide_hwif_t *hwif, *mate; |
@@ -49,18 +64,10 @@ static int __init ide_4drives_init(void) | |||
49 | mate = ide_find_port(); | 64 | mate = ide_find_port(); |
50 | if (mate) { | 65 | if (mate) { |
51 | ide_init_port_hw(mate, &hw); | 66 | ide_init_port_hw(mate, &hw); |
52 | mate->drives[0].select.all ^= 0x20; | ||
53 | mate->drives[1].select.all ^= 0x20; | ||
54 | idx[1] = mate->index; | 67 | idx[1] = mate->index; |
55 | |||
56 | if (hwif) { | ||
57 | hwif->mate = mate; | ||
58 | mate->mate = hwif; | ||
59 | hwif->serialized = mate->serialized = 1; | ||
60 | } | ||
61 | } | 68 | } |
62 | 69 | ||
63 | ide_device_add(idx, NULL); | 70 | ide_device_add(idx, &ide_4drives_port_info); |
64 | 71 | ||
65 | return 0; | 72 | return 0; |
66 | } | 73 | } |
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index 8dbf4d9b6447..27b1e0b7ecb4 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c | |||
@@ -66,8 +66,6 @@ MODULE_LICENSE("Dual MPL/GPL"); | |||
66 | #ifdef CONFIG_PCMCIA_DEBUG | 66 | #ifdef CONFIG_PCMCIA_DEBUG |
67 | INT_MODULE_PARM(pc_debug, 0); | 67 | INT_MODULE_PARM(pc_debug, 0); |
68 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) | 68 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) |
69 | /*static char *version = | ||
70 | "ide-cs.c 1.3 2002/10/26 05:45:31 (David Hinds)";*/ | ||
71 | #else | 69 | #else |
72 | #define DEBUG(n, args...) | 70 | #define DEBUG(n, args...) |
73 | #endif | 71 | #endif |
@@ -154,6 +152,11 @@ static const struct ide_port_ops idecs_port_ops = { | |||
154 | .quirkproc = ide_undecoded_slave, | 152 | .quirkproc = ide_undecoded_slave, |
155 | }; | 153 | }; |
156 | 154 | ||
155 | static const struct ide_port_info idecs_port_info = { | ||
156 | .port_ops = &idecs_port_ops, | ||
157 | .host_flags = IDE_HFLAG_NO_DMA, | ||
158 | }; | ||
159 | |||
157 | static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl, | 160 | static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl, |
158 | unsigned long irq, struct pcmcia_device *handle) | 161 | unsigned long irq, struct pcmcia_device *handle) |
159 | { | 162 | { |
@@ -187,13 +190,11 @@ static ide_hwif_t *idecs_register(unsigned long io, unsigned long ctl, | |||
187 | 190 | ||
188 | i = hwif->index; | 191 | i = hwif->index; |
189 | 192 | ||
190 | ide_init_port_data(hwif, i); | ||
191 | ide_init_port_hw(hwif, &hw); | 193 | ide_init_port_hw(hwif, &hw); |
192 | hwif->port_ops = &idecs_port_ops; | ||
193 | 194 | ||
194 | idx[0] = i; | 195 | idx[0] = i; |
195 | 196 | ||
196 | ide_device_add(idx, NULL); | 197 | ide_device_add(idx, &idecs_port_info); |
197 | 198 | ||
198 | if (hwif->present) | 199 | if (hwif->present) |
199 | return hwif; | 200 | return hwif; |
diff --git a/drivers/ide/legacy/ide_platform.c b/drivers/ide/legacy/ide_platform.c index d3bc3f24e05d..a249562b34b5 100644 --- a/drivers/ide/legacy/ide_platform.c +++ b/drivers/ide/legacy/ide_platform.c | |||
@@ -44,6 +44,10 @@ static void __devinit plat_ide_setup_ports(hw_regs_t *hw, | |||
44 | hw->chipset = ide_generic; | 44 | hw->chipset = ide_generic; |
45 | } | 45 | } |
46 | 46 | ||
47 | static const struct ide_port_info platform_ide_port_info = { | ||
48 | .host_flags = IDE_HFLAG_NO_DMA, | ||
49 | }; | ||
50 | |||
47 | static int __devinit plat_ide_probe(struct platform_device *pdev) | 51 | static int __devinit plat_ide_probe(struct platform_device *pdev) |
48 | { | 52 | { |
49 | struct resource *res_base, *res_alt, *res_irq; | 53 | struct resource *res_base, *res_alt, *res_irq; |
@@ -54,6 +58,7 @@ static int __devinit plat_ide_probe(struct platform_device *pdev) | |||
54 | int ret = 0; | 58 | int ret = 0; |
55 | int mmio = 0; | 59 | int mmio = 0; |
56 | hw_regs_t hw; | 60 | hw_regs_t hw; |
61 | struct ide_port_info d = platform_ide_port_info; | ||
57 | 62 | ||
58 | pdata = pdev->dev.platform_data; | 63 | pdata = pdev->dev.platform_data; |
59 | 64 | ||
@@ -102,13 +107,13 @@ static int __devinit plat_ide_probe(struct platform_device *pdev) | |||
102 | ide_init_port_hw(hwif, &hw); | 107 | ide_init_port_hw(hwif, &hw); |
103 | 108 | ||
104 | if (mmio) { | 109 | if (mmio) { |
105 | hwif->host_flags = IDE_HFLAG_MMIO; | 110 | d.host_flags |= IDE_HFLAG_MMIO; |
106 | default_hwif_mmiops(hwif); | 111 | default_hwif_mmiops(hwif); |
107 | } | 112 | } |
108 | 113 | ||
109 | idx[0] = hwif->index; | 114 | idx[0] = hwif->index; |
110 | 115 | ||
111 | ide_device_add(idx, NULL); | 116 | ide_device_add(idx, &d); |
112 | 117 | ||
113 | platform_set_drvdata(pdev, hwif); | 118 | platform_set_drvdata(pdev, hwif); |
114 | 119 | ||
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c index 2e84290d0bcc..0a6195bcfeda 100644 --- a/drivers/ide/legacy/macide.c +++ b/drivers/ide/legacy/macide.c | |||
@@ -130,7 +130,6 @@ static int __init macide_init(void) | |||
130 | u8 index = hwif->index; | 130 | u8 index = hwif->index; |
131 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; | 131 | u8 idx[4] = { index, 0xff, 0xff, 0xff }; |
132 | 132 | ||
133 | ide_init_port_data(hwif, index); | ||
134 | ide_init_port_hw(hwif, &hw); | 133 | ide_init_port_hw(hwif, &hw); |
135 | 134 | ||
136 | ide_device_add(idx, NULL); | 135 | ide_device_add(idx, NULL); |
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c index 8ff6e2d20834..9c2b9d078f69 100644 --- a/drivers/ide/legacy/q40ide.c +++ b/drivers/ide/legacy/q40ide.c | |||
@@ -142,7 +142,6 @@ static int __init q40ide_init(void) | |||
142 | 142 | ||
143 | hwif = ide_find_port(); | 143 | hwif = ide_find_port(); |
144 | if (hwif) { | 144 | if (hwif) { |
145 | ide_init_port_data(hwif, hwif->index); | ||
146 | ide_init_port_hw(hwif, &hw); | 145 | ide_init_port_hw(hwif, &hw); |
147 | 146 | ||
148 | /* Q40 has a byte-swapped IDE interface */ | 147 | /* Q40 has a byte-swapped IDE interface */ |
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c index 51dba82f8812..2338f344ea24 100644 --- a/drivers/ide/legacy/qd65xx.c +++ b/drivers/ide/legacy/qd65xx.c | |||
@@ -207,6 +207,7 @@ static void qd6500_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
207 | static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio) | 207 | static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio) |
208 | { | 208 | { |
209 | ide_hwif_t *hwif = drive->hwif; | 209 | ide_hwif_t *hwif = drive->hwif; |
210 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
210 | unsigned int cycle_time; | 211 | unsigned int cycle_time; |
211 | int active_time = 175; | 212 | int active_time = 175; |
212 | int recovery_time = 415; /* worst case values from the dos driver */ | 213 | int recovery_time = 415; /* worst case values from the dos driver */ |
@@ -236,7 +237,7 @@ static void qd6580_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
236 | active_time = 110; | 237 | active_time = 110; |
237 | recovery_time = cycle_time - 120; | 238 | recovery_time = cycle_time - 120; |
238 | } else { | 239 | } else { |
239 | active_time = ide_pio_timings[pio].active_time; | 240 | active_time = t->active; |
240 | recovery_time = cycle_time - active_time; | 241 | recovery_time = cycle_time - active_time; |
241 | } | 242 | } |
242 | } | 243 | } |
@@ -281,17 +282,18 @@ static int __init qd_testreg(int port) | |||
281 | return (readreg != QD_TESTVAL); | 282 | return (readreg != QD_TESTVAL); |
282 | } | 283 | } |
283 | 284 | ||
284 | static void __init qd6500_port_init_devs(ide_hwif_t *hwif) | 285 | static void __init qd6500_init_dev(ide_drive_t *drive) |
285 | { | 286 | { |
287 | ide_hwif_t *hwif = drive->hwif; | ||
286 | u8 base = (hwif->config_data & 0xff00) >> 8; | 288 | u8 base = (hwif->config_data & 0xff00) >> 8; |
287 | u8 config = QD_CONFIG(hwif); | 289 | u8 config = QD_CONFIG(hwif); |
288 | 290 | ||
289 | hwif->drives[0].drive_data = QD6500_DEF_DATA; | 291 | drive->drive_data = QD6500_DEF_DATA; |
290 | hwif->drives[1].drive_data = QD6500_DEF_DATA; | ||
291 | } | 292 | } |
292 | 293 | ||
293 | static void __init qd6580_port_init_devs(ide_hwif_t *hwif) | 294 | static void __init qd6580_init_dev(ide_drive_t *drive) |
294 | { | 295 | { |
296 | ide_hwif_t *hwif = drive->hwif; | ||
295 | u16 t1, t2; | 297 | u16 t1, t2; |
296 | u8 base = (hwif->config_data & 0xff00) >> 8; | 298 | u8 base = (hwif->config_data & 0xff00) >> 8; |
297 | u8 config = QD_CONFIG(hwif); | 299 | u8 config = QD_CONFIG(hwif); |
@@ -302,18 +304,17 @@ static void __init qd6580_port_init_devs(ide_hwif_t *hwif) | |||
302 | } else | 304 | } else |
303 | t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; | 305 | t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; |
304 | 306 | ||
305 | hwif->drives[0].drive_data = t1; | 307 | drive->drive_data = drive->select.b.unit ? t2 : t1; |
306 | hwif->drives[1].drive_data = t2; | ||
307 | } | 308 | } |
308 | 309 | ||
309 | static const struct ide_port_ops qd6500_port_ops = { | 310 | static const struct ide_port_ops qd6500_port_ops = { |
310 | .port_init_devs = qd6500_port_init_devs, | 311 | .init_dev = qd6500_init_dev, |
311 | .set_pio_mode = qd6500_set_pio_mode, | 312 | .set_pio_mode = qd6500_set_pio_mode, |
312 | .selectproc = qd65xx_select, | 313 | .selectproc = qd65xx_select, |
313 | }; | 314 | }; |
314 | 315 | ||
315 | static const struct ide_port_ops qd6580_port_ops = { | 316 | static const struct ide_port_ops qd6580_port_ops = { |
316 | .port_init_devs = qd6580_port_init_devs, | 317 | .init_dev = qd6580_init_dev, |
317 | .set_pio_mode = qd6580_set_pio_mode, | 318 | .set_pio_mode = qd6580_set_pio_mode, |
318 | .selectproc = qd65xx_select, | 319 | .selectproc = qd65xx_select, |
319 | }; | 320 | }; |
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c index 1a6c27b32498..48d57cae63c6 100644 --- a/drivers/ide/mips/au1xxx-ide.c +++ b/drivers/ide/mips/au1xxx-ide.c | |||
@@ -213,10 +213,8 @@ static int auide_build_dmatable(ide_drive_t *drive) | |||
213 | { | 213 | { |
214 | int i, iswrite, count = 0; | 214 | int i, iswrite, count = 0; |
215 | ide_hwif_t *hwif = HWIF(drive); | 215 | ide_hwif_t *hwif = HWIF(drive); |
216 | |||
217 | struct request *rq = HWGROUP(drive)->rq; | 216 | struct request *rq = HWGROUP(drive)->rq; |
218 | 217 | _auide_hwif *ahwif = &auide_hwif; | |
219 | _auide_hwif *ahwif = (_auide_hwif*)hwif->hwif_data; | ||
220 | struct scatterlist *sg; | 218 | struct scatterlist *sg; |
221 | 219 | ||
222 | iswrite = (rq_data_dir(rq) == WRITE); | 220 | iswrite = (rq_data_dir(rq) == WRITE); |
@@ -402,7 +400,7 @@ static const struct ide_dma_ops au1xxx_dma_ops = { | |||
402 | 400 | ||
403 | static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) | 401 | static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) |
404 | { | 402 | { |
405 | _auide_hwif *auide = (_auide_hwif *)hwif->hwif_data; | 403 | _auide_hwif *auide = &auide_hwif; |
406 | dbdev_tab_t source_dev_tab, target_dev_tab; | 404 | dbdev_tab_t source_dev_tab, target_dev_tab; |
407 | u32 dev_id, tsize, devwidth, flags; | 405 | u32 dev_id, tsize, devwidth, flags; |
408 | 406 | ||
@@ -463,7 +461,7 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) | |||
463 | #else | 461 | #else |
464 | static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) | 462 | static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) |
465 | { | 463 | { |
466 | _auide_hwif *auide = (_auide_hwif *)hwif->hwif_data; | 464 | _auide_hwif *auide = &auide_hwif; |
467 | dbdev_tab_t source_dev_tab; | 465 | dbdev_tab_t source_dev_tab; |
468 | int flags; | 466 | int flags; |
469 | 467 | ||
@@ -600,8 +598,6 @@ static int au_ide_probe(struct device *dev) | |||
600 | 598 | ||
601 | ide_init_port_hw(hwif, &hw); | 599 | ide_init_port_hw(hwif, &hw); |
602 | 600 | ||
603 | hwif->dev = dev; | ||
604 | |||
605 | /* If the user has selected DDMA assisted copies, | 601 | /* If the user has selected DDMA assisted copies, |
606 | then set up a few local I/O function entry points | 602 | then set up a few local I/O function entry points |
607 | */ | 603 | */ |
@@ -610,11 +606,8 @@ static int au_ide_probe(struct device *dev) | |||
610 | hwif->input_data = au1xxx_input_data; | 606 | hwif->input_data = au1xxx_input_data; |
611 | hwif->output_data = au1xxx_output_data; | 607 | hwif->output_data = au1xxx_output_data; |
612 | #endif | 608 | #endif |
613 | hwif->select_data = 0; /* no chipset-specific code */ | ||
614 | hwif->config_data = 0; /* no chipset-specific code */ | ||
615 | 609 | ||
616 | auide_hwif.hwif = hwif; | 610 | auide_hwif.hwif = hwif; |
617 | hwif->hwif_data = &auide_hwif; | ||
618 | 611 | ||
619 | idx[0] = hwif->index; | 612 | idx[0] = hwif->index; |
620 | 613 | ||
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c index 52fee3d2771a..9f1212cc4aed 100644 --- a/drivers/ide/mips/swarm.c +++ b/drivers/ide/mips/swarm.c | |||
@@ -61,6 +61,11 @@ static struct resource swarm_ide_resource = { | |||
61 | 61 | ||
62 | static struct platform_device *swarm_ide_dev; | 62 | static struct platform_device *swarm_ide_dev; |
63 | 63 | ||
64 | static const struct ide_port_info swarm_port_info = { | ||
65 | .name = DRV_NAME, | ||
66 | .host_flags = IDE_HFLAG_MMIO | IDE_HFLAG_NO_DMA, | ||
67 | }; | ||
68 | |||
64 | /* | 69 | /* |
65 | * swarm_ide_probe - if the board header indicates the existence of | 70 | * swarm_ide_probe - if the board header indicates the existence of |
66 | * Generic Bus IDE, allocate a HWIF for it. | 71 | * Generic Bus IDE, allocate a HWIF for it. |
@@ -77,12 +82,6 @@ static int __devinit swarm_ide_probe(struct device *dev) | |||
77 | if (!SIBYTE_HAVE_IDE) | 82 | if (!SIBYTE_HAVE_IDE) |
78 | return -ENODEV; | 83 | return -ENODEV; |
79 | 84 | ||
80 | hwif = ide_find_port(); | ||
81 | if (hwif == NULL) { | ||
82 | printk(KERN_ERR DRV_NAME ": no free slot for interface\n"); | ||
83 | return -ENOMEM; | ||
84 | } | ||
85 | |||
86 | base = ioremap(A_IO_EXT_BASE, 0x800); | 85 | base = ioremap(A_IO_EXT_BASE, 0x800); |
87 | offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS)); | 86 | offset = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_START_ADDR, IDE_CS)); |
88 | size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS)); | 87 | size = __raw_readq(base + R_IO_EXT_REG(R_IO_EXT_MULT_SIZE, IDE_CS)); |
@@ -109,10 +108,6 @@ static int __devinit swarm_ide_probe(struct device *dev) | |||
109 | 108 | ||
110 | base = ioremap(offset, size); | 109 | base = ioremap(offset, size); |
111 | 110 | ||
112 | /* Setup MMIO ops. */ | ||
113 | hwif->host_flags = IDE_HFLAG_MMIO; | ||
114 | default_hwif_mmiops(hwif); | ||
115 | |||
116 | for (i = 0; i <= 7; i++) | 111 | for (i = 0; i <= 7; i++) |
117 | hw.io_ports_array[i] = | 112 | hw.io_ports_array[i] = |
118 | (unsigned long)(base + ((0x1f0 + i) << 5)); | 113 | (unsigned long)(base + ((0x1f0 + i) << 5)); |
@@ -121,15 +116,26 @@ static int __devinit swarm_ide_probe(struct device *dev) | |||
121 | hw.irq = K_INT_GB_IDE; | 116 | hw.irq = K_INT_GB_IDE; |
122 | hw.chipset = ide_generic; | 117 | hw.chipset = ide_generic; |
123 | 118 | ||
119 | hwif = ide_find_port_slot(&swarm_port_info); | ||
120 | if (hwif == NULL) | ||
121 | goto err; | ||
122 | |||
124 | ide_init_port_hw(hwif, &hw); | 123 | ide_init_port_hw(hwif, &hw); |
125 | 124 | ||
125 | /* Setup MMIO ops. */ | ||
126 | default_hwif_mmiops(hwif); | ||
127 | |||
126 | idx[0] = hwif->index; | 128 | idx[0] = hwif->index; |
127 | 129 | ||
128 | ide_device_add(idx, NULL); | 130 | ide_device_add(idx, &swarm_port_info); |
129 | 131 | ||
130 | dev_set_drvdata(dev, hwif); | 132 | dev_set_drvdata(dev, hwif); |
131 | 133 | ||
132 | return 0; | 134 | return 0; |
135 | err: | ||
136 | release_resource(&swarm_ide_resource); | ||
137 | iounmap(base); | ||
138 | return -ENOMEM; | ||
133 | } | 139 | } |
134 | 140 | ||
135 | static struct device_driver swarm_ide_driver = { | 141 | static struct device_driver swarm_ide_driver = { |
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c index f2de00adf147..80d19c0eb780 100644 --- a/drivers/ide/pci/alim15x3.c +++ b/drivers/ide/pci/alim15x3.c | |||
@@ -69,7 +69,8 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
69 | { | 69 | { |
70 | ide_hwif_t *hwif = HWIF(drive); | 70 | ide_hwif_t *hwif = HWIF(drive); |
71 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 71 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
72 | int s_time, a_time, c_time; | 72 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); |
73 | int s_time = t->setup, a_time = t->active, c_time = t->cycle; | ||
73 | u8 s_clc, a_clc, r_clc; | 74 | u8 s_clc, a_clc, r_clc; |
74 | unsigned long flags; | 75 | unsigned long flags; |
75 | int bus_speed = ide_pci_clk ? ide_pci_clk : 33; | 76 | int bus_speed = ide_pci_clk ? ide_pci_clk : 33; |
@@ -78,13 +79,10 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
78 | u8 cd_dma_fifo = 0; | 79 | u8 cd_dma_fifo = 0; |
79 | int unit = drive->select.b.unit & 1; | 80 | int unit = drive->select.b.unit & 1; |
80 | 81 | ||
81 | s_time = ide_pio_timings[pio].setup_time; | ||
82 | a_time = ide_pio_timings[pio].active_time; | ||
83 | if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) | 82 | if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) |
84 | s_clc = 0; | 83 | s_clc = 0; |
85 | if ((a_clc = (a_time * bus_speed + 999) / 1000) >= 8) | 84 | if ((a_clc = (a_time * bus_speed + 999) / 1000) >= 8) |
86 | a_clc = 0; | 85 | a_clc = 0; |
87 | c_time = ide_pio_timings[pio].cycle_time; | ||
88 | 86 | ||
89 | if (!(r_clc = (c_time * bus_speed + 999) / 1000 - a_clc - s_clc)) { | 87 | if (!(r_clc = (c_time * bus_speed + 999) / 1000 - a_clc - s_clc)) { |
90 | r_clc = 1; | 88 | r_clc = 1; |
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c index ad222206a429..0bfcdd0e77b3 100644 --- a/drivers/ide/pci/amd74xx.c +++ b/drivers/ide/pci/amd74xx.c | |||
@@ -21,8 +21,6 @@ | |||
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/ide.h> | 22 | #include <linux/ide.h> |
23 | 23 | ||
24 | #include "ide-timing.h" | ||
25 | |||
26 | enum { | 24 | enum { |
27 | AMD_IDE_CONFIG = 0x41, | 25 | AMD_IDE_CONFIG = 0x41, |
28 | AMD_CABLE_DETECT = 0x42, | 26 | AMD_CABLE_DETECT = 0x42, |
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c index cd1ba14984ab..1ad1e23e3105 100644 --- a/drivers/ide/pci/cmd640.c +++ b/drivers/ide/pci/cmd640.c | |||
@@ -521,6 +521,7 @@ static void program_drive_counts(ide_drive_t *drive, unsigned int index) | |||
521 | static void cmd640_set_mode(ide_drive_t *drive, unsigned int index, | 521 | static void cmd640_set_mode(ide_drive_t *drive, unsigned int index, |
522 | u8 pio_mode, unsigned int cycle_time) | 522 | u8 pio_mode, unsigned int cycle_time) |
523 | { | 523 | { |
524 | struct ide_timing *t; | ||
524 | int setup_time, active_time, recovery_time, clock_time; | 525 | int setup_time, active_time, recovery_time, clock_time; |
525 | u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; | 526 | u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; |
526 | int bus_speed; | 527 | int bus_speed; |
@@ -532,8 +533,11 @@ static void cmd640_set_mode(ide_drive_t *drive, unsigned int index, | |||
532 | 533 | ||
533 | if (pio_mode > 5) | 534 | if (pio_mode > 5) |
534 | pio_mode = 5; | 535 | pio_mode = 5; |
535 | setup_time = ide_pio_timings[pio_mode].setup_time; | 536 | |
536 | active_time = ide_pio_timings[pio_mode].active_time; | 537 | t = ide_timing_find_mode(XFER_PIO_0 + pio_mode); |
538 | setup_time = t->setup; | ||
539 | active_time = t->active; | ||
540 | |||
537 | recovery_time = cycle_time - (setup_time + active_time); | 541 | recovery_time = cycle_time - (setup_time + active_time); |
538 | clock_time = 1000 / bus_speed; | 542 | clock_time = 1000 / bus_speed; |
539 | cycle_count = DIV_ROUND_UP(cycle_time, clock_time); | 543 | cycle_count = DIV_ROUND_UP(cycle_time, clock_time); |
@@ -607,11 +611,40 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
607 | 611 | ||
608 | display_clocks(index); | 612 | display_clocks(index); |
609 | } | 613 | } |
614 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
615 | |||
616 | static void cmd640_init_dev(ide_drive_t *drive) | ||
617 | { | ||
618 | unsigned int i = drive->hwif->channel * 2 + drive->select.b.unit; | ||
619 | |||
620 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
621 | /* | ||
622 | * Reset timing to the slowest speed and turn off prefetch. | ||
623 | * This way, the drive identify code has a better chance. | ||
624 | */ | ||
625 | setup_counts[i] = 4; /* max possible */ | ||
626 | active_counts[i] = 16; /* max possible */ | ||
627 | recovery_counts[i] = 16; /* max possible */ | ||
628 | program_drive_counts(drive, i); | ||
629 | set_prefetch_mode(drive, i, 0); | ||
630 | printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch cleared\n", i); | ||
631 | #else | ||
632 | /* | ||
633 | * Set the drive unmask flags to match the prefetch setting. | ||
634 | */ | ||
635 | check_prefetch(drive, i); | ||
636 | printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n", | ||
637 | i, drive->no_io_32bit ? "off" : "on"); | ||
638 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
639 | } | ||
640 | |||
610 | 641 | ||
611 | static const struct ide_port_ops cmd640_port_ops = { | 642 | static const struct ide_port_ops cmd640_port_ops = { |
643 | .init_dev = cmd640_init_dev, | ||
644 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
612 | .set_pio_mode = cmd640_set_pio_mode, | 645 | .set_pio_mode = cmd640_set_pio_mode, |
646 | #endif | ||
613 | }; | 647 | }; |
614 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
615 | 648 | ||
616 | static int pci_conf1(void) | 649 | static int pci_conf1(void) |
617 | { | 650 | { |
@@ -654,10 +687,8 @@ static const struct ide_port_info cmd640_port_info __initdata = { | |||
654 | IDE_HFLAG_NO_DMA | | 687 | IDE_HFLAG_NO_DMA | |
655 | IDE_HFLAG_ABUSE_PREFETCH | | 688 | IDE_HFLAG_ABUSE_PREFETCH | |
656 | IDE_HFLAG_ABUSE_FAST_DEVSEL, | 689 | IDE_HFLAG_ABUSE_FAST_DEVSEL, |
657 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
658 | .port_ops = &cmd640_port_ops, | 690 | .port_ops = &cmd640_port_ops, |
659 | .pio_mask = ATA_PIO5, | 691 | .pio_mask = ATA_PIO5, |
660 | #endif | ||
661 | }; | 692 | }; |
662 | 693 | ||
663 | static int cmd640x_init_one(unsigned long base, unsigned long ctl) | 694 | static int cmd640x_init_one(unsigned long base, unsigned long ctl) |
@@ -683,12 +714,8 @@ static int cmd640x_init_one(unsigned long base, unsigned long ctl) | |||
683 | */ | 714 | */ |
684 | static int __init cmd640x_init(void) | 715 | static int __init cmd640x_init(void) |
685 | { | 716 | { |
686 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
687 | int second_port_toggled = 0; | ||
688 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
689 | int second_port_cmd640 = 0, rc; | 717 | int second_port_cmd640 = 0, rc; |
690 | const char *bus_type, *port2; | 718 | const char *bus_type, *port2; |
691 | unsigned int index; | ||
692 | u8 b, cfr; | 719 | u8 b, cfr; |
693 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | 720 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
694 | hw_regs_t hw[2]; | 721 | hw_regs_t hw[2]; |
@@ -774,88 +801,44 @@ static int __init cmd640x_init(void) | |||
774 | put_cmd640_reg(CMDTIM, 0); | 801 | put_cmd640_reg(CMDTIM, 0); |
775 | put_cmd640_reg(BRST, 0x40); | 802 | put_cmd640_reg(BRST, 0x40); |
776 | 803 | ||
777 | cmd_hwif1 = ide_find_port(); | 804 | b = get_cmd640_reg(CNTRL); |
778 | 805 | ||
779 | /* | 806 | /* |
780 | * Try to enable the secondary interface, if not already enabled | 807 | * Try to enable the secondary interface, if not already enabled |
781 | */ | 808 | */ |
782 | if (cmd_hwif1 && | 809 | if (secondary_port_responding()) { |
783 | cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) { | 810 | if ((b & CNTRL_ENA_2ND)) { |
784 | port2 = "not probed"; | 811 | second_port_cmd640 = 1; |
812 | port2 = "okay"; | ||
813 | } else if (cmd640_vlb) { | ||
814 | second_port_cmd640 = 1; | ||
815 | port2 = "alive"; | ||
816 | } else | ||
817 | port2 = "not cmd640"; | ||
785 | } else { | 818 | } else { |
786 | b = get_cmd640_reg(CNTRL); | 819 | put_cmd640_reg(CNTRL, b ^ CNTRL_ENA_2ND); /* toggle the bit */ |
787 | if (secondary_port_responding()) { | 820 | if (secondary_port_responding()) { |
788 | if ((b & CNTRL_ENA_2ND)) { | 821 | second_port_cmd640 = 1; |
789 | second_port_cmd640 = 1; | 822 | port2 = "enabled"; |
790 | port2 = "okay"; | ||
791 | } else if (cmd640_vlb) { | ||
792 | second_port_cmd640 = 1; | ||
793 | port2 = "alive"; | ||
794 | } else | ||
795 | port2 = "not cmd640"; | ||
796 | } else { | 823 | } else { |
797 | put_cmd640_reg(CNTRL, b ^ CNTRL_ENA_2ND); /* toggle the bit */ | 824 | put_cmd640_reg(CNTRL, b); /* restore original setting */ |
798 | if (secondary_port_responding()) { | 825 | port2 = "not responding"; |
799 | second_port_cmd640 = 1; | ||
800 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
801 | second_port_toggled = 1; | ||
802 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
803 | port2 = "enabled"; | ||
804 | } else { | ||
805 | put_cmd640_reg(CNTRL, b); /* restore original setting */ | ||
806 | port2 = "not responding"; | ||
807 | } | ||
808 | } | 826 | } |
809 | } | 827 | } |
810 | 828 | ||
811 | /* | 829 | /* |
812 | * Initialize data for secondary cmd640 port, if enabled | 830 | * Initialize data for secondary cmd640 port, if enabled |
813 | */ | 831 | */ |
814 | if (second_port_cmd640 && cmd_hwif1) { | 832 | if (second_port_cmd640) { |
815 | ide_init_port_hw(cmd_hwif1, &hw[1]); | 833 | cmd_hwif1 = ide_find_port(); |
816 | idx[1] = cmd_hwif1->index; | 834 | if (cmd_hwif1) { |
835 | ide_init_port_hw(cmd_hwif1, &hw[1]); | ||
836 | idx[1] = cmd_hwif1->index; | ||
837 | } | ||
817 | } | 838 | } |
818 | printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n", | 839 | printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n", |
819 | second_port_cmd640 ? "" : "not ", port2); | 840 | second_port_cmd640 ? "" : "not ", port2); |
820 | 841 | ||
821 | /* | ||
822 | * Establish initial timings/prefetch for all drives. | ||
823 | * Do not unnecessarily disturb any prior BIOS setup of these. | ||
824 | */ | ||
825 | for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) { | ||
826 | ide_drive_t *drive; | ||
827 | |||
828 | if (index > 1) { | ||
829 | if (cmd_hwif1 == NULL) | ||
830 | continue; | ||
831 | drive = &cmd_hwif1->drives[index & 1]; | ||
832 | } else { | ||
833 | if (cmd_hwif0 == NULL) | ||
834 | continue; | ||
835 | drive = &cmd_hwif0->drives[index & 1]; | ||
836 | } | ||
837 | |||
838 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | ||
839 | /* | ||
840 | * Reset timing to the slowest speed and turn off prefetch. | ||
841 | * This way, the drive identify code has a better chance. | ||
842 | */ | ||
843 | setup_counts [index] = 4; /* max possible */ | ||
844 | active_counts [index] = 16; /* max possible */ | ||
845 | recovery_counts [index] = 16; /* max possible */ | ||
846 | program_drive_counts(drive, index); | ||
847 | set_prefetch_mode(drive, index, 0); | ||
848 | printk("cmd640: drive%d timings/prefetch cleared\n", index); | ||
849 | #else | ||
850 | /* | ||
851 | * Set the drive unmask flags to match the prefetch setting | ||
852 | */ | ||
853 | check_prefetch(drive, index); | ||
854 | printk("cmd640: drive%d timings/prefetch(%s) preserved\n", | ||
855 | index, drive->no_io_32bit ? "off" : "on"); | ||
856 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | ||
857 | } | ||
858 | |||
859 | #ifdef CMD640_DUMP_REGS | 842 | #ifdef CMD640_DUMP_REGS |
860 | cmd640_dump_regs(); | 843 | cmd640_dump_regs(); |
861 | #endif | 844 | #endif |
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c index ca4774aa27ee..cfa784bacf48 100644 --- a/drivers/ide/pci/cmd64x.c +++ b/drivers/ide/pci/cmd64x.c | |||
@@ -116,6 +116,7 @@ static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio) | |||
116 | { | 116 | { |
117 | ide_hwif_t *hwif = HWIF(drive); | 117 | ide_hwif_t *hwif = HWIF(drive); |
118 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 118 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
119 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
119 | unsigned int cycle_time; | 120 | unsigned int cycle_time; |
120 | u8 setup_count, arttim = 0; | 121 | u8 setup_count, arttim = 0; |
121 | 122 | ||
@@ -124,10 +125,9 @@ static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio) | |||
124 | 125 | ||
125 | cycle_time = ide_pio_cycle_time(drive, pio); | 126 | cycle_time = ide_pio_cycle_time(drive, pio); |
126 | 127 | ||
127 | program_cycle_times(drive, cycle_time, | 128 | program_cycle_times(drive, cycle_time, t->active); |
128 | ide_pio_timings[pio].active_time); | ||
129 | 129 | ||
130 | setup_count = quantize_timing(ide_pio_timings[pio].setup_time, | 130 | setup_count = quantize_timing(t->setup, |
131 | 1000 / (ide_pci_clk ? ide_pci_clk : 33)); | 131 | 1000 / (ide_pci_clk ? ide_pci_clk : 33)); |
132 | 132 | ||
133 | /* | 133 | /* |
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c index 99fe91a191b8..dc97c48623f3 100644 --- a/drivers/ide/pci/cs5535.c +++ b/drivers/ide/pci/cs5535.c | |||
@@ -26,8 +26,6 @@ | |||
26 | #include <linux/pci.h> | 26 | #include <linux/pci.h> |
27 | #include <linux/ide.h> | 27 | #include <linux/ide.h> |
28 | 28 | ||
29 | #include "ide-timing.h" | ||
30 | |||
31 | #define MSR_ATAC_BASE 0x51300000 | 29 | #define MSR_ATAC_BASE 0x51300000 |
32 | #define ATAC_GLD_MSR_CAP (MSR_ATAC_BASE+0) | 30 | #define ATAC_GLD_MSR_CAP (MSR_ATAC_BASE+0) |
33 | #define ATAC_GLD_MSR_CONFIG (MSR_ATAC_BASE+0x01) | 31 | #define ATAC_GLD_MSR_CONFIG (MSR_ATAC_BASE+0x01) |
@@ -75,13 +73,11 @@ static unsigned int cs5535_udma_timings[5] = | |||
75 | */ | 73 | */ |
76 | static void cs5535_set_speed(ide_drive_t *drive, const u8 speed) | 74 | static void cs5535_set_speed(ide_drive_t *drive, const u8 speed) |
77 | { | 75 | { |
78 | |||
79 | u32 reg = 0, dummy; | 76 | u32 reg = 0, dummy; |
80 | int unit = drive->select.b.unit; | 77 | int unit = drive->select.b.unit; |
81 | 78 | ||
82 | |||
83 | /* Set the PIO timings */ | 79 | /* Set the PIO timings */ |
84 | if ((speed & XFER_MODE) == XFER_PIO) { | 80 | if (speed < XFER_SW_DMA_0) { |
85 | ide_drive_t *pair = ide_get_paired_drive(drive); | 81 | ide_drive_t *pair = ide_get_paired_drive(drive); |
86 | u8 cmd, pioa; | 82 | u8 cmd, pioa; |
87 | 83 | ||
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c index 8c534afcb6c8..e14ad5530fa4 100644 --- a/drivers/ide/pci/cy82c693.c +++ b/drivers/ide/pci/cy82c693.c | |||
@@ -133,6 +133,7 @@ static int calc_clk(int time, int bus_speed) | |||
133 | */ | 133 | */ |
134 | static void compute_clocks(u8 pio, pio_clocks_t *p_pclk) | 134 | static void compute_clocks(u8 pio, pio_clocks_t *p_pclk) |
135 | { | 135 | { |
136 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
136 | int clk1, clk2; | 137 | int clk1, clk2; |
137 | int bus_speed = ide_pci_clk ? ide_pci_clk : 33; | 138 | int bus_speed = ide_pci_clk ? ide_pci_clk : 33; |
138 | 139 | ||
@@ -141,15 +142,13 @@ static void compute_clocks(u8 pio, pio_clocks_t *p_pclk) | |||
141 | */ | 142 | */ |
142 | 143 | ||
143 | /* let's calc the address setup time clocks */ | 144 | /* let's calc the address setup time clocks */ |
144 | p_pclk->address_time = (u8)calc_clk(ide_pio_timings[pio].setup_time, bus_speed); | 145 | p_pclk->address_time = (u8)calc_clk(t->setup, bus_speed); |
145 | 146 | ||
146 | /* let's calc the active and recovery time clocks */ | 147 | /* let's calc the active and recovery time clocks */ |
147 | clk1 = calc_clk(ide_pio_timings[pio].active_time, bus_speed); | 148 | clk1 = calc_clk(t->active, bus_speed); |
148 | 149 | ||
149 | /* calc recovery timing */ | 150 | /* calc recovery timing */ |
150 | clk2 = ide_pio_timings[pio].cycle_time - | 151 | clk2 = t->cycle - t->active - t->setup; |
151 | ide_pio_timings[pio].active_time - | ||
152 | ide_pio_timings[pio].setup_time; | ||
153 | 152 | ||
154 | clk2 = calc_clk(clk2, bus_speed); | 153 | clk2 = calc_clk(clk2, bus_speed); |
155 | 154 | ||
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c index af0f30051d5a..0106e2a2df77 100644 --- a/drivers/ide/pci/delkin_cb.c +++ b/drivers/ide/pci/delkin_cb.c | |||
@@ -93,7 +93,6 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id) | |||
93 | 93 | ||
94 | i = hwif->index; | 94 | i = hwif->index; |
95 | 95 | ||
96 | ide_init_port_data(hwif, i); | ||
97 | ide_init_port_hw(hwif, &hw); | 96 | ide_init_port_hw(hwif, &hw); |
98 | 97 | ||
99 | idx[0] = i; | 98 | idx[0] = i; |
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c index 6ab04115286b..cbf647202994 100644 --- a/drivers/ide/pci/it821x.c +++ b/drivers/ide/pci/it821x.c | |||
@@ -512,8 +512,14 @@ static void __devinit it821x_quirkproc(ide_drive_t *drive) | |||
512 | } | 512 | } |
513 | 513 | ||
514 | static struct ide_dma_ops it821x_pass_through_dma_ops = { | 514 | static struct ide_dma_ops it821x_pass_through_dma_ops = { |
515 | .dma_host_set = ide_dma_host_set, | ||
516 | .dma_setup = ide_dma_setup, | ||
517 | .dma_exec_cmd = ide_dma_exec_cmd, | ||
515 | .dma_start = it821x_dma_start, | 518 | .dma_start = it821x_dma_start, |
516 | .dma_end = it821x_dma_end, | 519 | .dma_end = it821x_dma_end, |
520 | .dma_test_irq = ide_dma_test_irq, | ||
521 | .dma_timeout = ide_dma_timeout, | ||
522 | .dma_lost_irq = ide_dma_lost_irq, | ||
517 | }; | 523 | }; |
518 | 524 | ||
519 | /** | 525 | /** |
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c index 1584ebb6a185..789c66dfbde5 100644 --- a/drivers/ide/pci/scc_pata.c +++ b/drivers/ide/pci/scc_pata.c | |||
@@ -558,12 +558,9 @@ static int scc_ide_setup_pci_device(struct pci_dev *dev, | |||
558 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | 558 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
559 | int i; | 559 | int i; |
560 | 560 | ||
561 | hwif = ide_find_port(); | 561 | hwif = ide_find_port_slot(d); |
562 | if (hwif == NULL) { | 562 | if (hwif == NULL) |
563 | printk(KERN_ERR "%s: too many IDE interfaces, " | ||
564 | "no room in table\n", SCC_PATA_NAME); | ||
565 | return -ENOMEM; | 563 | return -ENOMEM; |
566 | } | ||
567 | 564 | ||
568 | memset(&hw, 0, sizeof(hw)); | 565 | memset(&hw, 0, sizeof(hw)); |
569 | for (i = 0; i <= 8; i++) | 566 | for (i = 0; i <= 8; i++) |
@@ -572,7 +569,6 @@ static int scc_ide_setup_pci_device(struct pci_dev *dev, | |||
572 | hw.dev = &dev->dev; | 569 | hw.dev = &dev->dev; |
573 | hw.chipset = ide_pci; | 570 | hw.chipset = ide_pci; |
574 | ide_init_port_hw(hwif, &hw); | 571 | ide_init_port_hw(hwif, &hw); |
575 | hwif->dev = &dev->dev; | ||
576 | 572 | ||
577 | idx[0] = hwif->index; | 573 | idx[0] = hwif->index; |
578 | 574 | ||
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c index 24513e3dcd6b..c79ff5b41088 100644 --- a/drivers/ide/pci/sgiioc4.c +++ b/drivers/ide/pci/sgiioc4.c | |||
@@ -568,6 +568,7 @@ static const struct ide_dma_ops sgiioc4_dma_ops = { | |||
568 | }; | 568 | }; |
569 | 569 | ||
570 | static const struct ide_port_info sgiioc4_port_info __devinitdata = { | 570 | static const struct ide_port_info sgiioc4_port_info __devinitdata = { |
571 | .name = DRV_NAME, | ||
571 | .chipset = ide_pci, | 572 | .chipset = ide_pci, |
572 | .init_dma = ide_dma_sgiioc4, | 573 | .init_dma = ide_dma_sgiioc4, |
573 | .port_ops = &sgiioc4_port_ops, | 574 | .port_ops = &sgiioc4_port_ops, |
@@ -587,13 +588,6 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev) | |||
587 | hw_regs_t hw; | 588 | hw_regs_t hw; |
588 | struct ide_port_info d = sgiioc4_port_info; | 589 | struct ide_port_info d = sgiioc4_port_info; |
589 | 590 | ||
590 | hwif = ide_find_port(); | ||
591 | if (hwif == NULL) { | ||
592 | printk(KERN_ERR "%s: too many IDE interfaces, no room in table\n", | ||
593 | DRV_NAME); | ||
594 | return -ENOMEM; | ||
595 | } | ||
596 | |||
597 | /* Get the CmdBlk and CtrlBlk Base Registers */ | 591 | /* Get the CmdBlk and CtrlBlk Base Registers */ |
598 | bar0 = pci_resource_start(dev, 0); | 592 | bar0 = pci_resource_start(dev, 0); |
599 | virt_base = ioremap(bar0, pci_resource_len(dev, 0)); | 593 | virt_base = ioremap(bar0, pci_resource_len(dev, 0)); |
@@ -608,11 +602,11 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev) | |||
608 | 602 | ||
609 | cmd_phys_base = bar0 + IOC4_CMD_OFFSET; | 603 | cmd_phys_base = bar0 + IOC4_CMD_OFFSET; |
610 | if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, | 604 | if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, |
611 | hwif->name)) { | 605 | DRV_NAME)) { |
612 | printk(KERN_ERR | 606 | printk(KERN_ERR |
613 | "%s : %s -- ERROR, Addresses " | 607 | "%s : %s -- ERROR, Addresses " |
614 | "0x%p to 0x%p ALREADY in use\n", | 608 | "0x%p to 0x%p ALREADY in use\n", |
615 | __func__, hwif->name, (void *) cmd_phys_base, | 609 | __func__, DRV_NAME, (void *) cmd_phys_base, |
616 | (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE); | 610 | (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE); |
617 | return -ENOMEM; | 611 | return -ENOMEM; |
618 | } | 612 | } |
@@ -623,9 +617,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev) | |||
623 | hw.irq = dev->irq; | 617 | hw.irq = dev->irq; |
624 | hw.chipset = ide_pci; | 618 | hw.chipset = ide_pci; |
625 | hw.dev = &dev->dev; | 619 | hw.dev = &dev->dev; |
626 | ide_init_port_hw(hwif, &hw); | ||
627 | 620 | ||
628 | hwif->dev = &dev->dev; | 621 | hwif = ide_find_port_slot(&d); |
622 | if (hwif == NULL) | ||
623 | goto err; | ||
624 | |||
625 | ide_init_port_hw(hwif, &hw); | ||
629 | 626 | ||
630 | /* The IOC4 uses MMIO rather than Port IO. */ | 627 | /* The IOC4 uses MMIO rather than Port IO. */ |
631 | default_hwif_mmiops(hwif); | 628 | default_hwif_mmiops(hwif); |
@@ -641,6 +638,10 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev) | |||
641 | return -EIO; | 638 | return -EIO; |
642 | 639 | ||
643 | return 0; | 640 | return 0; |
641 | err: | ||
642 | release_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE); | ||
643 | iounmap(virt_base); | ||
644 | return -ENOMEM; | ||
644 | } | 645 | } |
645 | 646 | ||
646 | static unsigned int __devinit | 647 | static unsigned int __devinit |
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c index b75e9bb390a7..6e9d7655d89c 100644 --- a/drivers/ide/pci/siimage.c +++ b/drivers/ide/pci/siimage.c | |||
@@ -421,8 +421,7 @@ static int sil_sata_reset_poll(ide_drive_t *drive) | |||
421 | if ((sata_stat & 0x03) != 0x03) { | 421 | if ((sata_stat & 0x03) != 0x03) { |
422 | printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", | 422 | printk(KERN_WARNING "%s: reset phy dead, status=0x%08x\n", |
423 | hwif->name, sata_stat); | 423 | hwif->name, sata_stat); |
424 | HWGROUP(drive)->polling = 0; | 424 | return -ENXIO; |
425 | return ide_started; | ||
426 | } | 425 | } |
427 | } | 426 | } |
428 | 427 | ||
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c index e127eb25ab63..2389945ca95d 100644 --- a/drivers/ide/pci/sis5513.c +++ b/drivers/ide/pci/sis5513.c | |||
@@ -52,8 +52,6 @@ | |||
52 | #include <linux/init.h> | 52 | #include <linux/init.h> |
53 | #include <linux/ide.h> | 53 | #include <linux/ide.h> |
54 | 54 | ||
55 | #include "ide-timing.h" | ||
56 | |||
57 | /* registers layout and init values are chipset family dependant */ | 55 | /* registers layout and init values are chipset family dependant */ |
58 | 56 | ||
59 | #define ATA_16 0x01 | 57 | #define ATA_16 0x01 |
@@ -616,7 +614,6 @@ MODULE_LICENSE("GPL"); | |||
616 | /* | 614 | /* |
617 | * TODO: | 615 | * TODO: |
618 | * - CLEANUP | 616 | * - CLEANUP |
619 | * - Use drivers/ide/ide-timing.h ! | ||
620 | * - More checks in the config registers (force values instead of | 617 | * - More checks in the config registers (force values instead of |
621 | * relying on the BIOS setting them correctly). | 618 | * relying on the BIOS setting them correctly). |
622 | * - Further optimisations ? | 619 | * - Further optimisations ? |
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c index ce84fa045d39..6efbde297174 100644 --- a/drivers/ide/pci/sl82c105.c +++ b/drivers/ide/pci/sl82c105.c | |||
@@ -47,10 +47,11 @@ | |||
47 | */ | 47 | */ |
48 | static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio) | 48 | static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio) |
49 | { | 49 | { |
50 | struct ide_timing *t = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
50 | unsigned int cmd_on, cmd_off; | 51 | unsigned int cmd_on, cmd_off; |
51 | u8 iordy = 0; | 52 | u8 iordy = 0; |
52 | 53 | ||
53 | cmd_on = (ide_pio_timings[pio].active_time + 29) / 30; | 54 | cmd_on = (t->active + 29) / 30; |
54 | cmd_off = (ide_pio_cycle_time(drive, pio) - 30 * cmd_on + 29) / 30; | 55 | cmd_off = (ide_pio_cycle_time(drive, pio) - 30 * cmd_on + 29) / 30; |
55 | 56 | ||
56 | if (cmd_on == 0) | 57 | if (cmd_on == 0) |
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c index 3ed9728abd24..e47384c70c40 100644 --- a/drivers/ide/pci/via82cxxx.c +++ b/drivers/ide/pci/via82cxxx.c | |||
@@ -35,8 +35,6 @@ | |||
35 | #include <asm/processor.h> | 35 | #include <asm/processor.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include "ide-timing.h" | ||
39 | |||
40 | #define VIA_IDE_ENABLE 0x40 | 38 | #define VIA_IDE_ENABLE 0x40 |
41 | #define VIA_IDE_CONFIG 0x41 | 39 | #define VIA_IDE_CONFIG 0x41 |
42 | #define VIA_FIFO_CONFIG 0x43 | 40 | #define VIA_FIFO_CONFIG 0x43 |
diff --git a/drivers/ide/ppc/Makefile b/drivers/ide/ppc/Makefile index 65af5848b28c..74e52adcdf4b 100644 --- a/drivers/ide/ppc/Makefile +++ b/drivers/ide/ppc/Makefile | |||
@@ -1,3 +1,2 @@ | |||
1 | 1 | ||
2 | obj-$(CONFIG_BLK_DEV_IDE_PMAC) += pmac.o | 2 | obj-$(CONFIG_BLK_DEV_IDE_PMAC) += pmac.o |
3 | obj-$(CONFIG_BLK_DEV_MPC8xx_IDE) += mpc8xx.o | ||
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c deleted file mode 100644 index 236f9c38e519..000000000000 --- a/drivers/ide/ppc/mpc8xx.c +++ /dev/null | |||
@@ -1,851 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de | ||
3 | * Modified for direct IDE interface | ||
4 | * by Thomas Lange, thomas@corelatus.com | ||
5 | * Modified for direct IDE interface on 8xx without using the PCMCIA | ||
6 | * controller | ||
7 | * by Steven.Scholz@imc-berlin.de | ||
8 | * Moved out of arch/ppc/kernel/m8xx_setup.c, other minor cleanups | ||
9 | * by Mathew Locke <mattl@mvista.com> | ||
10 | */ | ||
11 | |||
12 | #include <linux/errno.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/mm.h> | ||
15 | #include <linux/stddef.h> | ||
16 | #include <linux/unistd.h> | ||
17 | #include <linux/ptrace.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/user.h> | ||
20 | #include <linux/tty.h> | ||
21 | #include <linux/major.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/reboot.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/ioport.h> | ||
26 | #include <linux/ide.h> | ||
27 | #include <linux/bootmem.h> | ||
28 | |||
29 | #include <asm/mpc8xx.h> | ||
30 | #include <asm/mmu.h> | ||
31 | #include <asm/processor.h> | ||
32 | #include <asm/io.h> | ||
33 | #include <asm/pgtable.h> | ||
34 | #include <asm/ide.h> | ||
35 | #include <asm/8xx_immap.h> | ||
36 | #include <asm/machdep.h> | ||
37 | #include <asm/irq.h> | ||
38 | |||
39 | #define DRV_NAME "ide-mpc8xx" | ||
40 | |||
41 | static int identify (volatile u8 *p); | ||
42 | static void print_fixed (volatile u8 *p); | ||
43 | static void print_funcid (int func); | ||
44 | static int check_ide_device (unsigned long base); | ||
45 | |||
46 | static void ide_interrupt_ack (void *dev); | ||
47 | static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio); | ||
48 | |||
49 | typedef struct ide_ioport_desc { | ||
50 | unsigned long base_off; /* Offset to PCMCIA memory */ | ||
51 | unsigned long reg_off[IDE_NR_PORTS]; /* controller register offsets */ | ||
52 | int irq; /* IRQ */ | ||
53 | } ide_ioport_desc_t; | ||
54 | |||
55 | ide_ioport_desc_t ioport_dsc[MAX_HWIFS] = { | ||
56 | #ifdef IDE0_BASE_OFFSET | ||
57 | { IDE0_BASE_OFFSET, | ||
58 | { | ||
59 | IDE0_DATA_REG_OFFSET, | ||
60 | IDE0_ERROR_REG_OFFSET, | ||
61 | IDE0_NSECTOR_REG_OFFSET, | ||
62 | IDE0_SECTOR_REG_OFFSET, | ||
63 | IDE0_LCYL_REG_OFFSET, | ||
64 | IDE0_HCYL_REG_OFFSET, | ||
65 | IDE0_SELECT_REG_OFFSET, | ||
66 | IDE0_STATUS_REG_OFFSET, | ||
67 | IDE0_CONTROL_REG_OFFSET, | ||
68 | IDE0_IRQ_REG_OFFSET, | ||
69 | }, | ||
70 | IDE0_INTERRUPT, | ||
71 | }, | ||
72 | #ifdef IDE1_BASE_OFFSET | ||
73 | { IDE1_BASE_OFFSET, | ||
74 | { | ||
75 | IDE1_DATA_REG_OFFSET, | ||
76 | IDE1_ERROR_REG_OFFSET, | ||
77 | IDE1_NSECTOR_REG_OFFSET, | ||
78 | IDE1_SECTOR_REG_OFFSET, | ||
79 | IDE1_LCYL_REG_OFFSET, | ||
80 | IDE1_HCYL_REG_OFFSET, | ||
81 | IDE1_SELECT_REG_OFFSET, | ||
82 | IDE1_STATUS_REG_OFFSET, | ||
83 | IDE1_CONTROL_REG_OFFSET, | ||
84 | IDE1_IRQ_REG_OFFSET, | ||
85 | }, | ||
86 | IDE1_INTERRUPT, | ||
87 | }, | ||
88 | #endif /* IDE1_BASE_OFFSET */ | ||
89 | #endif /* IDE0_BASE_OFFSET */ | ||
90 | }; | ||
91 | |||
92 | ide_pio_timings_t ide_pio_clocks[6]; | ||
93 | int hold_time[6] = {30, 20, 15, 10, 10, 10 }; /* PIO Mode 5 with IORDY (nonstandard) */ | ||
94 | |||
95 | /* | ||
96 | * Warning: only 1 (ONE) PCMCIA slot supported here, | ||
97 | * which must be correctly initialized by the firmware (PPCBoot). | ||
98 | */ | ||
99 | static int _slot_ = -1; /* will be read from PCMCIA registers */ | ||
100 | |||
101 | /* Make clock cycles and always round up */ | ||
102 | #define PCMCIA_MK_CLKS( t, T ) (( (t) * ((T)/1000000) + 999U ) / 1000U ) | ||
103 | |||
104 | #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4)) | ||
105 | #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4)) | ||
106 | |||
107 | /* | ||
108 | * The TQM850L hardware has two pins swapped! Grrrrgh! | ||
109 | */ | ||
110 | #ifdef CONFIG_TQM850L | ||
111 | #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXOE | ||
112 | #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXRESET | ||
113 | #else | ||
114 | #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXRESET | ||
115 | #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXOE | ||
116 | #endif | ||
117 | |||
118 | #if defined(CONFIG_BLK_DEV_MPC8xx_IDE) && defined(CONFIG_IDE_8xx_PCCARD) | ||
119 | #define PCMCIA_SCHLVL IDE0_INTERRUPT /* Status Change Interrupt Level */ | ||
120 | static int pcmcia_schlvl = PCMCIA_SCHLVL; | ||
121 | #endif | ||
122 | |||
123 | /* | ||
124 | * See include/linux/ide.h for definition of hw_regs_t (p, base) | ||
125 | */ | ||
126 | |||
127 | /* | ||
128 | * m8xx_ide_init_ports() for a direct IDE interface _using_ | ||
129 | * MPC8xx's internal PCMCIA interface | ||
130 | */ | ||
131 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) | ||
132 | static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port) | ||
133 | { | ||
134 | unsigned long *p = hw->io_ports_array; | ||
135 | int i; | ||
136 | |||
137 | typedef struct { | ||
138 | ulong br; | ||
139 | ulong or; | ||
140 | } pcmcia_win_t; | ||
141 | volatile pcmcia_win_t *win; | ||
142 | volatile pcmconf8xx_t *pcmp; | ||
143 | |||
144 | uint *pgcrx; | ||
145 | u32 pcmcia_phy_base; | ||
146 | u32 pcmcia_phy_end; | ||
147 | static unsigned long pcmcia_base = 0; | ||
148 | unsigned long base; | ||
149 | |||
150 | *p = 0; | ||
151 | |||
152 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); | ||
153 | |||
154 | if (!pcmcia_base) { | ||
155 | /* | ||
156 | * Read out PCMCIA registers. Since the reset values | ||
157 | * are undefined, we sure hope that they have been | ||
158 | * set up by firmware | ||
159 | */ | ||
160 | |||
161 | /* Scan all registers for valid settings */ | ||
162 | pcmcia_phy_base = 0xFFFFFFFF; | ||
163 | pcmcia_phy_end = 0; | ||
164 | /* br0 is start of brX and orX regs */ | ||
165 | win = (pcmcia_win_t *) \ | ||
166 | (&(((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0)); | ||
167 | for (i = 0; i < 8; i++) { | ||
168 | if (win->or & 1) { /* This bank is marked as valid */ | ||
169 | if (win->br < pcmcia_phy_base) { | ||
170 | pcmcia_phy_base = win->br; | ||
171 | } | ||
172 | if ((win->br + PCMCIA_MEM_SIZE) > pcmcia_phy_end) { | ||
173 | pcmcia_phy_end = win->br + PCMCIA_MEM_SIZE; | ||
174 | } | ||
175 | /* Check which slot that has been defined */ | ||
176 | _slot_ = (win->or >> 2) & 1; | ||
177 | |||
178 | } /* Valid bank */ | ||
179 | win++; | ||
180 | } /* for */ | ||
181 | |||
182 | printk ("PCMCIA slot %c: phys mem %08x...%08x (size %08x)\n", | ||
183 | 'A' + _slot_, | ||
184 | pcmcia_phy_base, pcmcia_phy_end, | ||
185 | pcmcia_phy_end - pcmcia_phy_base); | ||
186 | |||
187 | if (!request_mem_region(pcmcia_phy_base, | ||
188 | pcmcia_phy_end - pcmcia_phy_base, | ||
189 | DRV_NAME)) { | ||
190 | printk(KERN_ERR "%s: resources busy\n", DRV_NAME); | ||
191 | return -EBUSY; | ||
192 | } | ||
193 | |||
194 | pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base, | ||
195 | pcmcia_phy_end-pcmcia_phy_base); | ||
196 | |||
197 | #ifdef DEBUG | ||
198 | printk ("PCMCIA virt base: %08lx\n", pcmcia_base); | ||
199 | #endif | ||
200 | /* Compute clock cycles for PIO timings */ | ||
201 | for (i=0; i<6; ++i) { | ||
202 | bd_t *binfo = (bd_t *)__res; | ||
203 | |||
204 | hold_time[i] = | ||
205 | PCMCIA_MK_CLKS (hold_time[i], | ||
206 | binfo->bi_busfreq); | ||
207 | ide_pio_clocks[i].setup_time = | ||
208 | PCMCIA_MK_CLKS (ide_pio_timings[i].setup_time, | ||
209 | binfo->bi_busfreq); | ||
210 | ide_pio_clocks[i].active_time = | ||
211 | PCMCIA_MK_CLKS (ide_pio_timings[i].active_time, | ||
212 | binfo->bi_busfreq); | ||
213 | ide_pio_clocks[i].cycle_time = | ||
214 | PCMCIA_MK_CLKS (ide_pio_timings[i].cycle_time, | ||
215 | binfo->bi_busfreq); | ||
216 | #if 0 | ||
217 | printk ("PIO mode %d timings: %d/%d/%d => %d/%d/%d\n", | ||
218 | i, | ||
219 | ide_pio_clocks[i].setup_time, | ||
220 | ide_pio_clocks[i].active_time, | ||
221 | ide_pio_clocks[i].hold_time, | ||
222 | ide_pio_clocks[i].cycle_time, | ||
223 | ide_pio_timings[i].setup_time, | ||
224 | ide_pio_timings[i].active_time, | ||
225 | ide_pio_timings[i].hold_time, | ||
226 | ide_pio_timings[i].cycle_time); | ||
227 | #endif | ||
228 | } | ||
229 | } | ||
230 | |||
231 | if (_slot_ == -1) { | ||
232 | printk ("PCMCIA slot has not been defined! Using A as default\n"); | ||
233 | _slot_ = 0; | ||
234 | } | ||
235 | |||
236 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
237 | |||
238 | #ifdef DEBUG | ||
239 | printk ("PIPR = 0x%08X slot %c ==> mask = 0x%X\n", | ||
240 | pcmp->pcmc_pipr, | ||
241 | 'A' + _slot_, | ||
242 | M8XX_PCMCIA_CD1(_slot_) | M8XX_PCMCIA_CD2(_slot_) ); | ||
243 | #endif /* DEBUG */ | ||
244 | |||
245 | if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) { | ||
246 | printk ("No card in slot %c: PIPR=%08x\n", | ||
247 | 'A' + _slot_, (u32) pcmp->pcmc_pipr); | ||
248 | return -ENODEV; /* No card in slot */ | ||
249 | } | ||
250 | |||
251 | check_ide_device (pcmcia_base); | ||
252 | |||
253 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
254 | |||
255 | base = pcmcia_base + ioport_dsc[data_port].base_off; | ||
256 | #ifdef DEBUG | ||
257 | printk ("base: %08x + %08x = %08x\n", | ||
258 | pcmcia_base, ioport_dsc[data_port].base_off, base); | ||
259 | #endif | ||
260 | |||
261 | for (i = 0; i < IDE_NR_PORTS; ++i) { | ||
262 | #ifdef DEBUG | ||
263 | printk ("port[%d]: %08x + %08x = %08x\n", | ||
264 | i, | ||
265 | base, | ||
266 | ioport_dsc[data_port].reg_off[i], | ||
267 | i, base + ioport_dsc[data_port].reg_off[i]); | ||
268 | #endif | ||
269 | *p++ = base + ioport_dsc[data_port].reg_off[i]; | ||
270 | } | ||
271 | |||
272 | hw->irq = ioport_dsc[data_port].irq; | ||
273 | hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack; | ||
274 | |||
275 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
276 | { | ||
277 | unsigned int reg; | ||
278 | |||
279 | if (_slot_) | ||
280 | pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcrb; | ||
281 | else | ||
282 | pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcra; | ||
283 | |||
284 | reg = *pgcrx; | ||
285 | reg |= mk_int_int_mask (pcmcia_schlvl) << 24; | ||
286 | reg |= mk_int_int_mask (pcmcia_schlvl) << 16; | ||
287 | *pgcrx = reg; | ||
288 | } | ||
289 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
290 | |||
291 | /* Enable Harddisk Interrupt, | ||
292 | * and make it edge sensitive | ||
293 | */ | ||
294 | /* (11-18) Set edge detect for irq, no wakeup from low power mode */ | ||
295 | ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel |= | ||
296 | (0x80000000 >> ioport_dsc[data_port].irq); | ||
297 | |||
298 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
299 | /* Make sure we don't get garbage irq */ | ||
300 | ((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pscr = 0xFFFF; | ||
301 | |||
302 | /* Enable falling edge irq */ | ||
303 | pcmp->pcmc_per = 0x100000 >> (16 * _slot_); | ||
304 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
305 | |||
306 | hw->chipset = ide_generic; | ||
307 | |||
308 | return 0; | ||
309 | } | ||
310 | #endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */ | ||
311 | |||
312 | /* | ||
313 | * m8xx_ide_init_ports() for a direct IDE interface _not_ using | ||
314 | * MPC8xx's internal PCMCIA interface | ||
315 | */ | ||
316 | #if defined(CONFIG_IDE_EXT_DIRECT) | ||
317 | static int __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port) | ||
318 | { | ||
319 | unsigned long *p = hw->io_ports_array; | ||
320 | int i; | ||
321 | |||
322 | u32 ide_phy_base; | ||
323 | u32 ide_phy_end; | ||
324 | static unsigned long ide_base = 0; | ||
325 | unsigned long base; | ||
326 | |||
327 | *p = 0; | ||
328 | |||
329 | if (!ide_base) { | ||
330 | |||
331 | /* TODO: | ||
332 | * - add code to read ORx, BRx | ||
333 | */ | ||
334 | ide_phy_base = CFG_ATA_BASE_ADDR; | ||
335 | ide_phy_end = CFG_ATA_BASE_ADDR + 0x200; | ||
336 | |||
337 | printk ("IDE phys mem : %08x...%08x (size %08x)\n", | ||
338 | ide_phy_base, ide_phy_end, | ||
339 | ide_phy_end - ide_phy_base); | ||
340 | |||
341 | if (!request_mem_region(ide_phy_base, 0x200, DRV_NAME)) { | ||
342 | printk(KERN_ERR "%s: resources busy\n", DRV_NAME); | ||
343 | return -EBUSY; | ||
344 | } | ||
345 | |||
346 | ide_base=(unsigned long)ioremap(ide_phy_base, | ||
347 | ide_phy_end-ide_phy_base); | ||
348 | |||
349 | #ifdef DEBUG | ||
350 | printk ("IDE virt base: %08lx\n", ide_base); | ||
351 | #endif | ||
352 | } | ||
353 | |||
354 | base = ide_base + ioport_dsc[data_port].base_off; | ||
355 | #ifdef DEBUG | ||
356 | printk ("base: %08x + %08x = %08x\n", | ||
357 | ide_base, ioport_dsc[data_port].base_off, base); | ||
358 | #endif | ||
359 | |||
360 | for (i = 0; i < IDE_NR_PORTS; ++i) { | ||
361 | #ifdef DEBUG | ||
362 | printk ("port[%d]: %08x + %08x = %08x\n", | ||
363 | i, | ||
364 | base, | ||
365 | ioport_dsc[data_port].reg_off[i], | ||
366 | i, base + ioport_dsc[data_port].reg_off[i]); | ||
367 | #endif | ||
368 | *p++ = base + ioport_dsc[data_port].reg_off[i]; | ||
369 | } | ||
370 | |||
371 | /* direct connected IDE drive, i.e. external IRQ */ | ||
372 | hw->irq = ioport_dsc[data_port].irq; | ||
373 | hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack; | ||
374 | |||
375 | /* Enable Harddisk Interrupt, | ||
376 | * and make it edge sensitive | ||
377 | */ | ||
378 | /* (11-18) Set edge detect for irq, no wakeup from low power mode */ | ||
379 | ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |= | ||
380 | (0x80000000 >> ioport_dsc[data_port].irq); | ||
381 | |||
382 | hw->chipset = ide_generic; | ||
383 | |||
384 | return 0; | ||
385 | } | ||
386 | #endif /* CONFIG_IDE_8xx_DIRECT */ | ||
387 | |||
388 | |||
389 | /* -------------------------------------------------------------------- */ | ||
390 | |||
391 | |||
392 | /* PCMCIA Timing */ | ||
393 | #ifndef PCMCIA_SHT | ||
394 | #define PCMCIA_SHT(t) ((t & 0x0F)<<16) /* Strobe Hold Time */ | ||
395 | #define PCMCIA_SST(t) ((t & 0x0F)<<12) /* Strobe Setup Time */ | ||
396 | #define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */ | ||
397 | #endif | ||
398 | |||
399 | /* Calculate PIO timings */ | ||
400 | static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio) | ||
401 | { | ||
402 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) | ||
403 | volatile pcmconf8xx_t *pcmp; | ||
404 | ulong timing, mask, reg; | ||
405 | |||
406 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); | ||
407 | |||
408 | mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF)); | ||
409 | |||
410 | timing = PCMCIA_SHT(hold_time[pio] ) | ||
411 | | PCMCIA_SST(ide_pio_clocks[pio].setup_time ) | ||
412 | | PCMCIA_SL (ide_pio_clocks[pio].active_time) | ||
413 | ; | ||
414 | |||
415 | #if 1 | ||
416 | printk ("Setting timing bits 0x%08lx in PCMCIA controller\n", timing); | ||
417 | #endif | ||
418 | if ((reg = pcmp->pcmc_por0 & mask) != 0) | ||
419 | pcmp->pcmc_por0 = reg | timing; | ||
420 | |||
421 | if ((reg = pcmp->pcmc_por1 & mask) != 0) | ||
422 | pcmp->pcmc_por1 = reg | timing; | ||
423 | |||
424 | if ((reg = pcmp->pcmc_por2 & mask) != 0) | ||
425 | pcmp->pcmc_por2 = reg | timing; | ||
426 | |||
427 | if ((reg = pcmp->pcmc_por3 & mask) != 0) | ||
428 | pcmp->pcmc_por3 = reg | timing; | ||
429 | |||
430 | if ((reg = pcmp->pcmc_por4 & mask) != 0) | ||
431 | pcmp->pcmc_por4 = reg | timing; | ||
432 | |||
433 | if ((reg = pcmp->pcmc_por5 & mask) != 0) | ||
434 | pcmp->pcmc_por5 = reg | timing; | ||
435 | |||
436 | if ((reg = pcmp->pcmc_por6 & mask) != 0) | ||
437 | pcmp->pcmc_por6 = reg | timing; | ||
438 | |||
439 | if ((reg = pcmp->pcmc_por7 & mask) != 0) | ||
440 | pcmp->pcmc_por7 = reg | timing; | ||
441 | |||
442 | #elif defined(CONFIG_IDE_EXT_DIRECT) | ||
443 | |||
444 | printk("%s[%d] %s: not implemented yet!\n", | ||
445 | __FILE__, __LINE__, __func__); | ||
446 | #endif /* defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_PCMCIA */ | ||
447 | } | ||
448 | |||
449 | static const struct ide_port_ops m8xx_port_ops = { | ||
450 | .set_pio_mode = m8xx_ide_set_pio_mode, | ||
451 | }; | ||
452 | |||
453 | static void | ||
454 | ide_interrupt_ack (void *dev) | ||
455 | { | ||
456 | #ifdef CONFIG_IDE_8xx_PCCARD | ||
457 | u_int pscr, pipr; | ||
458 | |||
459 | #if (PCMCIA_SOCKETS_NO == 2) | ||
460 | u_int _slot_; | ||
461 | #endif | ||
462 | |||
463 | /* get interrupt sources */ | ||
464 | |||
465 | pscr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr; | ||
466 | pipr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr; | ||
467 | |||
468 | /* | ||
469 | * report only if both card detect signals are the same | ||
470 | * not too nice done, | ||
471 | * we depend on that CD2 is the bit to the left of CD1... | ||
472 | */ | ||
473 | |||
474 | if(_slot_==-1){ | ||
475 | printk("PCMCIA slot has not been defined! Using A as default\n"); | ||
476 | _slot_=0; | ||
477 | } | ||
478 | |||
479 | if(((pipr & M8XX_PCMCIA_CD2(_slot_)) >> 1) ^ | ||
480 | (pipr & M8XX_PCMCIA_CD1(_slot_)) ) { | ||
481 | printk ("card detect interrupt\n"); | ||
482 | } | ||
483 | /* clear the interrupt sources */ | ||
484 | ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr = pscr; | ||
485 | |||
486 | #else /* ! CONFIG_IDE_8xx_PCCARD */ | ||
487 | /* | ||
488 | * Only CONFIG_IDE_8xx_PCCARD is using the interrupt of the | ||
489 | * MPC8xx's PCMCIA controller, so there is nothing to be done here | ||
490 | * for CONFIG_IDE_8xx_DIRECT and CONFIG_IDE_EXT_DIRECT. | ||
491 | * The interrupt is handled somewhere else. -- Steven | ||
492 | */ | ||
493 | #endif /* CONFIG_IDE_8xx_PCCARD */ | ||
494 | } | ||
495 | |||
496 | |||
497 | |||
498 | /* | ||
499 | * CIS Tupel codes | ||
500 | */ | ||
501 | #define CISTPL_NULL 0x00 | ||
502 | #define CISTPL_DEVICE 0x01 | ||
503 | #define CISTPL_LONGLINK_CB 0x02 | ||
504 | #define CISTPL_INDIRECT 0x03 | ||
505 | #define CISTPL_CONFIG_CB 0x04 | ||
506 | #define CISTPL_CFTABLE_ENTRY_CB 0x05 | ||
507 | #define CISTPL_LONGLINK_MFC 0x06 | ||
508 | #define CISTPL_BAR 0x07 | ||
509 | #define CISTPL_PWR_MGMNT 0x08 | ||
510 | #define CISTPL_EXTDEVICE 0x09 | ||
511 | #define CISTPL_CHECKSUM 0x10 | ||
512 | #define CISTPL_LONGLINK_A 0x11 | ||
513 | #define CISTPL_LONGLINK_C 0x12 | ||
514 | #define CISTPL_LINKTARGET 0x13 | ||
515 | #define CISTPL_NO_LINK 0x14 | ||
516 | #define CISTPL_VERS_1 0x15 | ||
517 | #define CISTPL_ALTSTR 0x16 | ||
518 | #define CISTPL_DEVICE_A 0x17 | ||
519 | #define CISTPL_JEDEC_C 0x18 | ||
520 | #define CISTPL_JEDEC_A 0x19 | ||
521 | #define CISTPL_CONFIG 0x1a | ||
522 | #define CISTPL_CFTABLE_ENTRY 0x1b | ||
523 | #define CISTPL_DEVICE_OC 0x1c | ||
524 | #define CISTPL_DEVICE_OA 0x1d | ||
525 | #define CISTPL_DEVICE_GEO 0x1e | ||
526 | #define CISTPL_DEVICE_GEO_A 0x1f | ||
527 | #define CISTPL_MANFID 0x20 | ||
528 | #define CISTPL_FUNCID 0x21 | ||
529 | #define CISTPL_FUNCE 0x22 | ||
530 | #define CISTPL_SWIL 0x23 | ||
531 | #define CISTPL_END 0xff | ||
532 | |||
533 | /* | ||
534 | * CIS Function ID codes | ||
535 | */ | ||
536 | #define CISTPL_FUNCID_MULTI 0x00 | ||
537 | #define CISTPL_FUNCID_MEMORY 0x01 | ||
538 | #define CISTPL_FUNCID_SERIAL 0x02 | ||
539 | #define CISTPL_FUNCID_PARALLEL 0x03 | ||
540 | #define CISTPL_FUNCID_FIXED 0x04 | ||
541 | #define CISTPL_FUNCID_VIDEO 0x05 | ||
542 | #define CISTPL_FUNCID_NETWORK 0x06 | ||
543 | #define CISTPL_FUNCID_AIMS 0x07 | ||
544 | #define CISTPL_FUNCID_SCSI 0x08 | ||
545 | |||
546 | /* | ||
547 | * Fixed Disk FUNCE codes | ||
548 | */ | ||
549 | #define CISTPL_IDE_INTERFACE 0x01 | ||
550 | |||
551 | #define CISTPL_FUNCE_IDE_IFACE 0x01 | ||
552 | #define CISTPL_FUNCE_IDE_MASTER 0x02 | ||
553 | #define CISTPL_FUNCE_IDE_SLAVE 0x03 | ||
554 | |||
555 | /* First feature byte */ | ||
556 | #define CISTPL_IDE_SILICON 0x04 | ||
557 | #define CISTPL_IDE_UNIQUE 0x08 | ||
558 | #define CISTPL_IDE_DUAL 0x10 | ||
559 | |||
560 | /* Second feature byte */ | ||
561 | #define CISTPL_IDE_HAS_SLEEP 0x01 | ||
562 | #define CISTPL_IDE_HAS_STANDBY 0x02 | ||
563 | #define CISTPL_IDE_HAS_IDLE 0x04 | ||
564 | #define CISTPL_IDE_LOW_POWER 0x08 | ||
565 | #define CISTPL_IDE_REG_INHIBIT 0x10 | ||
566 | #define CISTPL_IDE_HAS_INDEX 0x20 | ||
567 | #define CISTPL_IDE_IOIS16 0x40 | ||
568 | |||
569 | |||
570 | /* -------------------------------------------------------------------- */ | ||
571 | |||
572 | |||
573 | #define MAX_TUPEL_SZ 512 | ||
574 | #define MAX_FEATURES 4 | ||
575 | |||
576 | static int check_ide_device (unsigned long base) | ||
577 | { | ||
578 | volatile u8 *ident = NULL; | ||
579 | volatile u8 *feature_p[MAX_FEATURES]; | ||
580 | volatile u8 *p, *start; | ||
581 | int n_features = 0; | ||
582 | u8 func_id = ~0; | ||
583 | u8 code, len; | ||
584 | unsigned short config_base = 0; | ||
585 | int found = 0; | ||
586 | int i; | ||
587 | |||
588 | #ifdef DEBUG | ||
589 | printk ("PCMCIA MEM: %08lX\n", base); | ||
590 | #endif | ||
591 | start = p = (volatile u8 *) base; | ||
592 | |||
593 | while ((p - start) < MAX_TUPEL_SZ) { | ||
594 | |||
595 | code = *p; p += 2; | ||
596 | |||
597 | if (code == 0xFF) { /* End of chain */ | ||
598 | break; | ||
599 | } | ||
600 | |||
601 | len = *p; p += 2; | ||
602 | #ifdef DEBUG_PCMCIA | ||
603 | { volatile u8 *q = p; | ||
604 | printk ("\nTuple code %02x length %d\n\tData:", | ||
605 | code, len); | ||
606 | |||
607 | for (i = 0; i < len; ++i) { | ||
608 | printk (" %02x", *q); | ||
609 | q+= 2; | ||
610 | } | ||
611 | } | ||
612 | #endif /* DEBUG_PCMCIA */ | ||
613 | switch (code) { | ||
614 | case CISTPL_VERS_1: | ||
615 | ident = p + 4; | ||
616 | break; | ||
617 | case CISTPL_FUNCID: | ||
618 | func_id = *p; | ||
619 | break; | ||
620 | case CISTPL_FUNCE: | ||
621 | if (n_features < MAX_FEATURES) | ||
622 | feature_p[n_features++] = p; | ||
623 | break; | ||
624 | case CISTPL_CONFIG: | ||
625 | config_base = (*(p+6) << 8) + (*(p+4)); | ||
626 | default: | ||
627 | break; | ||
628 | } | ||
629 | p += 2 * len; | ||
630 | } | ||
631 | |||
632 | found = identify (ident); | ||
633 | |||
634 | if (func_id != ((u8)~0)) { | ||
635 | print_funcid (func_id); | ||
636 | |||
637 | if (func_id == CISTPL_FUNCID_FIXED) | ||
638 | found = 1; | ||
639 | else | ||
640 | return (1); /* no disk drive */ | ||
641 | } | ||
642 | |||
643 | for (i=0; i<n_features; ++i) { | ||
644 | print_fixed (feature_p[i]); | ||
645 | } | ||
646 | |||
647 | if (!found) { | ||
648 | printk ("unknown card type\n"); | ||
649 | return (1); | ||
650 | } | ||
651 | |||
652 | /* set level mode irq and I/O mapped device in config reg*/ | ||
653 | *((u8 *)(base + config_base)) = 0x41; | ||
654 | |||
655 | return (0); | ||
656 | } | ||
657 | |||
658 | /* ------------------------------------------------------------------------- */ | ||
659 | |||
660 | static void print_funcid (int func) | ||
661 | { | ||
662 | switch (func) { | ||
663 | case CISTPL_FUNCID_MULTI: | ||
664 | printk (" Multi-Function"); | ||
665 | break; | ||
666 | case CISTPL_FUNCID_MEMORY: | ||
667 | printk (" Memory"); | ||
668 | break; | ||
669 | case CISTPL_FUNCID_SERIAL: | ||
670 | printk (" Serial Port"); | ||
671 | break; | ||
672 | case CISTPL_FUNCID_PARALLEL: | ||
673 | printk (" Parallel Port"); | ||
674 | break; | ||
675 | case CISTPL_FUNCID_FIXED: | ||
676 | printk (" Fixed Disk"); | ||
677 | break; | ||
678 | case CISTPL_FUNCID_VIDEO: | ||
679 | printk (" Video Adapter"); | ||
680 | break; | ||
681 | case CISTPL_FUNCID_NETWORK: | ||
682 | printk (" Network Adapter"); | ||
683 | break; | ||
684 | case CISTPL_FUNCID_AIMS: | ||
685 | printk (" AIMS Card"); | ||
686 | break; | ||
687 | case CISTPL_FUNCID_SCSI: | ||
688 | printk (" SCSI Adapter"); | ||
689 | break; | ||
690 | default: | ||
691 | printk (" Unknown"); | ||
692 | break; | ||
693 | } | ||
694 | printk (" Card\n"); | ||
695 | } | ||
696 | |||
697 | /* ------------------------------------------------------------------------- */ | ||
698 | |||
699 | static void print_fixed (volatile u8 *p) | ||
700 | { | ||
701 | if (p == NULL) | ||
702 | return; | ||
703 | |||
704 | switch (*p) { | ||
705 | case CISTPL_FUNCE_IDE_IFACE: | ||
706 | { u8 iface = *(p+2); | ||
707 | |||
708 | printk ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown"); | ||
709 | printk (" interface "); | ||
710 | break; | ||
711 | } | ||
712 | case CISTPL_FUNCE_IDE_MASTER: | ||
713 | case CISTPL_FUNCE_IDE_SLAVE: | ||
714 | { u8 f1 = *(p+2); | ||
715 | u8 f2 = *(p+4); | ||
716 | |||
717 | printk ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]"); | ||
718 | |||
719 | if (f1 & CISTPL_IDE_UNIQUE) | ||
720 | printk (" [unique]"); | ||
721 | |||
722 | printk ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]"); | ||
723 | |||
724 | if (f2 & CISTPL_IDE_HAS_SLEEP) | ||
725 | printk (" [sleep]"); | ||
726 | |||
727 | if (f2 & CISTPL_IDE_HAS_STANDBY) | ||
728 | printk (" [standby]"); | ||
729 | |||
730 | if (f2 & CISTPL_IDE_HAS_IDLE) | ||
731 | printk (" [idle]"); | ||
732 | |||
733 | if (f2 & CISTPL_IDE_LOW_POWER) | ||
734 | printk (" [low power]"); | ||
735 | |||
736 | if (f2 & CISTPL_IDE_REG_INHIBIT) | ||
737 | printk (" [reg inhibit]"); | ||
738 | |||
739 | if (f2 & CISTPL_IDE_HAS_INDEX) | ||
740 | printk (" [index]"); | ||
741 | |||
742 | if (f2 & CISTPL_IDE_IOIS16) | ||
743 | printk (" [IOis16]"); | ||
744 | |||
745 | break; | ||
746 | } | ||
747 | } | ||
748 | printk ("\n"); | ||
749 | } | ||
750 | |||
751 | /* ------------------------------------------------------------------------- */ | ||
752 | |||
753 | |||
754 | #define MAX_IDENT_CHARS 64 | ||
755 | #define MAX_IDENT_FIELDS 4 | ||
756 | |||
757 | static u8 *known_cards[] = { | ||
758 | "ARGOSY PnPIDE D5", | ||
759 | NULL | ||
760 | }; | ||
761 | |||
762 | static int identify (volatile u8 *p) | ||
763 | { | ||
764 | u8 id_str[MAX_IDENT_CHARS]; | ||
765 | u8 data; | ||
766 | u8 *t; | ||
767 | u8 **card; | ||
768 | int i, done; | ||
769 | |||
770 | if (p == NULL) | ||
771 | return (0); /* Don't know */ | ||
772 | |||
773 | t = id_str; | ||
774 | done =0; | ||
775 | |||
776 | for (i=0; i<=4 && !done; ++i, p+=2) { | ||
777 | while ((data = *p) != '\0') { | ||
778 | if (data == 0xFF) { | ||
779 | done = 1; | ||
780 | break; | ||
781 | } | ||
782 | *t++ = data; | ||
783 | if (t == &id_str[MAX_IDENT_CHARS-1]) { | ||
784 | done = 1; | ||
785 | break; | ||
786 | } | ||
787 | p += 2; | ||
788 | } | ||
789 | if (!done) | ||
790 | *t++ = ' '; | ||
791 | } | ||
792 | *t = '\0'; | ||
793 | while (--t > id_str) { | ||
794 | if (*t == ' ') | ||
795 | *t = '\0'; | ||
796 | else | ||
797 | break; | ||
798 | } | ||
799 | printk ("Card ID: %s\n", id_str); | ||
800 | |||
801 | for (card=known_cards; *card; ++card) { | ||
802 | if (strcmp(*card, id_str) == 0) { /* found! */ | ||
803 | return (1); | ||
804 | } | ||
805 | } | ||
806 | |||
807 | return (0); /* don't know */ | ||
808 | } | ||
809 | |||
810 | static int __init mpc8xx_ide_probe(void) | ||
811 | { | ||
812 | hw_regs_t hw; | ||
813 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; | ||
814 | |||
815 | #ifdef IDE0_BASE_OFFSET | ||
816 | memset(&hw, 0, sizeof(hw)); | ||
817 | if (!m8xx_ide_init_ports(&hw, 0)) { | ||
818 | ide_hwif_t *hwif = ide_find_port(); | ||
819 | |||
820 | if (hwif) { | ||
821 | ide_init_port_hw(hwif, &hw); | ||
822 | hwif->pio_mask = ATA_PIO4; | ||
823 | hwif->port_ops = &m8xx_port_ops; | ||
824 | |||
825 | idx[0] = hwif->index; | ||
826 | } | ||
827 | } | ||
828 | #ifdef IDE1_BASE_OFFSET | ||
829 | memset(&hw, 0, sizeof(hw)); | ||
830 | if (!m8xx_ide_init_ports(&hw, 1)) { | ||
831 | ide_hwif_t *mate = ide_find_port(); | ||
832 | |||
833 | if (mate) { | ||
834 | ide_init_port_hw(mate, &hw); | ||
835 | mate->pio_mask = ATA_PIO4; | ||
836 | mate->port_ops = &m8xx_port_ops; | ||
837 | |||
838 | idx[1] = mate->index; | ||
839 | } | ||
840 | } | ||
841 | #endif | ||
842 | #endif | ||
843 | |||
844 | ide_device_add(idx, NULL); | ||
845 | |||
846 | return 0; | ||
847 | } | ||
848 | |||
849 | module_init(mpc8xx_ide_probe); | ||
850 | |||
851 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c index dcb2c466bb97..93fb9067c043 100644 --- a/drivers/ide/ppc/pmac.c +++ b/drivers/ide/ppc/pmac.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * for doing DMA. | 5 | * for doing DMA. |
6 | * | 6 | * |
7 | * Copyright (C) 1998-2003 Paul Mackerras & Ben. Herrenschmidt | 7 | * Copyright (C) 1998-2003 Paul Mackerras & Ben. Herrenschmidt |
8 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz | 8 | * Copyright (C) 2007-2008 Bartlomiej Zolnierkiewicz |
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or | 10 | * This program is free software; you can redistribute it and/or |
11 | * modify it under the terms of the GNU General Public License | 11 | * modify it under the terms of the GNU General Public License |
@@ -48,8 +48,6 @@ | |||
48 | #include <asm/mediabay.h> | 48 | #include <asm/mediabay.h> |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #include "../ide-timing.h" | ||
52 | |||
53 | #undef IDE_PMAC_DEBUG | 51 | #undef IDE_PMAC_DEBUG |
54 | 52 | ||
55 | #define DMA_WAIT_TIMEOUT 50 | 53 | #define DMA_WAIT_TIMEOUT 50 |
@@ -495,6 +493,7 @@ static void pmac_outbsync(ide_hwif_t *hwif, u8 value, unsigned long port) | |||
495 | static void | 493 | static void |
496 | pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio) | 494 | pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio) |
497 | { | 495 | { |
496 | struct ide_timing *tim = ide_timing_find_mode(XFER_PIO_0 + pio); | ||
498 | u32 *timings, t; | 497 | u32 *timings, t; |
499 | unsigned accessTicks, recTicks; | 498 | unsigned accessTicks, recTicks; |
500 | unsigned accessTime, recTime; | 499 | unsigned accessTime, recTime; |
@@ -526,10 +525,9 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
526 | } | 525 | } |
527 | case controller_kl_ata4: | 526 | case controller_kl_ata4: |
528 | /* 66Mhz cell */ | 527 | /* 66Mhz cell */ |
529 | recTime = cycle_time - ide_pio_timings[pio].active_time | 528 | recTime = cycle_time - tim->active - tim->setup; |
530 | - ide_pio_timings[pio].setup_time; | ||
531 | recTime = max(recTime, 150U); | 529 | recTime = max(recTime, 150U); |
532 | accessTime = ide_pio_timings[pio].active_time; | 530 | accessTime = tim->active; |
533 | accessTime = max(accessTime, 150U); | 531 | accessTime = max(accessTime, 150U); |
534 | accessTicks = SYSCLK_TICKS_66(accessTime); | 532 | accessTicks = SYSCLK_TICKS_66(accessTime); |
535 | accessTicks = min(accessTicks, 0x1fU); | 533 | accessTicks = min(accessTicks, 0x1fU); |
@@ -542,10 +540,9 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
542 | default: { | 540 | default: { |
543 | /* 33Mhz cell */ | 541 | /* 33Mhz cell */ |
544 | int ebit = 0; | 542 | int ebit = 0; |
545 | recTime = cycle_time - ide_pio_timings[pio].active_time | 543 | recTime = cycle_time - tim->active - tim->setup; |
546 | - ide_pio_timings[pio].setup_time; | ||
547 | recTime = max(recTime, 150U); | 544 | recTime = max(recTime, 150U); |
548 | accessTime = ide_pio_timings[pio].active_time; | 545 | accessTime = tim->active; |
549 | accessTime = max(accessTime, 150U); | 546 | accessTime = max(accessTime, 150U); |
550 | accessTicks = SYSCLK_TICKS(accessTime); | 547 | accessTicks = SYSCLK_TICKS(accessTime); |
551 | accessTicks = min(accessTicks, 0x1fU); | 548 | accessTicks = min(accessTicks, 0x1fU); |
@@ -1151,8 +1148,6 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) | |||
1151 | base = ioremap(macio_resource_start(mdev, 0), 0x400); | 1148 | base = ioremap(macio_resource_start(mdev, 0), 0x400); |
1152 | regbase = (unsigned long) base; | 1149 | regbase = (unsigned long) base; |
1153 | 1150 | ||
1154 | hwif->dev = &mdev->bus->pdev->dev; | ||
1155 | |||
1156 | pmif->mdev = mdev; | 1151 | pmif->mdev = mdev; |
1157 | pmif->node = mdev->ofdev.node; | 1152 | pmif->node = mdev->ofdev.node; |
1158 | pmif->regbase = regbase; | 1153 | pmif->regbase = regbase; |
@@ -1174,7 +1169,8 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) | |||
1174 | memset(&hw, 0, sizeof(hw)); | 1169 | memset(&hw, 0, sizeof(hw)); |
1175 | pmac_ide_init_ports(&hw, pmif->regbase); | 1170 | pmac_ide_init_ports(&hw, pmif->regbase); |
1176 | hw.irq = irq; | 1171 | hw.irq = irq; |
1177 | hw.dev = &mdev->ofdev.dev; | 1172 | hw.dev = &mdev->bus->pdev->dev; |
1173 | hw.parent = &mdev->ofdev.dev; | ||
1178 | 1174 | ||
1179 | rc = pmac_ide_setup_device(pmif, hwif, &hw); | 1175 | rc = pmac_ide_setup_device(pmif, hwif, &hw); |
1180 | if (rc != 0) { | 1176 | if (rc != 0) { |
@@ -1274,7 +1270,6 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1274 | goto out_free_pmif; | 1270 | goto out_free_pmif; |
1275 | } | 1271 | } |
1276 | 1272 | ||
1277 | hwif->dev = &pdev->dev; | ||
1278 | pmif->mdev = NULL; | 1273 | pmif->mdev = NULL; |
1279 | pmif->node = np; | 1274 | pmif->node = np; |
1280 | 1275 | ||
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c index abcfb1739d4d..65fc08b6b6d0 100644 --- a/drivers/ide/setup-pci.c +++ b/drivers/ide/setup-pci.c | |||
@@ -6,19 +6,15 @@ | |||
6 | * May be copied or modified under the terms of the GNU General Public License | 6 | * May be copied or modified under the terms of the GNU General Public License |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/module.h> | ||
10 | #include <linux/types.h> | 9 | #include <linux/types.h> |
11 | #include <linux/kernel.h> | 10 | #include <linux/kernel.h> |
12 | #include <linux/pci.h> | 11 | #include <linux/pci.h> |
13 | #include <linux/init.h> | 12 | #include <linux/init.h> |
14 | #include <linux/timer.h> | ||
15 | #include <linux/mm.h> | ||
16 | #include <linux/interrupt.h> | 13 | #include <linux/interrupt.h> |
17 | #include <linux/ide.h> | 14 | #include <linux/ide.h> |
18 | #include <linux/dma-mapping.h> | 15 | #include <linux/dma-mapping.h> |
19 | 16 | ||
20 | #include <asm/io.h> | 17 | #include <asm/io.h> |
21 | #include <asm/irq.h> | ||
22 | 18 | ||
23 | /** | 19 | /** |
24 | * ide_setup_pci_baseregs - place a PCI IDE controller native | 20 | * ide_setup_pci_baseregs - place a PCI IDE controller native |
@@ -319,25 +315,22 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, | |||
319 | 315 | ||
320 | ctl = pci_resource_start(dev, 2*port+1); | 316 | ctl = pci_resource_start(dev, 2*port+1); |
321 | base = pci_resource_start(dev, 2*port); | 317 | base = pci_resource_start(dev, 2*port); |
322 | if ((ctl && !base) || (base && !ctl)) { | 318 | } else { |
323 | printk(KERN_ERR "%s: inconsistent baseregs (BIOS) " | ||
324 | "for port %d, skipping\n", d->name, port); | ||
325 | return NULL; | ||
326 | } | ||
327 | } | ||
328 | if (!ctl) { | ||
329 | /* Use default values */ | 319 | /* Use default values */ |
330 | ctl = port ? 0x374 : 0x3f4; | 320 | ctl = port ? 0x374 : 0x3f4; |
331 | base = port ? 0x170 : 0x1f0; | 321 | base = port ? 0x170 : 0x1f0; |
332 | } | 322 | } |
333 | 323 | ||
334 | hwif = ide_find_port_slot(d); | 324 | if (!base || !ctl) { |
335 | if (hwif == NULL) { | 325 | printk(KERN_ERR "%s: bad PCI BARs for port %d, skipping\n", |
336 | printk(KERN_ERR "%s: too many IDE interfaces, no room in " | 326 | d->name, port); |
337 | "table\n", d->name); | ||
338 | return NULL; | 327 | return NULL; |
339 | } | 328 | } |
340 | 329 | ||
330 | hwif = ide_find_port_slot(d); | ||
331 | if (hwif == NULL) | ||
332 | return NULL; | ||
333 | |||
341 | memset(&hw, 0, sizeof(hw)); | 334 | memset(&hw, 0, sizeof(hw)); |
342 | hw.irq = irq; | 335 | hw.irq = irq; |
343 | hw.dev = &dev->dev; | 336 | hw.dev = &dev->dev; |
@@ -346,8 +339,6 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, | |||
346 | 339 | ||
347 | ide_init_port_hw(hwif, &hw); | 340 | ide_init_port_hw(hwif, &hw); |
348 | 341 | ||
349 | hwif->dev = &dev->dev; | ||
350 | |||
351 | return hwif; | 342 | return hwif; |
352 | } | 343 | } |
353 | 344 | ||
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 636af2862308..1921b8dbb242 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig | |||
@@ -179,17 +179,29 @@ config FUJITSU_LAPTOP | |||
179 | tristate "Fujitsu Laptop Extras" | 179 | tristate "Fujitsu Laptop Extras" |
180 | depends on X86 | 180 | depends on X86 |
181 | depends on ACPI | 181 | depends on ACPI |
182 | depends on INPUT | ||
182 | depends on BACKLIGHT_CLASS_DEVICE | 183 | depends on BACKLIGHT_CLASS_DEVICE |
183 | ---help--- | 184 | ---help--- |
184 | This is a driver for laptops built by Fujitsu: | 185 | This is a driver for laptops built by Fujitsu: |
185 | 186 | ||
186 | * P2xxx/P5xxx/S6xxx/S7xxx series Lifebooks | 187 | * P2xxx/P5xxx/S6xxx/S7xxx series Lifebooks |
187 | * Possibly other Fujitsu laptop models | 188 | * Possibly other Fujitsu laptop models |
189 | * Tested with S6410 and S7020 | ||
188 | 190 | ||
189 | It adds support for LCD brightness control. | 191 | It adds support for LCD brightness control and some hotkeys. |
190 | 192 | ||
191 | If you have a Fujitsu laptop, say Y or M here. | 193 | If you have a Fujitsu laptop, say Y or M here. |
192 | 194 | ||
195 | config FUJITSU_LAPTOP_DEBUG | ||
196 | bool "Verbose debug mode for Fujitsu Laptop Extras" | ||
197 | depends on FUJITSU_LAPTOP | ||
198 | default n | ||
199 | ---help--- | ||
200 | Enables extra debug output from the fujitsu extras driver, at the | ||
201 | expense of a slight increase in driver size. | ||
202 | |||
203 | If you are not sure, say N here. | ||
204 | |||
193 | config TC1100_WMI | 205 | config TC1100_WMI |
194 | tristate "HP Compaq TC1100 Tablet WMI Extras (EXPERIMENTAL)" | 206 | tristate "HP Compaq TC1100 Tablet WMI Extras (EXPERIMENTAL)" |
195 | depends on X86 && !X86_64 | 207 | depends on X86 && !X86_64 |
@@ -219,6 +231,23 @@ config MSI_LAPTOP | |||
219 | 231 | ||
220 | If you have an MSI S270 laptop, say Y or M here. | 232 | If you have an MSI S270 laptop, say Y or M here. |
221 | 233 | ||
234 | config COMPAL_LAPTOP | ||
235 | tristate "Compal Laptop Extras" | ||
236 | depends on X86 | ||
237 | depends on ACPI_EC | ||
238 | depends on BACKLIGHT_CLASS_DEVICE | ||
239 | ---help--- | ||
240 | This is a driver for laptops built by Compal: | ||
241 | |||
242 | Compal FL90/IFL90 | ||
243 | Compal FL91/IFL91 | ||
244 | Compal FL92/JFL92 | ||
245 | Compal FT00/IFT00 | ||
246 | |||
247 | It adds support for Bluetooth, WLAN and LCD brightness control. | ||
248 | |||
249 | If you have an Compal FL9x/IFL9x/FT00 laptop, say Y or M here. | ||
250 | |||
222 | config SONY_LAPTOP | 251 | config SONY_LAPTOP |
223 | tristate "Sony Laptop Extras" | 252 | tristate "Sony Laptop Extras" |
224 | depends on X86 && ACPI | 253 | depends on X86 && ACPI |
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 1952875a272e..a6dac6a2e7e5 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile | |||
@@ -5,10 +5,11 @@ obj- := misc.o # Dummy rule to force built-in.o to be made | |||
5 | 5 | ||
6 | obj-$(CONFIG_IBM_ASM) += ibmasm/ | 6 | obj-$(CONFIG_IBM_ASM) += ibmasm/ |
7 | obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ | 7 | obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ |
8 | obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o | ||
9 | obj-$(CONFIG_ACER_WMI) += acer-wmi.o | ||
10 | obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o | 8 | obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o |
11 | obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o | 9 | obj-$(CONFIG_EEEPC_LAPTOP) += eeepc-laptop.o |
10 | obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o | ||
11 | obj-$(CONFIG_COMPAL_LAPTOP) += compal-laptop.o | ||
12 | obj-$(CONFIG_ACER_WMI) += acer-wmi.o | ||
12 | obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o | 13 | obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o |
13 | obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o | 14 | obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o |
14 | obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o | 15 | obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o |
diff --git a/drivers/misc/acer-wmi.c b/drivers/misc/acer-wmi.c index dd13a3749927..e7a3fe508dff 100644 --- a/drivers/misc/acer-wmi.c +++ b/drivers/misc/acer-wmi.c | |||
@@ -22,18 +22,18 @@ | |||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 | */ | 23 | */ |
24 | 24 | ||
25 | #define ACER_WMI_VERSION "0.1" | ||
26 | |||
27 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
28 | #include <linux/module.h> | 26 | #include <linux/module.h> |
29 | #include <linux/init.h> | 27 | #include <linux/init.h> |
30 | #include <linux/types.h> | 28 | #include <linux/types.h> |
31 | #include <linux/dmi.h> | 29 | #include <linux/dmi.h> |
30 | #include <linux/fb.h> | ||
32 | #include <linux/backlight.h> | 31 | #include <linux/backlight.h> |
33 | #include <linux/leds.h> | 32 | #include <linux/leds.h> |
34 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
35 | #include <linux/acpi.h> | 34 | #include <linux/acpi.h> |
36 | #include <linux/i8042.h> | 35 | #include <linux/i8042.h> |
36 | #include <linux/debugfs.h> | ||
37 | 37 | ||
38 | #include <acpi/acpi_drivers.h> | 38 | #include <acpi/acpi_drivers.h> |
39 | 39 | ||
@@ -87,6 +87,7 @@ struct acer_quirks { | |||
87 | * Acer ACPI method GUIDs | 87 | * Acer ACPI method GUIDs |
88 | */ | 88 | */ |
89 | #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" | 89 | #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" |
90 | #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C" | ||
90 | #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3" | 91 | #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3" |
91 | #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A" | 92 | #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A" |
92 | 93 | ||
@@ -150,6 +151,12 @@ struct acer_data { | |||
150 | int brightness; | 151 | int brightness; |
151 | }; | 152 | }; |
152 | 153 | ||
154 | struct acer_debug { | ||
155 | struct dentry *root; | ||
156 | struct dentry *devices; | ||
157 | u32 wmid_devices; | ||
158 | }; | ||
159 | |||
153 | /* Each low-level interface must define at least some of the following */ | 160 | /* Each low-level interface must define at least some of the following */ |
154 | struct wmi_interface { | 161 | struct wmi_interface { |
155 | /* The WMI device type */ | 162 | /* The WMI device type */ |
@@ -160,6 +167,9 @@ struct wmi_interface { | |||
160 | 167 | ||
161 | /* Private data for the current interface */ | 168 | /* Private data for the current interface */ |
162 | struct acer_data data; | 169 | struct acer_data data; |
170 | |||
171 | /* debugfs entries associated with this interface */ | ||
172 | struct acer_debug debug; | ||
163 | }; | 173 | }; |
164 | 174 | ||
165 | /* The static interface pointer, points to the currently detected interface */ | 175 | /* The static interface pointer, points to the currently detected interface */ |
@@ -174,7 +184,7 @@ static struct wmi_interface *interface; | |||
174 | struct quirk_entry { | 184 | struct quirk_entry { |
175 | u8 wireless; | 185 | u8 wireless; |
176 | u8 mailled; | 186 | u8 mailled; |
177 | u8 brightness; | 187 | s8 brightness; |
178 | u8 bluetooth; | 188 | u8 bluetooth; |
179 | }; | 189 | }; |
180 | 190 | ||
@@ -198,6 +208,10 @@ static int dmi_matched(const struct dmi_system_id *dmi) | |||
198 | static struct quirk_entry quirk_unknown = { | 208 | static struct quirk_entry quirk_unknown = { |
199 | }; | 209 | }; |
200 | 210 | ||
211 | static struct quirk_entry quirk_acer_aspire_1520 = { | ||
212 | .brightness = -1, | ||
213 | }; | ||
214 | |||
201 | static struct quirk_entry quirk_acer_travelmate_2490 = { | 215 | static struct quirk_entry quirk_acer_travelmate_2490 = { |
202 | .mailled = 1, | 216 | .mailled = 1, |
203 | }; | 217 | }; |
@@ -207,9 +221,31 @@ static struct quirk_entry quirk_medion_md_98300 = { | |||
207 | .wireless = 1, | 221 | .wireless = 1, |
208 | }; | 222 | }; |
209 | 223 | ||
224 | static struct quirk_entry quirk_fujitsu_amilo_li_1718 = { | ||
225 | .wireless = 2, | ||
226 | }; | ||
227 | |||
210 | static struct dmi_system_id acer_quirks[] = { | 228 | static struct dmi_system_id acer_quirks[] = { |
211 | { | 229 | { |
212 | .callback = dmi_matched, | 230 | .callback = dmi_matched, |
231 | .ident = "Acer Aspire 1360", | ||
232 | .matches = { | ||
233 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | ||
234 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"), | ||
235 | }, | ||
236 | .driver_data = &quirk_acer_aspire_1520, | ||
237 | }, | ||
238 | { | ||
239 | .callback = dmi_matched, | ||
240 | .ident = "Acer Aspire 1520", | ||
241 | .matches = { | ||
242 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | ||
243 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"), | ||
244 | }, | ||
245 | .driver_data = &quirk_acer_aspire_1520, | ||
246 | }, | ||
247 | { | ||
248 | .callback = dmi_matched, | ||
213 | .ident = "Acer Aspire 3100", | 249 | .ident = "Acer Aspire 3100", |
214 | .matches = { | 250 | .matches = { |
215 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), | 251 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
@@ -300,6 +336,15 @@ static struct dmi_system_id acer_quirks[] = { | |||
300 | }, | 336 | }, |
301 | { | 337 | { |
302 | .callback = dmi_matched, | 338 | .callback = dmi_matched, |
339 | .ident = "Fujitsu Siemens Amilo Li 1718", | ||
340 | .matches = { | ||
341 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), | ||
342 | DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"), | ||
343 | }, | ||
344 | .driver_data = &quirk_fujitsu_amilo_li_1718, | ||
345 | }, | ||
346 | { | ||
347 | .callback = dmi_matched, | ||
303 | .ident = "Medion MD 98300", | 348 | .ident = "Medion MD 98300", |
304 | .matches = { | 349 | .matches = { |
305 | DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), | 350 | DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), |
@@ -393,6 +438,12 @@ struct wmi_interface *iface) | |||
393 | return AE_ERROR; | 438 | return AE_ERROR; |
394 | *value = result & 0x1; | 439 | *value = result & 0x1; |
395 | return AE_OK; | 440 | return AE_OK; |
441 | case 2: | ||
442 | err = ec_read(0x71, &result); | ||
443 | if (err) | ||
444 | return AE_ERROR; | ||
445 | *value = result & 0x1; | ||
446 | return AE_OK; | ||
396 | default: | 447 | default: |
397 | err = ec_read(0xA, &result); | 448 | err = ec_read(0xA, &result); |
398 | if (err) | 449 | if (err) |
@@ -506,6 +557,15 @@ static acpi_status AMW0_set_capabilities(void) | |||
506 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; | 557 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
507 | union acpi_object *obj; | 558 | union acpi_object *obj; |
508 | 559 | ||
560 | /* | ||
561 | * On laptops with this strange GUID (non Acer), normal probing doesn't | ||
562 | * work. | ||
563 | */ | ||
564 | if (wmi_has_guid(AMW0_GUID2)) { | ||
565 | interface->capability |= ACER_CAP_WIRELESS; | ||
566 | return AE_OK; | ||
567 | } | ||
568 | |||
509 | args.eax = ACER_AMW0_WRITE; | 569 | args.eax = ACER_AMW0_WRITE; |
510 | args.ecx = args.edx = 0; | 570 | args.ecx = args.edx = 0; |
511 | 571 | ||
@@ -552,7 +612,8 @@ static acpi_status AMW0_set_capabilities(void) | |||
552 | * appear to use the same EC register for brightness, even if they | 612 | * appear to use the same EC register for brightness, even if they |
553 | * differ for wireless, etc | 613 | * differ for wireless, etc |
554 | */ | 614 | */ |
555 | interface->capability |= ACER_CAP_BRIGHTNESS; | 615 | if (quirks->brightness >= 0) |
616 | interface->capability |= ACER_CAP_BRIGHTNESS; | ||
556 | 617 | ||
557 | return AE_OK; | 618 | return AE_OK; |
558 | } | 619 | } |
@@ -807,7 +868,15 @@ static int read_brightness(struct backlight_device *bd) | |||
807 | 868 | ||
808 | static int update_bl_status(struct backlight_device *bd) | 869 | static int update_bl_status(struct backlight_device *bd) |
809 | { | 870 | { |
810 | set_u32(bd->props.brightness, ACER_CAP_BRIGHTNESS); | 871 | int intensity = bd->props.brightness; |
872 | |||
873 | if (bd->props.power != FB_BLANK_UNBLANK) | ||
874 | intensity = 0; | ||
875 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) | ||
876 | intensity = 0; | ||
877 | |||
878 | set_u32(intensity, ACER_CAP_BRIGHTNESS); | ||
879 | |||
811 | return 0; | 880 | return 0; |
812 | } | 881 | } |
813 | 882 | ||
@@ -829,8 +898,9 @@ static int __devinit acer_backlight_init(struct device *dev) | |||
829 | 898 | ||
830 | acer_backlight_device = bd; | 899 | acer_backlight_device = bd; |
831 | 900 | ||
901 | bd->props.power = FB_BLANK_UNBLANK; | ||
902 | bd->props.brightness = max_brightness; | ||
832 | bd->props.max_brightness = max_brightness; | 903 | bd->props.max_brightness = max_brightness; |
833 | bd->props.brightness = read_brightness(NULL); | ||
834 | backlight_update_status(bd); | 904 | backlight_update_status(bd); |
835 | return 0; | 905 | return 0; |
836 | } | 906 | } |
@@ -894,6 +964,28 @@ static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR, | |||
894 | show_interface, NULL); | 964 | show_interface, NULL); |
895 | 965 | ||
896 | /* | 966 | /* |
967 | * debugfs functions | ||
968 | */ | ||
969 | static u32 get_wmid_devices(void) | ||
970 | { | ||
971 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
972 | union acpi_object *obj; | ||
973 | acpi_status status; | ||
974 | |||
975 | status = wmi_query_block(WMID_GUID2, 1, &out); | ||
976 | if (ACPI_FAILURE(status)) | ||
977 | return 0; | ||
978 | |||
979 | obj = (union acpi_object *) out.pointer; | ||
980 | if (obj && obj->type == ACPI_TYPE_BUFFER && | ||
981 | obj->buffer.length == sizeof(u32)) { | ||
982 | return *((u32 *) obj->buffer.pointer); | ||
983 | } else { | ||
984 | return 0; | ||
985 | } | ||
986 | } | ||
987 | |||
988 | /* | ||
897 | * Platform device | 989 | * Platform device |
898 | */ | 990 | */ |
899 | static int __devinit acer_platform_probe(struct platform_device *device) | 991 | static int __devinit acer_platform_probe(struct platform_device *device) |
@@ -1052,12 +1144,40 @@ error_sysfs: | |||
1052 | return retval; | 1144 | return retval; |
1053 | } | 1145 | } |
1054 | 1146 | ||
1147 | static void remove_debugfs(void) | ||
1148 | { | ||
1149 | debugfs_remove(interface->debug.devices); | ||
1150 | debugfs_remove(interface->debug.root); | ||
1151 | } | ||
1152 | |||
1153 | static int create_debugfs(void) | ||
1154 | { | ||
1155 | interface->debug.root = debugfs_create_dir("acer-wmi", NULL); | ||
1156 | if (!interface->debug.root) { | ||
1157 | printk(ACER_ERR "Failed to create debugfs directory"); | ||
1158 | return -ENOMEM; | ||
1159 | } | ||
1160 | |||
1161 | interface->debug.devices = debugfs_create_u32("devices", S_IRUGO, | ||
1162 | interface->debug.root, | ||
1163 | &interface->debug.wmid_devices); | ||
1164 | if (!interface->debug.devices) | ||
1165 | goto error_debugfs; | ||
1166 | |||
1167 | return 0; | ||
1168 | |||
1169 | error_debugfs: | ||
1170 | remove_debugfs(); | ||
1171 | return -ENOMEM; | ||
1172 | } | ||
1173 | |||
1055 | static int __init acer_wmi_init(void) | 1174 | static int __init acer_wmi_init(void) |
1056 | { | 1175 | { |
1057 | int err; | 1176 | int err; |
1058 | 1177 | ||
1059 | printk(ACER_INFO "Acer Laptop ACPI-WMI Extras version %s\n", | 1178 | printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n"); |
1060 | ACER_WMI_VERSION); | 1179 | |
1180 | find_quirks(); | ||
1061 | 1181 | ||
1062 | /* | 1182 | /* |
1063 | * Detect which ACPI-WMI interface we're using. | 1183 | * Detect which ACPI-WMI interface we're using. |
@@ -1092,8 +1212,6 @@ static int __init acer_wmi_init(void) | |||
1092 | if (wmi_has_guid(AMW0_GUID1)) | 1212 | if (wmi_has_guid(AMW0_GUID1)) |
1093 | AMW0_find_mailled(); | 1213 | AMW0_find_mailled(); |
1094 | 1214 | ||
1095 | find_quirks(); | ||
1096 | |||
1097 | if (!interface) { | 1215 | if (!interface) { |
1098 | printk(ACER_ERR "No or unsupported WMI interface, unable to " | 1216 | printk(ACER_ERR "No or unsupported WMI interface, unable to " |
1099 | "load\n"); | 1217 | "load\n"); |
@@ -1111,6 +1229,13 @@ static int __init acer_wmi_init(void) | |||
1111 | if (err) | 1229 | if (err) |
1112 | return err; | 1230 | return err; |
1113 | 1231 | ||
1232 | if (wmi_has_guid(WMID_GUID2)) { | ||
1233 | interface->debug.wmid_devices = get_wmid_devices(); | ||
1234 | err = create_debugfs(); | ||
1235 | if (err) | ||
1236 | return err; | ||
1237 | } | ||
1238 | |||
1114 | /* Override any initial settings with values from the commandline */ | 1239 | /* Override any initial settings with values from the commandline */ |
1115 | acer_commandline_init(); | 1240 | acer_commandline_init(); |
1116 | 1241 | ||
diff --git a/drivers/misc/compal-laptop.c b/drivers/misc/compal-laptop.c new file mode 100644 index 000000000000..344b790a6253 --- /dev/null +++ b/drivers/misc/compal-laptop.c | |||
@@ -0,0 +1,404 @@ | |||
1 | /*-*-linux-c-*-*/ | ||
2 | |||
3 | /* | ||
4 | Copyright (C) 2008 Cezary Jackiewicz <cezary.jackiewicz (at) gmail.com> | ||
5 | |||
6 | based on MSI driver | ||
7 | |||
8 | Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de> | ||
9 | |||
10 | This program is free software; you can redistribute it and/or modify | ||
11 | it under the terms of the GNU General Public License as published by | ||
12 | the Free Software Foundation; either version 2 of the License, or | ||
13 | (at your option) any later version. | ||
14 | |||
15 | This program is distributed in the hope that it will be useful, but | ||
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | General Public License for more details. | ||
19 | |||
20 | You should have received a copy of the GNU General Public License | ||
21 | along with this program; if not, write to the Free Software | ||
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
23 | 02110-1301, USA. | ||
24 | */ | ||
25 | |||
26 | /* | ||
27 | * comapl-laptop.c - Compal laptop support. | ||
28 | * | ||
29 | * This driver exports a few files in /sys/devices/platform/compal-laptop/: | ||
30 | * | ||
31 | * wlan - wlan subsystem state: contains 0 or 1 (rw) | ||
32 | * | ||
33 | * bluetooth - Bluetooth subsystem state: contains 0 or 1 (rw) | ||
34 | * | ||
35 | * raw - raw value taken from embedded controller register (ro) | ||
36 | * | ||
37 | * In addition to these platform device attributes the driver | ||
38 | * registers itself in the Linux backlight control subsystem and is | ||
39 | * available to userspace under /sys/class/backlight/compal-laptop/. | ||
40 | * | ||
41 | * This driver might work on other laptops produced by Compal. If you | ||
42 | * want to try it you can pass force=1 as argument to the module which | ||
43 | * will force it to load even when the DMI data doesn't identify the | ||
44 | * laptop as FL9x. | ||
45 | */ | ||
46 | |||
47 | #include <linux/module.h> | ||
48 | #include <linux/kernel.h> | ||
49 | #include <linux/init.h> | ||
50 | #include <linux/acpi.h> | ||
51 | #include <linux/dmi.h> | ||
52 | #include <linux/backlight.h> | ||
53 | #include <linux/platform_device.h> | ||
54 | #include <linux/autoconf.h> | ||
55 | |||
56 | #define COMPAL_DRIVER_VERSION "0.2.6" | ||
57 | |||
58 | #define COMPAL_LCD_LEVEL_MAX 8 | ||
59 | |||
60 | #define COMPAL_EC_COMMAND_WIRELESS 0xBB | ||
61 | #define COMPAL_EC_COMMAND_LCD_LEVEL 0xB9 | ||
62 | |||
63 | #define KILLSWITCH_MASK 0x10 | ||
64 | #define WLAN_MASK 0x01 | ||
65 | #define BT_MASK 0x02 | ||
66 | |||
67 | static int force; | ||
68 | module_param(force, bool, 0); | ||
69 | MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); | ||
70 | |||
71 | /* Hardware access */ | ||
72 | |||
73 | static int set_lcd_level(int level) | ||
74 | { | ||
75 | if (level < 0 || level >= COMPAL_LCD_LEVEL_MAX) | ||
76 | return -EINVAL; | ||
77 | |||
78 | ec_write(COMPAL_EC_COMMAND_LCD_LEVEL, level); | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | static int get_lcd_level(void) | ||
84 | { | ||
85 | u8 result; | ||
86 | |||
87 | ec_read(COMPAL_EC_COMMAND_LCD_LEVEL, &result); | ||
88 | |||
89 | return (int) result; | ||
90 | } | ||
91 | |||
92 | static int set_wlan_state(int state) | ||
93 | { | ||
94 | u8 result, value; | ||
95 | |||
96 | ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); | ||
97 | |||
98 | if ((result & KILLSWITCH_MASK) == 0) | ||
99 | return -EINVAL; | ||
100 | else { | ||
101 | if (state) | ||
102 | value = (u8) (result | WLAN_MASK); | ||
103 | else | ||
104 | value = (u8) (result & ~WLAN_MASK); | ||
105 | ec_write(COMPAL_EC_COMMAND_WIRELESS, value); | ||
106 | } | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | static int set_bluetooth_state(int state) | ||
112 | { | ||
113 | u8 result, value; | ||
114 | |||
115 | ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); | ||
116 | |||
117 | if ((result & KILLSWITCH_MASK) == 0) | ||
118 | return -EINVAL; | ||
119 | else { | ||
120 | if (state) | ||
121 | value = (u8) (result | BT_MASK); | ||
122 | else | ||
123 | value = (u8) (result & ~BT_MASK); | ||
124 | ec_write(COMPAL_EC_COMMAND_WIRELESS, value); | ||
125 | } | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static int get_wireless_state(int *wlan, int *bluetooth) | ||
131 | { | ||
132 | u8 result; | ||
133 | |||
134 | ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); | ||
135 | |||
136 | if (wlan) { | ||
137 | if ((result & KILLSWITCH_MASK) == 0) | ||
138 | *wlan = 0; | ||
139 | else | ||
140 | *wlan = result & WLAN_MASK; | ||
141 | } | ||
142 | |||
143 | if (bluetooth) { | ||
144 | if ((result & KILLSWITCH_MASK) == 0) | ||
145 | *bluetooth = 0; | ||
146 | else | ||
147 | *bluetooth = (result & BT_MASK) >> 1; | ||
148 | } | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | /* Backlight device stuff */ | ||
154 | |||
155 | static int bl_get_brightness(struct backlight_device *b) | ||
156 | { | ||
157 | return get_lcd_level(); | ||
158 | } | ||
159 | |||
160 | |||
161 | static int bl_update_status(struct backlight_device *b) | ||
162 | { | ||
163 | return set_lcd_level(b->props.brightness); | ||
164 | } | ||
165 | |||
166 | static struct backlight_ops compalbl_ops = { | ||
167 | .get_brightness = bl_get_brightness, | ||
168 | .update_status = bl_update_status, | ||
169 | }; | ||
170 | |||
171 | static struct backlight_device *compalbl_device; | ||
172 | |||
173 | /* Platform device */ | ||
174 | |||
175 | static ssize_t show_wlan(struct device *dev, | ||
176 | struct device_attribute *attr, char *buf) | ||
177 | { | ||
178 | int ret, enabled; | ||
179 | |||
180 | ret = get_wireless_state(&enabled, NULL); | ||
181 | if (ret < 0) | ||
182 | return ret; | ||
183 | |||
184 | return sprintf(buf, "%i\n", enabled); | ||
185 | } | ||
186 | |||
187 | static ssize_t show_raw(struct device *dev, | ||
188 | struct device_attribute *attr, char *buf) | ||
189 | { | ||
190 | u8 result; | ||
191 | |||
192 | ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); | ||
193 | |||
194 | return sprintf(buf, "%i\n", result); | ||
195 | } | ||
196 | |||
197 | static ssize_t show_bluetooth(struct device *dev, | ||
198 | struct device_attribute *attr, char *buf) | ||
199 | { | ||
200 | int ret, enabled; | ||
201 | |||
202 | ret = get_wireless_state(NULL, &enabled); | ||
203 | if (ret < 0) | ||
204 | return ret; | ||
205 | |||
206 | return sprintf(buf, "%i\n", enabled); | ||
207 | } | ||
208 | |||
209 | static ssize_t store_wlan_state(struct device *dev, | ||
210 | struct device_attribute *attr, const char *buf, size_t count) | ||
211 | { | ||
212 | int state, ret; | ||
213 | |||
214 | if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1)) | ||
215 | return -EINVAL; | ||
216 | |||
217 | ret = set_wlan_state(state); | ||
218 | if (ret < 0) | ||
219 | return ret; | ||
220 | |||
221 | return count; | ||
222 | } | ||
223 | |||
224 | static ssize_t store_bluetooth_state(struct device *dev, | ||
225 | struct device_attribute *attr, const char *buf, size_t count) | ||
226 | { | ||
227 | int state, ret; | ||
228 | |||
229 | if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1)) | ||
230 | return -EINVAL; | ||
231 | |||
232 | ret = set_bluetooth_state(state); | ||
233 | if (ret < 0) | ||
234 | return ret; | ||
235 | |||
236 | return count; | ||
237 | } | ||
238 | |||
239 | static DEVICE_ATTR(bluetooth, 0644, show_bluetooth, store_bluetooth_state); | ||
240 | static DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan_state); | ||
241 | static DEVICE_ATTR(raw, 0444, show_raw, NULL); | ||
242 | |||
243 | static struct attribute *compal_attributes[] = { | ||
244 | &dev_attr_bluetooth.attr, | ||
245 | &dev_attr_wlan.attr, | ||
246 | &dev_attr_raw.attr, | ||
247 | NULL | ||
248 | }; | ||
249 | |||
250 | static struct attribute_group compal_attribute_group = { | ||
251 | .attrs = compal_attributes | ||
252 | }; | ||
253 | |||
254 | static struct platform_driver compal_driver = { | ||
255 | .driver = { | ||
256 | .name = "compal-laptop", | ||
257 | .owner = THIS_MODULE, | ||
258 | } | ||
259 | }; | ||
260 | |||
261 | static struct platform_device *compal_device; | ||
262 | |||
263 | /* Initialization */ | ||
264 | |||
265 | static int dmi_check_cb(const struct dmi_system_id *id) | ||
266 | { | ||
267 | printk(KERN_INFO "compal-laptop: Identified laptop model '%s'.\n", | ||
268 | id->ident); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | static struct dmi_system_id __initdata compal_dmi_table[] = { | ||
274 | { | ||
275 | .ident = "FL90/IFL90", | ||
276 | .matches = { | ||
277 | DMI_MATCH(DMI_BOARD_NAME, "IFL90"), | ||
278 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), | ||
279 | }, | ||
280 | .callback = dmi_check_cb | ||
281 | }, | ||
282 | { | ||
283 | .ident = "FL90/IFL90", | ||
284 | .matches = { | ||
285 | DMI_MATCH(DMI_BOARD_NAME, "IFL90"), | ||
286 | DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"), | ||
287 | }, | ||
288 | .callback = dmi_check_cb | ||
289 | }, | ||
290 | { | ||
291 | .ident = "FL91/IFL91", | ||
292 | .matches = { | ||
293 | DMI_MATCH(DMI_BOARD_NAME, "IFL91"), | ||
294 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), | ||
295 | }, | ||
296 | .callback = dmi_check_cb | ||
297 | }, | ||
298 | { | ||
299 | .ident = "FL92/JFL92", | ||
300 | .matches = { | ||
301 | DMI_MATCH(DMI_BOARD_NAME, "JFL92"), | ||
302 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), | ||
303 | }, | ||
304 | .callback = dmi_check_cb | ||
305 | }, | ||
306 | { | ||
307 | .ident = "FT00/IFT00", | ||
308 | .matches = { | ||
309 | DMI_MATCH(DMI_BOARD_NAME, "IFT00"), | ||
310 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), | ||
311 | }, | ||
312 | .callback = dmi_check_cb | ||
313 | }, | ||
314 | { } | ||
315 | }; | ||
316 | |||
317 | static int __init compal_init(void) | ||
318 | { | ||
319 | int ret; | ||
320 | |||
321 | if (acpi_disabled) | ||
322 | return -ENODEV; | ||
323 | |||
324 | if (!force && !dmi_check_system(compal_dmi_table)) | ||
325 | return -ENODEV; | ||
326 | |||
327 | /* Register backlight stuff */ | ||
328 | |||
329 | compalbl_device = backlight_device_register("compal-laptop", NULL, NULL, | ||
330 | &compalbl_ops); | ||
331 | if (IS_ERR(compalbl_device)) | ||
332 | return PTR_ERR(compalbl_device); | ||
333 | |||
334 | compalbl_device->props.max_brightness = COMPAL_LCD_LEVEL_MAX-1; | ||
335 | |||
336 | ret = platform_driver_register(&compal_driver); | ||
337 | if (ret) | ||
338 | goto fail_backlight; | ||
339 | |||
340 | /* Register platform stuff */ | ||
341 | |||
342 | compal_device = platform_device_alloc("compal-laptop", -1); | ||
343 | if (!compal_device) { | ||
344 | ret = -ENOMEM; | ||
345 | goto fail_platform_driver; | ||
346 | } | ||
347 | |||
348 | ret = platform_device_add(compal_device); | ||
349 | if (ret) | ||
350 | goto fail_platform_device1; | ||
351 | |||
352 | ret = sysfs_create_group(&compal_device->dev.kobj, | ||
353 | &compal_attribute_group); | ||
354 | if (ret) | ||
355 | goto fail_platform_device2; | ||
356 | |||
357 | printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION | ||
358 | " successfully loaded.\n"); | ||
359 | |||
360 | return 0; | ||
361 | |||
362 | fail_platform_device2: | ||
363 | |||
364 | platform_device_del(compal_device); | ||
365 | |||
366 | fail_platform_device1: | ||
367 | |||
368 | platform_device_put(compal_device); | ||
369 | |||
370 | fail_platform_driver: | ||
371 | |||
372 | platform_driver_unregister(&compal_driver); | ||
373 | |||
374 | fail_backlight: | ||
375 | |||
376 | backlight_device_unregister(compalbl_device); | ||
377 | |||
378 | return ret; | ||
379 | } | ||
380 | |||
381 | static void __exit compal_cleanup(void) | ||
382 | { | ||
383 | |||
384 | sysfs_remove_group(&compal_device->dev.kobj, &compal_attribute_group); | ||
385 | platform_device_unregister(compal_device); | ||
386 | platform_driver_unregister(&compal_driver); | ||
387 | backlight_device_unregister(compalbl_device); | ||
388 | |||
389 | printk(KERN_INFO "compal-laptop: driver unloaded.\n"); | ||
390 | } | ||
391 | |||
392 | module_init(compal_init); | ||
393 | module_exit(compal_cleanup); | ||
394 | |||
395 | MODULE_AUTHOR("Cezary Jackiewicz"); | ||
396 | MODULE_DESCRIPTION("Compal Laptop Support"); | ||
397 | MODULE_VERSION(COMPAL_DRIVER_VERSION); | ||
398 | MODULE_LICENSE("GPL"); | ||
399 | |||
400 | MODULE_ALIAS("dmi:*:rnIFL90:rvrIFT00:*"); | ||
401 | MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*"); | ||
402 | MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*"); | ||
403 | MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*"); | ||
404 | MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*"); | ||
diff --git a/drivers/misc/eeepc-laptop.c b/drivers/misc/eeepc-laptop.c index 6d727609097f..9e8d79e7e9f4 100644 --- a/drivers/misc/eeepc-laptop.c +++ b/drivers/misc/eeepc-laptop.c | |||
@@ -87,7 +87,7 @@ enum { | |||
87 | CM_ASL_LID | 87 | CM_ASL_LID |
88 | }; | 88 | }; |
89 | 89 | ||
90 | const char *cm_getv[] = { | 90 | static const char *cm_getv[] = { |
91 | "WLDG", NULL, NULL, NULL, | 91 | "WLDG", NULL, NULL, NULL, |
92 | "CAMG", NULL, NULL, NULL, | 92 | "CAMG", NULL, NULL, NULL, |
93 | NULL, "PBLG", NULL, NULL, | 93 | NULL, "PBLG", NULL, NULL, |
@@ -96,7 +96,7 @@ const char *cm_getv[] = { | |||
96 | "CRDG", "LIDG" | 96 | "CRDG", "LIDG" |
97 | }; | 97 | }; |
98 | 98 | ||
99 | const char *cm_setv[] = { | 99 | static const char *cm_setv[] = { |
100 | "WLDS", NULL, NULL, NULL, | 100 | "WLDS", NULL, NULL, NULL, |
101 | "CAMS", NULL, NULL, NULL, | 101 | "CAMS", NULL, NULL, NULL, |
102 | "SDSP", "PBLS", "HDPS", NULL, | 102 | "SDSP", "PBLS", "HDPS", NULL, |
diff --git a/drivers/misc/fujitsu-laptop.c b/drivers/misc/fujitsu-laptop.c index 6d14e8fe1537..7a1ef6c262de 100644 --- a/drivers/misc/fujitsu-laptop.c +++ b/drivers/misc/fujitsu-laptop.c | |||
@@ -1,12 +1,14 @@ | |||
1 | /*-*-linux-c-*-*/ | 1 | /*-*-linux-c-*-*/ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | Copyright (C) 2007 Jonathan Woithe <jwoithe@physics.adelaide.edu.au> | 4 | Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@physics.adelaide.edu.au> |
5 | Copyright (C) 2008 Peter Gruber <nokos@gmx.net> | ||
5 | Based on earlier work: | 6 | Based on earlier work: |
6 | Copyright (C) 2003 Shane Spencer <shane@bogomip.com> | 7 | Copyright (C) 2003 Shane Spencer <shane@bogomip.com> |
7 | Adrian Yee <brewt-fujitsu@brewt.org> | 8 | Adrian Yee <brewt-fujitsu@brewt.org> |
8 | 9 | ||
9 | Templated from msi-laptop.c which is copyright by its respective authors. | 10 | Templated from msi-laptop.c and thinkpad_acpi.c which is copyright |
11 | by its respective authors. | ||
10 | 12 | ||
11 | This program is free software; you can redistribute it and/or modify | 13 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | 14 | it under the terms of the GNU General Public License as published by |
@@ -39,8 +41,17 @@ | |||
39 | * registers itself in the Linux backlight control subsystem and is | 41 | * registers itself in the Linux backlight control subsystem and is |
40 | * available to userspace under /sys/class/backlight/fujitsu-laptop/. | 42 | * available to userspace under /sys/class/backlight/fujitsu-laptop/. |
41 | * | 43 | * |
42 | * This driver has been tested on a Fujitsu Lifebook S7020. It should | 44 | * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are |
43 | * work on most P-series and S-series Lifebooks, but YMMV. | 45 | * also supported by this driver. |
46 | * | ||
47 | * This driver has been tested on a Fujitsu Lifebook S6410 and S7020. It | ||
48 | * should work on most P-series and S-series Lifebooks, but YMMV. | ||
49 | * | ||
50 | * The module parameter use_alt_lcd_levels switches between different ACPI | ||
51 | * brightness controls which are used by different Fujitsu laptops. In most | ||
52 | * cases the correct method is automatically detected. "use_alt_lcd_levels=1" | ||
53 | * is applicable for a Fujitsu Lifebook S6410 if autodetection fails. | ||
54 | * | ||
44 | */ | 55 | */ |
45 | 56 | ||
46 | #include <linux/module.h> | 57 | #include <linux/module.h> |
@@ -49,30 +60,105 @@ | |||
49 | #include <linux/acpi.h> | 60 | #include <linux/acpi.h> |
50 | #include <linux/dmi.h> | 61 | #include <linux/dmi.h> |
51 | #include <linux/backlight.h> | 62 | #include <linux/backlight.h> |
63 | #include <linux/input.h> | ||
64 | #include <linux/kfifo.h> | ||
65 | #include <linux/video_output.h> | ||
52 | #include <linux/platform_device.h> | 66 | #include <linux/platform_device.h> |
53 | 67 | ||
54 | #define FUJITSU_DRIVER_VERSION "0.3" | 68 | #define FUJITSU_DRIVER_VERSION "0.4.2" |
55 | 69 | ||
56 | #define FUJITSU_LCD_N_LEVELS 8 | 70 | #define FUJITSU_LCD_N_LEVELS 8 |
57 | 71 | ||
58 | #define ACPI_FUJITSU_CLASS "fujitsu" | 72 | #define ACPI_FUJITSU_CLASS "fujitsu" |
59 | #define ACPI_FUJITSU_HID "FUJ02B1" | 73 | #define ACPI_FUJITSU_HID "FUJ02B1" |
60 | #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI extras driver" | 74 | #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver" |
61 | #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1" | 75 | #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1" |
62 | 76 | #define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3" | |
77 | #define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver" | ||
78 | #define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3" | ||
79 | |||
80 | #define ACPI_FUJITSU_NOTIFY_CODE1 0x80 | ||
81 | |||
82 | #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86 | ||
83 | #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87 | ||
84 | |||
85 | /* Hotkey details */ | ||
86 | #define LOCK_KEY 0x410 /* codes for the keys in the GIRB register */ | ||
87 | #define DISPLAY_KEY 0x411 /* keys are mapped to KEY_SCREENLOCK (the key with the key symbol) */ | ||
88 | #define ENERGY_KEY 0x412 /* KEY_MEDIA (the key with the laptop symbol, KEY_EMAIL (E key)) */ | ||
89 | #define REST_KEY 0x413 /* KEY_SUSPEND (R key) */ | ||
90 | |||
91 | #define MAX_HOTKEY_RINGBUFFER_SIZE 100 | ||
92 | #define RINGBUFFERSIZE 40 | ||
93 | |||
94 | /* Debugging */ | ||
95 | #define FUJLAPTOP_LOG ACPI_FUJITSU_HID ": " | ||
96 | #define FUJLAPTOP_ERR KERN_ERR FUJLAPTOP_LOG | ||
97 | #define FUJLAPTOP_NOTICE KERN_NOTICE FUJLAPTOP_LOG | ||
98 | #define FUJLAPTOP_INFO KERN_INFO FUJLAPTOP_LOG | ||
99 | #define FUJLAPTOP_DEBUG KERN_DEBUG FUJLAPTOP_LOG | ||
100 | |||
101 | #define FUJLAPTOP_DBG_ALL 0xffff | ||
102 | #define FUJLAPTOP_DBG_ERROR 0x0001 | ||
103 | #define FUJLAPTOP_DBG_WARN 0x0002 | ||
104 | #define FUJLAPTOP_DBG_INFO 0x0004 | ||
105 | #define FUJLAPTOP_DBG_TRACE 0x0008 | ||
106 | |||
107 | #define dbg_printk(a_dbg_level, format, arg...) \ | ||
108 | do { if (dbg_level & a_dbg_level) \ | ||
109 | printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \ | ||
110 | } while (0) | ||
111 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG | ||
112 | #define vdbg_printk(a_dbg_level, format, arg...) \ | ||
113 | dbg_printk(a_dbg_level, format, ## arg) | ||
114 | #else | ||
115 | #define vdbg_printk(a_dbg_level, format, arg...) | ||
116 | #endif | ||
117 | |||
118 | /* Device controlling the backlight and associated keys */ | ||
63 | struct fujitsu_t { | 119 | struct fujitsu_t { |
64 | acpi_handle acpi_handle; | 120 | acpi_handle acpi_handle; |
121 | struct acpi_device *dev; | ||
122 | struct input_dev *input; | ||
123 | char phys[32]; | ||
65 | struct backlight_device *bl_device; | 124 | struct backlight_device *bl_device; |
66 | struct platform_device *pf_device; | 125 | struct platform_device *pf_device; |
67 | 126 | ||
68 | unsigned long fuj02b1_state; | 127 | unsigned int max_brightness; |
69 | unsigned int brightness_changed; | 128 | unsigned int brightness_changed; |
70 | unsigned int brightness_level; | 129 | unsigned int brightness_level; |
71 | }; | 130 | }; |
72 | 131 | ||
73 | static struct fujitsu_t *fujitsu; | 132 | static struct fujitsu_t *fujitsu; |
133 | static int use_alt_lcd_levels = -1; | ||
134 | static int disable_brightness_keys = -1; | ||
135 | static int disable_brightness_adjust = -1; | ||
136 | |||
137 | /* Device used to access other hotkeys on the laptop */ | ||
138 | struct fujitsu_hotkey_t { | ||
139 | acpi_handle acpi_handle; | ||
140 | struct acpi_device *dev; | ||
141 | struct input_dev *input; | ||
142 | char phys[32]; | ||
143 | struct platform_device *pf_device; | ||
144 | struct kfifo *fifo; | ||
145 | spinlock_t fifo_lock; | ||
146 | |||
147 | unsigned int irb; /* info about the pressed buttons */ | ||
148 | }; | ||
74 | 149 | ||
75 | /* Hardware access */ | 150 | static struct fujitsu_hotkey_t *fujitsu_hotkey; |
151 | |||
152 | static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event, | ||
153 | void *data); | ||
154 | |||
155 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG | ||
156 | static u32 dbg_level = 0x03; | ||
157 | #endif | ||
158 | |||
159 | static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data); | ||
160 | |||
161 | /* Hardware access for LCD brightness control */ | ||
76 | 162 | ||
77 | static int set_lcd_level(int level) | 163 | static int set_lcd_level(int level) |
78 | { | 164 | { |
@@ -81,7 +167,10 @@ static int set_lcd_level(int level) | |||
81 | struct acpi_object_list arg_list = { 1, &arg0 }; | 167 | struct acpi_object_list arg_list = { 1, &arg0 }; |
82 | acpi_handle handle = NULL; | 168 | acpi_handle handle = NULL; |
83 | 169 | ||
84 | if (level < 0 || level >= FUJITSU_LCD_N_LEVELS) | 170 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n", |
171 | level); | ||
172 | |||
173 | if (level < 0 || level >= fujitsu->max_brightness) | ||
85 | return -EINVAL; | 174 | return -EINVAL; |
86 | 175 | ||
87 | if (!fujitsu) | 176 | if (!fujitsu) |
@@ -89,7 +178,38 @@ static int set_lcd_level(int level) | |||
89 | 178 | ||
90 | status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle); | 179 | status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle); |
91 | if (ACPI_FAILURE(status)) { | 180 | if (ACPI_FAILURE(status)) { |
92 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "SBLL not present\n")); | 181 | vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n"); |
182 | return -ENODEV; | ||
183 | } | ||
184 | |||
185 | arg0.integer.value = level; | ||
186 | |||
187 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); | ||
188 | if (ACPI_FAILURE(status)) | ||
189 | return -ENODEV; | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static int set_lcd_level_alt(int level) | ||
195 | { | ||
196 | acpi_status status = AE_OK; | ||
197 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | ||
198 | struct acpi_object_list arg_list = { 1, &arg0 }; | ||
199 | acpi_handle handle = NULL; | ||
200 | |||
201 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n", | ||
202 | level); | ||
203 | |||
204 | if (level < 0 || level >= fujitsu->max_brightness) | ||
205 | return -EINVAL; | ||
206 | |||
207 | if (!fujitsu) | ||
208 | return -EINVAL; | ||
209 | |||
210 | status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle); | ||
211 | if (ACPI_FAILURE(status)) { | ||
212 | vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n"); | ||
93 | return -ENODEV; | 213 | return -ENODEV; |
94 | } | 214 | } |
95 | 215 | ||
@@ -107,13 +227,52 @@ static int get_lcd_level(void) | |||
107 | unsigned long state = 0; | 227 | unsigned long state = 0; |
108 | acpi_status status = AE_OK; | 228 | acpi_status status = AE_OK; |
109 | 229 | ||
110 | // Get the Brightness | 230 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n"); |
231 | |||
111 | status = | 232 | status = |
112 | acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); | 233 | acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state); |
113 | if (status < 0) | 234 | if (status < 0) |
114 | return status; | 235 | return status; |
115 | 236 | ||
116 | fujitsu->fuj02b1_state = state; | 237 | fujitsu->brightness_level = state & 0x0fffffff; |
238 | |||
239 | if (state & 0x80000000) | ||
240 | fujitsu->brightness_changed = 1; | ||
241 | else | ||
242 | fujitsu->brightness_changed = 0; | ||
243 | |||
244 | return fujitsu->brightness_level; | ||
245 | } | ||
246 | |||
247 | static int get_max_brightness(void) | ||
248 | { | ||
249 | unsigned long state = 0; | ||
250 | acpi_status status = AE_OK; | ||
251 | |||
252 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n"); | ||
253 | |||
254 | status = | ||
255 | acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state); | ||
256 | if (status < 0) | ||
257 | return status; | ||
258 | |||
259 | fujitsu->max_brightness = state; | ||
260 | |||
261 | return fujitsu->max_brightness; | ||
262 | } | ||
263 | |||
264 | static int get_lcd_level_alt(void) | ||
265 | { | ||
266 | unsigned long state = 0; | ||
267 | acpi_status status = AE_OK; | ||
268 | |||
269 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLS\n"); | ||
270 | |||
271 | status = | ||
272 | acpi_evaluate_integer(fujitsu->acpi_handle, "GBLS", NULL, &state); | ||
273 | if (status < 0) | ||
274 | return status; | ||
275 | |||
117 | fujitsu->brightness_level = state & 0x0fffffff; | 276 | fujitsu->brightness_level = state & 0x0fffffff; |
118 | 277 | ||
119 | if (state & 0x80000000) | 278 | if (state & 0x80000000) |
@@ -128,12 +287,18 @@ static int get_lcd_level(void) | |||
128 | 287 | ||
129 | static int bl_get_brightness(struct backlight_device *b) | 288 | static int bl_get_brightness(struct backlight_device *b) |
130 | { | 289 | { |
131 | return get_lcd_level(); | 290 | if (use_alt_lcd_levels) |
291 | return get_lcd_level_alt(); | ||
292 | else | ||
293 | return get_lcd_level(); | ||
132 | } | 294 | } |
133 | 295 | ||
134 | static int bl_update_status(struct backlight_device *b) | 296 | static int bl_update_status(struct backlight_device *b) |
135 | { | 297 | { |
136 | return set_lcd_level(b->props.brightness); | 298 | if (use_alt_lcd_levels) |
299 | return set_lcd_level_alt(b->props.brightness); | ||
300 | else | ||
301 | return set_lcd_level(b->props.brightness); | ||
137 | } | 302 | } |
138 | 303 | ||
139 | static struct backlight_ops fujitsubl_ops = { | 304 | static struct backlight_ops fujitsubl_ops = { |
@@ -141,7 +306,35 @@ static struct backlight_ops fujitsubl_ops = { | |||
141 | .update_status = bl_update_status, | 306 | .update_status = bl_update_status, |
142 | }; | 307 | }; |
143 | 308 | ||
144 | /* Platform device */ | 309 | /* Platform LCD brightness device */ |
310 | |||
311 | static ssize_t | ||
312 | show_max_brightness(struct device *dev, | ||
313 | struct device_attribute *attr, char *buf) | ||
314 | { | ||
315 | |||
316 | int ret; | ||
317 | |||
318 | ret = get_max_brightness(); | ||
319 | if (ret < 0) | ||
320 | return ret; | ||
321 | |||
322 | return sprintf(buf, "%i\n", ret); | ||
323 | } | ||
324 | |||
325 | static ssize_t | ||
326 | show_brightness_changed(struct device *dev, | ||
327 | struct device_attribute *attr, char *buf) | ||
328 | { | ||
329 | |||
330 | int ret; | ||
331 | |||
332 | ret = fujitsu->brightness_changed; | ||
333 | if (ret < 0) | ||
334 | return ret; | ||
335 | |||
336 | return sprintf(buf, "%i\n", ret); | ||
337 | } | ||
145 | 338 | ||
146 | static ssize_t show_lcd_level(struct device *dev, | 339 | static ssize_t show_lcd_level(struct device *dev, |
147 | struct device_attribute *attr, char *buf) | 340 | struct device_attribute *attr, char *buf) |
@@ -149,7 +342,10 @@ static ssize_t show_lcd_level(struct device *dev, | |||
149 | 342 | ||
150 | int ret; | 343 | int ret; |
151 | 344 | ||
152 | ret = get_lcd_level(); | 345 | if (use_alt_lcd_levels) |
346 | ret = get_lcd_level_alt(); | ||
347 | else | ||
348 | ret = get_lcd_level(); | ||
153 | if (ret < 0) | 349 | if (ret < 0) |
154 | return ret; | 350 | return ret; |
155 | 351 | ||
@@ -164,19 +360,61 @@ static ssize_t store_lcd_level(struct device *dev, | |||
164 | int level, ret; | 360 | int level, ret; |
165 | 361 | ||
166 | if (sscanf(buf, "%i", &level) != 1 | 362 | if (sscanf(buf, "%i", &level) != 1 |
167 | || (level < 0 || level >= FUJITSU_LCD_N_LEVELS)) | 363 | || (level < 0 || level >= fujitsu->max_brightness)) |
168 | return -EINVAL; | 364 | return -EINVAL; |
169 | 365 | ||
170 | ret = set_lcd_level(level); | 366 | if (use_alt_lcd_levels) |
367 | ret = set_lcd_level_alt(level); | ||
368 | else | ||
369 | ret = set_lcd_level(level); | ||
370 | if (ret < 0) | ||
371 | return ret; | ||
372 | |||
373 | if (use_alt_lcd_levels) | ||
374 | ret = get_lcd_level_alt(); | ||
375 | else | ||
376 | ret = get_lcd_level(); | ||
171 | if (ret < 0) | 377 | if (ret < 0) |
172 | return ret; | 378 | return ret; |
173 | 379 | ||
174 | return count; | 380 | return count; |
175 | } | 381 | } |
176 | 382 | ||
383 | /* Hardware access for hotkey device */ | ||
384 | |||
385 | static int get_irb(void) | ||
386 | { | ||
387 | unsigned long state = 0; | ||
388 | acpi_status status = AE_OK; | ||
389 | |||
390 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "Get irb\n"); | ||
391 | |||
392 | status = | ||
393 | acpi_evaluate_integer(fujitsu_hotkey->acpi_handle, "GIRB", NULL, | ||
394 | &state); | ||
395 | if (status < 0) | ||
396 | return status; | ||
397 | |||
398 | fujitsu_hotkey->irb = state; | ||
399 | |||
400 | return fujitsu_hotkey->irb; | ||
401 | } | ||
402 | |||
403 | static ssize_t | ||
404 | ignore_store(struct device *dev, | ||
405 | struct device_attribute *attr, const char *buf, size_t count) | ||
406 | { | ||
407 | return count; | ||
408 | } | ||
409 | |||
410 | static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store); | ||
411 | static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed, | ||
412 | ignore_store); | ||
177 | static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level); | 413 | static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level); |
178 | 414 | ||
179 | static struct attribute *fujitsupf_attributes[] = { | 415 | static struct attribute *fujitsupf_attributes[] = { |
416 | &dev_attr_brightness_changed.attr, | ||
417 | &dev_attr_max_brightness.attr, | ||
180 | &dev_attr_lcd_level.attr, | 418 | &dev_attr_lcd_level.attr, |
181 | NULL | 419 | NULL |
182 | }; | 420 | }; |
@@ -192,14 +430,52 @@ static struct platform_driver fujitsupf_driver = { | |||
192 | } | 430 | } |
193 | }; | 431 | }; |
194 | 432 | ||
195 | /* ACPI device */ | 433 | static int dmi_check_cb_s6410(const struct dmi_system_id *id) |
434 | { | ||
435 | acpi_handle handle; | ||
436 | int have_blnf; | ||
437 | printk(KERN_INFO "fujitsu-laptop: Identified laptop model '%s'.\n", | ||
438 | id->ident); | ||
439 | have_blnf = ACPI_SUCCESS | ||
440 | (acpi_get_handle(NULL, "\\_SB.PCI0.GFX0.LCD.BLNF", &handle)); | ||
441 | if (use_alt_lcd_levels == -1) { | ||
442 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detecting usealt\n"); | ||
443 | use_alt_lcd_levels = 1; | ||
444 | } | ||
445 | if (disable_brightness_keys == -1) { | ||
446 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | ||
447 | "auto-detecting disable_keys\n"); | ||
448 | disable_brightness_keys = have_blnf ? 1 : 0; | ||
449 | } | ||
450 | if (disable_brightness_adjust == -1) { | ||
451 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | ||
452 | "auto-detecting disable_adjust\n"); | ||
453 | disable_brightness_adjust = have_blnf ? 0 : 1; | ||
454 | } | ||
455 | return 0; | ||
456 | } | ||
457 | |||
458 | static struct dmi_system_id __initdata fujitsu_dmi_table[] = { | ||
459 | { | ||
460 | .ident = "Fujitsu Siemens", | ||
461 | .matches = { | ||
462 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), | ||
463 | DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"), | ||
464 | }, | ||
465 | .callback = dmi_check_cb_s6410}, | ||
466 | {} | ||
467 | }; | ||
468 | |||
469 | /* ACPI device for LCD brightness control */ | ||
196 | 470 | ||
197 | static int acpi_fujitsu_add(struct acpi_device *device) | 471 | static int acpi_fujitsu_add(struct acpi_device *device) |
198 | { | 472 | { |
473 | acpi_status status; | ||
474 | acpi_handle handle; | ||
199 | int result = 0; | 475 | int result = 0; |
200 | int state = 0; | 476 | int state = 0; |
201 | 477 | struct input_dev *input; | |
202 | ACPI_FUNCTION_TRACE("acpi_fujitsu_add"); | 478 | int error; |
203 | 479 | ||
204 | if (!device) | 480 | if (!device) |
205 | return -EINVAL; | 481 | return -EINVAL; |
@@ -209,10 +485,42 @@ static int acpi_fujitsu_add(struct acpi_device *device) | |||
209 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); | 485 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); |
210 | acpi_driver_data(device) = fujitsu; | 486 | acpi_driver_data(device) = fujitsu; |
211 | 487 | ||
488 | status = acpi_install_notify_handler(device->handle, | ||
489 | ACPI_DEVICE_NOTIFY, | ||
490 | acpi_fujitsu_notify, fujitsu); | ||
491 | |||
492 | if (ACPI_FAILURE(status)) { | ||
493 | printk(KERN_ERR "Error installing notify handler\n"); | ||
494 | error = -ENODEV; | ||
495 | goto err_stop; | ||
496 | } | ||
497 | |||
498 | fujitsu->input = input = input_allocate_device(); | ||
499 | if (!input) { | ||
500 | error = -ENOMEM; | ||
501 | goto err_uninstall_notify; | ||
502 | } | ||
503 | |||
504 | snprintf(fujitsu->phys, sizeof(fujitsu->phys), | ||
505 | "%s/video/input0", acpi_device_hid(device)); | ||
506 | |||
507 | input->name = acpi_device_name(device); | ||
508 | input->phys = fujitsu->phys; | ||
509 | input->id.bustype = BUS_HOST; | ||
510 | input->id.product = 0x06; | ||
511 | input->dev.parent = &device->dev; | ||
512 | input->evbit[0] = BIT(EV_KEY); | ||
513 | set_bit(KEY_BRIGHTNESSUP, input->keybit); | ||
514 | set_bit(KEY_BRIGHTNESSDOWN, input->keybit); | ||
515 | set_bit(KEY_UNKNOWN, input->keybit); | ||
516 | |||
517 | error = input_register_device(input); | ||
518 | if (error) | ||
519 | goto err_free_input_dev; | ||
520 | |||
212 | result = acpi_bus_get_power(fujitsu->acpi_handle, &state); | 521 | result = acpi_bus_get_power(fujitsu->acpi_handle, &state); |
213 | if (result) { | 522 | if (result) { |
214 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 523 | printk(KERN_ERR "Error reading power state\n"); |
215 | "Error reading power state\n")); | ||
216 | goto end; | 524 | goto end; |
217 | } | 525 | } |
218 | 526 | ||
@@ -220,22 +528,373 @@ static int acpi_fujitsu_add(struct acpi_device *device) | |||
220 | acpi_device_name(device), acpi_device_bid(device), | 528 | acpi_device_name(device), acpi_device_bid(device), |
221 | !device->power.state ? "on" : "off"); | 529 | !device->power.state ? "on" : "off"); |
222 | 530 | ||
223 | end: | 531 | fujitsu->dev = device; |
532 | |||
533 | if (ACPI_SUCCESS | ||
534 | (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) { | ||
535 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); | ||
536 | if (ACPI_FAILURE | ||
537 | (acpi_evaluate_object | ||
538 | (device->handle, METHOD_NAME__INI, NULL, NULL))) | ||
539 | printk(KERN_ERR "_INI Method failed\n"); | ||
540 | } | ||
541 | |||
542 | /* do config (detect defaults) */ | ||
543 | dmi_check_system(fujitsu_dmi_table); | ||
544 | use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0; | ||
545 | disable_brightness_keys = disable_brightness_keys == 1 ? 1 : 0; | ||
546 | disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0; | ||
547 | vdbg_printk(FUJLAPTOP_DBG_INFO, | ||
548 | "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n", | ||
549 | use_alt_lcd_levels, disable_brightness_keys, | ||
550 | disable_brightness_adjust); | ||
551 | |||
552 | if (get_max_brightness() <= 0) | ||
553 | fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS; | ||
554 | if (use_alt_lcd_levels) | ||
555 | get_lcd_level_alt(); | ||
556 | else | ||
557 | get_lcd_level(); | ||
558 | |||
559 | return result; | ||
560 | |||
561 | end: | ||
562 | err_free_input_dev: | ||
563 | input_free_device(input); | ||
564 | err_uninstall_notify: | ||
565 | acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, | ||
566 | acpi_fujitsu_notify); | ||
567 | err_stop: | ||
224 | 568 | ||
225 | return result; | 569 | return result; |
226 | } | 570 | } |
227 | 571 | ||
228 | static int acpi_fujitsu_remove(struct acpi_device *device, int type) | 572 | static int acpi_fujitsu_remove(struct acpi_device *device, int type) |
229 | { | 573 | { |
230 | ACPI_FUNCTION_TRACE("acpi_fujitsu_remove"); | 574 | acpi_status status; |
575 | struct fujitsu_t *fujitsu = NULL; | ||
231 | 576 | ||
232 | if (!device || !acpi_driver_data(device)) | 577 | if (!device || !acpi_driver_data(device)) |
233 | return -EINVAL; | 578 | return -EINVAL; |
579 | |||
580 | fujitsu = acpi_driver_data(device); | ||
581 | |||
582 | status = acpi_remove_notify_handler(fujitsu->acpi_handle, | ||
583 | ACPI_DEVICE_NOTIFY, | ||
584 | acpi_fujitsu_notify); | ||
585 | |||
586 | if (!device || !acpi_driver_data(device)) | ||
587 | return -EINVAL; | ||
588 | |||
234 | fujitsu->acpi_handle = NULL; | 589 | fujitsu->acpi_handle = NULL; |
235 | 590 | ||
236 | return 0; | 591 | return 0; |
237 | } | 592 | } |
238 | 593 | ||
594 | /* Brightness notify */ | ||
595 | |||
596 | static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data) | ||
597 | { | ||
598 | struct input_dev *input; | ||
599 | int keycode; | ||
600 | int oldb, newb; | ||
601 | |||
602 | input = fujitsu->input; | ||
603 | |||
604 | switch (event) { | ||
605 | case ACPI_FUJITSU_NOTIFY_CODE1: | ||
606 | keycode = 0; | ||
607 | oldb = fujitsu->brightness_level; | ||
608 | get_lcd_level(); /* the alt version always yields changed */ | ||
609 | newb = fujitsu->brightness_level; | ||
610 | |||
611 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | ||
612 | "brightness button event [%i -> %i (%i)]\n", | ||
613 | oldb, newb, fujitsu->brightness_changed); | ||
614 | |||
615 | if (oldb == newb && fujitsu->brightness_changed) { | ||
616 | keycode = 0; | ||
617 | if (disable_brightness_keys != 1) { | ||
618 | if (oldb == 0) { | ||
619 | acpi_bus_generate_proc_event(fujitsu-> | ||
620 | dev, | ||
621 | ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, | ||
622 | 0); | ||
623 | keycode = KEY_BRIGHTNESSDOWN; | ||
624 | } else if (oldb == | ||
625 | (fujitsu->max_brightness) - 1) { | ||
626 | acpi_bus_generate_proc_event(fujitsu-> | ||
627 | dev, | ||
628 | ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, | ||
629 | 0); | ||
630 | keycode = KEY_BRIGHTNESSUP; | ||
631 | } | ||
632 | } | ||
633 | } else if (oldb < newb) { | ||
634 | if (disable_brightness_adjust != 1) { | ||
635 | if (use_alt_lcd_levels) | ||
636 | set_lcd_level_alt(newb); | ||
637 | else | ||
638 | set_lcd_level(newb); | ||
639 | } | ||
640 | if (disable_brightness_keys != 1) { | ||
641 | acpi_bus_generate_proc_event(fujitsu->dev, | ||
642 | ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, | ||
643 | 0); | ||
644 | keycode = KEY_BRIGHTNESSUP; | ||
645 | } | ||
646 | } else if (oldb > newb) { | ||
647 | if (disable_brightness_adjust != 1) { | ||
648 | if (use_alt_lcd_levels) | ||
649 | set_lcd_level_alt(newb); | ||
650 | else | ||
651 | set_lcd_level(newb); | ||
652 | } | ||
653 | if (disable_brightness_keys != 1) { | ||
654 | acpi_bus_generate_proc_event(fujitsu->dev, | ||
655 | ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, | ||
656 | 0); | ||
657 | keycode = KEY_BRIGHTNESSDOWN; | ||
658 | } | ||
659 | } else { | ||
660 | keycode = KEY_UNKNOWN; | ||
661 | } | ||
662 | break; | ||
663 | default: | ||
664 | keycode = KEY_UNKNOWN; | ||
665 | vdbg_printk(FUJLAPTOP_DBG_WARN, | ||
666 | "unsupported event [0x%x]\n", event); | ||
667 | break; | ||
668 | } | ||
669 | |||
670 | if (keycode != 0) { | ||
671 | input_report_key(input, keycode, 1); | ||
672 | input_sync(input); | ||
673 | input_report_key(input, keycode, 0); | ||
674 | input_sync(input); | ||
675 | } | ||
676 | |||
677 | return; | ||
678 | } | ||
679 | |||
680 | /* ACPI device for hotkey handling */ | ||
681 | |||
682 | static int acpi_fujitsu_hotkey_add(struct acpi_device *device) | ||
683 | { | ||
684 | acpi_status status; | ||
685 | acpi_handle handle; | ||
686 | int result = 0; | ||
687 | int state = 0; | ||
688 | struct input_dev *input; | ||
689 | int error; | ||
690 | int i; | ||
691 | |||
692 | if (!device) | ||
693 | return -EINVAL; | ||
694 | |||
695 | fujitsu_hotkey->acpi_handle = device->handle; | ||
696 | sprintf(acpi_device_name(device), "%s", | ||
697 | ACPI_FUJITSU_HOTKEY_DEVICE_NAME); | ||
698 | sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS); | ||
699 | acpi_driver_data(device) = fujitsu_hotkey; | ||
700 | |||
701 | status = acpi_install_notify_handler(device->handle, | ||
702 | ACPI_DEVICE_NOTIFY, | ||
703 | acpi_fujitsu_hotkey_notify, | ||
704 | fujitsu_hotkey); | ||
705 | |||
706 | if (ACPI_FAILURE(status)) { | ||
707 | printk(KERN_ERR "Error installing notify handler\n"); | ||
708 | error = -ENODEV; | ||
709 | goto err_stop; | ||
710 | } | ||
711 | |||
712 | /* kfifo */ | ||
713 | spin_lock_init(&fujitsu_hotkey->fifo_lock); | ||
714 | fujitsu_hotkey->fifo = | ||
715 | kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL, | ||
716 | &fujitsu_hotkey->fifo_lock); | ||
717 | if (IS_ERR(fujitsu_hotkey->fifo)) { | ||
718 | printk(KERN_ERR "kfifo_alloc failed\n"); | ||
719 | error = PTR_ERR(fujitsu_hotkey->fifo); | ||
720 | goto err_stop; | ||
721 | } | ||
722 | |||
723 | fujitsu_hotkey->input = input = input_allocate_device(); | ||
724 | if (!input) { | ||
725 | error = -ENOMEM; | ||
726 | goto err_uninstall_notify; | ||
727 | } | ||
728 | |||
729 | snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys), | ||
730 | "%s/video/input0", acpi_device_hid(device)); | ||
731 | |||
732 | input->name = acpi_device_name(device); | ||
733 | input->phys = fujitsu_hotkey->phys; | ||
734 | input->id.bustype = BUS_HOST; | ||
735 | input->id.product = 0x06; | ||
736 | input->dev.parent = &device->dev; | ||
737 | input->evbit[0] = BIT(EV_KEY); | ||
738 | set_bit(KEY_SCREENLOCK, input->keybit); | ||
739 | set_bit(KEY_MEDIA, input->keybit); | ||
740 | set_bit(KEY_EMAIL, input->keybit); | ||
741 | set_bit(KEY_SUSPEND, input->keybit); | ||
742 | set_bit(KEY_UNKNOWN, input->keybit); | ||
743 | |||
744 | error = input_register_device(input); | ||
745 | if (error) | ||
746 | goto err_free_input_dev; | ||
747 | |||
748 | result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state); | ||
749 | if (result) { | ||
750 | printk(KERN_ERR "Error reading power state\n"); | ||
751 | goto end; | ||
752 | } | ||
753 | |||
754 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", | ||
755 | acpi_device_name(device), acpi_device_bid(device), | ||
756 | !device->power.state ? "on" : "off"); | ||
757 | |||
758 | fujitsu_hotkey->dev = device; | ||
759 | |||
760 | if (ACPI_SUCCESS | ||
761 | (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) { | ||
762 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n"); | ||
763 | if (ACPI_FAILURE | ||
764 | (acpi_evaluate_object | ||
765 | (device->handle, METHOD_NAME__INI, NULL, NULL))) | ||
766 | printk(KERN_ERR "_INI Method failed\n"); | ||
767 | } | ||
768 | |||
769 | i = 0; /* Discard hotkey ringbuffer */ | ||
770 | while (get_irb() != 0 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) ; | ||
771 | vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i); | ||
772 | |||
773 | return result; | ||
774 | |||
775 | end: | ||
776 | err_free_input_dev: | ||
777 | input_free_device(input); | ||
778 | err_uninstall_notify: | ||
779 | acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, | ||
780 | acpi_fujitsu_hotkey_notify); | ||
781 | kfifo_free(fujitsu_hotkey->fifo); | ||
782 | err_stop: | ||
783 | |||
784 | return result; | ||
785 | } | ||
786 | |||
787 | static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type) | ||
788 | { | ||
789 | acpi_status status; | ||
790 | struct fujitsu_hotkey_t *fujitsu_hotkey = NULL; | ||
791 | |||
792 | if (!device || !acpi_driver_data(device)) | ||
793 | return -EINVAL; | ||
794 | |||
795 | fujitsu_hotkey = acpi_driver_data(device); | ||
796 | |||
797 | status = acpi_remove_notify_handler(fujitsu_hotkey->acpi_handle, | ||
798 | ACPI_DEVICE_NOTIFY, | ||
799 | acpi_fujitsu_hotkey_notify); | ||
800 | |||
801 | fujitsu_hotkey->acpi_handle = NULL; | ||
802 | |||
803 | kfifo_free(fujitsu_hotkey->fifo); | ||
804 | |||
805 | return 0; | ||
806 | } | ||
807 | |||
808 | static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event, | ||
809 | void *data) | ||
810 | { | ||
811 | struct input_dev *input; | ||
812 | int keycode, keycode_r; | ||
813 | unsigned int irb = 1; | ||
814 | int i, status; | ||
815 | |||
816 | input = fujitsu_hotkey->input; | ||
817 | |||
818 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "Hotkey event\n"); | ||
819 | |||
820 | switch (event) { | ||
821 | case ACPI_FUJITSU_NOTIFY_CODE1: | ||
822 | i = 0; | ||
823 | while ((irb = get_irb()) != 0 | ||
824 | && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) { | ||
825 | vdbg_printk(FUJLAPTOP_DBG_TRACE, "GIRB result [%x]\n", | ||
826 | irb); | ||
827 | |||
828 | switch (irb & 0x4ff) { | ||
829 | case LOCK_KEY: | ||
830 | keycode = KEY_SCREENLOCK; | ||
831 | break; | ||
832 | case DISPLAY_KEY: | ||
833 | keycode = KEY_MEDIA; | ||
834 | break; | ||
835 | case ENERGY_KEY: | ||
836 | keycode = KEY_EMAIL; | ||
837 | break; | ||
838 | case REST_KEY: | ||
839 | keycode = KEY_SUSPEND; | ||
840 | break; | ||
841 | case 0: | ||
842 | keycode = 0; | ||
843 | break; | ||
844 | default: | ||
845 | vdbg_printk(FUJLAPTOP_DBG_WARN, | ||
846 | "Unknown GIRB result [%x]\n", irb); | ||
847 | keycode = -1; | ||
848 | break; | ||
849 | } | ||
850 | if (keycode > 0) { | ||
851 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | ||
852 | "Push keycode into ringbuffer [%d]\n", | ||
853 | keycode); | ||
854 | status = kfifo_put(fujitsu_hotkey->fifo, | ||
855 | (unsigned char *)&keycode, | ||
856 | sizeof(keycode)); | ||
857 | if (status != sizeof(keycode)) { | ||
858 | vdbg_printk(FUJLAPTOP_DBG_WARN, | ||
859 | "Could not push keycode [0x%x]\n", | ||
860 | keycode); | ||
861 | } else { | ||
862 | input_report_key(input, keycode, 1); | ||
863 | input_sync(input); | ||
864 | } | ||
865 | } else if (keycode == 0) { | ||
866 | while ((status = | ||
867 | kfifo_get | ||
868 | (fujitsu_hotkey->fifo, (unsigned char *) | ||
869 | &keycode_r, | ||
870 | sizeof | ||
871 | (keycode_r))) == sizeof(keycode_r)) { | ||
872 | input_report_key(input, keycode_r, 0); | ||
873 | input_sync(input); | ||
874 | vdbg_printk(FUJLAPTOP_DBG_TRACE, | ||
875 | "Pop keycode from ringbuffer [%d]\n", | ||
876 | keycode_r); | ||
877 | } | ||
878 | } | ||
879 | } | ||
880 | |||
881 | break; | ||
882 | default: | ||
883 | keycode = KEY_UNKNOWN; | ||
884 | vdbg_printk(FUJLAPTOP_DBG_WARN, | ||
885 | "Unsupported event [0x%x]\n", event); | ||
886 | input_report_key(input, keycode, 1); | ||
887 | input_sync(input); | ||
888 | input_report_key(input, keycode, 0); | ||
889 | input_sync(input); | ||
890 | break; | ||
891 | } | ||
892 | |||
893 | return; | ||
894 | } | ||
895 | |||
896 | /* Initialization */ | ||
897 | |||
239 | static const struct acpi_device_id fujitsu_device_ids[] = { | 898 | static const struct acpi_device_id fujitsu_device_ids[] = { |
240 | {ACPI_FUJITSU_HID, 0}, | 899 | {ACPI_FUJITSU_HID, 0}, |
241 | {"", 0}, | 900 | {"", 0}, |
@@ -251,11 +910,24 @@ static struct acpi_driver acpi_fujitsu_driver = { | |||
251 | }, | 910 | }, |
252 | }; | 911 | }; |
253 | 912 | ||
254 | /* Initialization */ | 913 | static const struct acpi_device_id fujitsu_hotkey_device_ids[] = { |
914 | {ACPI_FUJITSU_HOTKEY_HID, 0}, | ||
915 | {"", 0}, | ||
916 | }; | ||
917 | |||
918 | static struct acpi_driver acpi_fujitsu_hotkey_driver = { | ||
919 | .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME, | ||
920 | .class = ACPI_FUJITSU_CLASS, | ||
921 | .ids = fujitsu_hotkey_device_ids, | ||
922 | .ops = { | ||
923 | .add = acpi_fujitsu_hotkey_add, | ||
924 | .remove = acpi_fujitsu_hotkey_remove, | ||
925 | }, | ||
926 | }; | ||
255 | 927 | ||
256 | static int __init fujitsu_init(void) | 928 | static int __init fujitsu_init(void) |
257 | { | 929 | { |
258 | int ret, result; | 930 | int ret, result, max_brightness; |
259 | 931 | ||
260 | if (acpi_disabled) | 932 | if (acpi_disabled) |
261 | return -ENODEV; | 933 | return -ENODEV; |
@@ -271,19 +943,6 @@ static int __init fujitsu_init(void) | |||
271 | goto fail_acpi; | 943 | goto fail_acpi; |
272 | } | 944 | } |
273 | 945 | ||
274 | /* Register backlight stuff */ | ||
275 | |||
276 | fujitsu->bl_device = | ||
277 | backlight_device_register("fujitsu-laptop", NULL, NULL, | ||
278 | &fujitsubl_ops); | ||
279 | if (IS_ERR(fujitsu->bl_device)) | ||
280 | return PTR_ERR(fujitsu->bl_device); | ||
281 | |||
282 | fujitsu->bl_device->props.max_brightness = FUJITSU_LCD_N_LEVELS - 1; | ||
283 | ret = platform_driver_register(&fujitsupf_driver); | ||
284 | if (ret) | ||
285 | goto fail_backlight; | ||
286 | |||
287 | /* Register platform stuff */ | 946 | /* Register platform stuff */ |
288 | 947 | ||
289 | fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1); | 948 | fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1); |
@@ -302,28 +961,68 @@ static int __init fujitsu_init(void) | |||
302 | if (ret) | 961 | if (ret) |
303 | goto fail_platform_device2; | 962 | goto fail_platform_device2; |
304 | 963 | ||
964 | /* Register backlight stuff */ | ||
965 | |||
966 | fujitsu->bl_device = | ||
967 | backlight_device_register("fujitsu-laptop", NULL, NULL, | ||
968 | &fujitsubl_ops); | ||
969 | if (IS_ERR(fujitsu->bl_device)) | ||
970 | return PTR_ERR(fujitsu->bl_device); | ||
971 | |||
972 | max_brightness = fujitsu->max_brightness; | ||
973 | |||
974 | fujitsu->bl_device->props.max_brightness = max_brightness - 1; | ||
975 | fujitsu->bl_device->props.brightness = fujitsu->brightness_level; | ||
976 | |||
977 | ret = platform_driver_register(&fujitsupf_driver); | ||
978 | if (ret) | ||
979 | goto fail_backlight; | ||
980 | |||
981 | /* Register hotkey driver */ | ||
982 | |||
983 | fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL); | ||
984 | if (!fujitsu_hotkey) { | ||
985 | ret = -ENOMEM; | ||
986 | goto fail_hotkey; | ||
987 | } | ||
988 | memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t)); | ||
989 | |||
990 | result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver); | ||
991 | if (result < 0) { | ||
992 | ret = -ENODEV; | ||
993 | goto fail_hotkey1; | ||
994 | } | ||
995 | |||
305 | printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION | 996 | printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION |
306 | " successfully loaded.\n"); | 997 | " successfully loaded.\n"); |
307 | 998 | ||
308 | return 0; | 999 | return 0; |
309 | 1000 | ||
310 | fail_platform_device2: | 1001 | fail_hotkey1: |
311 | 1002 | ||
312 | platform_device_del(fujitsu->pf_device); | 1003 | kfree(fujitsu_hotkey); |
313 | |||
314 | fail_platform_device1: | ||
315 | |||
316 | platform_device_put(fujitsu->pf_device); | ||
317 | 1004 | ||
318 | fail_platform_driver: | 1005 | fail_hotkey: |
319 | 1006 | ||
320 | platform_driver_unregister(&fujitsupf_driver); | 1007 | platform_driver_unregister(&fujitsupf_driver); |
321 | 1008 | ||
322 | fail_backlight: | 1009 | fail_backlight: |
323 | 1010 | ||
324 | backlight_device_unregister(fujitsu->bl_device); | 1011 | backlight_device_unregister(fujitsu->bl_device); |
325 | 1012 | ||
326 | fail_acpi: | 1013 | fail_platform_device2: |
1014 | |||
1015 | platform_device_del(fujitsu->pf_device); | ||
1016 | |||
1017 | fail_platform_device1: | ||
1018 | |||
1019 | platform_device_put(fujitsu->pf_device); | ||
1020 | |||
1021 | fail_platform_driver: | ||
1022 | |||
1023 | acpi_bus_unregister_driver(&acpi_fujitsu_driver); | ||
1024 | |||
1025 | fail_acpi: | ||
327 | 1026 | ||
328 | kfree(fujitsu); | 1027 | kfree(fujitsu); |
329 | 1028 | ||
@@ -342,19 +1041,43 @@ static void __exit fujitsu_cleanup(void) | |||
342 | 1041 | ||
343 | kfree(fujitsu); | 1042 | kfree(fujitsu); |
344 | 1043 | ||
1044 | acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver); | ||
1045 | |||
1046 | kfree(fujitsu_hotkey); | ||
1047 | |||
345 | printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n"); | 1048 | printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n"); |
346 | } | 1049 | } |
347 | 1050 | ||
348 | module_init(fujitsu_init); | 1051 | module_init(fujitsu_init); |
349 | module_exit(fujitsu_cleanup); | 1052 | module_exit(fujitsu_cleanup); |
350 | 1053 | ||
351 | MODULE_AUTHOR("Jonathan Woithe"); | 1054 | module_param(use_alt_lcd_levels, uint, 0644); |
1055 | MODULE_PARM_DESC(use_alt_lcd_levels, | ||
1056 | "Use alternative interface for lcd_levels (needed for Lifebook s6410)."); | ||
1057 | module_param(disable_brightness_keys, uint, 0644); | ||
1058 | MODULE_PARM_DESC(disable_brightness_keys, | ||
1059 | "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device)."); | ||
1060 | module_param(disable_brightness_adjust, uint, 0644); | ||
1061 | MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment ."); | ||
1062 | #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG | ||
1063 | module_param_named(debug, dbg_level, uint, 0644); | ||
1064 | MODULE_PARM_DESC(debug, "Sets debug level bit-mask"); | ||
1065 | #endif | ||
1066 | |||
1067 | MODULE_AUTHOR("Jonathan Woithe, Peter Gruber"); | ||
352 | MODULE_DESCRIPTION("Fujitsu laptop extras support"); | 1068 | MODULE_DESCRIPTION("Fujitsu laptop extras support"); |
353 | MODULE_VERSION(FUJITSU_DRIVER_VERSION); | 1069 | MODULE_VERSION(FUJITSU_DRIVER_VERSION); |
354 | MODULE_LICENSE("GPL"); | 1070 | MODULE_LICENSE("GPL"); |
355 | 1071 | ||
1072 | MODULE_ALIAS | ||
1073 | ("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*"); | ||
1074 | MODULE_ALIAS | ||
1075 | ("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*"); | ||
1076 | |||
356 | static struct pnp_device_id pnp_ids[] = { | 1077 | static struct pnp_device_id pnp_ids[] = { |
357 | { .id = "FUJ02bf" }, | 1078 | { .id = "FUJ02bf" }, |
1079 | { .id = "FUJ02B1" }, | ||
1080 | { .id = "FUJ02E3" }, | ||
358 | { .id = "" } | 1081 | { .id = "" } |
359 | }; | 1082 | }; |
360 | MODULE_DEVICE_TABLE(pnp, pnp_ids); | 1083 | MODULE_DEVICE_TABLE(pnp, pnp_ids); |
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index f9ad960d7c1a..66e5a5487c20 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * Block driver for media (i.e., flash cards) | 2 | * Block driver for media (i.e., flash cards) |
3 | * | 3 | * |
4 | * Copyright 2002 Hewlett-Packard Company | 4 | * Copyright 2002 Hewlett-Packard Company |
5 | * Copyright 2005-2007 Pierre Ossman | 5 | * Copyright 2005-2008 Pierre Ossman |
6 | * | 6 | * |
7 | * Use consistent with the GNU GPL is permitted, | 7 | * Use consistent with the GNU GPL is permitted, |
8 | * provided that this copyright notice is | 8 | * provided that this copyright notice is |
@@ -237,17 +237,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
237 | if (brq.data.blocks > card->host->max_blk_count) | 237 | if (brq.data.blocks > card->host->max_blk_count) |
238 | brq.data.blocks = card->host->max_blk_count; | 238 | brq.data.blocks = card->host->max_blk_count; |
239 | 239 | ||
240 | /* | ||
241 | * If the host doesn't support multiple block writes, force | ||
242 | * block writes to single block. SD cards are excepted from | ||
243 | * this rule as they support querying the number of | ||
244 | * successfully written sectors. | ||
245 | */ | ||
246 | if (rq_data_dir(req) != READ && | ||
247 | !(card->host->caps & MMC_CAP_MULTIWRITE) && | ||
248 | !mmc_card_sd(card)) | ||
249 | brq.data.blocks = 1; | ||
250 | |||
251 | if (brq.data.blocks > 1) { | 240 | if (brq.data.blocks > 1) { |
252 | /* SPI multiblock writes terminate using a special | 241 | /* SPI multiblock writes terminate using a special |
253 | * token, not a STOP_TRANSMISSION request. | 242 | * token, not a STOP_TRANSMISSION request. |
@@ -296,22 +285,24 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
296 | 285 | ||
297 | mmc_queue_bounce_post(mq); | 286 | mmc_queue_bounce_post(mq); |
298 | 287 | ||
288 | /* | ||
289 | * Check for errors here, but don't jump to cmd_err | ||
290 | * until later as we need to wait for the card to leave | ||
291 | * programming mode even when things go wrong. | ||
292 | */ | ||
299 | if (brq.cmd.error) { | 293 | if (brq.cmd.error) { |
300 | printk(KERN_ERR "%s: error %d sending read/write command\n", | 294 | printk(KERN_ERR "%s: error %d sending read/write command\n", |
301 | req->rq_disk->disk_name, brq.cmd.error); | 295 | req->rq_disk->disk_name, brq.cmd.error); |
302 | goto cmd_err; | ||
303 | } | 296 | } |
304 | 297 | ||
305 | if (brq.data.error) { | 298 | if (brq.data.error) { |
306 | printk(KERN_ERR "%s: error %d transferring data\n", | 299 | printk(KERN_ERR "%s: error %d transferring data\n", |
307 | req->rq_disk->disk_name, brq.data.error); | 300 | req->rq_disk->disk_name, brq.data.error); |
308 | goto cmd_err; | ||
309 | } | 301 | } |
310 | 302 | ||
311 | if (brq.stop.error) { | 303 | if (brq.stop.error) { |
312 | printk(KERN_ERR "%s: error %d sending stop command\n", | 304 | printk(KERN_ERR "%s: error %d sending stop command\n", |
313 | req->rq_disk->disk_name, brq.stop.error); | 305 | req->rq_disk->disk_name, brq.stop.error); |
314 | goto cmd_err; | ||
315 | } | 306 | } |
316 | 307 | ||
317 | if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { | 308 | if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { |
@@ -344,6 +335,9 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
344 | #endif | 335 | #endif |
345 | } | 336 | } |
346 | 337 | ||
338 | if (brq.cmd.error || brq.data.error || brq.stop.error) | ||
339 | goto cmd_err; | ||
340 | |||
347 | /* | 341 | /* |
348 | * A block was successfully transferred. | 342 | * A block was successfully transferred. |
349 | */ | 343 | */ |
@@ -362,30 +356,32 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) | |||
362 | * mark the known good sectors as ok. | 356 | * mark the known good sectors as ok. |
363 | * | 357 | * |
364 | * If the card is not SD, we can still ok written sectors | 358 | * If the card is not SD, we can still ok written sectors |
365 | * if the controller can do proper error reporting. | 359 | * as reported by the controller (which might be less than |
360 | * the real number of written sectors, but never more). | ||
366 | * | 361 | * |
367 | * For reads we just fail the entire chunk as that should | 362 | * For reads we just fail the entire chunk as that should |
368 | * be safe in all cases. | 363 | * be safe in all cases. |
369 | */ | 364 | */ |
370 | if (rq_data_dir(req) != READ && mmc_card_sd(card)) { | 365 | if (rq_data_dir(req) != READ) { |
371 | u32 blocks; | 366 | if (mmc_card_sd(card)) { |
372 | unsigned int bytes; | 367 | u32 blocks; |
373 | 368 | unsigned int bytes; | |
374 | blocks = mmc_sd_num_wr_blocks(card); | 369 | |
375 | if (blocks != (u32)-1) { | 370 | blocks = mmc_sd_num_wr_blocks(card); |
376 | if (card->csd.write_partial) | 371 | if (blocks != (u32)-1) { |
377 | bytes = blocks << md->block_bits; | 372 | if (card->csd.write_partial) |
378 | else | 373 | bytes = blocks << md->block_bits; |
379 | bytes = blocks << 9; | 374 | else |
375 | bytes = blocks << 9; | ||
376 | spin_lock_irq(&md->lock); | ||
377 | ret = __blk_end_request(req, 0, bytes); | ||
378 | spin_unlock_irq(&md->lock); | ||
379 | } | ||
380 | } else { | ||
380 | spin_lock_irq(&md->lock); | 381 | spin_lock_irq(&md->lock); |
381 | ret = __blk_end_request(req, 0, bytes); | 382 | ret = __blk_end_request(req, 0, brq.data.bytes_xfered); |
382 | spin_unlock_irq(&md->lock); | 383 | spin_unlock_irq(&md->lock); |
383 | } | 384 | } |
384 | } else if (rq_data_dir(req) != READ && | ||
385 | (card->host->caps & MMC_CAP_MULTIWRITE)) { | ||
386 | spin_lock_irq(&md->lock); | ||
387 | ret = __blk_end_request(req, 0, brq.data.bytes_xfered); | ||
388 | spin_unlock_irq(&md->lock); | ||
389 | } | 385 | } |
390 | 386 | ||
391 | mmc_release_host(card->host); | 387 | mmc_release_host(card->host); |
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c index ffadee549a41..d6b9b486417c 100644 --- a/drivers/mmc/card/mmc_test.c +++ b/drivers/mmc/card/mmc_test.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/mmc/card/mmc_test.c | 2 | * linux/drivers/mmc/card/mmc_test.c |
3 | * | 3 | * |
4 | * Copyright 2007 Pierre Ossman | 4 | * Copyright 2007-2008 Pierre Ossman |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
@@ -26,13 +26,17 @@ | |||
26 | struct mmc_test_card { | 26 | struct mmc_test_card { |
27 | struct mmc_card *card; | 27 | struct mmc_card *card; |
28 | 28 | ||
29 | u8 scratch[BUFFER_SIZE]; | ||
29 | u8 *buffer; | 30 | u8 *buffer; |
30 | }; | 31 | }; |
31 | 32 | ||
32 | /*******************************************************************/ | 33 | /*******************************************************************/ |
33 | /* Helper functions */ | 34 | /* General helper functions */ |
34 | /*******************************************************************/ | 35 | /*******************************************************************/ |
35 | 36 | ||
37 | /* | ||
38 | * Configure correct block size in card | ||
39 | */ | ||
36 | static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size) | 40 | static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size) |
37 | { | 41 | { |
38 | struct mmc_command cmd; | 42 | struct mmc_command cmd; |
@@ -48,117 +52,61 @@ static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size) | |||
48 | return 0; | 52 | return 0; |
49 | } | 53 | } |
50 | 54 | ||
51 | static int __mmc_test_transfer(struct mmc_test_card *test, int write, | 55 | /* |
52 | unsigned broken_xfer, u8 *buffer, unsigned addr, | 56 | * Fill in the mmc_request structure given a set of transfer parameters. |
53 | unsigned blocks, unsigned blksz) | 57 | */ |
58 | static void mmc_test_prepare_mrq(struct mmc_test_card *test, | ||
59 | struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len, | ||
60 | unsigned dev_addr, unsigned blocks, unsigned blksz, int write) | ||
54 | { | 61 | { |
55 | int ret, busy; | 62 | BUG_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop); |
56 | |||
57 | struct mmc_request mrq; | ||
58 | struct mmc_command cmd; | ||
59 | struct mmc_command stop; | ||
60 | struct mmc_data data; | ||
61 | |||
62 | struct scatterlist sg; | ||
63 | |||
64 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
65 | |||
66 | mrq.cmd = &cmd; | ||
67 | mrq.data = &data; | ||
68 | |||
69 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
70 | 63 | ||
71 | if (broken_xfer) { | 64 | if (blocks > 1) { |
72 | if (blocks > 1) { | 65 | mrq->cmd->opcode = write ? |
73 | cmd.opcode = write ? | 66 | MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK; |
74 | MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK; | ||
75 | } else { | ||
76 | cmd.opcode = MMC_SEND_STATUS; | ||
77 | } | ||
78 | } else { | 67 | } else { |
79 | if (blocks > 1) { | 68 | mrq->cmd->opcode = write ? |
80 | cmd.opcode = write ? | 69 | MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK; |
81 | MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK; | ||
82 | } else { | ||
83 | cmd.opcode = write ? | ||
84 | MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK; | ||
85 | } | ||
86 | } | 70 | } |
87 | 71 | ||
88 | if (broken_xfer && blocks == 1) | 72 | mrq->cmd->arg = dev_addr; |
89 | cmd.arg = test->card->rca << 16; | 73 | mrq->cmd->flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
90 | else | ||
91 | cmd.arg = addr; | ||
92 | cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; | ||
93 | 74 | ||
94 | memset(&stop, 0, sizeof(struct mmc_command)); | 75 | if (blocks == 1) |
95 | 76 | mrq->stop = NULL; | |
96 | if (!broken_xfer && (blocks > 1)) { | 77 | else { |
97 | stop.opcode = MMC_STOP_TRANSMISSION; | 78 | mrq->stop->opcode = MMC_STOP_TRANSMISSION; |
98 | stop.arg = 0; | 79 | mrq->stop->arg = 0; |
99 | stop.flags = MMC_RSP_R1B | MMC_CMD_AC; | 80 | mrq->stop->flags = MMC_RSP_R1B | MMC_CMD_AC; |
100 | |||
101 | mrq.stop = &stop; | ||
102 | } | 81 | } |
103 | 82 | ||
104 | memset(&data, 0, sizeof(struct mmc_data)); | 83 | mrq->data->blksz = blksz; |
105 | 84 | mrq->data->blocks = blocks; | |
106 | data.blksz = blksz; | 85 | mrq->data->flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; |
107 | data.blocks = blocks; | 86 | mrq->data->sg = sg; |
108 | data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ; | 87 | mrq->data->sg_len = sg_len; |
109 | data.sg = &sg; | ||
110 | data.sg_len = 1; | ||
111 | |||
112 | sg_init_one(&sg, buffer, blocks * blksz); | ||
113 | |||
114 | mmc_set_data_timeout(&data, test->card); | ||
115 | 88 | ||
116 | mmc_wait_for_req(test->card->host, &mrq); | 89 | mmc_set_data_timeout(mrq->data, test->card); |
117 | 90 | } | |
118 | ret = 0; | ||
119 | |||
120 | if (broken_xfer) { | ||
121 | if (!ret && cmd.error) | ||
122 | ret = cmd.error; | ||
123 | if (!ret && data.error == 0) | ||
124 | ret = RESULT_FAIL; | ||
125 | if (!ret && data.error != -ETIMEDOUT) | ||
126 | ret = data.error; | ||
127 | if (!ret && stop.error) | ||
128 | ret = stop.error; | ||
129 | if (blocks > 1) { | ||
130 | if (!ret && data.bytes_xfered > blksz) | ||
131 | ret = RESULT_FAIL; | ||
132 | } else { | ||
133 | if (!ret && data.bytes_xfered > 0) | ||
134 | ret = RESULT_FAIL; | ||
135 | } | ||
136 | } else { | ||
137 | if (!ret && cmd.error) | ||
138 | ret = cmd.error; | ||
139 | if (!ret && data.error) | ||
140 | ret = data.error; | ||
141 | if (!ret && stop.error) | ||
142 | ret = stop.error; | ||
143 | if (!ret && data.bytes_xfered != blocks * blksz) | ||
144 | ret = RESULT_FAIL; | ||
145 | } | ||
146 | 91 | ||
147 | if (ret == -EINVAL) | 92 | /* |
148 | ret = RESULT_UNSUP_HOST; | 93 | * Wait for the card to finish the busy state |
94 | */ | ||
95 | static int mmc_test_wait_busy(struct mmc_test_card *test) | ||
96 | { | ||
97 | int ret, busy; | ||
98 | struct mmc_command cmd; | ||
149 | 99 | ||
150 | busy = 0; | 100 | busy = 0; |
151 | do { | 101 | do { |
152 | int ret2; | ||
153 | |||
154 | memset(&cmd, 0, sizeof(struct mmc_command)); | 102 | memset(&cmd, 0, sizeof(struct mmc_command)); |
155 | 103 | ||
156 | cmd.opcode = MMC_SEND_STATUS; | 104 | cmd.opcode = MMC_SEND_STATUS; |
157 | cmd.arg = test->card->rca << 16; | 105 | cmd.arg = test->card->rca << 16; |
158 | cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; | 106 | cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; |
159 | 107 | ||
160 | ret2 = mmc_wait_for_cmd(test->card->host, &cmd, 0); | 108 | ret = mmc_wait_for_cmd(test->card->host, &cmd, 0); |
161 | if (ret2) | 109 | if (ret) |
162 | break; | 110 | break; |
163 | 111 | ||
164 | if (!busy && !(cmd.resp[0] & R1_READY_FOR_DATA)) { | 112 | if (!busy && !(cmd.resp[0] & R1_READY_FOR_DATA)) { |
@@ -172,14 +120,57 @@ static int __mmc_test_transfer(struct mmc_test_card *test, int write, | |||
172 | return ret; | 120 | return ret; |
173 | } | 121 | } |
174 | 122 | ||
175 | static int mmc_test_transfer(struct mmc_test_card *test, int write, | 123 | /* |
176 | u8 *buffer, unsigned addr, unsigned blocks, unsigned blksz) | 124 | * Transfer a single sector of kernel addressable data |
125 | */ | ||
126 | static int mmc_test_buffer_transfer(struct mmc_test_card *test, | ||
127 | u8 *buffer, unsigned addr, unsigned blksz, int write) | ||
177 | { | 128 | { |
178 | return __mmc_test_transfer(test, write, 0, buffer, | 129 | int ret; |
179 | addr, blocks, blksz); | 130 | |
131 | struct mmc_request mrq; | ||
132 | struct mmc_command cmd; | ||
133 | struct mmc_command stop; | ||
134 | struct mmc_data data; | ||
135 | |||
136 | struct scatterlist sg; | ||
137 | |||
138 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
139 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
140 | memset(&data, 0, sizeof(struct mmc_data)); | ||
141 | memset(&stop, 0, sizeof(struct mmc_command)); | ||
142 | |||
143 | mrq.cmd = &cmd; | ||
144 | mrq.data = &data; | ||
145 | mrq.stop = &stop; | ||
146 | |||
147 | sg_init_one(&sg, buffer, blksz); | ||
148 | |||
149 | mmc_test_prepare_mrq(test, &mrq, &sg, 1, addr, 1, blksz, write); | ||
150 | |||
151 | mmc_wait_for_req(test->card->host, &mrq); | ||
152 | |||
153 | if (cmd.error) | ||
154 | return cmd.error; | ||
155 | if (data.error) | ||
156 | return data.error; | ||
157 | |||
158 | ret = mmc_test_wait_busy(test); | ||
159 | if (ret) | ||
160 | return ret; | ||
161 | |||
162 | return 0; | ||
180 | } | 163 | } |
181 | 164 | ||
182 | static int mmc_test_prepare_verify(struct mmc_test_card *test, int write) | 165 | /*******************************************************************/ |
166 | /* Test preparation and cleanup */ | ||
167 | /*******************************************************************/ | ||
168 | |||
169 | /* | ||
170 | * Fill the first couple of sectors of the card with known data | ||
171 | * so that bad reads/writes can be detected | ||
172 | */ | ||
173 | static int __mmc_test_prepare(struct mmc_test_card *test, int write) | ||
183 | { | 174 | { |
184 | int ret, i; | 175 | int ret, i; |
185 | 176 | ||
@@ -188,15 +179,14 @@ static int mmc_test_prepare_verify(struct mmc_test_card *test, int write) | |||
188 | return ret; | 179 | return ret; |
189 | 180 | ||
190 | if (write) | 181 | if (write) |
191 | memset(test->buffer, 0xDF, BUFFER_SIZE); | 182 | memset(test->buffer, 0xDF, 512); |
192 | else { | 183 | else { |
193 | for (i = 0;i < BUFFER_SIZE;i++) | 184 | for (i = 0;i < 512;i++) |
194 | test->buffer[i] = i; | 185 | test->buffer[i] = i; |
195 | } | 186 | } |
196 | 187 | ||
197 | for (i = 0;i < BUFFER_SIZE / 512;i++) { | 188 | for (i = 0;i < BUFFER_SIZE / 512;i++) { |
198 | ret = mmc_test_transfer(test, 1, test->buffer + i * 512, | 189 | ret = mmc_test_buffer_transfer(test, test->buffer, i * 512, 512, 1); |
199 | i * 512, 1, 512); | ||
200 | if (ret) | 190 | if (ret) |
201 | return ret; | 191 | return ret; |
202 | } | 192 | } |
@@ -204,41 +194,218 @@ static int mmc_test_prepare_verify(struct mmc_test_card *test, int write) | |||
204 | return 0; | 194 | return 0; |
205 | } | 195 | } |
206 | 196 | ||
207 | static int mmc_test_prepare_verify_write(struct mmc_test_card *test) | 197 | static int mmc_test_prepare_write(struct mmc_test_card *test) |
198 | { | ||
199 | return __mmc_test_prepare(test, 1); | ||
200 | } | ||
201 | |||
202 | static int mmc_test_prepare_read(struct mmc_test_card *test) | ||
203 | { | ||
204 | return __mmc_test_prepare(test, 0); | ||
205 | } | ||
206 | |||
207 | static int mmc_test_cleanup(struct mmc_test_card *test) | ||
208 | { | 208 | { |
209 | return mmc_test_prepare_verify(test, 1); | 209 | int ret, i; |
210 | |||
211 | ret = mmc_test_set_blksize(test, 512); | ||
212 | if (ret) | ||
213 | return ret; | ||
214 | |||
215 | memset(test->buffer, 0, 512); | ||
216 | |||
217 | for (i = 0;i < BUFFER_SIZE / 512;i++) { | ||
218 | ret = mmc_test_buffer_transfer(test, test->buffer, i * 512, 512, 1); | ||
219 | if (ret) | ||
220 | return ret; | ||
221 | } | ||
222 | |||
223 | return 0; | ||
210 | } | 224 | } |
211 | 225 | ||
212 | static int mmc_test_prepare_verify_read(struct mmc_test_card *test) | 226 | /*******************************************************************/ |
227 | /* Test execution helpers */ | ||
228 | /*******************************************************************/ | ||
229 | |||
230 | /* | ||
231 | * Modifies the mmc_request to perform the "short transfer" tests | ||
232 | */ | ||
233 | static void mmc_test_prepare_broken_mrq(struct mmc_test_card *test, | ||
234 | struct mmc_request *mrq, int write) | ||
213 | { | 235 | { |
214 | return mmc_test_prepare_verify(test, 0); | 236 | BUG_ON(!mrq || !mrq->cmd || !mrq->data); |
237 | |||
238 | if (mrq->data->blocks > 1) { | ||
239 | mrq->cmd->opcode = write ? | ||
240 | MMC_WRITE_BLOCK : MMC_READ_SINGLE_BLOCK; | ||
241 | mrq->stop = NULL; | ||
242 | } else { | ||
243 | mrq->cmd->opcode = MMC_SEND_STATUS; | ||
244 | mrq->cmd->arg = test->card->rca << 16; | ||
245 | } | ||
215 | } | 246 | } |
216 | 247 | ||
217 | static int mmc_test_verified_transfer(struct mmc_test_card *test, int write, | 248 | /* |
218 | u8 *buffer, unsigned addr, unsigned blocks, unsigned blksz) | 249 | * Checks that a normal transfer didn't have any errors |
250 | */ | ||
251 | static int mmc_test_check_result(struct mmc_test_card *test, | ||
252 | struct mmc_request *mrq) | ||
219 | { | 253 | { |
220 | int ret, i, sectors; | 254 | int ret; |
221 | 255 | ||
222 | /* | 256 | BUG_ON(!mrq || !mrq->cmd || !mrq->data); |
223 | * It is assumed that the above preparation has been done. | 257 | |
224 | */ | 258 | ret = 0; |
225 | 259 | ||
226 | memset(test->buffer, 0, BUFFER_SIZE); | 260 | if (!ret && mrq->cmd->error) |
261 | ret = mrq->cmd->error; | ||
262 | if (!ret && mrq->data->error) | ||
263 | ret = mrq->data->error; | ||
264 | if (!ret && mrq->stop && mrq->stop->error) | ||
265 | ret = mrq->stop->error; | ||
266 | if (!ret && mrq->data->bytes_xfered != | ||
267 | mrq->data->blocks * mrq->data->blksz) | ||
268 | ret = RESULT_FAIL; | ||
269 | |||
270 | if (ret == -EINVAL) | ||
271 | ret = RESULT_UNSUP_HOST; | ||
272 | |||
273 | return ret; | ||
274 | } | ||
275 | |||
276 | /* | ||
277 | * Checks that a "short transfer" behaved as expected | ||
278 | */ | ||
279 | static int mmc_test_check_broken_result(struct mmc_test_card *test, | ||
280 | struct mmc_request *mrq) | ||
281 | { | ||
282 | int ret; | ||
283 | |||
284 | BUG_ON(!mrq || !mrq->cmd || !mrq->data); | ||
285 | |||
286 | ret = 0; | ||
287 | |||
288 | if (!ret && mrq->cmd->error) | ||
289 | ret = mrq->cmd->error; | ||
290 | if (!ret && mrq->data->error == 0) | ||
291 | ret = RESULT_FAIL; | ||
292 | if (!ret && mrq->data->error != -ETIMEDOUT) | ||
293 | ret = mrq->data->error; | ||
294 | if (!ret && mrq->stop && mrq->stop->error) | ||
295 | ret = mrq->stop->error; | ||
296 | if (mrq->data->blocks > 1) { | ||
297 | if (!ret && mrq->data->bytes_xfered > mrq->data->blksz) | ||
298 | ret = RESULT_FAIL; | ||
299 | } else { | ||
300 | if (!ret && mrq->data->bytes_xfered > 0) | ||
301 | ret = RESULT_FAIL; | ||
302 | } | ||
303 | |||
304 | if (ret == -EINVAL) | ||
305 | ret = RESULT_UNSUP_HOST; | ||
306 | |||
307 | return ret; | ||
308 | } | ||
309 | |||
310 | /* | ||
311 | * Tests a basic transfer with certain parameters | ||
312 | */ | ||
313 | static int mmc_test_simple_transfer(struct mmc_test_card *test, | ||
314 | struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, | ||
315 | unsigned blocks, unsigned blksz, int write) | ||
316 | { | ||
317 | struct mmc_request mrq; | ||
318 | struct mmc_command cmd; | ||
319 | struct mmc_command stop; | ||
320 | struct mmc_data data; | ||
321 | |||
322 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
323 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
324 | memset(&data, 0, sizeof(struct mmc_data)); | ||
325 | memset(&stop, 0, sizeof(struct mmc_command)); | ||
326 | |||
327 | mrq.cmd = &cmd; | ||
328 | mrq.data = &data; | ||
329 | mrq.stop = &stop; | ||
330 | |||
331 | mmc_test_prepare_mrq(test, &mrq, sg, sg_len, dev_addr, | ||
332 | blocks, blksz, write); | ||
333 | |||
334 | mmc_wait_for_req(test->card->host, &mrq); | ||
335 | |||
336 | mmc_test_wait_busy(test); | ||
337 | |||
338 | return mmc_test_check_result(test, &mrq); | ||
339 | } | ||
340 | |||
341 | /* | ||
342 | * Tests a transfer where the card will fail completely or partly | ||
343 | */ | ||
344 | static int mmc_test_broken_transfer(struct mmc_test_card *test, | ||
345 | unsigned blocks, unsigned blksz, int write) | ||
346 | { | ||
347 | struct mmc_request mrq; | ||
348 | struct mmc_command cmd; | ||
349 | struct mmc_command stop; | ||
350 | struct mmc_data data; | ||
351 | |||
352 | struct scatterlist sg; | ||
353 | |||
354 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
355 | memset(&cmd, 0, sizeof(struct mmc_command)); | ||
356 | memset(&data, 0, sizeof(struct mmc_data)); | ||
357 | memset(&stop, 0, sizeof(struct mmc_command)); | ||
358 | |||
359 | mrq.cmd = &cmd; | ||
360 | mrq.data = &data; | ||
361 | mrq.stop = &stop; | ||
362 | |||
363 | sg_init_one(&sg, test->buffer, blocks * blksz); | ||
364 | |||
365 | mmc_test_prepare_mrq(test, &mrq, &sg, 1, 0, blocks, blksz, write); | ||
366 | mmc_test_prepare_broken_mrq(test, &mrq, write); | ||
367 | |||
368 | mmc_wait_for_req(test->card->host, &mrq); | ||
369 | |||
370 | mmc_test_wait_busy(test); | ||
371 | |||
372 | return mmc_test_check_broken_result(test, &mrq); | ||
373 | } | ||
374 | |||
375 | /* | ||
376 | * Does a complete transfer test where data is also validated | ||
377 | * | ||
378 | * Note: mmc_test_prepare() must have been done before this call | ||
379 | */ | ||
380 | static int mmc_test_transfer(struct mmc_test_card *test, | ||
381 | struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, | ||
382 | unsigned blocks, unsigned blksz, int write) | ||
383 | { | ||
384 | int ret, i; | ||
385 | unsigned long flags; | ||
227 | 386 | ||
228 | if (write) { | 387 | if (write) { |
229 | for (i = 0;i < blocks * blksz;i++) | 388 | for (i = 0;i < blocks * blksz;i++) |
230 | buffer[i] = i; | 389 | test->scratch[i] = i; |
390 | } else { | ||
391 | memset(test->scratch, 0, BUFFER_SIZE); | ||
231 | } | 392 | } |
393 | local_irq_save(flags); | ||
394 | sg_copy_from_buffer(sg, sg_len, test->scratch, BUFFER_SIZE); | ||
395 | local_irq_restore(flags); | ||
232 | 396 | ||
233 | ret = mmc_test_set_blksize(test, blksz); | 397 | ret = mmc_test_set_blksize(test, blksz); |
234 | if (ret) | 398 | if (ret) |
235 | return ret; | 399 | return ret; |
236 | 400 | ||
237 | ret = mmc_test_transfer(test, write, buffer, addr, blocks, blksz); | 401 | ret = mmc_test_simple_transfer(test, sg, sg_len, dev_addr, |
402 | blocks, blksz, write); | ||
238 | if (ret) | 403 | if (ret) |
239 | return ret; | 404 | return ret; |
240 | 405 | ||
241 | if (write) { | 406 | if (write) { |
407 | int sectors; | ||
408 | |||
242 | ret = mmc_test_set_blksize(test, 512); | 409 | ret = mmc_test_set_blksize(test, 512); |
243 | if (ret) | 410 | if (ret) |
244 | return ret; | 411 | return ret; |
@@ -253,9 +420,9 @@ static int mmc_test_verified_transfer(struct mmc_test_card *test, int write, | |||
253 | memset(test->buffer, 0, sectors * 512); | 420 | memset(test->buffer, 0, sectors * 512); |
254 | 421 | ||
255 | for (i = 0;i < sectors;i++) { | 422 | for (i = 0;i < sectors;i++) { |
256 | ret = mmc_test_transfer(test, 0, | 423 | ret = mmc_test_buffer_transfer(test, |
257 | test->buffer + i * 512, | 424 | test->buffer + i * 512, |
258 | addr + i * 512, 1, 512); | 425 | dev_addr + i * 512, 512, 0); |
259 | if (ret) | 426 | if (ret) |
260 | return ret; | 427 | return ret; |
261 | } | 428 | } |
@@ -270,8 +437,11 @@ static int mmc_test_verified_transfer(struct mmc_test_card *test, int write, | |||
270 | return RESULT_FAIL; | 437 | return RESULT_FAIL; |
271 | } | 438 | } |
272 | } else { | 439 | } else { |
440 | local_irq_save(flags); | ||
441 | sg_copy_to_buffer(sg, sg_len, test->scratch, BUFFER_SIZE); | ||
442 | local_irq_restore(flags); | ||
273 | for (i = 0;i < blocks * blksz;i++) { | 443 | for (i = 0;i < blocks * blksz;i++) { |
274 | if (buffer[i] != (u8)i) | 444 | if (test->scratch[i] != (u8)i) |
275 | return RESULT_FAIL; | 445 | return RESULT_FAIL; |
276 | } | 446 | } |
277 | } | 447 | } |
@@ -279,26 +449,6 @@ static int mmc_test_verified_transfer(struct mmc_test_card *test, int write, | |||
279 | return 0; | 449 | return 0; |
280 | } | 450 | } |
281 | 451 | ||
282 | static int mmc_test_cleanup_verify(struct mmc_test_card *test) | ||
283 | { | ||
284 | int ret, i; | ||
285 | |||
286 | ret = mmc_test_set_blksize(test, 512); | ||
287 | if (ret) | ||
288 | return ret; | ||
289 | |||
290 | memset(test->buffer, 0, BUFFER_SIZE); | ||
291 | |||
292 | for (i = 0;i < BUFFER_SIZE / 512;i++) { | ||
293 | ret = mmc_test_transfer(test, 1, test->buffer + i * 512, | ||
294 | i * 512, 1, 512); | ||
295 | if (ret) | ||
296 | return ret; | ||
297 | } | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | /*******************************************************************/ | 452 | /*******************************************************************/ |
303 | /* Tests */ | 453 | /* Tests */ |
304 | /*******************************************************************/ | 454 | /*******************************************************************/ |
@@ -314,12 +464,15 @@ struct mmc_test_case { | |||
314 | static int mmc_test_basic_write(struct mmc_test_card *test) | 464 | static int mmc_test_basic_write(struct mmc_test_card *test) |
315 | { | 465 | { |
316 | int ret; | 466 | int ret; |
467 | struct scatterlist sg; | ||
317 | 468 | ||
318 | ret = mmc_test_set_blksize(test, 512); | 469 | ret = mmc_test_set_blksize(test, 512); |
319 | if (ret) | 470 | if (ret) |
320 | return ret; | 471 | return ret; |
321 | 472 | ||
322 | ret = mmc_test_transfer(test, 1, test->buffer, 0, 1, 512); | 473 | sg_init_one(&sg, test->buffer, 512); |
474 | |||
475 | ret = mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1); | ||
323 | if (ret) | 476 | if (ret) |
324 | return ret; | 477 | return ret; |
325 | 478 | ||
@@ -329,12 +482,15 @@ static int mmc_test_basic_write(struct mmc_test_card *test) | |||
329 | static int mmc_test_basic_read(struct mmc_test_card *test) | 482 | static int mmc_test_basic_read(struct mmc_test_card *test) |
330 | { | 483 | { |
331 | int ret; | 484 | int ret; |
485 | struct scatterlist sg; | ||
332 | 486 | ||
333 | ret = mmc_test_set_blksize(test, 512); | 487 | ret = mmc_test_set_blksize(test, 512); |
334 | if (ret) | 488 | if (ret) |
335 | return ret; | 489 | return ret; |
336 | 490 | ||
337 | ret = mmc_test_transfer(test, 0, test->buffer, 0, 1, 512); | 491 | sg_init_one(&sg, test->buffer, 512); |
492 | |||
493 | ret = mmc_test_simple_transfer(test, &sg, 1, 0, 1, 512, 1); | ||
338 | if (ret) | 494 | if (ret) |
339 | return ret; | 495 | return ret; |
340 | 496 | ||
@@ -344,8 +500,11 @@ static int mmc_test_basic_read(struct mmc_test_card *test) | |||
344 | static int mmc_test_verify_write(struct mmc_test_card *test) | 500 | static int mmc_test_verify_write(struct mmc_test_card *test) |
345 | { | 501 | { |
346 | int ret; | 502 | int ret; |
503 | struct scatterlist sg; | ||
504 | |||
505 | sg_init_one(&sg, test->buffer, 512); | ||
347 | 506 | ||
348 | ret = mmc_test_verified_transfer(test, 1, test->buffer, 0, 1, 512); | 507 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1); |
349 | if (ret) | 508 | if (ret) |
350 | return ret; | 509 | return ret; |
351 | 510 | ||
@@ -355,8 +514,11 @@ static int mmc_test_verify_write(struct mmc_test_card *test) | |||
355 | static int mmc_test_verify_read(struct mmc_test_card *test) | 514 | static int mmc_test_verify_read(struct mmc_test_card *test) |
356 | { | 515 | { |
357 | int ret; | 516 | int ret; |
517 | struct scatterlist sg; | ||
518 | |||
519 | sg_init_one(&sg, test->buffer, 512); | ||
358 | 520 | ||
359 | ret = mmc_test_verified_transfer(test, 0, test->buffer, 0, 1, 512); | 521 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0); |
360 | if (ret) | 522 | if (ret) |
361 | return ret; | 523 | return ret; |
362 | 524 | ||
@@ -367,6 +529,7 @@ static int mmc_test_multi_write(struct mmc_test_card *test) | |||
367 | { | 529 | { |
368 | int ret; | 530 | int ret; |
369 | unsigned int size; | 531 | unsigned int size; |
532 | struct scatterlist sg; | ||
370 | 533 | ||
371 | if (test->card->host->max_blk_count == 1) | 534 | if (test->card->host->max_blk_count == 1) |
372 | return RESULT_UNSUP_HOST; | 535 | return RESULT_UNSUP_HOST; |
@@ -379,8 +542,9 @@ static int mmc_test_multi_write(struct mmc_test_card *test) | |||
379 | if (size < 1024) | 542 | if (size < 1024) |
380 | return RESULT_UNSUP_HOST; | 543 | return RESULT_UNSUP_HOST; |
381 | 544 | ||
382 | ret = mmc_test_verified_transfer(test, 1, test->buffer, 0, | 545 | sg_init_one(&sg, test->buffer, size); |
383 | size / 512, 512); | 546 | |
547 | ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1); | ||
384 | if (ret) | 548 | if (ret) |
385 | return ret; | 549 | return ret; |
386 | 550 | ||
@@ -391,6 +555,7 @@ static int mmc_test_multi_read(struct mmc_test_card *test) | |||
391 | { | 555 | { |
392 | int ret; | 556 | int ret; |
393 | unsigned int size; | 557 | unsigned int size; |
558 | struct scatterlist sg; | ||
394 | 559 | ||
395 | if (test->card->host->max_blk_count == 1) | 560 | if (test->card->host->max_blk_count == 1) |
396 | return RESULT_UNSUP_HOST; | 561 | return RESULT_UNSUP_HOST; |
@@ -403,8 +568,9 @@ static int mmc_test_multi_read(struct mmc_test_card *test) | |||
403 | if (size < 1024) | 568 | if (size < 1024) |
404 | return RESULT_UNSUP_HOST; | 569 | return RESULT_UNSUP_HOST; |
405 | 570 | ||
406 | ret = mmc_test_verified_transfer(test, 0, test->buffer, 0, | 571 | sg_init_one(&sg, test->buffer, size); |
407 | size / 512, 512); | 572 | |
573 | ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0); | ||
408 | if (ret) | 574 | if (ret) |
409 | return ret; | 575 | return ret; |
410 | 576 | ||
@@ -414,13 +580,14 @@ static int mmc_test_multi_read(struct mmc_test_card *test) | |||
414 | static int mmc_test_pow2_write(struct mmc_test_card *test) | 580 | static int mmc_test_pow2_write(struct mmc_test_card *test) |
415 | { | 581 | { |
416 | int ret, i; | 582 | int ret, i; |
583 | struct scatterlist sg; | ||
417 | 584 | ||
418 | if (!test->card->csd.write_partial) | 585 | if (!test->card->csd.write_partial) |
419 | return RESULT_UNSUP_CARD; | 586 | return RESULT_UNSUP_CARD; |
420 | 587 | ||
421 | for (i = 1; i < 512;i <<= 1) { | 588 | for (i = 1; i < 512;i <<= 1) { |
422 | ret = mmc_test_verified_transfer(test, 1, | 589 | sg_init_one(&sg, test->buffer, i); |
423 | test->buffer, 0, 1, i); | 590 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1); |
424 | if (ret) | 591 | if (ret) |
425 | return ret; | 592 | return ret; |
426 | } | 593 | } |
@@ -431,13 +598,14 @@ static int mmc_test_pow2_write(struct mmc_test_card *test) | |||
431 | static int mmc_test_pow2_read(struct mmc_test_card *test) | 598 | static int mmc_test_pow2_read(struct mmc_test_card *test) |
432 | { | 599 | { |
433 | int ret, i; | 600 | int ret, i; |
601 | struct scatterlist sg; | ||
434 | 602 | ||
435 | if (!test->card->csd.read_partial) | 603 | if (!test->card->csd.read_partial) |
436 | return RESULT_UNSUP_CARD; | 604 | return RESULT_UNSUP_CARD; |
437 | 605 | ||
438 | for (i = 1; i < 512;i <<= 1) { | 606 | for (i = 1; i < 512;i <<= 1) { |
439 | ret = mmc_test_verified_transfer(test, 0, | 607 | sg_init_one(&sg, test->buffer, i); |
440 | test->buffer, 0, 1, i); | 608 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0); |
441 | if (ret) | 609 | if (ret) |
442 | return ret; | 610 | return ret; |
443 | } | 611 | } |
@@ -448,13 +616,14 @@ static int mmc_test_pow2_read(struct mmc_test_card *test) | |||
448 | static int mmc_test_weird_write(struct mmc_test_card *test) | 616 | static int mmc_test_weird_write(struct mmc_test_card *test) |
449 | { | 617 | { |
450 | int ret, i; | 618 | int ret, i; |
619 | struct scatterlist sg; | ||
451 | 620 | ||
452 | if (!test->card->csd.write_partial) | 621 | if (!test->card->csd.write_partial) |
453 | return RESULT_UNSUP_CARD; | 622 | return RESULT_UNSUP_CARD; |
454 | 623 | ||
455 | for (i = 3; i < 512;i += 7) { | 624 | for (i = 3; i < 512;i += 7) { |
456 | ret = mmc_test_verified_transfer(test, 1, | 625 | sg_init_one(&sg, test->buffer, i); |
457 | test->buffer, 0, 1, i); | 626 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 1); |
458 | if (ret) | 627 | if (ret) |
459 | return ret; | 628 | return ret; |
460 | } | 629 | } |
@@ -465,13 +634,14 @@ static int mmc_test_weird_write(struct mmc_test_card *test) | |||
465 | static int mmc_test_weird_read(struct mmc_test_card *test) | 634 | static int mmc_test_weird_read(struct mmc_test_card *test) |
466 | { | 635 | { |
467 | int ret, i; | 636 | int ret, i; |
637 | struct scatterlist sg; | ||
468 | 638 | ||
469 | if (!test->card->csd.read_partial) | 639 | if (!test->card->csd.read_partial) |
470 | return RESULT_UNSUP_CARD; | 640 | return RESULT_UNSUP_CARD; |
471 | 641 | ||
472 | for (i = 3; i < 512;i += 7) { | 642 | for (i = 3; i < 512;i += 7) { |
473 | ret = mmc_test_verified_transfer(test, 0, | 643 | sg_init_one(&sg, test->buffer, i); |
474 | test->buffer, 0, 1, i); | 644 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, i, 0); |
475 | if (ret) | 645 | if (ret) |
476 | return ret; | 646 | return ret; |
477 | } | 647 | } |
@@ -482,10 +652,11 @@ static int mmc_test_weird_read(struct mmc_test_card *test) | |||
482 | static int mmc_test_align_write(struct mmc_test_card *test) | 652 | static int mmc_test_align_write(struct mmc_test_card *test) |
483 | { | 653 | { |
484 | int ret, i; | 654 | int ret, i; |
655 | struct scatterlist sg; | ||
485 | 656 | ||
486 | for (i = 1;i < 4;i++) { | 657 | for (i = 1;i < 4;i++) { |
487 | ret = mmc_test_verified_transfer(test, 1, test->buffer + i, | 658 | sg_init_one(&sg, test->buffer + i, 512); |
488 | 0, 1, 512); | 659 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1); |
489 | if (ret) | 660 | if (ret) |
490 | return ret; | 661 | return ret; |
491 | } | 662 | } |
@@ -496,10 +667,11 @@ static int mmc_test_align_write(struct mmc_test_card *test) | |||
496 | static int mmc_test_align_read(struct mmc_test_card *test) | 667 | static int mmc_test_align_read(struct mmc_test_card *test) |
497 | { | 668 | { |
498 | int ret, i; | 669 | int ret, i; |
670 | struct scatterlist sg; | ||
499 | 671 | ||
500 | for (i = 1;i < 4;i++) { | 672 | for (i = 1;i < 4;i++) { |
501 | ret = mmc_test_verified_transfer(test, 0, test->buffer + i, | 673 | sg_init_one(&sg, test->buffer + i, 512); |
502 | 0, 1, 512); | 674 | ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0); |
503 | if (ret) | 675 | if (ret) |
504 | return ret; | 676 | return ret; |
505 | } | 677 | } |
@@ -511,6 +683,7 @@ static int mmc_test_align_multi_write(struct mmc_test_card *test) | |||
511 | { | 683 | { |
512 | int ret, i; | 684 | int ret, i; |
513 | unsigned int size; | 685 | unsigned int size; |
686 | struct scatterlist sg; | ||
514 | 687 | ||
515 | if (test->card->host->max_blk_count == 1) | 688 | if (test->card->host->max_blk_count == 1) |
516 | return RESULT_UNSUP_HOST; | 689 | return RESULT_UNSUP_HOST; |
@@ -524,8 +697,8 @@ static int mmc_test_align_multi_write(struct mmc_test_card *test) | |||
524 | return RESULT_UNSUP_HOST; | 697 | return RESULT_UNSUP_HOST; |
525 | 698 | ||
526 | for (i = 1;i < 4;i++) { | 699 | for (i = 1;i < 4;i++) { |
527 | ret = mmc_test_verified_transfer(test, 1, test->buffer + i, | 700 | sg_init_one(&sg, test->buffer + i, size); |
528 | 0, size / 512, 512); | 701 | ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1); |
529 | if (ret) | 702 | if (ret) |
530 | return ret; | 703 | return ret; |
531 | } | 704 | } |
@@ -537,6 +710,7 @@ static int mmc_test_align_multi_read(struct mmc_test_card *test) | |||
537 | { | 710 | { |
538 | int ret, i; | 711 | int ret, i; |
539 | unsigned int size; | 712 | unsigned int size; |
713 | struct scatterlist sg; | ||
540 | 714 | ||
541 | if (test->card->host->max_blk_count == 1) | 715 | if (test->card->host->max_blk_count == 1) |
542 | return RESULT_UNSUP_HOST; | 716 | return RESULT_UNSUP_HOST; |
@@ -550,8 +724,8 @@ static int mmc_test_align_multi_read(struct mmc_test_card *test) | |||
550 | return RESULT_UNSUP_HOST; | 724 | return RESULT_UNSUP_HOST; |
551 | 725 | ||
552 | for (i = 1;i < 4;i++) { | 726 | for (i = 1;i < 4;i++) { |
553 | ret = mmc_test_verified_transfer(test, 0, test->buffer + i, | 727 | sg_init_one(&sg, test->buffer + i, size); |
554 | 0, size / 512, 512); | 728 | ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0); |
555 | if (ret) | 729 | if (ret) |
556 | return ret; | 730 | return ret; |
557 | } | 731 | } |
@@ -567,7 +741,7 @@ static int mmc_test_xfersize_write(struct mmc_test_card *test) | |||
567 | if (ret) | 741 | if (ret) |
568 | return ret; | 742 | return ret; |
569 | 743 | ||
570 | ret = __mmc_test_transfer(test, 1, 1, test->buffer, 0, 1, 512); | 744 | ret = mmc_test_broken_transfer(test, 1, 512, 1); |
571 | if (ret) | 745 | if (ret) |
572 | return ret; | 746 | return ret; |
573 | 747 | ||
@@ -582,7 +756,7 @@ static int mmc_test_xfersize_read(struct mmc_test_card *test) | |||
582 | if (ret) | 756 | if (ret) |
583 | return ret; | 757 | return ret; |
584 | 758 | ||
585 | ret = __mmc_test_transfer(test, 0, 1, test->buffer, 0, 1, 512); | 759 | ret = mmc_test_broken_transfer(test, 1, 512, 0); |
586 | if (ret) | 760 | if (ret) |
587 | return ret; | 761 | return ret; |
588 | 762 | ||
@@ -600,7 +774,7 @@ static int mmc_test_multi_xfersize_write(struct mmc_test_card *test) | |||
600 | if (ret) | 774 | if (ret) |
601 | return ret; | 775 | return ret; |
602 | 776 | ||
603 | ret = __mmc_test_transfer(test, 1, 1, test->buffer, 0, 2, 512); | 777 | ret = mmc_test_broken_transfer(test, 2, 512, 1); |
604 | if (ret) | 778 | if (ret) |
605 | return ret; | 779 | return ret; |
606 | 780 | ||
@@ -618,7 +792,7 @@ static int mmc_test_multi_xfersize_read(struct mmc_test_card *test) | |||
618 | if (ret) | 792 | if (ret) |
619 | return ret; | 793 | return ret; |
620 | 794 | ||
621 | ret = __mmc_test_transfer(test, 0, 1, test->buffer, 0, 2, 512); | 795 | ret = mmc_test_broken_transfer(test, 2, 512, 0); |
622 | if (ret) | 796 | if (ret) |
623 | return ret; | 797 | return ret; |
624 | 798 | ||
@@ -638,86 +812,86 @@ static const struct mmc_test_case mmc_test_cases[] = { | |||
638 | 812 | ||
639 | { | 813 | { |
640 | .name = "Basic write (with data verification)", | 814 | .name = "Basic write (with data verification)", |
641 | .prepare = mmc_test_prepare_verify_write, | 815 | .prepare = mmc_test_prepare_write, |
642 | .run = mmc_test_verify_write, | 816 | .run = mmc_test_verify_write, |
643 | .cleanup = mmc_test_cleanup_verify, | 817 | .cleanup = mmc_test_cleanup, |
644 | }, | 818 | }, |
645 | 819 | ||
646 | { | 820 | { |
647 | .name = "Basic read (with data verification)", | 821 | .name = "Basic read (with data verification)", |
648 | .prepare = mmc_test_prepare_verify_read, | 822 | .prepare = mmc_test_prepare_read, |
649 | .run = mmc_test_verify_read, | 823 | .run = mmc_test_verify_read, |
650 | .cleanup = mmc_test_cleanup_verify, | 824 | .cleanup = mmc_test_cleanup, |
651 | }, | 825 | }, |
652 | 826 | ||
653 | { | 827 | { |
654 | .name = "Multi-block write", | 828 | .name = "Multi-block write", |
655 | .prepare = mmc_test_prepare_verify_write, | 829 | .prepare = mmc_test_prepare_write, |
656 | .run = mmc_test_multi_write, | 830 | .run = mmc_test_multi_write, |
657 | .cleanup = mmc_test_cleanup_verify, | 831 | .cleanup = mmc_test_cleanup, |
658 | }, | 832 | }, |
659 | 833 | ||
660 | { | 834 | { |
661 | .name = "Multi-block read", | 835 | .name = "Multi-block read", |
662 | .prepare = mmc_test_prepare_verify_read, | 836 | .prepare = mmc_test_prepare_read, |
663 | .run = mmc_test_multi_read, | 837 | .run = mmc_test_multi_read, |
664 | .cleanup = mmc_test_cleanup_verify, | 838 | .cleanup = mmc_test_cleanup, |
665 | }, | 839 | }, |
666 | 840 | ||
667 | { | 841 | { |
668 | .name = "Power of two block writes", | 842 | .name = "Power of two block writes", |
669 | .prepare = mmc_test_prepare_verify_write, | 843 | .prepare = mmc_test_prepare_write, |
670 | .run = mmc_test_pow2_write, | 844 | .run = mmc_test_pow2_write, |
671 | .cleanup = mmc_test_cleanup_verify, | 845 | .cleanup = mmc_test_cleanup, |
672 | }, | 846 | }, |
673 | 847 | ||
674 | { | 848 | { |
675 | .name = "Power of two block reads", | 849 | .name = "Power of two block reads", |
676 | .prepare = mmc_test_prepare_verify_read, | 850 | .prepare = mmc_test_prepare_read, |
677 | .run = mmc_test_pow2_read, | 851 | .run = mmc_test_pow2_read, |
678 | .cleanup = mmc_test_cleanup_verify, | 852 | .cleanup = mmc_test_cleanup, |
679 | }, | 853 | }, |
680 | 854 | ||
681 | { | 855 | { |
682 | .name = "Weird sized block writes", | 856 | .name = "Weird sized block writes", |
683 | .prepare = mmc_test_prepare_verify_write, | 857 | .prepare = mmc_test_prepare_write, |
684 | .run = mmc_test_weird_write, | 858 | .run = mmc_test_weird_write, |
685 | .cleanup = mmc_test_cleanup_verify, | 859 | .cleanup = mmc_test_cleanup, |
686 | }, | 860 | }, |
687 | 861 | ||
688 | { | 862 | { |
689 | .name = "Weird sized block reads", | 863 | .name = "Weird sized block reads", |
690 | .prepare = mmc_test_prepare_verify_read, | 864 | .prepare = mmc_test_prepare_read, |
691 | .run = mmc_test_weird_read, | 865 | .run = mmc_test_weird_read, |
692 | .cleanup = mmc_test_cleanup_verify, | 866 | .cleanup = mmc_test_cleanup, |
693 | }, | 867 | }, |
694 | 868 | ||
695 | { | 869 | { |
696 | .name = "Badly aligned write", | 870 | .name = "Badly aligned write", |
697 | .prepare = mmc_test_prepare_verify_write, | 871 | .prepare = mmc_test_prepare_write, |
698 | .run = mmc_test_align_write, | 872 | .run = mmc_test_align_write, |
699 | .cleanup = mmc_test_cleanup_verify, | 873 | .cleanup = mmc_test_cleanup, |
700 | }, | 874 | }, |
701 | 875 | ||
702 | { | 876 | { |
703 | .name = "Badly aligned read", | 877 | .name = "Badly aligned read", |
704 | .prepare = mmc_test_prepare_verify_read, | 878 | .prepare = mmc_test_prepare_read, |
705 | .run = mmc_test_align_read, | 879 | .run = mmc_test_align_read, |
706 | .cleanup = mmc_test_cleanup_verify, | 880 | .cleanup = mmc_test_cleanup, |
707 | }, | 881 | }, |
708 | 882 | ||
709 | { | 883 | { |
710 | .name = "Badly aligned multi-block write", | 884 | .name = "Badly aligned multi-block write", |
711 | .prepare = mmc_test_prepare_verify_write, | 885 | .prepare = mmc_test_prepare_write, |
712 | .run = mmc_test_align_multi_write, | 886 | .run = mmc_test_align_multi_write, |
713 | .cleanup = mmc_test_cleanup_verify, | 887 | .cleanup = mmc_test_cleanup, |
714 | }, | 888 | }, |
715 | 889 | ||
716 | { | 890 | { |
717 | .name = "Badly aligned multi-block read", | 891 | .name = "Badly aligned multi-block read", |
718 | .prepare = mmc_test_prepare_verify_read, | 892 | .prepare = mmc_test_prepare_read, |
719 | .run = mmc_test_align_multi_read, | 893 | .run = mmc_test_align_multi_read, |
720 | .cleanup = mmc_test_cleanup_verify, | 894 | .cleanup = mmc_test_cleanup, |
721 | }, | 895 | }, |
722 | 896 | ||
723 | { | 897 | { |
@@ -743,7 +917,7 @@ static const struct mmc_test_case mmc_test_cases[] = { | |||
743 | 917 | ||
744 | static struct mutex mmc_test_lock; | 918 | static struct mutex mmc_test_lock; |
745 | 919 | ||
746 | static void mmc_test_run(struct mmc_test_card *test) | 920 | static void mmc_test_run(struct mmc_test_card *test, int testcase) |
747 | { | 921 | { |
748 | int i, ret; | 922 | int i, ret; |
749 | 923 | ||
@@ -753,6 +927,9 @@ static void mmc_test_run(struct mmc_test_card *test) | |||
753 | mmc_claim_host(test->card->host); | 927 | mmc_claim_host(test->card->host); |
754 | 928 | ||
755 | for (i = 0;i < ARRAY_SIZE(mmc_test_cases);i++) { | 929 | for (i = 0;i < ARRAY_SIZE(mmc_test_cases);i++) { |
930 | if (testcase && ((i + 1) != testcase)) | ||
931 | continue; | ||
932 | |||
756 | printk(KERN_INFO "%s: Test case %d. %s...\n", | 933 | printk(KERN_INFO "%s: Test case %d. %s...\n", |
757 | mmc_hostname(test->card->host), i + 1, | 934 | mmc_hostname(test->card->host), i + 1, |
758 | mmc_test_cases[i].name); | 935 | mmc_test_cases[i].name); |
@@ -824,9 +1001,12 @@ static ssize_t mmc_test_store(struct device *dev, | |||
824 | { | 1001 | { |
825 | struct mmc_card *card; | 1002 | struct mmc_card *card; |
826 | struct mmc_test_card *test; | 1003 | struct mmc_test_card *test; |
1004 | int testcase; | ||
827 | 1005 | ||
828 | card = container_of(dev, struct mmc_card, dev); | 1006 | card = container_of(dev, struct mmc_card, dev); |
829 | 1007 | ||
1008 | testcase = simple_strtol(buf, NULL, 10); | ||
1009 | |||
830 | test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL); | 1010 | test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL); |
831 | if (!test) | 1011 | if (!test) |
832 | return -ENOMEM; | 1012 | return -ENOMEM; |
@@ -836,7 +1016,7 @@ static ssize_t mmc_test_store(struct device *dev, | |||
836 | test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL); | 1016 | test->buffer = kzalloc(BUFFER_SIZE, GFP_KERNEL); |
837 | if (test->buffer) { | 1017 | if (test->buffer) { |
838 | mutex_lock(&mmc_test_lock); | 1018 | mutex_lock(&mmc_test_lock); |
839 | mmc_test_run(test); | 1019 | mmc_test_run(test, testcase); |
840 | mutex_unlock(&mmc_test_lock); | 1020 | mutex_unlock(&mmc_test_lock); |
841 | } | 1021 | } |
842 | 1022 | ||
@@ -852,6 +1032,9 @@ static int mmc_test_probe(struct mmc_card *card) | |||
852 | { | 1032 | { |
853 | int ret; | 1033 | int ret; |
854 | 1034 | ||
1035 | if ((card->type != MMC_TYPE_MMC) && (card->type != MMC_TYPE_SD)) | ||
1036 | return -ENODEV; | ||
1037 | |||
855 | mutex_init(&mmc_test_lock); | 1038 | mutex_init(&mmc_test_lock); |
856 | 1039 | ||
857 | ret = device_create_file(&card->dev, &dev_attr_test); | 1040 | ret = device_create_file(&card->dev, &dev_attr_test); |
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c index eeea84c309e6..78ad48718ab0 100644 --- a/drivers/mmc/card/sdio_uart.c +++ b/drivers/mmc/card/sdio_uart.c | |||
@@ -885,12 +885,14 @@ static void sdio_uart_set_termios(struct tty_struct *tty, struct ktermios *old_t | |||
885 | sdio_uart_release_func(port); | 885 | sdio_uart_release_func(port); |
886 | } | 886 | } |
887 | 887 | ||
888 | static void sdio_uart_break_ctl(struct tty_struct *tty, int break_state) | 888 | static int sdio_uart_break_ctl(struct tty_struct *tty, int break_state) |
889 | { | 889 | { |
890 | struct sdio_uart_port *port = tty->driver_data; | 890 | struct sdio_uart_port *port = tty->driver_data; |
891 | int result; | ||
891 | 892 | ||
892 | if (sdio_uart_claim_func(port) != 0) | 893 | result = sdio_uart_claim_func(port); |
893 | return; | 894 | if (result != 0) |
895 | return result; | ||
894 | 896 | ||
895 | if (break_state == -1) | 897 | if (break_state == -1) |
896 | port->lcr |= UART_LCR_SBC; | 898 | port->lcr |= UART_LCR_SBC; |
@@ -899,6 +901,7 @@ static void sdio_uart_break_ctl(struct tty_struct *tty, int break_state) | |||
899 | sdio_out(port, UART_LCR, port->lcr); | 901 | sdio_out(port, UART_LCR, port->lcr); |
900 | 902 | ||
901 | sdio_uart_release_func(port); | 903 | sdio_uart_release_func(port); |
904 | return 0; | ||
902 | } | 905 | } |
903 | 906 | ||
904 | static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file) | 907 | static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file) |
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 01ced4c5a61d..3ee5b8c3b5ce 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * Copyright (C) 2003-2004 Russell King, All Rights Reserved. | 4 | * Copyright (C) 2003-2004 Russell King, All Rights Reserved. |
5 | * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved. | 5 | * SD support Copyright (C) 2004 Ian Molton, All Rights Reserved. |
6 | * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved. | 6 | * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved. |
7 | * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. | 7 | * MMCv4 support Copyright (C) 2006 Philip Langdale, All Rights Reserved. |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -295,6 +295,33 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) | |||
295 | EXPORT_SYMBOL(mmc_set_data_timeout); | 295 | EXPORT_SYMBOL(mmc_set_data_timeout); |
296 | 296 | ||
297 | /** | 297 | /** |
298 | * mmc_align_data_size - pads a transfer size to a more optimal value | ||
299 | * @card: the MMC card associated with the data transfer | ||
300 | * @sz: original transfer size | ||
301 | * | ||
302 | * Pads the original data size with a number of extra bytes in | ||
303 | * order to avoid controller bugs and/or performance hits | ||
304 | * (e.g. some controllers revert to PIO for certain sizes). | ||
305 | * | ||
306 | * Returns the improved size, which might be unmodified. | ||
307 | * | ||
308 | * Note that this function is only relevant when issuing a | ||
309 | * single scatter gather entry. | ||
310 | */ | ||
311 | unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz) | ||
312 | { | ||
313 | /* | ||
314 | * FIXME: We don't have a system for the controller to tell | ||
315 | * the core about its problems yet, so for now we just 32-bit | ||
316 | * align the size. | ||
317 | */ | ||
318 | sz = ((sz + 3) / 4) * 4; | ||
319 | |||
320 | return sz; | ||
321 | } | ||
322 | EXPORT_SYMBOL(mmc_align_data_size); | ||
323 | |||
324 | /** | ||
298 | * __mmc_claim_host - exclusively claim a host | 325 | * __mmc_claim_host - exclusively claim a host |
299 | * @host: mmc host to claim | 326 | * @host: mmc host to claim |
300 | * @abort: whether or not the operation should be aborted | 327 | * @abort: whether or not the operation should be aborted |
@@ -638,6 +665,9 @@ void mmc_rescan(struct work_struct *work) | |||
638 | */ | 665 | */ |
639 | mmc_bus_put(host); | 666 | mmc_bus_put(host); |
640 | 667 | ||
668 | if (host->ops->get_cd && host->ops->get_cd(host) == 0) | ||
669 | goto out; | ||
670 | |||
641 | mmc_claim_host(host); | 671 | mmc_claim_host(host); |
642 | 672 | ||
643 | mmc_power_up(host); | 673 | mmc_power_up(host); |
@@ -652,7 +682,7 @@ void mmc_rescan(struct work_struct *work) | |||
652 | if (!err) { | 682 | if (!err) { |
653 | if (mmc_attach_sdio(host, ocr)) | 683 | if (mmc_attach_sdio(host, ocr)) |
654 | mmc_power_off(host); | 684 | mmc_power_off(host); |
655 | return; | 685 | goto out; |
656 | } | 686 | } |
657 | 687 | ||
658 | /* | 688 | /* |
@@ -662,7 +692,7 @@ void mmc_rescan(struct work_struct *work) | |||
662 | if (!err) { | 692 | if (!err) { |
663 | if (mmc_attach_sd(host, ocr)) | 693 | if (mmc_attach_sd(host, ocr)) |
664 | mmc_power_off(host); | 694 | mmc_power_off(host); |
665 | return; | 695 | goto out; |
666 | } | 696 | } |
667 | 697 | ||
668 | /* | 698 | /* |
@@ -672,7 +702,7 @@ void mmc_rescan(struct work_struct *work) | |||
672 | if (!err) { | 702 | if (!err) { |
673 | if (mmc_attach_mmc(host, ocr)) | 703 | if (mmc_attach_mmc(host, ocr)) |
674 | mmc_power_off(host); | 704 | mmc_power_off(host); |
675 | return; | 705 | goto out; |
676 | } | 706 | } |
677 | 707 | ||
678 | mmc_release_host(host); | 708 | mmc_release_host(host); |
@@ -683,6 +713,9 @@ void mmc_rescan(struct work_struct *work) | |||
683 | 713 | ||
684 | mmc_bus_put(host); | 714 | mmc_bus_put(host); |
685 | } | 715 | } |
716 | out: | ||
717 | if (host->caps & MMC_CAP_NEEDS_POLL) | ||
718 | mmc_schedule_delayed_work(&host->detect, HZ); | ||
686 | } | 719 | } |
687 | 720 | ||
688 | void mmc_start_host(struct mmc_host *host) | 721 | void mmc_start_host(struct mmc_host *host) |
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 3da29eef8f7d..fdd7c760be8c 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c | |||
@@ -288,7 +288,7 @@ static struct device_type mmc_type = { | |||
288 | /* | 288 | /* |
289 | * Handle the detection and initialisation of a card. | 289 | * Handle the detection and initialisation of a card. |
290 | * | 290 | * |
291 | * In the case of a resume, "curcard" will contain the card | 291 | * In the case of a resume, "oldcard" will contain the card |
292 | * we're trying to reinitialise. | 292 | * we're trying to reinitialise. |
293 | */ | 293 | */ |
294 | static int mmc_init_card(struct mmc_host *host, u32 ocr, | 294 | static int mmc_init_card(struct mmc_host *host, u32 ocr, |
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 7ef3b15c5e3d..26fc098d77cd 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c | |||
@@ -326,7 +326,7 @@ static struct device_type sd_type = { | |||
326 | /* | 326 | /* |
327 | * Handle the detection and initialisation of a card. | 327 | * Handle the detection and initialisation of a card. |
328 | * | 328 | * |
329 | * In the case of a resume, "curcard" will contain the card | 329 | * In the case of a resume, "oldcard" will contain the card |
330 | * we're trying to reinitialise. | 330 | * we're trying to reinitialise. |
331 | */ | 331 | */ |
332 | static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | 332 | static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, |
@@ -494,13 +494,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, | |||
494 | * Check if read-only switch is active. | 494 | * Check if read-only switch is active. |
495 | */ | 495 | */ |
496 | if (!oldcard) { | 496 | if (!oldcard) { |
497 | if (!host->ops->get_ro) { | 497 | if (!host->ops->get_ro || host->ops->get_ro(host) < 0) { |
498 | printk(KERN_WARNING "%s: host does not " | 498 | printk(KERN_WARNING "%s: host does not " |
499 | "support reading read-only " | 499 | "support reading read-only " |
500 | "switch. assuming write-enable.\n", | 500 | "switch. assuming write-enable.\n", |
501 | mmc_hostname(host)); | 501 | mmc_hostname(host)); |
502 | } else { | 502 | } else { |
503 | if (host->ops->get_ro(host)) | 503 | if (host->ops->get_ro(host) > 0) |
504 | mmc_card_set_readonly(card); | 504 | mmc_card_set_readonly(card); |
505 | } | 505 | } |
506 | } | 506 | } |
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c index d5e51b1c7b3f..956bd7677502 100644 --- a/drivers/mmc/core/sdio_cis.c +++ b/drivers/mmc/core/sdio_cis.c | |||
@@ -129,6 +129,12 @@ static int cistpl_funce_func(struct sdio_func *func, | |||
129 | /* TPLFE_MAX_BLK_SIZE */ | 129 | /* TPLFE_MAX_BLK_SIZE */ |
130 | func->max_blksize = buf[12] | (buf[13] << 8); | 130 | func->max_blksize = buf[12] | (buf[13] << 8); |
131 | 131 | ||
132 | /* TPLFE_ENABLE_TIMEOUT_VAL, present in ver 1.1 and above */ | ||
133 | if (vsn > SDIO_SDIO_REV_1_00) | ||
134 | func->enable_timeout = (buf[28] | (buf[29] << 8)) * 10; | ||
135 | else | ||
136 | func->enable_timeout = jiffies_to_msecs(HZ); | ||
137 | |||
132 | return 0; | 138 | return 0; |
133 | } | 139 | } |
134 | 140 | ||
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c index 625b92ce9cef..f61fc2d4cd0a 100644 --- a/drivers/mmc/core/sdio_io.c +++ b/drivers/mmc/core/sdio_io.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/mmc/core/sdio_io.c | 2 | * linux/drivers/mmc/core/sdio_io.c |
3 | * | 3 | * |
4 | * Copyright 2007 Pierre Ossman | 4 | * Copyright 2007-2008 Pierre Ossman |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 7 | * it under the terms of the GNU General Public License as published by |
@@ -76,11 +76,7 @@ int sdio_enable_func(struct sdio_func *func) | |||
76 | if (ret) | 76 | if (ret) |
77 | goto err; | 77 | goto err; |
78 | 78 | ||
79 | /* | 79 | timeout = jiffies + msecs_to_jiffies(func->enable_timeout); |
80 | * FIXME: This should timeout based on information in the CIS, | ||
81 | * but we don't have card to parse that yet. | ||
82 | */ | ||
83 | timeout = jiffies + HZ; | ||
84 | 80 | ||
85 | while (1) { | 81 | while (1) { |
86 | ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, ®); | 82 | ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, ®); |
@@ -167,10 +163,8 @@ int sdio_set_block_size(struct sdio_func *func, unsigned blksz) | |||
167 | return -EINVAL; | 163 | return -EINVAL; |
168 | 164 | ||
169 | if (blksz == 0) { | 165 | if (blksz == 0) { |
170 | blksz = min(min( | 166 | blksz = min(func->max_blksize, func->card->host->max_blk_size); |
171 | func->max_blksize, | 167 | blksz = min(blksz, 512u); |
172 | func->card->host->max_blk_size), | ||
173 | 512u); | ||
174 | } | 168 | } |
175 | 169 | ||
176 | ret = mmc_io_rw_direct(func->card, 1, 0, | 170 | ret = mmc_io_rw_direct(func->card, 1, 0, |
@@ -186,9 +180,116 @@ int sdio_set_block_size(struct sdio_func *func, unsigned blksz) | |||
186 | func->cur_blksize = blksz; | 180 | func->cur_blksize = blksz; |
187 | return 0; | 181 | return 0; |
188 | } | 182 | } |
189 | |||
190 | EXPORT_SYMBOL_GPL(sdio_set_block_size); | 183 | EXPORT_SYMBOL_GPL(sdio_set_block_size); |
191 | 184 | ||
185 | /* | ||
186 | * Calculate the maximum byte mode transfer size | ||
187 | */ | ||
188 | static inline unsigned int sdio_max_byte_size(struct sdio_func *func) | ||
189 | { | ||
190 | unsigned mval = min(func->card->host->max_seg_size, | ||
191 | func->card->host->max_blk_size); | ||
192 | mval = min(mval, func->max_blksize); | ||
193 | return min(mval, 512u); /* maximum size for byte mode */ | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * sdio_align_size - pads a transfer size to a more optimal value | ||
198 | * @func: SDIO function | ||
199 | * @sz: original transfer size | ||
200 | * | ||
201 | * Pads the original data size with a number of extra bytes in | ||
202 | * order to avoid controller bugs and/or performance hits | ||
203 | * (e.g. some controllers revert to PIO for certain sizes). | ||
204 | * | ||
205 | * If possible, it will also adjust the size so that it can be | ||
206 | * handled in just a single request. | ||
207 | * | ||
208 | * Returns the improved size, which might be unmodified. | ||
209 | */ | ||
210 | unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) | ||
211 | { | ||
212 | unsigned int orig_sz; | ||
213 | unsigned int blk_sz, byte_sz; | ||
214 | unsigned chunk_sz; | ||
215 | |||
216 | orig_sz = sz; | ||
217 | |||
218 | /* | ||
219 | * Do a first check with the controller, in case it | ||
220 | * wants to increase the size up to a point where it | ||
221 | * might need more than one block. | ||
222 | */ | ||
223 | sz = mmc_align_data_size(func->card, sz); | ||
224 | |||
225 | /* | ||
226 | * If we can still do this with just a byte transfer, then | ||
227 | * we're done. | ||
228 | */ | ||
229 | if (sz <= sdio_max_byte_size(func)) | ||
230 | return sz; | ||
231 | |||
232 | if (func->card->cccr.multi_block) { | ||
233 | /* | ||
234 | * Check if the transfer is already block aligned | ||
235 | */ | ||
236 | if ((sz % func->cur_blksize) == 0) | ||
237 | return sz; | ||
238 | |||
239 | /* | ||
240 | * Realign it so that it can be done with one request, | ||
241 | * and recheck if the controller still likes it. | ||
242 | */ | ||
243 | blk_sz = ((sz + func->cur_blksize - 1) / | ||
244 | func->cur_blksize) * func->cur_blksize; | ||
245 | blk_sz = mmc_align_data_size(func->card, blk_sz); | ||
246 | |||
247 | /* | ||
248 | * This value is only good if it is still just | ||
249 | * one request. | ||
250 | */ | ||
251 | if ((blk_sz % func->cur_blksize) == 0) | ||
252 | return blk_sz; | ||
253 | |||
254 | /* | ||
255 | * We failed to do one request, but at least try to | ||
256 | * pad the remainder properly. | ||
257 | */ | ||
258 | byte_sz = mmc_align_data_size(func->card, | ||
259 | sz % func->cur_blksize); | ||
260 | if (byte_sz <= sdio_max_byte_size(func)) { | ||
261 | blk_sz = sz / func->cur_blksize; | ||
262 | return blk_sz * func->cur_blksize + byte_sz; | ||
263 | } | ||
264 | } else { | ||
265 | /* | ||
266 | * We need multiple requests, so first check that the | ||
267 | * controller can handle the chunk size; | ||
268 | */ | ||
269 | chunk_sz = mmc_align_data_size(func->card, | ||
270 | sdio_max_byte_size(func)); | ||
271 | if (chunk_sz == sdio_max_byte_size(func)) { | ||
272 | /* | ||
273 | * Fix up the size of the remainder (if any) | ||
274 | */ | ||
275 | byte_sz = orig_sz % chunk_sz; | ||
276 | if (byte_sz) { | ||
277 | byte_sz = mmc_align_data_size(func->card, | ||
278 | byte_sz); | ||
279 | } | ||
280 | |||
281 | return (orig_sz / chunk_sz) * chunk_sz + byte_sz; | ||
282 | } | ||
283 | } | ||
284 | |||
285 | /* | ||
286 | * The controller is simply incapable of transferring the size | ||
287 | * we want in decent manner, so just return the original size. | ||
288 | */ | ||
289 | return orig_sz; | ||
290 | } | ||
291 | EXPORT_SYMBOL_GPL(sdio_align_size); | ||
292 | |||
192 | /* Split an arbitrarily sized data transfer into several | 293 | /* Split an arbitrarily sized data transfer into several |
193 | * IO_RW_EXTENDED commands. */ | 294 | * IO_RW_EXTENDED commands. */ |
194 | static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, | 295 | static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, |
@@ -199,14 +300,13 @@ static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, | |||
199 | int ret; | 300 | int ret; |
200 | 301 | ||
201 | /* Do the bulk of the transfer using block mode (if supported). */ | 302 | /* Do the bulk of the transfer using block mode (if supported). */ |
202 | if (func->card->cccr.multi_block) { | 303 | if (func->card->cccr.multi_block && (size > sdio_max_byte_size(func))) { |
203 | /* Blocks per command is limited by host count, host transfer | 304 | /* Blocks per command is limited by host count, host transfer |
204 | * size (we only use a single sg entry) and the maximum for | 305 | * size (we only use a single sg entry) and the maximum for |
205 | * IO_RW_EXTENDED of 511 blocks. */ | 306 | * IO_RW_EXTENDED of 511 blocks. */ |
206 | max_blocks = min(min( | 307 | max_blocks = min(func->card->host->max_blk_count, |
207 | func->card->host->max_blk_count, | 308 | func->card->host->max_seg_size / func->cur_blksize); |
208 | func->card->host->max_seg_size / func->cur_blksize), | 309 | max_blocks = min(max_blocks, 511u); |
209 | 511u); | ||
210 | 310 | ||
211 | while (remainder > func->cur_blksize) { | 311 | while (remainder > func->cur_blksize) { |
212 | unsigned blocks; | 312 | unsigned blocks; |
@@ -231,11 +331,7 @@ static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, | |||
231 | 331 | ||
232 | /* Write the remainder using byte mode. */ | 332 | /* Write the remainder using byte mode. */ |
233 | while (remainder > 0) { | 333 | while (remainder > 0) { |
234 | size = remainder; | 334 | size = min(remainder, sdio_max_byte_size(func)); |
235 | if (size > func->cur_blksize) | ||
236 | size = func->cur_blksize; | ||
237 | if (size > 512) | ||
238 | size = 512; /* maximum size for byte mode */ | ||
239 | 335 | ||
240 | ret = mmc_io_rw_extended(func->card, write, func->num, addr, | 336 | ret = mmc_io_rw_extended(func->card, write, func->num, addr, |
241 | incr_addr, buf, 1, size); | 337 | incr_addr, buf, 1, size); |
@@ -260,11 +356,10 @@ static int sdio_io_rw_ext_helper(struct sdio_func *func, int write, | |||
260 | * function. If there is a problem reading the address, 0xff | 356 | * function. If there is a problem reading the address, 0xff |
261 | * is returned and @err_ret will contain the error code. | 357 | * is returned and @err_ret will contain the error code. |
262 | */ | 358 | */ |
263 | unsigned char sdio_readb(struct sdio_func *func, unsigned int addr, | 359 | u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret) |
264 | int *err_ret) | ||
265 | { | 360 | { |
266 | int ret; | 361 | int ret; |
267 | unsigned char val; | 362 | u8 val; |
268 | 363 | ||
269 | BUG_ON(!func); | 364 | BUG_ON(!func); |
270 | 365 | ||
@@ -293,8 +388,7 @@ EXPORT_SYMBOL_GPL(sdio_readb); | |||
293 | * function. @err_ret will contain the status of the actual | 388 | * function. @err_ret will contain the status of the actual |
294 | * transfer. | 389 | * transfer. |
295 | */ | 390 | */ |
296 | void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr, | 391 | void sdio_writeb(struct sdio_func *func, u8 b, unsigned int addr, int *err_ret) |
297 | int *err_ret) | ||
298 | { | 392 | { |
299 | int ret; | 393 | int ret; |
300 | 394 | ||
@@ -355,7 +449,6 @@ int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr, | |||
355 | { | 449 | { |
356 | return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count); | 450 | return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count); |
357 | } | 451 | } |
358 | |||
359 | EXPORT_SYMBOL_GPL(sdio_readsb); | 452 | EXPORT_SYMBOL_GPL(sdio_readsb); |
360 | 453 | ||
361 | /** | 454 | /** |
@@ -385,8 +478,7 @@ EXPORT_SYMBOL_GPL(sdio_writesb); | |||
385 | * function. If there is a problem reading the address, 0xffff | 478 | * function. If there is a problem reading the address, 0xffff |
386 | * is returned and @err_ret will contain the error code. | 479 | * is returned and @err_ret will contain the error code. |
387 | */ | 480 | */ |
388 | unsigned short sdio_readw(struct sdio_func *func, unsigned int addr, | 481 | u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret) |
389 | int *err_ret) | ||
390 | { | 482 | { |
391 | int ret; | 483 | int ret; |
392 | 484 | ||
@@ -400,7 +492,7 @@ unsigned short sdio_readw(struct sdio_func *func, unsigned int addr, | |||
400 | return 0xFFFF; | 492 | return 0xFFFF; |
401 | } | 493 | } |
402 | 494 | ||
403 | return le16_to_cpu(*(u16*)func->tmpbuf); | 495 | return le16_to_cpup((__le16 *)func->tmpbuf); |
404 | } | 496 | } |
405 | EXPORT_SYMBOL_GPL(sdio_readw); | 497 | EXPORT_SYMBOL_GPL(sdio_readw); |
406 | 498 | ||
@@ -415,12 +507,11 @@ EXPORT_SYMBOL_GPL(sdio_readw); | |||
415 | * function. @err_ret will contain the status of the actual | 507 | * function. @err_ret will contain the status of the actual |
416 | * transfer. | 508 | * transfer. |
417 | */ | 509 | */ |
418 | void sdio_writew(struct sdio_func *func, unsigned short b, unsigned int addr, | 510 | void sdio_writew(struct sdio_func *func, u16 b, unsigned int addr, int *err_ret) |
419 | int *err_ret) | ||
420 | { | 511 | { |
421 | int ret; | 512 | int ret; |
422 | 513 | ||
423 | *(u16*)func->tmpbuf = cpu_to_le16(b); | 514 | *(__le16 *)func->tmpbuf = cpu_to_le16(b); |
424 | 515 | ||
425 | ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2); | 516 | ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2); |
426 | if (err_ret) | 517 | if (err_ret) |
@@ -439,8 +530,7 @@ EXPORT_SYMBOL_GPL(sdio_writew); | |||
439 | * 0xffffffff is returned and @err_ret will contain the error | 530 | * 0xffffffff is returned and @err_ret will contain the error |
440 | * code. | 531 | * code. |
441 | */ | 532 | */ |
442 | unsigned long sdio_readl(struct sdio_func *func, unsigned int addr, | 533 | u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret) |
443 | int *err_ret) | ||
444 | { | 534 | { |
445 | int ret; | 535 | int ret; |
446 | 536 | ||
@@ -454,7 +544,7 @@ unsigned long sdio_readl(struct sdio_func *func, unsigned int addr, | |||
454 | return 0xFFFFFFFF; | 544 | return 0xFFFFFFFF; |
455 | } | 545 | } |
456 | 546 | ||
457 | return le32_to_cpu(*(u32*)func->tmpbuf); | 547 | return le32_to_cpup((__le32 *)func->tmpbuf); |
458 | } | 548 | } |
459 | EXPORT_SYMBOL_GPL(sdio_readl); | 549 | EXPORT_SYMBOL_GPL(sdio_readl); |
460 | 550 | ||
@@ -469,12 +559,11 @@ EXPORT_SYMBOL_GPL(sdio_readl); | |||
469 | * function. @err_ret will contain the status of the actual | 559 | * function. @err_ret will contain the status of the actual |
470 | * transfer. | 560 | * transfer. |
471 | */ | 561 | */ |
472 | void sdio_writel(struct sdio_func *func, unsigned long b, unsigned int addr, | 562 | void sdio_writel(struct sdio_func *func, u32 b, unsigned int addr, int *err_ret) |
473 | int *err_ret) | ||
474 | { | 563 | { |
475 | int ret; | 564 | int ret; |
476 | 565 | ||
477 | *(u32*)func->tmpbuf = cpu_to_le32(b); | 566 | *(__le32 *)func->tmpbuf = cpu_to_le32(b); |
478 | 567 | ||
479 | ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4); | 568 | ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4); |
480 | if (err_ret) | 569 | if (err_ret) |
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index dead61754ad7..dc6f2579f85c 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig | |||
@@ -26,18 +26,31 @@ config MMC_PXA | |||
26 | 26 | ||
27 | config MMC_SDHCI | 27 | config MMC_SDHCI |
28 | tristate "Secure Digital Host Controller Interface support" | 28 | tristate "Secure Digital Host Controller Interface support" |
29 | depends on PCI | 29 | depends on HAS_DMA |
30 | help | 30 | help |
31 | This select the generic Secure Digital Host Controller Interface. | 31 | This selects the generic Secure Digital Host Controller Interface. |
32 | It is used by manufacturers such as Texas Instruments(R), Ricoh(R) | 32 | It is used by manufacturers such as Texas Instruments(R), Ricoh(R) |
33 | and Toshiba(R). Most controllers found in laptops are of this type. | 33 | and Toshiba(R). Most controllers found in laptops are of this type. |
34 | |||
35 | If you have a controller with this interface, say Y or M here. You | ||
36 | also need to enable an appropriate bus interface. | ||
37 | |||
38 | If unsure, say N. | ||
39 | |||
40 | config MMC_SDHCI_PCI | ||
41 | tristate "SDHCI support on PCI bus" | ||
42 | depends on MMC_SDHCI && PCI | ||
43 | help | ||
44 | This selects the PCI Secure Digital Host Controller Interface. | ||
45 | Most controllers found today are PCI devices. | ||
46 | |||
34 | If you have a controller with this interface, say Y or M here. | 47 | If you have a controller with this interface, say Y or M here. |
35 | 48 | ||
36 | If unsure, say N. | 49 | If unsure, say N. |
37 | 50 | ||
38 | config MMC_RICOH_MMC | 51 | config MMC_RICOH_MMC |
39 | tristate "Ricoh MMC Controller Disabler (EXPERIMENTAL)" | 52 | tristate "Ricoh MMC Controller Disabler (EXPERIMENTAL)" |
40 | depends on PCI && EXPERIMENTAL && MMC_SDHCI | 53 | depends on MMC_SDHCI_PCI |
41 | help | 54 | help |
42 | This selects the disabler for the Ricoh MMC Controller. This | 55 | This selects the disabler for the Ricoh MMC Controller. This |
43 | proprietary controller is unnecessary because the SDHCI driver | 56 | proprietary controller is unnecessary because the SDHCI driver |
@@ -91,6 +104,16 @@ config MMC_AT91 | |||
91 | 104 | ||
92 | If unsure, say N. | 105 | If unsure, say N. |
93 | 106 | ||
107 | config MMC_ATMELMCI | ||
108 | tristate "Atmel Multimedia Card Interface support" | ||
109 | depends on AVR32 | ||
110 | help | ||
111 | This selects the Atmel Multimedia Card Interface driver. If | ||
112 | you have an AT32 (AVR32) platform with a Multimedia Card | ||
113 | slot, say Y or M here. | ||
114 | |||
115 | If unsure, say N. | ||
116 | |||
94 | config MMC_IMX | 117 | config MMC_IMX |
95 | tristate "Motorola i.MX Multimedia Card Interface support" | 118 | tristate "Motorola i.MX Multimedia Card Interface support" |
96 | depends on ARCH_IMX | 119 | depends on ARCH_IMX |
@@ -130,3 +153,24 @@ config MMC_SPI | |||
130 | 153 | ||
131 | If unsure, or if your system has no SPI master driver, say N. | 154 | If unsure, or if your system has no SPI master driver, say N. |
132 | 155 | ||
156 | config MMC_S3C | ||
157 | tristate "Samsung S3C SD/MMC Card Interface support" | ||
158 | depends on ARCH_S3C2410 && MMC | ||
159 | help | ||
160 | This selects a driver for the MCI interface found in | ||
161 | Samsung's S3C2410, S3C2412, S3C2440, S3C2442 CPUs. | ||
162 | If you have a board based on one of those and a MMC/SD | ||
163 | slot, say Y or M here. | ||
164 | |||
165 | If unsure, say N. | ||
166 | |||
167 | config MMC_SDRICOH_CS | ||
168 | tristate "MMC/SD driver for Ricoh Bay1Controllers (EXPERIMENTAL)" | ||
169 | depends on EXPERIMENTAL && MMC && PCI && PCMCIA | ||
170 | help | ||
171 | Say Y here if your Notebook reports a Ricoh Bay1Controller PCMCIA | ||
172 | card whenever you insert a MMC or SD card into the card slot. | ||
173 | |||
174 | To compile this driver as a module, choose M here: the | ||
175 | module will be called sdricoh_cs. | ||
176 | |||
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile index 3877c87e6da2..db52eebfb50e 100644 --- a/drivers/mmc/host/Makefile +++ b/drivers/mmc/host/Makefile | |||
@@ -10,11 +10,15 @@ obj-$(CONFIG_MMC_ARMMMCI) += mmci.o | |||
10 | obj-$(CONFIG_MMC_PXA) += pxamci.o | 10 | obj-$(CONFIG_MMC_PXA) += pxamci.o |
11 | obj-$(CONFIG_MMC_IMX) += imxmmc.o | 11 | obj-$(CONFIG_MMC_IMX) += imxmmc.o |
12 | obj-$(CONFIG_MMC_SDHCI) += sdhci.o | 12 | obj-$(CONFIG_MMC_SDHCI) += sdhci.o |
13 | obj-$(CONFIG_MMC_SDHCI_PCI) += sdhci-pci.o | ||
13 | obj-$(CONFIG_MMC_RICOH_MMC) += ricoh_mmc.o | 14 | obj-$(CONFIG_MMC_RICOH_MMC) += ricoh_mmc.o |
14 | obj-$(CONFIG_MMC_WBSD) += wbsd.o | 15 | obj-$(CONFIG_MMC_WBSD) += wbsd.o |
15 | obj-$(CONFIG_MMC_AU1X) += au1xmmc.o | 16 | obj-$(CONFIG_MMC_AU1X) += au1xmmc.o |
16 | obj-$(CONFIG_MMC_OMAP) += omap.o | 17 | obj-$(CONFIG_MMC_OMAP) += omap.o |
17 | obj-$(CONFIG_MMC_AT91) += at91_mci.o | 18 | obj-$(CONFIG_MMC_AT91) += at91_mci.o |
19 | obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o | ||
18 | obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o | 20 | obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o |
19 | obj-$(CONFIG_MMC_SPI) += mmc_spi.o | 21 | obj-$(CONFIG_MMC_SPI) += mmc_spi.o |
22 | obj-$(CONFIG_MMC_S3C) += s3cmci.o | ||
23 | obj-$(CONFIG_MMC_SDRICOH_CS) += sdricoh_cs.o | ||
20 | 24 | ||
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c index 8979ad330a4d..f15e2064305c 100644 --- a/drivers/mmc/host/at91_mci.c +++ b/drivers/mmc/host/at91_mci.c | |||
@@ -125,9 +125,72 @@ struct at91mci_host | |||
125 | 125 | ||
126 | /* Latest in the scatterlist that has been enabled for transfer */ | 126 | /* Latest in the scatterlist that has been enabled for transfer */ |
127 | int transfer_index; | 127 | int transfer_index; |
128 | |||
129 | /* Timer for timeouts */ | ||
130 | struct timer_list timer; | ||
128 | }; | 131 | }; |
129 | 132 | ||
130 | /* | 133 | /* |
134 | * Reset the controller and restore most of the state | ||
135 | */ | ||
136 | static void at91_reset_host(struct at91mci_host *host) | ||
137 | { | ||
138 | unsigned long flags; | ||
139 | u32 mr; | ||
140 | u32 sdcr; | ||
141 | u32 dtor; | ||
142 | u32 imr; | ||
143 | |||
144 | local_irq_save(flags); | ||
145 | imr = at91_mci_read(host, AT91_MCI_IMR); | ||
146 | |||
147 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff); | ||
148 | |||
149 | /* save current state */ | ||
150 | mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff; | ||
151 | sdcr = at91_mci_read(host, AT91_MCI_SDCR); | ||
152 | dtor = at91_mci_read(host, AT91_MCI_DTOR); | ||
153 | |||
154 | /* reset the controller */ | ||
155 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST); | ||
156 | |||
157 | /* restore state */ | ||
158 | at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN); | ||
159 | at91_mci_write(host, AT91_MCI_MR, mr); | ||
160 | at91_mci_write(host, AT91_MCI_SDCR, sdcr); | ||
161 | at91_mci_write(host, AT91_MCI_DTOR, dtor); | ||
162 | at91_mci_write(host, AT91_MCI_IER, imr); | ||
163 | |||
164 | /* make sure sdio interrupts will fire */ | ||
165 | at91_mci_read(host, AT91_MCI_SR); | ||
166 | |||
167 | local_irq_restore(flags); | ||
168 | } | ||
169 | |||
170 | static void at91_timeout_timer(unsigned long data) | ||
171 | { | ||
172 | struct at91mci_host *host; | ||
173 | |||
174 | host = (struct at91mci_host *)data; | ||
175 | |||
176 | if (host->request) { | ||
177 | dev_err(host->mmc->parent, "Timeout waiting end of packet\n"); | ||
178 | |||
179 | if (host->cmd && host->cmd->data) { | ||
180 | host->cmd->data->error = -ETIMEDOUT; | ||
181 | } else { | ||
182 | if (host->cmd) | ||
183 | host->cmd->error = -ETIMEDOUT; | ||
184 | else | ||
185 | host->request->cmd->error = -ETIMEDOUT; | ||
186 | } | ||
187 | |||
188 | at91_reset_host(host); | ||
189 | mmc_request_done(host->mmc, host->request); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /* | ||
131 | * Copy from sg to a dma block - used for transfers | 194 | * Copy from sg to a dma block - used for transfers |
132 | */ | 195 | */ |
133 | static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data) | 196 | static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data) |
@@ -135,9 +198,14 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data | |||
135 | unsigned int len, i, size; | 198 | unsigned int len, i, size; |
136 | unsigned *dmabuf = host->buffer; | 199 | unsigned *dmabuf = host->buffer; |
137 | 200 | ||
138 | size = host->total_length; | 201 | size = data->blksz * data->blocks; |
139 | len = data->sg_len; | 202 | len = data->sg_len; |
140 | 203 | ||
204 | /* AT91SAM926[0/3] Data Write Operation and number of bytes erratum */ | ||
205 | if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) | ||
206 | if (host->total_length == 12) | ||
207 | memset(dmabuf, 0, 12); | ||
208 | |||
141 | /* | 209 | /* |
142 | * Just loop through all entries. Size might not | 210 | * Just loop through all entries. Size might not |
143 | * be the entire list though so make sure that | 211 | * be the entire list though so make sure that |
@@ -159,9 +227,10 @@ static inline void at91_mci_sg_to_dma(struct at91mci_host *host, struct mmc_data | |||
159 | 227 | ||
160 | for (index = 0; index < (amount / 4); index++) | 228 | for (index = 0; index < (amount / 4); index++) |
161 | *dmabuf++ = swab32(sgbuffer[index]); | 229 | *dmabuf++ = swab32(sgbuffer[index]); |
162 | } | 230 | } else { |
163 | else | ||
164 | memcpy(dmabuf, sgbuffer, amount); | 231 | memcpy(dmabuf, sgbuffer, amount); |
232 | dmabuf += amount; | ||
233 | } | ||
165 | 234 | ||
166 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); | 235 | kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); |
167 | 236 | ||
@@ -233,11 +302,11 @@ static void at91_mci_pre_dma_read(struct at91mci_host *host) | |||
233 | 302 | ||
234 | if (i == 0) { | 303 | if (i == 0) { |
235 | at91_mci_write(host, ATMEL_PDC_RPR, sg->dma_address); | 304 | at91_mci_write(host, ATMEL_PDC_RPR, sg->dma_address); |
236 | at91_mci_write(host, ATMEL_PDC_RCR, sg->length / 4); | 305 | at91_mci_write(host, ATMEL_PDC_RCR, (data->blksz & 0x3) ? sg->length : sg->length / 4); |
237 | } | 306 | } |
238 | else { | 307 | else { |
239 | at91_mci_write(host, ATMEL_PDC_RNPR, sg->dma_address); | 308 | at91_mci_write(host, ATMEL_PDC_RNPR, sg->dma_address); |
240 | at91_mci_write(host, ATMEL_PDC_RNCR, sg->length / 4); | 309 | at91_mci_write(host, ATMEL_PDC_RNCR, (data->blksz & 0x3) ? sg->length : sg->length / 4); |
241 | } | 310 | } |
242 | } | 311 | } |
243 | 312 | ||
@@ -277,8 +346,6 @@ static void at91_mci_post_dma_read(struct at91mci_host *host) | |||
277 | 346 | ||
278 | dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE); | 347 | dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE); |
279 | 348 | ||
280 | data->bytes_xfered += sg->length; | ||
281 | |||
282 | if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */ | 349 | if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */ |
283 | unsigned int *buffer; | 350 | unsigned int *buffer; |
284 | int index; | 351 | int index; |
@@ -294,6 +361,8 @@ static void at91_mci_post_dma_read(struct at91mci_host *host) | |||
294 | } | 361 | } |
295 | 362 | ||
296 | flush_dcache_page(sg_page(sg)); | 363 | flush_dcache_page(sg_page(sg)); |
364 | |||
365 | data->bytes_xfered += sg->length; | ||
297 | } | 366 | } |
298 | 367 | ||
299 | /* Is there another transfer to trigger? */ | 368 | /* Is there another transfer to trigger? */ |
@@ -334,10 +403,32 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host) | |||
334 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE); | 403 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE); |
335 | } else | 404 | } else |
336 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY); | 405 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY); |
406 | } | ||
407 | |||
408 | /* | ||
409 | * Update bytes tranfered count during a write operation | ||
410 | */ | ||
411 | static void at91_mci_update_bytes_xfered(struct at91mci_host *host) | ||
412 | { | ||
413 | struct mmc_data *data; | ||
414 | |||
415 | /* always deal with the effective request (and not the current cmd) */ | ||
416 | |||
417 | if (host->request->cmd && host->request->cmd->error != 0) | ||
418 | return; | ||
337 | 419 | ||
338 | data->bytes_xfered = host->total_length; | 420 | if (host->request->data) { |
421 | data = host->request->data; | ||
422 | if (data->flags & MMC_DATA_WRITE) { | ||
423 | /* card is in IDLE mode now */ | ||
424 | pr_debug("-> bytes_xfered %d, total_length = %d\n", | ||
425 | data->bytes_xfered, host->total_length); | ||
426 | data->bytes_xfered = data->blksz * data->blocks; | ||
427 | } | ||
428 | } | ||
339 | } | 429 | } |
340 | 430 | ||
431 | |||
341 | /*Handle after command sent ready*/ | 432 | /*Handle after command sent ready*/ |
342 | static int at91_mci_handle_cmdrdy(struct at91mci_host *host) | 433 | static int at91_mci_handle_cmdrdy(struct at91mci_host *host) |
343 | { | 434 | { |
@@ -350,8 +441,7 @@ static int at91_mci_handle_cmdrdy(struct at91mci_host *host) | |||
350 | } else return 1; | 441 | } else return 1; |
351 | } else if (host->cmd->data->flags & MMC_DATA_WRITE) { | 442 | } else if (host->cmd->data->flags & MMC_DATA_WRITE) { |
352 | /*After sendding multi-block-write command, start DMA transfer*/ | 443 | /*After sendding multi-block-write command, start DMA transfer*/ |
353 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_TXBUFE); | 444 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_TXBUFE | AT91_MCI_BLKE); |
354 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE); | ||
355 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN); | 445 | at91_mci_write(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN); |
356 | } | 446 | } |
357 | 447 | ||
@@ -430,11 +520,19 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command | |||
430 | 520 | ||
431 | if (data) { | 521 | if (data) { |
432 | 522 | ||
433 | if ( data->blksz & 0x3 ) { | 523 | if (cpu_is_at91rm9200() || cpu_is_at91sam9261()) { |
434 | pr_debug("Unsupported block size\n"); | 524 | if (data->blksz & 0x3) { |
435 | cmd->error = -EINVAL; | 525 | pr_debug("Unsupported block size\n"); |
436 | mmc_request_done(host->mmc, host->request); | 526 | cmd->error = -EINVAL; |
437 | return; | 527 | mmc_request_done(host->mmc, host->request); |
528 | return; | ||
529 | } | ||
530 | if (data->flags & MMC_DATA_STREAM) { | ||
531 | pr_debug("Stream commands not supported\n"); | ||
532 | cmd->error = -EINVAL; | ||
533 | mmc_request_done(host->mmc, host->request); | ||
534 | return; | ||
535 | } | ||
438 | } | 536 | } |
439 | 537 | ||
440 | block_length = data->blksz; | 538 | block_length = data->blksz; |
@@ -481,8 +579,16 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command | |||
481 | ier = AT91_MCI_CMDRDY; | 579 | ier = AT91_MCI_CMDRDY; |
482 | } else { | 580 | } else { |
483 | /* zero block length and PDC mode */ | 581 | /* zero block length and PDC mode */ |
484 | mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff; | 582 | mr = at91_mci_read(host, AT91_MCI_MR) & 0x5fff; |
485 | at91_mci_write(host, AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE); | 583 | mr |= (data->blksz & 0x3) ? AT91_MCI_PDCFBYTE : 0; |
584 | mr |= (block_length << 16); | ||
585 | mr |= AT91_MCI_PDCMODE; | ||
586 | at91_mci_write(host, AT91_MCI_MR, mr); | ||
587 | |||
588 | if (!(cpu_is_at91rm9200() || cpu_is_at91sam9261())) | ||
589 | at91_mci_write(host, AT91_MCI_BLKR, | ||
590 | AT91_MCI_BLKR_BCNT(blocks) | | ||
591 | AT91_MCI_BLKR_BLKLEN(block_length)); | ||
486 | 592 | ||
487 | /* | 593 | /* |
488 | * Disable the PDC controller | 594 | * Disable the PDC controller |
@@ -508,6 +614,13 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command | |||
508 | * Handle a write | 614 | * Handle a write |
509 | */ | 615 | */ |
510 | host->total_length = block_length * blocks; | 616 | host->total_length = block_length * blocks; |
617 | /* | ||
618 | * AT91SAM926[0/3] Data Write Operation and | ||
619 | * number of bytes erratum | ||
620 | */ | ||
621 | if (cpu_is_at91sam9260 () || cpu_is_at91sam9263()) | ||
622 | if (host->total_length < 12) | ||
623 | host->total_length = 12; | ||
511 | host->buffer = dma_alloc_coherent(NULL, | 624 | host->buffer = dma_alloc_coherent(NULL, |
512 | host->total_length, | 625 | host->total_length, |
513 | &host->physical_address, GFP_KERNEL); | 626 | &host->physical_address, GFP_KERNEL); |
@@ -517,7 +630,9 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command | |||
517 | pr_debug("Transmitting %d bytes\n", host->total_length); | 630 | pr_debug("Transmitting %d bytes\n", host->total_length); |
518 | 631 | ||
519 | at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address); | 632 | at91_mci_write(host, ATMEL_PDC_TPR, host->physical_address); |
520 | at91_mci_write(host, ATMEL_PDC_TCR, host->total_length / 4); | 633 | at91_mci_write(host, ATMEL_PDC_TCR, (data->blksz & 0x3) ? |
634 | host->total_length : host->total_length / 4); | ||
635 | |||
521 | ier = AT91_MCI_CMDRDY; | 636 | ier = AT91_MCI_CMDRDY; |
522 | } | 637 | } |
523 | } | 638 | } |
@@ -552,20 +667,26 @@ static void at91_mci_process_next(struct at91mci_host *host) | |||
552 | else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) { | 667 | else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) { |
553 | host->flags |= FL_SENT_STOP; | 668 | host->flags |= FL_SENT_STOP; |
554 | at91_mci_send_command(host, host->request->stop); | 669 | at91_mci_send_command(host, host->request->stop); |
555 | } | 670 | } else { |
556 | else | 671 | del_timer(&host->timer); |
672 | /* the at91rm9200 mci controller hangs after some transfers, | ||
673 | * and the workaround is to reset it after each transfer. | ||
674 | */ | ||
675 | if (cpu_is_at91rm9200()) | ||
676 | at91_reset_host(host); | ||
557 | mmc_request_done(host->mmc, host->request); | 677 | mmc_request_done(host->mmc, host->request); |
678 | } | ||
558 | } | 679 | } |
559 | 680 | ||
560 | /* | 681 | /* |
561 | * Handle a command that has been completed | 682 | * Handle a command that has been completed |
562 | */ | 683 | */ |
563 | static void at91_mci_completed_command(struct at91mci_host *host) | 684 | static void at91_mci_completed_command(struct at91mci_host *host, unsigned int status) |
564 | { | 685 | { |
565 | struct mmc_command *cmd = host->cmd; | 686 | struct mmc_command *cmd = host->cmd; |
566 | unsigned int status; | 687 | struct mmc_data *data = cmd->data; |
567 | 688 | ||
568 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff); | 689 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB)); |
569 | 690 | ||
570 | cmd->resp[0] = at91_mci_read(host, AT91_MCI_RSPR(0)); | 691 | cmd->resp[0] = at91_mci_read(host, AT91_MCI_RSPR(0)); |
571 | cmd->resp[1] = at91_mci_read(host, AT91_MCI_RSPR(1)); | 692 | cmd->resp[1] = at91_mci_read(host, AT91_MCI_RSPR(1)); |
@@ -577,25 +698,34 @@ static void at91_mci_completed_command(struct at91mci_host *host) | |||
577 | host->buffer = NULL; | 698 | host->buffer = NULL; |
578 | } | 699 | } |
579 | 700 | ||
580 | status = at91_mci_read(host, AT91_MCI_SR); | 701 | pr_debug("Status = %08X/%08x [%08X %08X %08X %08X]\n", |
581 | 702 | status, at91_mci_read(host, AT91_MCI_SR), | |
582 | pr_debug("Status = %08X [%08X %08X %08X %08X]\n", | 703 | cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); |
583 | status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); | ||
584 | 704 | ||
585 | if (status & AT91_MCI_ERRORS) { | 705 | if (status & AT91_MCI_ERRORS) { |
586 | if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) { | 706 | if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) { |
587 | cmd->error = 0; | 707 | cmd->error = 0; |
588 | } | 708 | } |
589 | else { | 709 | else { |
590 | if (status & (AT91_MCI_RTOE | AT91_MCI_DTOE)) | 710 | if (status & (AT91_MCI_DTOE | AT91_MCI_DCRCE)) { |
591 | cmd->error = -ETIMEDOUT; | 711 | if (data) { |
592 | else if (status & (AT91_MCI_RCRCE | AT91_MCI_DCRCE)) | 712 | if (status & AT91_MCI_DTOE) |
593 | cmd->error = -EILSEQ; | 713 | data->error = -ETIMEDOUT; |
594 | else | 714 | else if (status & AT91_MCI_DCRCE) |
595 | cmd->error = -EIO; | 715 | data->error = -EILSEQ; |
716 | } | ||
717 | } else { | ||
718 | if (status & AT91_MCI_RTOE) | ||
719 | cmd->error = -ETIMEDOUT; | ||
720 | else if (status & AT91_MCI_RCRCE) | ||
721 | cmd->error = -EILSEQ; | ||
722 | else | ||
723 | cmd->error = -EIO; | ||
724 | } | ||
596 | 725 | ||
597 | pr_debug("Error detected and set to %d (cmd = %d, retries = %d)\n", | 726 | pr_debug("Error detected and set to %d/%d (cmd = %d, retries = %d)\n", |
598 | cmd->error, cmd->opcode, cmd->retries); | 727 | cmd->error, data ? data->error : 0, |
728 | cmd->opcode, cmd->retries); | ||
599 | } | 729 | } |
600 | } | 730 | } |
601 | else | 731 | else |
@@ -613,6 +743,8 @@ static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
613 | host->request = mrq; | 743 | host->request = mrq; |
614 | host->flags = 0; | 744 | host->flags = 0; |
615 | 745 | ||
746 | mod_timer(&host->timer, jiffies + HZ); | ||
747 | |||
616 | at91_mci_process_next(host); | 748 | at91_mci_process_next(host); |
617 | } | 749 | } |
618 | 750 | ||
@@ -736,6 +868,7 @@ static irqreturn_t at91_mci_irq(int irq, void *devid) | |||
736 | 868 | ||
737 | if (int_status & AT91_MCI_NOTBUSY) { | 869 | if (int_status & AT91_MCI_NOTBUSY) { |
738 | pr_debug("Card is ready\n"); | 870 | pr_debug("Card is ready\n"); |
871 | at91_mci_update_bytes_xfered(host); | ||
739 | completed = 1; | 872 | completed = 1; |
740 | } | 873 | } |
741 | 874 | ||
@@ -744,9 +877,21 @@ static irqreturn_t at91_mci_irq(int irq, void *devid) | |||
744 | 877 | ||
745 | if (int_status & AT91_MCI_BLKE) { | 878 | if (int_status & AT91_MCI_BLKE) { |
746 | pr_debug("Block transfer has ended\n"); | 879 | pr_debug("Block transfer has ended\n"); |
747 | completed = 1; | 880 | if (host->request->data && host->request->data->blocks > 1) { |
881 | /* multi block write : complete multi write | ||
882 | * command and send stop */ | ||
883 | completed = 1; | ||
884 | } else { | ||
885 | at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY); | ||
886 | } | ||
748 | } | 887 | } |
749 | 888 | ||
889 | if (int_status & AT91_MCI_SDIOIRQA) | ||
890 | mmc_signal_sdio_irq(host->mmc); | ||
891 | |||
892 | if (int_status & AT91_MCI_SDIOIRQB) | ||
893 | mmc_signal_sdio_irq(host->mmc); | ||
894 | |||
750 | if (int_status & AT91_MCI_TXRDY) | 895 | if (int_status & AT91_MCI_TXRDY) |
751 | pr_debug("Ready to transmit\n"); | 896 | pr_debug("Ready to transmit\n"); |
752 | 897 | ||
@@ -761,10 +906,10 @@ static irqreturn_t at91_mci_irq(int irq, void *devid) | |||
761 | 906 | ||
762 | if (completed) { | 907 | if (completed) { |
763 | pr_debug("Completed command\n"); | 908 | pr_debug("Completed command\n"); |
764 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff); | 909 | at91_mci_write(host, AT91_MCI_IDR, 0xffffffff & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB)); |
765 | at91_mci_completed_command(host); | 910 | at91_mci_completed_command(host, int_status); |
766 | } else | 911 | } else |
767 | at91_mci_write(host, AT91_MCI_IDR, int_status); | 912 | at91_mci_write(host, AT91_MCI_IDR, int_status & ~(AT91_MCI_SDIOIRQA | AT91_MCI_SDIOIRQB)); |
768 | 913 | ||
769 | return IRQ_HANDLED; | 914 | return IRQ_HANDLED; |
770 | } | 915 | } |
@@ -793,25 +938,33 @@ static irqreturn_t at91_mmc_det_irq(int irq, void *_host) | |||
793 | 938 | ||
794 | static int at91_mci_get_ro(struct mmc_host *mmc) | 939 | static int at91_mci_get_ro(struct mmc_host *mmc) |
795 | { | 940 | { |
796 | int read_only = 0; | ||
797 | struct at91mci_host *host = mmc_priv(mmc); | 941 | struct at91mci_host *host = mmc_priv(mmc); |
798 | 942 | ||
799 | if (host->board->wp_pin) { | 943 | if (host->board->wp_pin) |
800 | read_only = gpio_get_value(host->board->wp_pin); | 944 | return !!gpio_get_value(host->board->wp_pin); |
801 | printk(KERN_WARNING "%s: card is %s\n", mmc_hostname(mmc), | 945 | /* |
802 | (read_only ? "read-only" : "read-write") ); | 946 | * Board doesn't support read only detection; let the mmc core |
803 | } | 947 | * decide what to do. |
804 | else { | 948 | */ |
805 | printk(KERN_WARNING "%s: host does not support reading read-only " | 949 | return -ENOSYS; |
806 | "switch. Assuming write-enable.\n", mmc_hostname(mmc)); | 950 | } |
807 | } | 951 | |
808 | return read_only; | 952 | static void at91_mci_enable_sdio_irq(struct mmc_host *mmc, int enable) |
953 | { | ||
954 | struct at91mci_host *host = mmc_priv(mmc); | ||
955 | |||
956 | pr_debug("%s: sdio_irq %c : %s\n", mmc_hostname(host->mmc), | ||
957 | host->board->slot_b ? 'B':'A', enable ? "enable" : "disable"); | ||
958 | at91_mci_write(host, enable ? AT91_MCI_IER : AT91_MCI_IDR, | ||
959 | host->board->slot_b ? AT91_MCI_SDIOIRQB : AT91_MCI_SDIOIRQA); | ||
960 | |||
809 | } | 961 | } |
810 | 962 | ||
811 | static const struct mmc_host_ops at91_mci_ops = { | 963 | static const struct mmc_host_ops at91_mci_ops = { |
812 | .request = at91_mci_request, | 964 | .request = at91_mci_request, |
813 | .set_ios = at91_mci_set_ios, | 965 | .set_ios = at91_mci_set_ios, |
814 | .get_ro = at91_mci_get_ro, | 966 | .get_ro = at91_mci_get_ro, |
967 | .enable_sdio_irq = at91_mci_enable_sdio_irq, | ||
815 | }; | 968 | }; |
816 | 969 | ||
817 | /* | 970 | /* |
@@ -842,6 +995,7 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
842 | mmc->f_min = 375000; | 995 | mmc->f_min = 375000; |
843 | mmc->f_max = 25000000; | 996 | mmc->f_max = 25000000; |
844 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | 997 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
998 | mmc->caps = MMC_CAP_SDIO_IRQ; | ||
845 | 999 | ||
846 | mmc->max_blk_size = 4095; | 1000 | mmc->max_blk_size = 4095; |
847 | mmc->max_blk_count = mmc->max_req_size; | 1001 | mmc->max_blk_count = mmc->max_req_size; |
@@ -935,6 +1089,8 @@ static int __init at91_mci_probe(struct platform_device *pdev) | |||
935 | 1089 | ||
936 | mmc_add_host(mmc); | 1090 | mmc_add_host(mmc); |
937 | 1091 | ||
1092 | setup_timer(&host->timer, at91_timeout_timer, (unsigned long)host); | ||
1093 | |||
938 | /* | 1094 | /* |
939 | * monitor card insertion/removal if we can | 1095 | * monitor card insertion/removal if we can |
940 | */ | 1096 | */ |
@@ -995,6 +1151,7 @@ static int __exit at91_mci_remove(struct platform_device *pdev) | |||
995 | } | 1151 | } |
996 | 1152 | ||
997 | at91_mci_disable(host); | 1153 | at91_mci_disable(host); |
1154 | del_timer_sync(&host->timer); | ||
998 | mmc_remove_host(mmc); | 1155 | mmc_remove_host(mmc); |
999 | free_irq(host->irq, host); | 1156 | free_irq(host->irq, host); |
1000 | 1157 | ||
diff --git a/drivers/mmc/host/atmel-mci-regs.h b/drivers/mmc/host/atmel-mci-regs.h new file mode 100644 index 000000000000..a9a5657706c6 --- /dev/null +++ b/drivers/mmc/host/atmel-mci-regs.h | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Atmel MultiMedia Card Interface driver | ||
3 | * | ||
4 | * Copyright (C) 2004-2006 Atmel Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #ifndef __DRIVERS_MMC_ATMEL_MCI_H__ | ||
11 | #define __DRIVERS_MMC_ATMEL_MCI_H__ | ||
12 | |||
13 | /* MCI Register Definitions */ | ||
14 | #define MCI_CR 0x0000 /* Control */ | ||
15 | # define MCI_CR_MCIEN ( 1 << 0) /* MCI Enable */ | ||
16 | # define MCI_CR_MCIDIS ( 1 << 1) /* MCI Disable */ | ||
17 | # define MCI_CR_SWRST ( 1 << 7) /* Software Reset */ | ||
18 | #define MCI_MR 0x0004 /* Mode */ | ||
19 | # define MCI_MR_CLKDIV(x) ((x) << 0) /* Clock Divider */ | ||
20 | # define MCI_MR_RDPROOF ( 1 << 11) /* Read Proof */ | ||
21 | # define MCI_MR_WRPROOF ( 1 << 12) /* Write Proof */ | ||
22 | #define MCI_DTOR 0x0008 /* Data Timeout */ | ||
23 | # define MCI_DTOCYC(x) ((x) << 0) /* Data Timeout Cycles */ | ||
24 | # define MCI_DTOMUL(x) ((x) << 4) /* Data Timeout Multiplier */ | ||
25 | #define MCI_SDCR 0x000c /* SD Card / SDIO */ | ||
26 | # define MCI_SDCSEL_SLOT_A ( 0 << 0) /* Select SD slot A */ | ||
27 | # define MCI_SDCSEL_SLOT_B ( 1 << 0) /* Select SD slot A */ | ||
28 | # define MCI_SDCBUS_1BIT ( 0 << 7) /* 1-bit data bus */ | ||
29 | # define MCI_SDCBUS_4BIT ( 1 << 7) /* 4-bit data bus */ | ||
30 | #define MCI_ARGR 0x0010 /* Command Argument */ | ||
31 | #define MCI_CMDR 0x0014 /* Command */ | ||
32 | # define MCI_CMDR_CMDNB(x) ((x) << 0) /* Command Opcode */ | ||
33 | # define MCI_CMDR_RSPTYP_NONE ( 0 << 6) /* No response */ | ||
34 | # define MCI_CMDR_RSPTYP_48BIT ( 1 << 6) /* 48-bit response */ | ||
35 | # define MCI_CMDR_RSPTYP_136BIT ( 2 << 6) /* 136-bit response */ | ||
36 | # define MCI_CMDR_SPCMD_INIT ( 1 << 8) /* Initialization command */ | ||
37 | # define MCI_CMDR_SPCMD_SYNC ( 2 << 8) /* Synchronized command */ | ||
38 | # define MCI_CMDR_SPCMD_INT ( 4 << 8) /* Interrupt command */ | ||
39 | # define MCI_CMDR_SPCMD_INTRESP ( 5 << 8) /* Interrupt response */ | ||
40 | # define MCI_CMDR_OPDCMD ( 1 << 11) /* Open Drain */ | ||
41 | # define MCI_CMDR_MAXLAT_5CYC ( 0 << 12) /* Max latency 5 cycles */ | ||
42 | # define MCI_CMDR_MAXLAT_64CYC ( 1 << 12) /* Max latency 64 cycles */ | ||
43 | # define MCI_CMDR_START_XFER ( 1 << 16) /* Start data transfer */ | ||
44 | # define MCI_CMDR_STOP_XFER ( 2 << 16) /* Stop data transfer */ | ||
45 | # define MCI_CMDR_TRDIR_WRITE ( 0 << 18) /* Write data */ | ||
46 | # define MCI_CMDR_TRDIR_READ ( 1 << 18) /* Read data */ | ||
47 | # define MCI_CMDR_BLOCK ( 0 << 19) /* Single-block transfer */ | ||
48 | # define MCI_CMDR_MULTI_BLOCK ( 1 << 19) /* Multi-block transfer */ | ||
49 | # define MCI_CMDR_STREAM ( 2 << 19) /* MMC Stream transfer */ | ||
50 | # define MCI_CMDR_SDIO_BYTE ( 4 << 19) /* SDIO Byte transfer */ | ||
51 | # define MCI_CMDR_SDIO_BLOCK ( 5 << 19) /* SDIO Block transfer */ | ||
52 | # define MCI_CMDR_SDIO_SUSPEND ( 1 << 24) /* SDIO Suspend Command */ | ||
53 | # define MCI_CMDR_SDIO_RESUME ( 2 << 24) /* SDIO Resume Command */ | ||
54 | #define MCI_BLKR 0x0018 /* Block */ | ||
55 | # define MCI_BCNT(x) ((x) << 0) /* Data Block Count */ | ||
56 | # define MCI_BLKLEN(x) ((x) << 16) /* Data Block Length */ | ||
57 | #define MCI_RSPR 0x0020 /* Response 0 */ | ||
58 | #define MCI_RSPR1 0x0024 /* Response 1 */ | ||
59 | #define MCI_RSPR2 0x0028 /* Response 2 */ | ||
60 | #define MCI_RSPR3 0x002c /* Response 3 */ | ||
61 | #define MCI_RDR 0x0030 /* Receive Data */ | ||
62 | #define MCI_TDR 0x0034 /* Transmit Data */ | ||
63 | #define MCI_SR 0x0040 /* Status */ | ||
64 | #define MCI_IER 0x0044 /* Interrupt Enable */ | ||
65 | #define MCI_IDR 0x0048 /* Interrupt Disable */ | ||
66 | #define MCI_IMR 0x004c /* Interrupt Mask */ | ||
67 | # define MCI_CMDRDY ( 1 << 0) /* Command Ready */ | ||
68 | # define MCI_RXRDY ( 1 << 1) /* Receiver Ready */ | ||
69 | # define MCI_TXRDY ( 1 << 2) /* Transmitter Ready */ | ||
70 | # define MCI_BLKE ( 1 << 3) /* Data Block Ended */ | ||
71 | # define MCI_DTIP ( 1 << 4) /* Data Transfer In Progress */ | ||
72 | # define MCI_NOTBUSY ( 1 << 5) /* Data Not Busy */ | ||
73 | # define MCI_SDIOIRQA ( 1 << 8) /* SDIO IRQ in slot A */ | ||
74 | # define MCI_SDIOIRQB ( 1 << 9) /* SDIO IRQ in slot B */ | ||
75 | # define MCI_RINDE ( 1 << 16) /* Response Index Error */ | ||
76 | # define MCI_RDIRE ( 1 << 17) /* Response Direction Error */ | ||
77 | # define MCI_RCRCE ( 1 << 18) /* Response CRC Error */ | ||
78 | # define MCI_RENDE ( 1 << 19) /* Response End Bit Error */ | ||
79 | # define MCI_RTOE ( 1 << 20) /* Response Time-Out Error */ | ||
80 | # define MCI_DCRCE ( 1 << 21) /* Data CRC Error */ | ||
81 | # define MCI_DTOE ( 1 << 22) /* Data Time-Out Error */ | ||
82 | # define MCI_OVRE ( 1 << 30) /* RX Overrun Error */ | ||
83 | # define MCI_UNRE ( 1 << 31) /* TX Underrun Error */ | ||
84 | |||
85 | /* Register access macros */ | ||
86 | #define mci_readl(port,reg) \ | ||
87 | __raw_readl((port)->regs + MCI_##reg) | ||
88 | #define mci_writel(port,reg,value) \ | ||
89 | __raw_writel((value), (port)->regs + MCI_##reg) | ||
90 | |||
91 | #endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */ | ||
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c new file mode 100644 index 000000000000..cce873c5a149 --- /dev/null +++ b/drivers/mmc/host/atmel-mci.c | |||
@@ -0,0 +1,981 @@ | |||
1 | /* | ||
2 | * Atmel MultiMedia Card Interface driver | ||
3 | * | ||
4 | * Copyright (C) 2004-2008 Atmel Corporation | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | #include <linux/blkdev.h> | ||
11 | #include <linux/clk.h> | ||
12 | #include <linux/device.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/interrupt.h> | ||
15 | #include <linux/ioport.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/scatterlist.h> | ||
19 | |||
20 | #include <linux/mmc/host.h> | ||
21 | |||
22 | #include <asm/atmel-mci.h> | ||
23 | #include <asm/io.h> | ||
24 | #include <asm/unaligned.h> | ||
25 | |||
26 | #include <asm/arch/board.h> | ||
27 | #include <asm/arch/gpio.h> | ||
28 | |||
29 | #include "atmel-mci-regs.h" | ||
30 | |||
31 | #define ATMCI_DATA_ERROR_FLAGS (MCI_DCRCE | MCI_DTOE | MCI_OVRE | MCI_UNRE) | ||
32 | |||
33 | enum { | ||
34 | EVENT_CMD_COMPLETE = 0, | ||
35 | EVENT_DATA_ERROR, | ||
36 | EVENT_DATA_COMPLETE, | ||
37 | EVENT_STOP_SENT, | ||
38 | EVENT_STOP_COMPLETE, | ||
39 | EVENT_XFER_COMPLETE, | ||
40 | }; | ||
41 | |||
42 | struct atmel_mci { | ||
43 | struct mmc_host *mmc; | ||
44 | void __iomem *regs; | ||
45 | |||
46 | struct scatterlist *sg; | ||
47 | unsigned int pio_offset; | ||
48 | |||
49 | struct mmc_request *mrq; | ||
50 | struct mmc_command *cmd; | ||
51 | struct mmc_data *data; | ||
52 | |||
53 | u32 cmd_status; | ||
54 | u32 data_status; | ||
55 | u32 stop_status; | ||
56 | u32 stop_cmdr; | ||
57 | |||
58 | u32 mode_reg; | ||
59 | u32 sdc_reg; | ||
60 | |||
61 | struct tasklet_struct tasklet; | ||
62 | unsigned long pending_events; | ||
63 | unsigned long completed_events; | ||
64 | |||
65 | int present; | ||
66 | int detect_pin; | ||
67 | int wp_pin; | ||
68 | |||
69 | /* For detect pin debouncing */ | ||
70 | struct timer_list detect_timer; | ||
71 | |||
72 | unsigned long bus_hz; | ||
73 | unsigned long mapbase; | ||
74 | struct clk *mck; | ||
75 | struct platform_device *pdev; | ||
76 | }; | ||
77 | |||
78 | #define atmci_is_completed(host, event) \ | ||
79 | test_bit(event, &host->completed_events) | ||
80 | #define atmci_test_and_clear_pending(host, event) \ | ||
81 | test_and_clear_bit(event, &host->pending_events) | ||
82 | #define atmci_test_and_set_completed(host, event) \ | ||
83 | test_and_set_bit(event, &host->completed_events) | ||
84 | #define atmci_set_completed(host, event) \ | ||
85 | set_bit(event, &host->completed_events) | ||
86 | #define atmci_set_pending(host, event) \ | ||
87 | set_bit(event, &host->pending_events) | ||
88 | #define atmci_clear_pending(host, event) \ | ||
89 | clear_bit(event, &host->pending_events) | ||
90 | |||
91 | |||
92 | static void atmci_enable(struct atmel_mci *host) | ||
93 | { | ||
94 | clk_enable(host->mck); | ||
95 | mci_writel(host, CR, MCI_CR_MCIEN); | ||
96 | mci_writel(host, MR, host->mode_reg); | ||
97 | mci_writel(host, SDCR, host->sdc_reg); | ||
98 | } | ||
99 | |||
100 | static void atmci_disable(struct atmel_mci *host) | ||
101 | { | ||
102 | mci_writel(host, CR, MCI_CR_SWRST); | ||
103 | |||
104 | /* Stall until write is complete, then disable the bus clock */ | ||
105 | mci_readl(host, SR); | ||
106 | clk_disable(host->mck); | ||
107 | } | ||
108 | |||
109 | static inline unsigned int ns_to_clocks(struct atmel_mci *host, | ||
110 | unsigned int ns) | ||
111 | { | ||
112 | return (ns * (host->bus_hz / 1000000) + 999) / 1000; | ||
113 | } | ||
114 | |||
115 | static void atmci_set_timeout(struct atmel_mci *host, | ||
116 | struct mmc_data *data) | ||
117 | { | ||
118 | static unsigned dtomul_to_shift[] = { | ||
119 | 0, 4, 7, 8, 10, 12, 16, 20 | ||
120 | }; | ||
121 | unsigned timeout; | ||
122 | unsigned dtocyc; | ||
123 | unsigned dtomul; | ||
124 | |||
125 | timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks; | ||
126 | |||
127 | for (dtomul = 0; dtomul < 8; dtomul++) { | ||
128 | unsigned shift = dtomul_to_shift[dtomul]; | ||
129 | dtocyc = (timeout + (1 << shift) - 1) >> shift; | ||
130 | if (dtocyc < 15) | ||
131 | break; | ||
132 | } | ||
133 | |||
134 | if (dtomul >= 8) { | ||
135 | dtomul = 7; | ||
136 | dtocyc = 15; | ||
137 | } | ||
138 | |||
139 | dev_vdbg(&host->mmc->class_dev, "setting timeout to %u cycles\n", | ||
140 | dtocyc << dtomul_to_shift[dtomul]); | ||
141 | mci_writel(host, DTOR, (MCI_DTOMUL(dtomul) | MCI_DTOCYC(dtocyc))); | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * Return mask with command flags to be enabled for this command. | ||
146 | */ | ||
147 | static u32 atmci_prepare_command(struct mmc_host *mmc, | ||
148 | struct mmc_command *cmd) | ||
149 | { | ||
150 | struct mmc_data *data; | ||
151 | u32 cmdr; | ||
152 | |||
153 | cmd->error = -EINPROGRESS; | ||
154 | |||
155 | cmdr = MCI_CMDR_CMDNB(cmd->opcode); | ||
156 | |||
157 | if (cmd->flags & MMC_RSP_PRESENT) { | ||
158 | if (cmd->flags & MMC_RSP_136) | ||
159 | cmdr |= MCI_CMDR_RSPTYP_136BIT; | ||
160 | else | ||
161 | cmdr |= MCI_CMDR_RSPTYP_48BIT; | ||
162 | } | ||
163 | |||
164 | /* | ||
165 | * This should really be MAXLAT_5 for CMD2 and ACMD41, but | ||
166 | * it's too difficult to determine whether this is an ACMD or | ||
167 | * not. Better make it 64. | ||
168 | */ | ||
169 | cmdr |= MCI_CMDR_MAXLAT_64CYC; | ||
170 | |||
171 | if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN) | ||
172 | cmdr |= MCI_CMDR_OPDCMD; | ||
173 | |||
174 | data = cmd->data; | ||
175 | if (data) { | ||
176 | cmdr |= MCI_CMDR_START_XFER; | ||
177 | if (data->flags & MMC_DATA_STREAM) | ||
178 | cmdr |= MCI_CMDR_STREAM; | ||
179 | else if (data->blocks > 1) | ||
180 | cmdr |= MCI_CMDR_MULTI_BLOCK; | ||
181 | else | ||
182 | cmdr |= MCI_CMDR_BLOCK; | ||
183 | |||
184 | if (data->flags & MMC_DATA_READ) | ||
185 | cmdr |= MCI_CMDR_TRDIR_READ; | ||
186 | } | ||
187 | |||
188 | return cmdr; | ||
189 | } | ||
190 | |||
191 | static void atmci_start_command(struct atmel_mci *host, | ||
192 | struct mmc_command *cmd, | ||
193 | u32 cmd_flags) | ||
194 | { | ||
195 | /* Must read host->cmd after testing event flags */ | ||
196 | smp_rmb(); | ||
197 | WARN_ON(host->cmd); | ||
198 | host->cmd = cmd; | ||
199 | |||
200 | dev_vdbg(&host->mmc->class_dev, | ||
201 | "start command: ARGR=0x%08x CMDR=0x%08x\n", | ||
202 | cmd->arg, cmd_flags); | ||
203 | |||
204 | mci_writel(host, ARGR, cmd->arg); | ||
205 | mci_writel(host, CMDR, cmd_flags); | ||
206 | } | ||
207 | |||
208 | static void send_stop_cmd(struct mmc_host *mmc, struct mmc_data *data) | ||
209 | { | ||
210 | struct atmel_mci *host = mmc_priv(mmc); | ||
211 | |||
212 | atmci_start_command(host, data->stop, host->stop_cmdr); | ||
213 | mci_writel(host, IER, MCI_CMDRDY); | ||
214 | } | ||
215 | |||
216 | static void atmci_request_end(struct mmc_host *mmc, struct mmc_request *mrq) | ||
217 | { | ||
218 | struct atmel_mci *host = mmc_priv(mmc); | ||
219 | |||
220 | WARN_ON(host->cmd || host->data); | ||
221 | host->mrq = NULL; | ||
222 | |||
223 | atmci_disable(host); | ||
224 | |||
225 | mmc_request_done(mmc, mrq); | ||
226 | } | ||
227 | |||
228 | /* | ||
229 | * Returns a mask of interrupt flags to be enabled after the whole | ||
230 | * request has been prepared. | ||
231 | */ | ||
232 | static u32 atmci_submit_data(struct mmc_host *mmc, struct mmc_data *data) | ||
233 | { | ||
234 | struct atmel_mci *host = mmc_priv(mmc); | ||
235 | u32 iflags; | ||
236 | |||
237 | data->error = -EINPROGRESS; | ||
238 | |||
239 | WARN_ON(host->data); | ||
240 | host->sg = NULL; | ||
241 | host->data = data; | ||
242 | |||
243 | mci_writel(host, BLKR, MCI_BCNT(data->blocks) | ||
244 | | MCI_BLKLEN(data->blksz)); | ||
245 | dev_vdbg(&mmc->class_dev, "BLKR=0x%08x\n", | ||
246 | MCI_BCNT(data->blocks) | MCI_BLKLEN(data->blksz)); | ||
247 | |||
248 | iflags = ATMCI_DATA_ERROR_FLAGS; | ||
249 | host->sg = data->sg; | ||
250 | host->pio_offset = 0; | ||
251 | if (data->flags & MMC_DATA_READ) | ||
252 | iflags |= MCI_RXRDY; | ||
253 | else | ||
254 | iflags |= MCI_TXRDY; | ||
255 | |||
256 | return iflags; | ||
257 | } | ||
258 | |||
259 | static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq) | ||
260 | { | ||
261 | struct atmel_mci *host = mmc_priv(mmc); | ||
262 | struct mmc_data *data; | ||
263 | struct mmc_command *cmd; | ||
264 | u32 iflags; | ||
265 | u32 cmdflags = 0; | ||
266 | |||
267 | iflags = mci_readl(host, IMR); | ||
268 | if (iflags) | ||
269 | dev_warn(&mmc->class_dev, "WARNING: IMR=0x%08x\n", | ||
270 | mci_readl(host, IMR)); | ||
271 | |||
272 | WARN_ON(host->mrq != NULL); | ||
273 | |||
274 | /* | ||
275 | * We may "know" the card is gone even though there's still an | ||
276 | * electrical connection. If so, we really need to communicate | ||
277 | * this to the MMC core since there won't be any more | ||
278 | * interrupts as the card is completely removed. Otherwise, | ||
279 | * the MMC core might believe the card is still there even | ||
280 | * though the card was just removed very slowly. | ||
281 | */ | ||
282 | if (!host->present) { | ||
283 | mrq->cmd->error = -ENOMEDIUM; | ||
284 | mmc_request_done(mmc, mrq); | ||
285 | return; | ||
286 | } | ||
287 | |||
288 | host->mrq = mrq; | ||
289 | host->pending_events = 0; | ||
290 | host->completed_events = 0; | ||
291 | |||
292 | atmci_enable(host); | ||
293 | |||
294 | /* We don't support multiple blocks of weird lengths. */ | ||
295 | data = mrq->data; | ||
296 | if (data) { | ||
297 | if (data->blocks > 1 && data->blksz & 3) | ||
298 | goto fail; | ||
299 | atmci_set_timeout(host, data); | ||
300 | } | ||
301 | |||
302 | iflags = MCI_CMDRDY; | ||
303 | cmd = mrq->cmd; | ||
304 | cmdflags = atmci_prepare_command(mmc, cmd); | ||
305 | atmci_start_command(host, cmd, cmdflags); | ||
306 | |||
307 | if (data) | ||
308 | iflags |= atmci_submit_data(mmc, data); | ||
309 | |||
310 | if (mrq->stop) { | ||
311 | host->stop_cmdr = atmci_prepare_command(mmc, mrq->stop); | ||
312 | host->stop_cmdr |= MCI_CMDR_STOP_XFER; | ||
313 | if (!(data->flags & MMC_DATA_WRITE)) | ||
314 | host->stop_cmdr |= MCI_CMDR_TRDIR_READ; | ||
315 | if (data->flags & MMC_DATA_STREAM) | ||
316 | host->stop_cmdr |= MCI_CMDR_STREAM; | ||
317 | else | ||
318 | host->stop_cmdr |= MCI_CMDR_MULTI_BLOCK; | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * We could have enabled interrupts earlier, but I suspect | ||
323 | * that would open up a nice can of interesting race | ||
324 | * conditions (e.g. command and data complete, but stop not | ||
325 | * prepared yet.) | ||
326 | */ | ||
327 | mci_writel(host, IER, iflags); | ||
328 | |||
329 | return; | ||
330 | |||
331 | fail: | ||
332 | atmci_disable(host); | ||
333 | host->mrq = NULL; | ||
334 | mrq->cmd->error = -EINVAL; | ||
335 | mmc_request_done(mmc, mrq); | ||
336 | } | ||
337 | |||
338 | static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | ||
339 | { | ||
340 | struct atmel_mci *host = mmc_priv(mmc); | ||
341 | |||
342 | if (ios->clock) { | ||
343 | u32 clkdiv; | ||
344 | |||
345 | /* Set clock rate */ | ||
346 | clkdiv = DIV_ROUND_UP(host->bus_hz, 2 * ios->clock) - 1; | ||
347 | if (clkdiv > 255) { | ||
348 | dev_warn(&mmc->class_dev, | ||
349 | "clock %u too slow; using %lu\n", | ||
350 | ios->clock, host->bus_hz / (2 * 256)); | ||
351 | clkdiv = 255; | ||
352 | } | ||
353 | |||
354 | host->mode_reg = MCI_MR_CLKDIV(clkdiv) | MCI_MR_WRPROOF | ||
355 | | MCI_MR_RDPROOF; | ||
356 | } | ||
357 | |||
358 | switch (ios->bus_width) { | ||
359 | case MMC_BUS_WIDTH_1: | ||
360 | host->sdc_reg = 0; | ||
361 | break; | ||
362 | case MMC_BUS_WIDTH_4: | ||
363 | host->sdc_reg = MCI_SDCBUS_4BIT; | ||
364 | break; | ||
365 | } | ||
366 | |||
367 | switch (ios->power_mode) { | ||
368 | case MMC_POWER_ON: | ||
369 | /* Send init sequence (74 clock cycles) */ | ||
370 | atmci_enable(host); | ||
371 | mci_writel(host, CMDR, MCI_CMDR_SPCMD_INIT); | ||
372 | while (!(mci_readl(host, SR) & MCI_CMDRDY)) | ||
373 | cpu_relax(); | ||
374 | atmci_disable(host); | ||
375 | break; | ||
376 | default: | ||
377 | /* | ||
378 | * TODO: None of the currently available AVR32-based | ||
379 | * boards allow MMC power to be turned off. Implement | ||
380 | * power control when this can be tested properly. | ||
381 | */ | ||
382 | break; | ||
383 | } | ||
384 | } | ||
385 | |||
386 | static int atmci_get_ro(struct mmc_host *mmc) | ||
387 | { | ||
388 | int read_only = 0; | ||
389 | struct atmel_mci *host = mmc_priv(mmc); | ||
390 | |||
391 | if (host->wp_pin >= 0) { | ||
392 | read_only = gpio_get_value(host->wp_pin); | ||
393 | dev_dbg(&mmc->class_dev, "card is %s\n", | ||
394 | read_only ? "read-only" : "read-write"); | ||
395 | } else { | ||
396 | dev_dbg(&mmc->class_dev, | ||
397 | "no pin for checking read-only switch." | ||
398 | " Assuming write-enable.\n"); | ||
399 | } | ||
400 | |||
401 | return read_only; | ||
402 | } | ||
403 | |||
404 | static struct mmc_host_ops atmci_ops = { | ||
405 | .request = atmci_request, | ||
406 | .set_ios = atmci_set_ios, | ||
407 | .get_ro = atmci_get_ro, | ||
408 | }; | ||
409 | |||
410 | static void atmci_command_complete(struct atmel_mci *host, | ||
411 | struct mmc_command *cmd, u32 status) | ||
412 | { | ||
413 | /* Read the response from the card (up to 16 bytes) */ | ||
414 | cmd->resp[0] = mci_readl(host, RSPR); | ||
415 | cmd->resp[1] = mci_readl(host, RSPR); | ||
416 | cmd->resp[2] = mci_readl(host, RSPR); | ||
417 | cmd->resp[3] = mci_readl(host, RSPR); | ||
418 | |||
419 | if (status & MCI_RTOE) | ||
420 | cmd->error = -ETIMEDOUT; | ||
421 | else if ((cmd->flags & MMC_RSP_CRC) && (status & MCI_RCRCE)) | ||
422 | cmd->error = -EILSEQ; | ||
423 | else if (status & (MCI_RINDE | MCI_RDIRE | MCI_RENDE)) | ||
424 | cmd->error = -EIO; | ||
425 | else | ||
426 | cmd->error = 0; | ||
427 | |||
428 | if (cmd->error) { | ||
429 | dev_dbg(&host->mmc->class_dev, | ||
430 | "command error: status=0x%08x\n", status); | ||
431 | |||
432 | if (cmd->data) { | ||
433 | host->data = NULL; | ||
434 | mci_writel(host, IDR, MCI_NOTBUSY | ||
435 | | MCI_TXRDY | MCI_RXRDY | ||
436 | | ATMCI_DATA_ERROR_FLAGS); | ||
437 | } | ||
438 | } | ||
439 | } | ||
440 | |||
441 | static void atmci_detect_change(unsigned long data) | ||
442 | { | ||
443 | struct atmel_mci *host = (struct atmel_mci *)data; | ||
444 | struct mmc_request *mrq = host->mrq; | ||
445 | int present; | ||
446 | |||
447 | /* | ||
448 | * atmci_remove() sets detect_pin to -1 before freeing the | ||
449 | * interrupt. We must not re-enable the interrupt if it has | ||
450 | * been freed. | ||
451 | */ | ||
452 | smp_rmb(); | ||
453 | if (host->detect_pin < 0) | ||
454 | return; | ||
455 | |||
456 | enable_irq(gpio_to_irq(host->detect_pin)); | ||
457 | present = !gpio_get_value(host->detect_pin); | ||
458 | |||
459 | dev_vdbg(&host->pdev->dev, "detect change: %d (was %d)\n", | ||
460 | present, host->present); | ||
461 | |||
462 | if (present != host->present) { | ||
463 | dev_dbg(&host->mmc->class_dev, "card %s\n", | ||
464 | present ? "inserted" : "removed"); | ||
465 | host->present = present; | ||
466 | |||
467 | /* Reset controller if card is gone */ | ||
468 | if (!present) { | ||
469 | mci_writel(host, CR, MCI_CR_SWRST); | ||
470 | mci_writel(host, IDR, ~0UL); | ||
471 | mci_writel(host, CR, MCI_CR_MCIEN); | ||
472 | } | ||
473 | |||
474 | /* Clean up queue if present */ | ||
475 | if (mrq) { | ||
476 | /* | ||
477 | * Reset controller to terminate any ongoing | ||
478 | * commands or data transfers. | ||
479 | */ | ||
480 | mci_writel(host, CR, MCI_CR_SWRST); | ||
481 | |||
482 | if (!atmci_is_completed(host, EVENT_CMD_COMPLETE)) | ||
483 | mrq->cmd->error = -ENOMEDIUM; | ||
484 | |||
485 | if (mrq->data && !atmci_is_completed(host, | ||
486 | EVENT_DATA_COMPLETE)) { | ||
487 | host->data = NULL; | ||
488 | mrq->data->error = -ENOMEDIUM; | ||
489 | } | ||
490 | if (mrq->stop && !atmci_is_completed(host, | ||
491 | EVENT_STOP_COMPLETE)) | ||
492 | mrq->stop->error = -ENOMEDIUM; | ||
493 | |||
494 | host->cmd = NULL; | ||
495 | atmci_request_end(host->mmc, mrq); | ||
496 | } | ||
497 | |||
498 | mmc_detect_change(host->mmc, 0); | ||
499 | } | ||
500 | } | ||
501 | |||
502 | static void atmci_tasklet_func(unsigned long priv) | ||
503 | { | ||
504 | struct mmc_host *mmc = (struct mmc_host *)priv; | ||
505 | struct atmel_mci *host = mmc_priv(mmc); | ||
506 | struct mmc_request *mrq = host->mrq; | ||
507 | struct mmc_data *data = host->data; | ||
508 | |||
509 | dev_vdbg(&mmc->class_dev, | ||
510 | "tasklet: pending/completed/mask %lx/%lx/%x\n", | ||
511 | host->pending_events, host->completed_events, | ||
512 | mci_readl(host, IMR)); | ||
513 | |||
514 | if (atmci_test_and_clear_pending(host, EVENT_CMD_COMPLETE)) { | ||
515 | /* | ||
516 | * host->cmd must be set to NULL before the interrupt | ||
517 | * handler sees EVENT_CMD_COMPLETE | ||
518 | */ | ||
519 | host->cmd = NULL; | ||
520 | smp_wmb(); | ||
521 | atmci_set_completed(host, EVENT_CMD_COMPLETE); | ||
522 | atmci_command_complete(host, mrq->cmd, host->cmd_status); | ||
523 | |||
524 | if (!mrq->cmd->error && mrq->stop | ||
525 | && atmci_is_completed(host, EVENT_XFER_COMPLETE) | ||
526 | && !atmci_test_and_set_completed(host, | ||
527 | EVENT_STOP_SENT)) | ||
528 | send_stop_cmd(host->mmc, mrq->data); | ||
529 | } | ||
530 | if (atmci_test_and_clear_pending(host, EVENT_STOP_COMPLETE)) { | ||
531 | /* | ||
532 | * host->cmd must be set to NULL before the interrupt | ||
533 | * handler sees EVENT_STOP_COMPLETE | ||
534 | */ | ||
535 | host->cmd = NULL; | ||
536 | smp_wmb(); | ||
537 | atmci_set_completed(host, EVENT_STOP_COMPLETE); | ||
538 | atmci_command_complete(host, mrq->stop, host->stop_status); | ||
539 | } | ||
540 | if (atmci_test_and_clear_pending(host, EVENT_DATA_ERROR)) { | ||
541 | u32 status = host->data_status; | ||
542 | |||
543 | dev_vdbg(&mmc->class_dev, "data error: status=%08x\n", status); | ||
544 | |||
545 | atmci_set_completed(host, EVENT_DATA_ERROR); | ||
546 | atmci_set_completed(host, EVENT_DATA_COMPLETE); | ||
547 | |||
548 | if (status & MCI_DTOE) { | ||
549 | dev_dbg(&mmc->class_dev, | ||
550 | "data timeout error\n"); | ||
551 | data->error = -ETIMEDOUT; | ||
552 | } else if (status & MCI_DCRCE) { | ||
553 | dev_dbg(&mmc->class_dev, "data CRC error\n"); | ||
554 | data->error = -EILSEQ; | ||
555 | } else { | ||
556 | dev_dbg(&mmc->class_dev, | ||
557 | "data FIFO error (status=%08x)\n", | ||
558 | status); | ||
559 | data->error = -EIO; | ||
560 | } | ||
561 | |||
562 | if (host->present && data->stop | ||
563 | && atmci_is_completed(host, EVENT_CMD_COMPLETE) | ||
564 | && !atmci_test_and_set_completed( | ||
565 | host, EVENT_STOP_SENT)) | ||
566 | send_stop_cmd(host->mmc, data); | ||
567 | |||
568 | host->data = NULL; | ||
569 | } | ||
570 | if (atmci_test_and_clear_pending(host, EVENT_DATA_COMPLETE)) { | ||
571 | atmci_set_completed(host, EVENT_DATA_COMPLETE); | ||
572 | |||
573 | if (!atmci_is_completed(host, EVENT_DATA_ERROR)) { | ||
574 | data->bytes_xfered = data->blocks * data->blksz; | ||
575 | data->error = 0; | ||
576 | } | ||
577 | |||
578 | host->data = NULL; | ||
579 | } | ||
580 | |||
581 | if (host->mrq && !host->cmd && !host->data) | ||
582 | atmci_request_end(mmc, host->mrq); | ||
583 | } | ||
584 | |||
585 | static void atmci_read_data_pio(struct atmel_mci *host) | ||
586 | { | ||
587 | struct scatterlist *sg = host->sg; | ||
588 | void *buf = sg_virt(sg); | ||
589 | unsigned int offset = host->pio_offset; | ||
590 | struct mmc_data *data = host->data; | ||
591 | u32 value; | ||
592 | u32 status; | ||
593 | unsigned int nbytes = 0; | ||
594 | |||
595 | do { | ||
596 | value = mci_readl(host, RDR); | ||
597 | if (likely(offset + 4 <= sg->length)) { | ||
598 | put_unaligned(value, (u32 *)(buf + offset)); | ||
599 | |||
600 | offset += 4; | ||
601 | nbytes += 4; | ||
602 | |||
603 | if (offset == sg->length) { | ||
604 | host->sg = sg = sg_next(sg); | ||
605 | if (!sg) | ||
606 | goto done; | ||
607 | |||
608 | offset = 0; | ||
609 | buf = sg_virt(sg); | ||
610 | } | ||
611 | } else { | ||
612 | unsigned int remaining = sg->length - offset; | ||
613 | memcpy(buf + offset, &value, remaining); | ||
614 | nbytes += remaining; | ||
615 | |||
616 | flush_dcache_page(sg_page(sg)); | ||
617 | host->sg = sg = sg_next(sg); | ||
618 | if (!sg) | ||
619 | goto done; | ||
620 | |||
621 | offset = 4 - remaining; | ||
622 | buf = sg_virt(sg); | ||
623 | memcpy(buf, (u8 *)&value + remaining, offset); | ||
624 | nbytes += offset; | ||
625 | } | ||
626 | |||
627 | status = mci_readl(host, SR); | ||
628 | if (status & ATMCI_DATA_ERROR_FLAGS) { | ||
629 | mci_writel(host, IDR, (MCI_NOTBUSY | MCI_RXRDY | ||
630 | | ATMCI_DATA_ERROR_FLAGS)); | ||
631 | host->data_status = status; | ||
632 | atmci_set_pending(host, EVENT_DATA_ERROR); | ||
633 | tasklet_schedule(&host->tasklet); | ||
634 | break; | ||
635 | } | ||
636 | } while (status & MCI_RXRDY); | ||
637 | |||
638 | host->pio_offset = offset; | ||
639 | data->bytes_xfered += nbytes; | ||
640 | |||
641 | return; | ||
642 | |||
643 | done: | ||
644 | mci_writel(host, IDR, MCI_RXRDY); | ||
645 | mci_writel(host, IER, MCI_NOTBUSY); | ||
646 | data->bytes_xfered += nbytes; | ||
647 | atmci_set_completed(host, EVENT_XFER_COMPLETE); | ||
648 | if (data->stop && atmci_is_completed(host, EVENT_CMD_COMPLETE) | ||
649 | && !atmci_test_and_set_completed(host, EVENT_STOP_SENT)) | ||
650 | send_stop_cmd(host->mmc, data); | ||
651 | } | ||
652 | |||
653 | static void atmci_write_data_pio(struct atmel_mci *host) | ||
654 | { | ||
655 | struct scatterlist *sg = host->sg; | ||
656 | void *buf = sg_virt(sg); | ||
657 | unsigned int offset = host->pio_offset; | ||
658 | struct mmc_data *data = host->data; | ||
659 | u32 value; | ||
660 | u32 status; | ||
661 | unsigned int nbytes = 0; | ||
662 | |||
663 | do { | ||
664 | if (likely(offset + 4 <= sg->length)) { | ||
665 | value = get_unaligned((u32 *)(buf + offset)); | ||
666 | mci_writel(host, TDR, value); | ||
667 | |||
668 | offset += 4; | ||
669 | nbytes += 4; | ||
670 | if (offset == sg->length) { | ||
671 | host->sg = sg = sg_next(sg); | ||
672 | if (!sg) | ||
673 | goto done; | ||
674 | |||
675 | offset = 0; | ||
676 | buf = sg_virt(sg); | ||
677 | } | ||
678 | } else { | ||
679 | unsigned int remaining = sg->length - offset; | ||
680 | |||
681 | value = 0; | ||
682 | memcpy(&value, buf + offset, remaining); | ||
683 | nbytes += remaining; | ||
684 | |||
685 | host->sg = sg = sg_next(sg); | ||
686 | if (!sg) { | ||
687 | mci_writel(host, TDR, value); | ||
688 | goto done; | ||
689 | } | ||
690 | |||
691 | offset = 4 - remaining; | ||
692 | buf = sg_virt(sg); | ||
693 | memcpy((u8 *)&value + remaining, buf, offset); | ||
694 | mci_writel(host, TDR, value); | ||
695 | nbytes += offset; | ||
696 | } | ||
697 | |||
698 | status = mci_readl(host, SR); | ||
699 | if (status & ATMCI_DATA_ERROR_FLAGS) { | ||
700 | mci_writel(host, IDR, (MCI_NOTBUSY | MCI_TXRDY | ||
701 | | ATMCI_DATA_ERROR_FLAGS)); | ||
702 | host->data_status = status; | ||
703 | atmci_set_pending(host, EVENT_DATA_ERROR); | ||
704 | tasklet_schedule(&host->tasklet); | ||
705 | break; | ||
706 | } | ||
707 | } while (status & MCI_TXRDY); | ||
708 | |||
709 | host->pio_offset = offset; | ||
710 | data->bytes_xfered += nbytes; | ||
711 | |||
712 | return; | ||
713 | |||
714 | done: | ||
715 | mci_writel(host, IDR, MCI_TXRDY); | ||
716 | mci_writel(host, IER, MCI_NOTBUSY); | ||
717 | data->bytes_xfered += nbytes; | ||
718 | atmci_set_completed(host, EVENT_XFER_COMPLETE); | ||
719 | if (data->stop && atmci_is_completed(host, EVENT_CMD_COMPLETE) | ||
720 | && !atmci_test_and_set_completed(host, EVENT_STOP_SENT)) | ||
721 | send_stop_cmd(host->mmc, data); | ||
722 | } | ||
723 | |||
724 | static void atmci_cmd_interrupt(struct mmc_host *mmc, u32 status) | ||
725 | { | ||
726 | struct atmel_mci *host = mmc_priv(mmc); | ||
727 | |||
728 | mci_writel(host, IDR, MCI_CMDRDY); | ||
729 | |||
730 | if (atmci_is_completed(host, EVENT_STOP_SENT)) { | ||
731 | host->stop_status = status; | ||
732 | atmci_set_pending(host, EVENT_STOP_COMPLETE); | ||
733 | } else { | ||
734 | host->cmd_status = status; | ||
735 | atmci_set_pending(host, EVENT_CMD_COMPLETE); | ||
736 | } | ||
737 | |||
738 | tasklet_schedule(&host->tasklet); | ||
739 | } | ||
740 | |||
741 | static irqreturn_t atmci_interrupt(int irq, void *dev_id) | ||
742 | { | ||
743 | struct mmc_host *mmc = dev_id; | ||
744 | struct atmel_mci *host = mmc_priv(mmc); | ||
745 | u32 status, mask, pending; | ||
746 | unsigned int pass_count = 0; | ||
747 | |||
748 | spin_lock(&mmc->lock); | ||
749 | |||
750 | do { | ||
751 | status = mci_readl(host, SR); | ||
752 | mask = mci_readl(host, IMR); | ||
753 | pending = status & mask; | ||
754 | if (!pending) | ||
755 | break; | ||
756 | |||
757 | if (pending & ATMCI_DATA_ERROR_FLAGS) { | ||
758 | mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS | ||
759 | | MCI_RXRDY | MCI_TXRDY); | ||
760 | pending &= mci_readl(host, IMR); | ||
761 | host->data_status = status; | ||
762 | atmci_set_pending(host, EVENT_DATA_ERROR); | ||
763 | tasklet_schedule(&host->tasklet); | ||
764 | } | ||
765 | if (pending & MCI_NOTBUSY) { | ||
766 | mci_writel(host, IDR, (MCI_NOTBUSY | ||
767 | | ATMCI_DATA_ERROR_FLAGS)); | ||
768 | atmci_set_pending(host, EVENT_DATA_COMPLETE); | ||
769 | tasklet_schedule(&host->tasklet); | ||
770 | } | ||
771 | if (pending & MCI_RXRDY) | ||
772 | atmci_read_data_pio(host); | ||
773 | if (pending & MCI_TXRDY) | ||
774 | atmci_write_data_pio(host); | ||
775 | |||
776 | if (pending & MCI_CMDRDY) | ||
777 | atmci_cmd_interrupt(mmc, status); | ||
778 | } while (pass_count++ < 5); | ||
779 | |||
780 | spin_unlock(&mmc->lock); | ||
781 | |||
782 | return pass_count ? IRQ_HANDLED : IRQ_NONE; | ||
783 | } | ||
784 | |||
785 | static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id) | ||
786 | { | ||
787 | struct mmc_host *mmc = dev_id; | ||
788 | struct atmel_mci *host = mmc_priv(mmc); | ||
789 | |||
790 | /* | ||
791 | * Disable interrupts until the pin has stabilized and check | ||
792 | * the state then. Use mod_timer() since we may be in the | ||
793 | * middle of the timer routine when this interrupt triggers. | ||
794 | */ | ||
795 | disable_irq_nosync(irq); | ||
796 | mod_timer(&host->detect_timer, jiffies + msecs_to_jiffies(20)); | ||
797 | |||
798 | return IRQ_HANDLED; | ||
799 | } | ||
800 | |||
801 | static int __init atmci_probe(struct platform_device *pdev) | ||
802 | { | ||
803 | struct mci_platform_data *pdata; | ||
804 | struct atmel_mci *host; | ||
805 | struct mmc_host *mmc; | ||
806 | struct resource *regs; | ||
807 | int irq; | ||
808 | int ret; | ||
809 | |||
810 | regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
811 | if (!regs) | ||
812 | return -ENXIO; | ||
813 | pdata = pdev->dev.platform_data; | ||
814 | if (!pdata) | ||
815 | return -ENXIO; | ||
816 | irq = platform_get_irq(pdev, 0); | ||
817 | if (irq < 0) | ||
818 | return irq; | ||
819 | |||
820 | mmc = mmc_alloc_host(sizeof(struct atmel_mci), &pdev->dev); | ||
821 | if (!mmc) | ||
822 | return -ENOMEM; | ||
823 | |||
824 | host = mmc_priv(mmc); | ||
825 | host->pdev = pdev; | ||
826 | host->mmc = mmc; | ||
827 | host->detect_pin = pdata->detect_pin; | ||
828 | host->wp_pin = pdata->wp_pin; | ||
829 | |||
830 | host->mck = clk_get(&pdev->dev, "mci_clk"); | ||
831 | if (IS_ERR(host->mck)) { | ||
832 | ret = PTR_ERR(host->mck); | ||
833 | goto err_clk_get; | ||
834 | } | ||
835 | |||
836 | ret = -ENOMEM; | ||
837 | host->regs = ioremap(regs->start, regs->end - regs->start + 1); | ||
838 | if (!host->regs) | ||
839 | goto err_ioremap; | ||
840 | |||
841 | clk_enable(host->mck); | ||
842 | mci_writel(host, CR, MCI_CR_SWRST); | ||
843 | host->bus_hz = clk_get_rate(host->mck); | ||
844 | clk_disable(host->mck); | ||
845 | |||
846 | host->mapbase = regs->start; | ||
847 | |||
848 | mmc->ops = &atmci_ops; | ||
849 | mmc->f_min = (host->bus_hz + 511) / 512; | ||
850 | mmc->f_max = host->bus_hz / 2; | ||
851 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | ||
852 | mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
853 | |||
854 | mmc->max_hw_segs = 64; | ||
855 | mmc->max_phys_segs = 64; | ||
856 | mmc->max_req_size = 32768 * 512; | ||
857 | mmc->max_blk_size = 32768; | ||
858 | mmc->max_blk_count = 512; | ||
859 | |||
860 | tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)mmc); | ||
861 | |||
862 | ret = request_irq(irq, atmci_interrupt, 0, pdev->dev.bus_id, mmc); | ||
863 | if (ret) | ||
864 | goto err_request_irq; | ||
865 | |||
866 | /* Assume card is present if we don't have a detect pin */ | ||
867 | host->present = 1; | ||
868 | if (host->detect_pin >= 0) { | ||
869 | if (gpio_request(host->detect_pin, "mmc_detect")) { | ||
870 | dev_dbg(&mmc->class_dev, "no detect pin available\n"); | ||
871 | host->detect_pin = -1; | ||
872 | } else { | ||
873 | host->present = !gpio_get_value(host->detect_pin); | ||
874 | } | ||
875 | } | ||
876 | if (host->wp_pin >= 0) { | ||
877 | if (gpio_request(host->wp_pin, "mmc_wp")) { | ||
878 | dev_dbg(&mmc->class_dev, "no WP pin available\n"); | ||
879 | host->wp_pin = -1; | ||
880 | } | ||
881 | } | ||
882 | |||
883 | platform_set_drvdata(pdev, host); | ||
884 | |||
885 | mmc_add_host(mmc); | ||
886 | |||
887 | if (host->detect_pin >= 0) { | ||
888 | setup_timer(&host->detect_timer, atmci_detect_change, | ||
889 | (unsigned long)host); | ||
890 | |||
891 | ret = request_irq(gpio_to_irq(host->detect_pin), | ||
892 | atmci_detect_interrupt, | ||
893 | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, | ||
894 | "mmc-detect", mmc); | ||
895 | if (ret) { | ||
896 | dev_dbg(&mmc->class_dev, | ||
897 | "could not request IRQ %d for detect pin\n", | ||
898 | gpio_to_irq(host->detect_pin)); | ||
899 | gpio_free(host->detect_pin); | ||
900 | host->detect_pin = -1; | ||
901 | } | ||
902 | } | ||
903 | |||
904 | dev_info(&mmc->class_dev, | ||
905 | "Atmel MCI controller at 0x%08lx irq %d\n", | ||
906 | host->mapbase, irq); | ||
907 | |||
908 | return 0; | ||
909 | |||
910 | err_request_irq: | ||
911 | iounmap(host->regs); | ||
912 | err_ioremap: | ||
913 | clk_put(host->mck); | ||
914 | err_clk_get: | ||
915 | mmc_free_host(mmc); | ||
916 | return ret; | ||
917 | } | ||
918 | |||
919 | static int __exit atmci_remove(struct platform_device *pdev) | ||
920 | { | ||
921 | struct atmel_mci *host = platform_get_drvdata(pdev); | ||
922 | |||
923 | platform_set_drvdata(pdev, NULL); | ||
924 | |||
925 | if (host) { | ||
926 | if (host->detect_pin >= 0) { | ||
927 | int pin = host->detect_pin; | ||
928 | |||
929 | /* Make sure the timer doesn't enable the interrupt */ | ||
930 | host->detect_pin = -1; | ||
931 | smp_wmb(); | ||
932 | |||
933 | free_irq(gpio_to_irq(pin), host->mmc); | ||
934 | del_timer_sync(&host->detect_timer); | ||
935 | gpio_free(pin); | ||
936 | } | ||
937 | |||
938 | mmc_remove_host(host->mmc); | ||
939 | |||
940 | clk_enable(host->mck); | ||
941 | mci_writel(host, IDR, ~0UL); | ||
942 | mci_writel(host, CR, MCI_CR_MCIDIS); | ||
943 | mci_readl(host, SR); | ||
944 | clk_disable(host->mck); | ||
945 | |||
946 | if (host->wp_pin >= 0) | ||
947 | gpio_free(host->wp_pin); | ||
948 | |||
949 | free_irq(platform_get_irq(pdev, 0), host->mmc); | ||
950 | iounmap(host->regs); | ||
951 | |||
952 | clk_put(host->mck); | ||
953 | |||
954 | mmc_free_host(host->mmc); | ||
955 | } | ||
956 | return 0; | ||
957 | } | ||
958 | |||
959 | static struct platform_driver atmci_driver = { | ||
960 | .remove = __exit_p(atmci_remove), | ||
961 | .driver = { | ||
962 | .name = "atmel_mci", | ||
963 | }, | ||
964 | }; | ||
965 | |||
966 | static int __init atmci_init(void) | ||
967 | { | ||
968 | return platform_driver_probe(&atmci_driver, atmci_probe); | ||
969 | } | ||
970 | |||
971 | static void __exit atmci_exit(void) | ||
972 | { | ||
973 | platform_driver_unregister(&atmci_driver); | ||
974 | } | ||
975 | |||
976 | module_init(atmci_init); | ||
977 | module_exit(atmci_exit); | ||
978 | |||
979 | MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver"); | ||
980 | MODULE_AUTHOR("Haavard Skinnemoen <haavard.skinnemoen@atmel.com>"); | ||
981 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c index cc5f7bc546af..3f15eb204895 100644 --- a/drivers/mmc/host/au1xmmc.c +++ b/drivers/mmc/host/au1xmmc.c | |||
@@ -21,7 +21,7 @@ | |||
21 | * published by the Free Software Foundation. | 21 | * published by the Free Software Foundation. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* Why is a timer used to detect insert events? | 24 | /* Why don't we use the SD controllers' carddetect feature? |
25 | * | 25 | * |
26 | * From the AU1100 MMC application guide: | 26 | * From the AU1100 MMC application guide: |
27 | * If the Au1100-based design is intended to support both MultiMediaCards | 27 | * If the Au1100-based design is intended to support both MultiMediaCards |
@@ -30,8 +30,6 @@ | |||
30 | * In doing so, a MMC card never enters SPI-mode communications, | 30 | * In doing so, a MMC card never enters SPI-mode communications, |
31 | * but now the SecureDigital card-detect feature of CD/DAT3 is ineffective | 31 | * but now the SecureDigital card-detect feature of CD/DAT3 is ineffective |
32 | * (the low to high transition will not occur). | 32 | * (the low to high transition will not occur). |
33 | * | ||
34 | * So we use the timer to check the status manually. | ||
35 | */ | 33 | */ |
36 | 34 | ||
37 | #include <linux/module.h> | 35 | #include <linux/module.h> |
@@ -41,51 +39,110 @@ | |||
41 | #include <linux/interrupt.h> | 39 | #include <linux/interrupt.h> |
42 | #include <linux/dma-mapping.h> | 40 | #include <linux/dma-mapping.h> |
43 | #include <linux/scatterlist.h> | 41 | #include <linux/scatterlist.h> |
44 | 42 | #include <linux/leds.h> | |
45 | #include <linux/mmc/host.h> | 43 | #include <linux/mmc/host.h> |
44 | |||
46 | #include <asm/io.h> | 45 | #include <asm/io.h> |
47 | #include <asm/mach-au1x00/au1000.h> | 46 | #include <asm/mach-au1x00/au1000.h> |
48 | #include <asm/mach-au1x00/au1xxx_dbdma.h> | 47 | #include <asm/mach-au1x00/au1xxx_dbdma.h> |
49 | #include <asm/mach-au1x00/au1100_mmc.h> | 48 | #include <asm/mach-au1x00/au1100_mmc.h> |
50 | 49 | ||
51 | #include <au1xxx.h> | ||
52 | #include "au1xmmc.h" | ||
53 | |||
54 | #define DRIVER_NAME "au1xxx-mmc" | 50 | #define DRIVER_NAME "au1xxx-mmc" |
55 | 51 | ||
56 | /* Set this to enable special debugging macros */ | 52 | /* Set this to enable special debugging macros */ |
53 | /* #define DEBUG */ | ||
57 | 54 | ||
58 | #ifdef DEBUG | 55 | #ifdef DEBUG |
59 | #define DBG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args) | 56 | #define DBG(fmt, idx, args...) \ |
57 | printk(KERN_DEBUG "au1xmmc(%d): DEBUG: " fmt, idx, ##args) | ||
60 | #else | 58 | #else |
61 | #define DBG(fmt, idx, args...) | 59 | #define DBG(fmt, idx, args...) do {} while (0) |
62 | #endif | 60 | #endif |
63 | 61 | ||
64 | const struct { | 62 | /* Hardware definitions */ |
63 | #define AU1XMMC_DESCRIPTOR_COUNT 1 | ||
64 | #define AU1XMMC_DESCRIPTOR_SIZE 2048 | ||
65 | |||
66 | #define AU1XMMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \ | ||
67 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \ | ||
68 | MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36) | ||
69 | |||
70 | /* This gives us a hard value for the stop command that we can write directly | ||
71 | * to the command register. | ||
72 | */ | ||
73 | #define STOP_CMD \ | ||
74 | (SD_CMD_RT_1B | SD_CMD_CT_7 | (0xC << SD_CMD_CI_SHIFT) | SD_CMD_GO) | ||
75 | |||
76 | /* This is the set of interrupts that we configure by default. */ | ||
77 | #define AU1XMMC_INTERRUPTS \ | ||
78 | (SD_CONFIG_SC | SD_CONFIG_DT | SD_CONFIG_RAT | \ | ||
79 | SD_CONFIG_CR | SD_CONFIG_I) | ||
80 | |||
81 | /* The poll event (looking for insert/remove events runs twice a second. */ | ||
82 | #define AU1XMMC_DETECT_TIMEOUT (HZ/2) | ||
83 | |||
84 | struct au1xmmc_host { | ||
85 | struct mmc_host *mmc; | ||
86 | struct mmc_request *mrq; | ||
87 | |||
88 | u32 flags; | ||
65 | u32 iobase; | 89 | u32 iobase; |
66 | u32 tx_devid, rx_devid; | 90 | u32 clock; |
67 | u16 bcsrpwr; | 91 | u32 bus_width; |
68 | u16 bcsrstatus; | 92 | u32 power_mode; |
69 | u16 wpstatus; | ||
70 | } au1xmmc_card_table[] = { | ||
71 | { SD0_BASE, DSCR_CMD0_SDMS_TX0, DSCR_CMD0_SDMS_RX0, | ||
72 | BCSR_BOARD_SD0PWR, BCSR_INT_SD0INSERT, BCSR_STATUS_SD0WP }, | ||
73 | #ifndef CONFIG_MIPS_DB1200 | ||
74 | { SD1_BASE, DSCR_CMD0_SDMS_TX1, DSCR_CMD0_SDMS_RX1, | ||
75 | BCSR_BOARD_DS1PWR, BCSR_INT_SD1INSERT, BCSR_STATUS_SD1WP } | ||
76 | #endif | ||
77 | }; | ||
78 | 93 | ||
79 | #define AU1XMMC_CONTROLLER_COUNT (ARRAY_SIZE(au1xmmc_card_table)) | 94 | int status; |
80 | 95 | ||
81 | /* This array stores pointers for the hosts (used by the IRQ handler) */ | 96 | struct { |
82 | struct au1xmmc_host *au1xmmc_hosts[AU1XMMC_CONTROLLER_COUNT]; | 97 | int len; |
83 | static int dma = 1; | 98 | int dir; |
99 | } dma; | ||
84 | 100 | ||
85 | #ifdef MODULE | 101 | struct { |
86 | module_param(dma, bool, 0); | 102 | int index; |
87 | MODULE_PARM_DESC(dma, "Use DMA engine for data transfers (0 = disabled)"); | 103 | int offset; |
88 | #endif | 104 | int len; |
105 | } pio; | ||
106 | |||
107 | u32 tx_chan; | ||
108 | u32 rx_chan; | ||
109 | |||
110 | int irq; | ||
111 | |||
112 | struct tasklet_struct finish_task; | ||
113 | struct tasklet_struct data_task; | ||
114 | struct au1xmmc_platform_data *platdata; | ||
115 | struct platform_device *pdev; | ||
116 | struct resource *ioarea; | ||
117 | }; | ||
118 | |||
119 | /* Status flags used by the host structure */ | ||
120 | #define HOST_F_XMIT 0x0001 | ||
121 | #define HOST_F_RECV 0x0002 | ||
122 | #define HOST_F_DMA 0x0010 | ||
123 | #define HOST_F_ACTIVE 0x0100 | ||
124 | #define HOST_F_STOP 0x1000 | ||
125 | |||
126 | #define HOST_S_IDLE 0x0001 | ||
127 | #define HOST_S_CMD 0x0002 | ||
128 | #define HOST_S_DATA 0x0003 | ||
129 | #define HOST_S_STOP 0x0004 | ||
130 | |||
131 | /* Easy access macros */ | ||
132 | #define HOST_STATUS(h) ((h)->iobase + SD_STATUS) | ||
133 | #define HOST_CONFIG(h) ((h)->iobase + SD_CONFIG) | ||
134 | #define HOST_ENABLE(h) ((h)->iobase + SD_ENABLE) | ||
135 | #define HOST_TXPORT(h) ((h)->iobase + SD_TXPORT) | ||
136 | #define HOST_RXPORT(h) ((h)->iobase + SD_RXPORT) | ||
137 | #define HOST_CMDARG(h) ((h)->iobase + SD_CMDARG) | ||
138 | #define HOST_BLKSIZE(h) ((h)->iobase + SD_BLKSIZE) | ||
139 | #define HOST_CMD(h) ((h)->iobase + SD_CMD) | ||
140 | #define HOST_CONFIG2(h) ((h)->iobase + SD_CONFIG2) | ||
141 | #define HOST_TIMEOUT(h) ((h)->iobase + SD_TIMEOUT) | ||
142 | #define HOST_DEBUG(h) ((h)->iobase + SD_DEBUG) | ||
143 | |||
144 | #define DMA_CHANNEL(h) \ | ||
145 | (((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan) | ||
89 | 146 | ||
90 | static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask) | 147 | static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask) |
91 | { | 148 | { |
@@ -119,14 +176,13 @@ static inline void IRQ_OFF(struct au1xmmc_host *host, u32 mask) | |||
119 | 176 | ||
120 | static inline void SEND_STOP(struct au1xmmc_host *host) | 177 | static inline void SEND_STOP(struct au1xmmc_host *host) |
121 | { | 178 | { |
122 | 179 | u32 config2; | |
123 | /* We know the value of CONFIG2, so avoid a read we don't need */ | ||
124 | u32 mask = SD_CONFIG2_EN; | ||
125 | 180 | ||
126 | WARN_ON(host->status != HOST_S_DATA); | 181 | WARN_ON(host->status != HOST_S_DATA); |
127 | host->status = HOST_S_STOP; | 182 | host->status = HOST_S_STOP; |
128 | 183 | ||
129 | au_writel(mask | SD_CONFIG2_DF, HOST_CONFIG2(host)); | 184 | config2 = au_readl(HOST_CONFIG2(host)); |
185 | au_writel(config2 | SD_CONFIG2_DF, HOST_CONFIG2(host)); | ||
130 | au_sync(); | 186 | au_sync(); |
131 | 187 | ||
132 | /* Send the stop commmand */ | 188 | /* Send the stop commmand */ |
@@ -135,35 +191,36 @@ static inline void SEND_STOP(struct au1xmmc_host *host) | |||
135 | 191 | ||
136 | static void au1xmmc_set_power(struct au1xmmc_host *host, int state) | 192 | static void au1xmmc_set_power(struct au1xmmc_host *host, int state) |
137 | { | 193 | { |
138 | 194 | if (host->platdata && host->platdata->set_power) | |
139 | u32 val = au1xmmc_card_table[host->id].bcsrpwr; | 195 | host->platdata->set_power(host->mmc, state); |
140 | |||
141 | bcsr->board &= ~val; | ||
142 | if (state) bcsr->board |= val; | ||
143 | |||
144 | au_sync_delay(1); | ||
145 | } | 196 | } |
146 | 197 | ||
147 | static inline int au1xmmc_card_inserted(struct au1xmmc_host *host) | 198 | static int au1xmmc_card_inserted(struct mmc_host *mmc) |
148 | { | 199 | { |
149 | return (bcsr->sig_status & au1xmmc_card_table[host->id].bcsrstatus) | 200 | struct au1xmmc_host *host = mmc_priv(mmc); |
150 | ? 1 : 0; | 201 | |
202 | if (host->platdata && host->platdata->card_inserted) | ||
203 | return !!host->platdata->card_inserted(host->mmc); | ||
204 | |||
205 | return -ENOSYS; | ||
151 | } | 206 | } |
152 | 207 | ||
153 | static int au1xmmc_card_readonly(struct mmc_host *mmc) | 208 | static int au1xmmc_card_readonly(struct mmc_host *mmc) |
154 | { | 209 | { |
155 | struct au1xmmc_host *host = mmc_priv(mmc); | 210 | struct au1xmmc_host *host = mmc_priv(mmc); |
156 | return (bcsr->status & au1xmmc_card_table[host->id].wpstatus) | 211 | |
157 | ? 1 : 0; | 212 | if (host->platdata && host->platdata->card_readonly) |
213 | return !!host->platdata->card_readonly(mmc); | ||
214 | |||
215 | return -ENOSYS; | ||
158 | } | 216 | } |
159 | 217 | ||
160 | static void au1xmmc_finish_request(struct au1xmmc_host *host) | 218 | static void au1xmmc_finish_request(struct au1xmmc_host *host) |
161 | { | 219 | { |
162 | |||
163 | struct mmc_request *mrq = host->mrq; | 220 | struct mmc_request *mrq = host->mrq; |
164 | 221 | ||
165 | host->mrq = NULL; | 222 | host->mrq = NULL; |
166 | host->flags &= HOST_F_ACTIVE; | 223 | host->flags &= HOST_F_ACTIVE | HOST_F_DMA; |
167 | 224 | ||
168 | host->dma.len = 0; | 225 | host->dma.len = 0; |
169 | host->dma.dir = 0; | 226 | host->dma.dir = 0; |
@@ -174,8 +231,6 @@ static void au1xmmc_finish_request(struct au1xmmc_host *host) | |||
174 | 231 | ||
175 | host->status = HOST_S_IDLE; | 232 | host->status = HOST_S_IDLE; |
176 | 233 | ||
177 | bcsr->disk_leds |= (1 << 8); | ||
178 | |||
179 | mmc_request_done(host->mmc, mrq); | 234 | mmc_request_done(host->mmc, mrq); |
180 | } | 235 | } |
181 | 236 | ||
@@ -235,18 +290,14 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait, | |||
235 | au_sync(); | 290 | au_sync(); |
236 | 291 | ||
237 | /* Wait for the command to go on the line */ | 292 | /* Wait for the command to go on the line */ |
238 | 293 | while (au_readl(HOST_CMD(host)) & SD_CMD_GO) | |
239 | while(1) { | 294 | /* nop */; |
240 | if (!(au_readl(HOST_CMD(host)) & SD_CMD_GO)) | ||
241 | break; | ||
242 | } | ||
243 | 295 | ||
244 | /* Wait for the command to come back */ | 296 | /* Wait for the command to come back */ |
245 | |||
246 | if (wait) { | 297 | if (wait) { |
247 | u32 status = au_readl(HOST_STATUS(host)); | 298 | u32 status = au_readl(HOST_STATUS(host)); |
248 | 299 | ||
249 | while(!(status & SD_STATUS_CR)) | 300 | while (!(status & SD_STATUS_CR)) |
250 | status = au_readl(HOST_STATUS(host)); | 301 | status = au_readl(HOST_STATUS(host)); |
251 | 302 | ||
252 | /* Clear the CR status */ | 303 | /* Clear the CR status */ |
@@ -260,12 +311,11 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait, | |||
260 | 311 | ||
261 | static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) | 312 | static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) |
262 | { | 313 | { |
263 | |||
264 | struct mmc_request *mrq = host->mrq; | 314 | struct mmc_request *mrq = host->mrq; |
265 | struct mmc_data *data; | 315 | struct mmc_data *data; |
266 | u32 crc; | 316 | u32 crc; |
267 | 317 | ||
268 | WARN_ON(host->status != HOST_S_DATA && host->status != HOST_S_STOP); | 318 | WARN_ON((host->status != HOST_S_DATA) && (host->status != HOST_S_STOP)); |
269 | 319 | ||
270 | if (host->mrq == NULL) | 320 | if (host->mrq == NULL) |
271 | return; | 321 | return; |
@@ -276,15 +326,13 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) | |||
276 | status = au_readl(HOST_STATUS(host)); | 326 | status = au_readl(HOST_STATUS(host)); |
277 | 327 | ||
278 | /* The transaction is really over when the SD_STATUS_DB bit is clear */ | 328 | /* The transaction is really over when the SD_STATUS_DB bit is clear */ |
279 | 329 | while ((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB)) | |
280 | while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB)) | ||
281 | status = au_readl(HOST_STATUS(host)); | 330 | status = au_readl(HOST_STATUS(host)); |
282 | 331 | ||
283 | data->error = 0; | 332 | data->error = 0; |
284 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir); | 333 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir); |
285 | 334 | ||
286 | /* Process any errors */ | 335 | /* Process any errors */ |
287 | |||
288 | crc = (status & (SD_STATUS_WC | SD_STATUS_RC)); | 336 | crc = (status & (SD_STATUS_WC | SD_STATUS_RC)); |
289 | if (host->flags & HOST_F_XMIT) | 337 | if (host->flags & HOST_F_XMIT) |
290 | crc |= ((status & 0x07) == 0x02) ? 0 : 1; | 338 | crc |= ((status & 0x07) == 0x02) ? 0 : 1; |
@@ -299,16 +347,16 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) | |||
299 | 347 | ||
300 | if (!data->error) { | 348 | if (!data->error) { |
301 | if (host->flags & HOST_F_DMA) { | 349 | if (host->flags & HOST_F_DMA) { |
350 | #ifdef CONFIG_SOC_AU1200 /* DBDMA */ | ||
302 | u32 chan = DMA_CHANNEL(host); | 351 | u32 chan = DMA_CHANNEL(host); |
303 | 352 | ||
304 | chan_tab_t *c = *((chan_tab_t **) chan); | 353 | chan_tab_t *c = *((chan_tab_t **)chan); |
305 | au1x_dma_chan_t *cp = c->chan_ptr; | 354 | au1x_dma_chan_t *cp = c->chan_ptr; |
306 | data->bytes_xfered = cp->ddma_bytecnt; | 355 | data->bytes_xfered = cp->ddma_bytecnt; |
307 | } | 356 | #endif |
308 | else | 357 | } else |
309 | data->bytes_xfered = | 358 | data->bytes_xfered = |
310 | (data->blocks * data->blksz) - | 359 | (data->blocks * data->blksz) - host->pio.len; |
311 | host->pio.len; | ||
312 | } | 360 | } |
313 | 361 | ||
314 | au1xmmc_finish_request(host); | 362 | au1xmmc_finish_request(host); |
@@ -316,7 +364,7 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) | |||
316 | 364 | ||
317 | static void au1xmmc_tasklet_data(unsigned long param) | 365 | static void au1xmmc_tasklet_data(unsigned long param) |
318 | { | 366 | { |
319 | struct au1xmmc_host *host = (struct au1xmmc_host *) param; | 367 | struct au1xmmc_host *host = (struct au1xmmc_host *)param; |
320 | 368 | ||
321 | u32 status = au_readl(HOST_STATUS(host)); | 369 | u32 status = au_readl(HOST_STATUS(host)); |
322 | au1xmmc_data_complete(host, status); | 370 | au1xmmc_data_complete(host, status); |
@@ -326,11 +374,10 @@ static void au1xmmc_tasklet_data(unsigned long param) | |||
326 | 374 | ||
327 | static void au1xmmc_send_pio(struct au1xmmc_host *host) | 375 | static void au1xmmc_send_pio(struct au1xmmc_host *host) |
328 | { | 376 | { |
329 | 377 | struct mmc_data *data; | |
330 | struct mmc_data *data = 0; | 378 | int sg_len, max, count; |
331 | int sg_len, max, count = 0; | 379 | unsigned char *sg_ptr, val; |
332 | unsigned char *sg_ptr; | 380 | u32 status; |
333 | u32 status = 0; | ||
334 | struct scatterlist *sg; | 381 | struct scatterlist *sg; |
335 | 382 | ||
336 | data = host->mrq->data; | 383 | data = host->mrq->data; |
@@ -345,14 +392,12 @@ static void au1xmmc_send_pio(struct au1xmmc_host *host) | |||
345 | /* This is the space left inside the buffer */ | 392 | /* This is the space left inside the buffer */ |
346 | sg_len = data->sg[host->pio.index].length - host->pio.offset; | 393 | sg_len = data->sg[host->pio.index].length - host->pio.offset; |
347 | 394 | ||
348 | /* Check to if we need less then the size of the sg_buffer */ | 395 | /* Check if we need less than the size of the sg_buffer */ |
349 | |||
350 | max = (sg_len > host->pio.len) ? host->pio.len : sg_len; | 396 | max = (sg_len > host->pio.len) ? host->pio.len : sg_len; |
351 | if (max > AU1XMMC_MAX_TRANSFER) max = AU1XMMC_MAX_TRANSFER; | 397 | if (max > AU1XMMC_MAX_TRANSFER) |
352 | 398 | max = AU1XMMC_MAX_TRANSFER; | |
353 | for(count = 0; count < max; count++ ) { | ||
354 | unsigned char val; | ||
355 | 399 | ||
400 | for (count = 0; count < max; count++) { | ||
356 | status = au_readl(HOST_STATUS(host)); | 401 | status = au_readl(HOST_STATUS(host)); |
357 | 402 | ||
358 | if (!(status & SD_STATUS_TH)) | 403 | if (!(status & SD_STATUS_TH)) |
@@ -360,7 +405,7 @@ static void au1xmmc_send_pio(struct au1xmmc_host *host) | |||
360 | 405 | ||
361 | val = *sg_ptr++; | 406 | val = *sg_ptr++; |
362 | 407 | ||
363 | au_writel((unsigned long) val, HOST_TXPORT(host)); | 408 | au_writel((unsigned long)val, HOST_TXPORT(host)); |
364 | au_sync(); | 409 | au_sync(); |
365 | } | 410 | } |
366 | 411 | ||
@@ -384,11 +429,10 @@ static void au1xmmc_send_pio(struct au1xmmc_host *host) | |||
384 | 429 | ||
385 | static void au1xmmc_receive_pio(struct au1xmmc_host *host) | 430 | static void au1xmmc_receive_pio(struct au1xmmc_host *host) |
386 | { | 431 | { |
387 | 432 | struct mmc_data *data; | |
388 | struct mmc_data *data = 0; | 433 | int max, count, sg_len = 0; |
389 | int sg_len = 0, max = 0, count = 0; | 434 | unsigned char *sg_ptr = NULL; |
390 | unsigned char *sg_ptr = 0; | 435 | u32 status, val; |
391 | u32 status = 0; | ||
392 | struct scatterlist *sg; | 436 | struct scatterlist *sg; |
393 | 437 | ||
394 | data = host->mrq->data; | 438 | data = host->mrq->data; |
@@ -405,33 +449,33 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host) | |||
405 | /* This is the space left inside the buffer */ | 449 | /* This is the space left inside the buffer */ |
406 | sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset; | 450 | sg_len = sg_dma_len(&data->sg[host->pio.index]) - host->pio.offset; |
407 | 451 | ||
408 | /* Check to if we need less then the size of the sg_buffer */ | 452 | /* Check if we need less than the size of the sg_buffer */ |
409 | if (sg_len < max) max = sg_len; | 453 | if (sg_len < max) |
454 | max = sg_len; | ||
410 | } | 455 | } |
411 | 456 | ||
412 | if (max > AU1XMMC_MAX_TRANSFER) | 457 | if (max > AU1XMMC_MAX_TRANSFER) |
413 | max = AU1XMMC_MAX_TRANSFER; | 458 | max = AU1XMMC_MAX_TRANSFER; |
414 | 459 | ||
415 | for(count = 0; count < max; count++ ) { | 460 | for (count = 0; count < max; count++) { |
416 | u32 val; | ||
417 | status = au_readl(HOST_STATUS(host)); | 461 | status = au_readl(HOST_STATUS(host)); |
418 | 462 | ||
419 | if (!(status & SD_STATUS_NE)) | 463 | if (!(status & SD_STATUS_NE)) |
420 | break; | 464 | break; |
421 | 465 | ||
422 | if (status & SD_STATUS_RC) { | 466 | if (status & SD_STATUS_RC) { |
423 | DBG("RX CRC Error [%d + %d].\n", host->id, | 467 | DBG("RX CRC Error [%d + %d].\n", host->pdev->id, |
424 | host->pio.len, count); | 468 | host->pio.len, count); |
425 | break; | 469 | break; |
426 | } | 470 | } |
427 | 471 | ||
428 | if (status & SD_STATUS_RO) { | 472 | if (status & SD_STATUS_RO) { |
429 | DBG("RX Overrun [%d + %d]\n", host->id, | 473 | DBG("RX Overrun [%d + %d]\n", host->pdev->id, |
430 | host->pio.len, count); | 474 | host->pio.len, count); |
431 | break; | 475 | break; |
432 | } | 476 | } |
433 | else if (status & SD_STATUS_RU) { | 477 | else if (status & SD_STATUS_RU) { |
434 | DBG("RX Underrun [%d + %d]\n", host->id, | 478 | DBG("RX Underrun [%d + %d]\n", host->pdev->id, |
435 | host->pio.len, count); | 479 | host->pio.len, count); |
436 | break; | 480 | break; |
437 | } | 481 | } |
@@ -439,7 +483,7 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host) | |||
439 | val = au_readl(HOST_RXPORT(host)); | 483 | val = au_readl(HOST_RXPORT(host)); |
440 | 484 | ||
441 | if (sg_ptr) | 485 | if (sg_ptr) |
442 | *sg_ptr++ = (unsigned char) (val & 0xFF); | 486 | *sg_ptr++ = (unsigned char)(val & 0xFF); |
443 | } | 487 | } |
444 | 488 | ||
445 | host->pio.len -= count; | 489 | host->pio.len -= count; |
@@ -451,7 +495,7 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host) | |||
451 | } | 495 | } |
452 | 496 | ||
453 | if (host->pio.len == 0) { | 497 | if (host->pio.len == 0) { |
454 | //IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF); | 498 | /* IRQ_OFF(host, SD_CONFIG_RA | SD_CONFIG_RF); */ |
455 | IRQ_OFF(host, SD_CONFIG_NE); | 499 | IRQ_OFF(host, SD_CONFIG_NE); |
456 | 500 | ||
457 | if (host->flags & HOST_F_STOP) | 501 | if (host->flags & HOST_F_STOP) |
@@ -461,17 +505,15 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host) | |||
461 | } | 505 | } |
462 | } | 506 | } |
463 | 507 | ||
464 | /* static void au1xmmc_cmd_complete | 508 | /* This is called when a command has been completed - grab the response |
465 | This is called when a command has been completed - grab the response | 509 | * and check for errors. Then start the data transfer if it is indicated. |
466 | and check for errors. Then start the data transfer if it is indicated. | 510 | */ |
467 | */ | ||
468 | |||
469 | static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) | 511 | static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) |
470 | { | 512 | { |
471 | |||
472 | struct mmc_request *mrq = host->mrq; | 513 | struct mmc_request *mrq = host->mrq; |
473 | struct mmc_command *cmd; | 514 | struct mmc_command *cmd; |
474 | int trans; | 515 | u32 r[4]; |
516 | int i, trans; | ||
475 | 517 | ||
476 | if (!host->mrq) | 518 | if (!host->mrq) |
477 | return; | 519 | return; |
@@ -481,9 +523,6 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) | |||
481 | 523 | ||
482 | if (cmd->flags & MMC_RSP_PRESENT) { | 524 | if (cmd->flags & MMC_RSP_PRESENT) { |
483 | if (cmd->flags & MMC_RSP_136) { | 525 | if (cmd->flags & MMC_RSP_136) { |
484 | u32 r[4]; | ||
485 | int i; | ||
486 | |||
487 | r[0] = au_readl(host->iobase + SD_RESP3); | 526 | r[0] = au_readl(host->iobase + SD_RESP3); |
488 | r[1] = au_readl(host->iobase + SD_RESP2); | 527 | r[1] = au_readl(host->iobase + SD_RESP2); |
489 | r[2] = au_readl(host->iobase + SD_RESP1); | 528 | r[2] = au_readl(host->iobase + SD_RESP1); |
@@ -491,10 +530,9 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) | |||
491 | 530 | ||
492 | /* The CRC is omitted from the response, so really | 531 | /* The CRC is omitted from the response, so really |
493 | * we only got 120 bytes, but the engine expects | 532 | * we only got 120 bytes, but the engine expects |
494 | * 128 bits, so we have to shift things up | 533 | * 128 bits, so we have to shift things up. |
495 | */ | 534 | */ |
496 | 535 | for (i = 0; i < 4; i++) { | |
497 | for(i = 0; i < 4; i++) { | ||
498 | cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8; | 536 | cmd->resp[i] = (r[i] & 0x00FFFFFF) << 8; |
499 | if (i != 3) | 537 | if (i != 3) |
500 | cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24; | 538 | cmd->resp[i] |= (r[i + 1] & 0xFF000000) >> 24; |
@@ -505,22 +543,20 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) | |||
505 | * our response omits the CRC, our data ends up | 543 | * our response omits the CRC, our data ends up |
506 | * being shifted 8 bits to the right. In this case, | 544 | * being shifted 8 bits to the right. In this case, |
507 | * that means that the OSR data starts at bit 31, | 545 | * that means that the OSR data starts at bit 31, |
508 | * so we can just read RESP0 and return that | 546 | * so we can just read RESP0 and return that. |
509 | */ | 547 | */ |
510 | cmd->resp[0] = au_readl(host->iobase + SD_RESP0); | 548 | cmd->resp[0] = au_readl(host->iobase + SD_RESP0); |
511 | } | 549 | } |
512 | } | 550 | } |
513 | 551 | ||
514 | /* Figure out errors */ | 552 | /* Figure out errors */ |
515 | |||
516 | if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC)) | 553 | if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC)) |
517 | cmd->error = -EILSEQ; | 554 | cmd->error = -EILSEQ; |
518 | 555 | ||
519 | trans = host->flags & (HOST_F_XMIT | HOST_F_RECV); | 556 | trans = host->flags & (HOST_F_XMIT | HOST_F_RECV); |
520 | 557 | ||
521 | if (!trans || cmd->error) { | 558 | if (!trans || cmd->error) { |
522 | 559 | IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA | SD_CONFIG_RF); | |
523 | IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF); | ||
524 | tasklet_schedule(&host->finish_task); | 560 | tasklet_schedule(&host->finish_task); |
525 | return; | 561 | return; |
526 | } | 562 | } |
@@ -528,6 +564,7 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) | |||
528 | host->status = HOST_S_DATA; | 564 | host->status = HOST_S_DATA; |
529 | 565 | ||
530 | if (host->flags & HOST_F_DMA) { | 566 | if (host->flags & HOST_F_DMA) { |
567 | #ifdef CONFIG_SOC_AU1200 /* DBDMA */ | ||
531 | u32 channel = DMA_CHANNEL(host); | 568 | u32 channel = DMA_CHANNEL(host); |
532 | 569 | ||
533 | /* Start the DMA as soon as the buffer gets something in it */ | 570 | /* Start the DMA as soon as the buffer gets something in it */ |
@@ -540,23 +577,21 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status) | |||
540 | } | 577 | } |
541 | 578 | ||
542 | au1xxx_dbdma_start(channel); | 579 | au1xxx_dbdma_start(channel); |
580 | #endif | ||
543 | } | 581 | } |
544 | } | 582 | } |
545 | 583 | ||
546 | static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate) | 584 | static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate) |
547 | { | 585 | { |
548 | |||
549 | unsigned int pbus = get_au1x00_speed(); | 586 | unsigned int pbus = get_au1x00_speed(); |
550 | unsigned int divisor; | 587 | unsigned int divisor; |
551 | u32 config; | 588 | u32 config; |
552 | 589 | ||
553 | /* From databook: | 590 | /* From databook: |
554 | divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1 | 591 | * divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1 |
555 | */ | 592 | */ |
556 | |||
557 | pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2); | 593 | pbus /= ((au_readl(SYS_POWERCTRL) & 0x3) + 2); |
558 | pbus /= 2; | 594 | pbus /= 2; |
559 | |||
560 | divisor = ((pbus / rate) / 2) - 1; | 595 | divisor = ((pbus / rate) / 2) - 1; |
561 | 596 | ||
562 | config = au_readl(HOST_CONFIG(host)); | 597 | config = au_readl(HOST_CONFIG(host)); |
@@ -568,15 +603,11 @@ static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate) | |||
568 | au_sync(); | 603 | au_sync(); |
569 | } | 604 | } |
570 | 605 | ||
571 | static int | 606 | static int au1xmmc_prepare_data(struct au1xmmc_host *host, |
572 | au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data) | 607 | struct mmc_data *data) |
573 | { | 608 | { |
574 | |||
575 | int datalen = data->blocks * data->blksz; | 609 | int datalen = data->blocks * data->blksz; |
576 | 610 | ||
577 | if (dma != 0) | ||
578 | host->flags |= HOST_F_DMA; | ||
579 | |||
580 | if (data->flags & MMC_DATA_READ) | 611 | if (data->flags & MMC_DATA_READ) |
581 | host->flags |= HOST_F_RECV; | 612 | host->flags |= HOST_F_RECV; |
582 | else | 613 | else |
@@ -596,12 +627,13 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data) | |||
596 | au_writel(data->blksz - 1, HOST_BLKSIZE(host)); | 627 | au_writel(data->blksz - 1, HOST_BLKSIZE(host)); |
597 | 628 | ||
598 | if (host->flags & HOST_F_DMA) { | 629 | if (host->flags & HOST_F_DMA) { |
630 | #ifdef CONFIG_SOC_AU1200 /* DBDMA */ | ||
599 | int i; | 631 | int i; |
600 | u32 channel = DMA_CHANNEL(host); | 632 | u32 channel = DMA_CHANNEL(host); |
601 | 633 | ||
602 | au1xxx_dbdma_stop(channel); | 634 | au1xxx_dbdma_stop(channel); |
603 | 635 | ||
604 | for(i = 0; i < host->dma.len; i++) { | 636 | for (i = 0; i < host->dma.len; i++) { |
605 | u32 ret = 0, flags = DDMA_FLAGS_NOIE; | 637 | u32 ret = 0, flags = DDMA_FLAGS_NOIE; |
606 | struct scatterlist *sg = &data->sg[i]; | 638 | struct scatterlist *sg = &data->sg[i]; |
607 | int sg_len = sg->length; | 639 | int sg_len = sg->length; |
@@ -611,23 +643,21 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data) | |||
611 | if (i == host->dma.len - 1) | 643 | if (i == host->dma.len - 1) |
612 | flags = DDMA_FLAGS_IE; | 644 | flags = DDMA_FLAGS_IE; |
613 | 645 | ||
614 | if (host->flags & HOST_F_XMIT){ | 646 | if (host->flags & HOST_F_XMIT) { |
615 | ret = au1xxx_dbdma_put_source_flags(channel, | 647 | ret = au1xxx_dbdma_put_source_flags(channel, |
616 | (void *) sg_virt(sg), len, flags); | 648 | (void *)sg_virt(sg), len, flags); |
617 | } | 649 | } else { |
618 | else { | 650 | ret = au1xxx_dbdma_put_dest_flags(channel, |
619 | ret = au1xxx_dbdma_put_dest_flags(channel, | 651 | (void *)sg_virt(sg), len, flags); |
620 | (void *) sg_virt(sg), | ||
621 | len, flags); | ||
622 | } | 652 | } |
623 | 653 | ||
624 | if (!ret) | 654 | if (!ret) |
625 | goto dataerr; | 655 | goto dataerr; |
626 | 656 | ||
627 | datalen -= len; | 657 | datalen -= len; |
628 | } | 658 | } |
629 | } | 659 | #endif |
630 | else { | 660 | } else { |
631 | host->pio.index = 0; | 661 | host->pio.index = 0; |
632 | host->pio.offset = 0; | 662 | host->pio.offset = 0; |
633 | host->pio.len = datalen; | 663 | host->pio.len = datalen; |
@@ -636,25 +666,21 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data) | |||
636 | IRQ_ON(host, SD_CONFIG_TH); | 666 | IRQ_ON(host, SD_CONFIG_TH); |
637 | else | 667 | else |
638 | IRQ_ON(host, SD_CONFIG_NE); | 668 | IRQ_ON(host, SD_CONFIG_NE); |
639 | //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF); | 669 | /* IRQ_ON(host, SD_CONFIG_RA | SD_CONFIG_RF); */ |
640 | } | 670 | } |
641 | 671 | ||
642 | return 0; | 672 | return 0; |
643 | 673 | ||
644 | dataerr: | 674 | dataerr: |
645 | dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir); | 675 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, |
676 | host->dma.dir); | ||
646 | return -ETIMEDOUT; | 677 | return -ETIMEDOUT; |
647 | } | 678 | } |
648 | 679 | ||
649 | /* static void au1xmmc_request | 680 | /* This actually starts a command or data transaction */ |
650 | This actually starts a command or data transaction | ||
651 | */ | ||
652 | |||
653 | static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq) | 681 | static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq) |
654 | { | 682 | { |
655 | |||
656 | struct au1xmmc_host *host = mmc_priv(mmc); | 683 | struct au1xmmc_host *host = mmc_priv(mmc); |
657 | unsigned int flags = 0; | ||
658 | int ret = 0; | 684 | int ret = 0; |
659 | 685 | ||
660 | WARN_ON(irqs_disabled()); | 686 | WARN_ON(irqs_disabled()); |
@@ -663,11 +689,15 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq) | |||
663 | host->mrq = mrq; | 689 | host->mrq = mrq; |
664 | host->status = HOST_S_CMD; | 690 | host->status = HOST_S_CMD; |
665 | 691 | ||
666 | bcsr->disk_leds &= ~(1 << 8); | 692 | /* fail request immediately if no card is present */ |
693 | if (0 == au1xmmc_card_inserted(mmc)) { | ||
694 | mrq->cmd->error = -ENOMEDIUM; | ||
695 | au1xmmc_finish_request(host); | ||
696 | return; | ||
697 | } | ||
667 | 698 | ||
668 | if (mrq->data) { | 699 | if (mrq->data) { |
669 | FLUSH_FIFO(host); | 700 | FLUSH_FIFO(host); |
670 | flags = mrq->data->flags; | ||
671 | ret = au1xmmc_prepare_data(host, mrq->data); | 701 | ret = au1xmmc_prepare_data(host, mrq->data); |
672 | } | 702 | } |
673 | 703 | ||
@@ -682,7 +712,6 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq) | |||
682 | 712 | ||
683 | static void au1xmmc_reset_controller(struct au1xmmc_host *host) | 713 | static void au1xmmc_reset_controller(struct au1xmmc_host *host) |
684 | { | 714 | { |
685 | |||
686 | /* Apply the clock */ | 715 | /* Apply the clock */ |
687 | au_writel(SD_ENABLE_CE, HOST_ENABLE(host)); | 716 | au_writel(SD_ENABLE_CE, HOST_ENABLE(host)); |
688 | au_sync_delay(1); | 717 | au_sync_delay(1); |
@@ -712,9 +741,10 @@ static void au1xmmc_reset_controller(struct au1xmmc_host *host) | |||
712 | } | 741 | } |
713 | 742 | ||
714 | 743 | ||
715 | static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios) | 744 | static void au1xmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
716 | { | 745 | { |
717 | struct au1xmmc_host *host = mmc_priv(mmc); | 746 | struct au1xmmc_host *host = mmc_priv(mmc); |
747 | u32 config2; | ||
718 | 748 | ||
719 | if (ios->power_mode == MMC_POWER_OFF) | 749 | if (ios->power_mode == MMC_POWER_OFF) |
720 | au1xmmc_set_power(host, 0); | 750 | au1xmmc_set_power(host, 0); |
@@ -726,21 +756,18 @@ static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios) | |||
726 | au1xmmc_set_clock(host, ios->clock); | 756 | au1xmmc_set_clock(host, ios->clock); |
727 | host->clock = ios->clock; | 757 | host->clock = ios->clock; |
728 | } | 758 | } |
729 | } | ||
730 | |||
731 | static void au1xmmc_dma_callback(int irq, void *dev_id) | ||
732 | { | ||
733 | struct au1xmmc_host *host = (struct au1xmmc_host *) dev_id; | ||
734 | |||
735 | /* Avoid spurious interrupts */ | ||
736 | 759 | ||
737 | if (!host->mrq) | 760 | config2 = au_readl(HOST_CONFIG2(host)); |
738 | return; | 761 | switch (ios->bus_width) { |
739 | 762 | case MMC_BUS_WIDTH_4: | |
740 | if (host->flags & HOST_F_STOP) | 763 | config2 |= SD_CONFIG2_WB; |
741 | SEND_STOP(host); | 764 | break; |
742 | 765 | case MMC_BUS_WIDTH_1: | |
743 | tasklet_schedule(&host->data_task); | 766 | config2 &= ~SD_CONFIG2_WB; |
767 | break; | ||
768 | } | ||
769 | au_writel(config2, HOST_CONFIG2(host)); | ||
770 | au_sync(); | ||
744 | } | 771 | } |
745 | 772 | ||
746 | #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT) | 773 | #define STATUS_TIMEOUT (SD_STATUS_RAT | SD_STATUS_DT) |
@@ -749,245 +776,354 @@ static void au1xmmc_dma_callback(int irq, void *dev_id) | |||
749 | 776 | ||
750 | static irqreturn_t au1xmmc_irq(int irq, void *dev_id) | 777 | static irqreturn_t au1xmmc_irq(int irq, void *dev_id) |
751 | { | 778 | { |
752 | 779 | struct au1xmmc_host *host = dev_id; | |
753 | u32 status; | 780 | u32 status; |
754 | int i, ret = 0; | ||
755 | |||
756 | disable_irq(AU1100_SD_IRQ); | ||
757 | 781 | ||
758 | for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) { | 782 | status = au_readl(HOST_STATUS(host)); |
759 | struct au1xmmc_host * host = au1xmmc_hosts[i]; | ||
760 | u32 handled = 1; | ||
761 | 783 | ||
762 | status = au_readl(HOST_STATUS(host)); | 784 | if (!(status & SD_STATUS_I)) |
785 | return IRQ_NONE; /* not ours */ | ||
763 | 786 | ||
764 | if (host->mrq && (status & STATUS_TIMEOUT)) { | 787 | if (status & SD_STATUS_SI) /* SDIO */ |
765 | if (status & SD_STATUS_RAT) | 788 | mmc_signal_sdio_irq(host->mmc); |
766 | host->mrq->cmd->error = -ETIMEDOUT; | ||
767 | 789 | ||
768 | else if (status & SD_STATUS_DT) | 790 | if (host->mrq && (status & STATUS_TIMEOUT)) { |
769 | host->mrq->data->error = -ETIMEDOUT; | 791 | if (status & SD_STATUS_RAT) |
792 | host->mrq->cmd->error = -ETIMEDOUT; | ||
793 | else if (status & SD_STATUS_DT) | ||
794 | host->mrq->data->error = -ETIMEDOUT; | ||
770 | 795 | ||
771 | /* In PIO mode, interrupts might still be enabled */ | 796 | /* In PIO mode, interrupts might still be enabled */ |
772 | IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH); | 797 | IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH); |
773 | 798 | ||
774 | //IRQ_OFF(host, SD_CONFIG_TH|SD_CONFIG_RA|SD_CONFIG_RF); | 799 | /* IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA | SD_CONFIG_RF); */ |
775 | tasklet_schedule(&host->finish_task); | 800 | tasklet_schedule(&host->finish_task); |
776 | } | 801 | } |
777 | #if 0 | 802 | #if 0 |
778 | else if (status & SD_STATUS_DD) { | 803 | else if (status & SD_STATUS_DD) { |
779 | 804 | /* Sometimes we get a DD before a NE in PIO mode */ | |
780 | /* Sometimes we get a DD before a NE in PIO mode */ | 805 | if (!(host->flags & HOST_F_DMA) && (status & SD_STATUS_NE)) |
781 | 806 | au1xmmc_receive_pio(host); | |
782 | if (!(host->flags & HOST_F_DMA) && | 807 | else { |
783 | (status & SD_STATUS_NE)) | 808 | au1xmmc_data_complete(host, status); |
784 | au1xmmc_receive_pio(host); | 809 | /* tasklet_schedule(&host->data_task); */ |
785 | else { | ||
786 | au1xmmc_data_complete(host, status); | ||
787 | //tasklet_schedule(&host->data_task); | ||
788 | } | ||
789 | } | 810 | } |
811 | } | ||
790 | #endif | 812 | #endif |
791 | else if (status & (SD_STATUS_CR)) { | 813 | else if (status & SD_STATUS_CR) { |
792 | if (host->status == HOST_S_CMD) | 814 | if (host->status == HOST_S_CMD) |
793 | au1xmmc_cmd_complete(host,status); | 815 | au1xmmc_cmd_complete(host, status); |
794 | } | 816 | |
795 | else if (!(host->flags & HOST_F_DMA)) { | 817 | } else if (!(host->flags & HOST_F_DMA)) { |
796 | if ((host->flags & HOST_F_XMIT) && | 818 | if ((host->flags & HOST_F_XMIT) && (status & STATUS_DATA_OUT)) |
797 | (status & STATUS_DATA_OUT)) | 819 | au1xmmc_send_pio(host); |
798 | au1xmmc_send_pio(host); | 820 | else if ((host->flags & HOST_F_RECV) && (status & STATUS_DATA_IN)) |
799 | else if ((host->flags & HOST_F_RECV) && | 821 | au1xmmc_receive_pio(host); |
800 | (status & STATUS_DATA_IN)) | 822 | |
801 | au1xmmc_receive_pio(host); | 823 | } else if (status & 0x203F3C70) { |
802 | } | 824 | DBG("Unhandled status %8.8x\n", host->pdev->id, |
803 | else if (status & 0x203FBC70) { | 825 | status); |
804 | DBG("Unhandled status %8.8x\n", host->id, status); | ||
805 | handled = 0; | ||
806 | } | ||
807 | |||
808 | au_writel(status, HOST_STATUS(host)); | ||
809 | au_sync(); | ||
810 | |||
811 | ret |= handled; | ||
812 | } | 826 | } |
813 | 827 | ||
814 | enable_irq(AU1100_SD_IRQ); | 828 | au_writel(status, HOST_STATUS(host)); |
815 | return ret; | 829 | au_sync(); |
830 | |||
831 | return IRQ_HANDLED; | ||
816 | } | 832 | } |
817 | 833 | ||
818 | static void au1xmmc_poll_event(unsigned long arg) | 834 | #ifdef CONFIG_SOC_AU1200 |
819 | { | 835 | /* 8bit memory DMA device */ |
820 | struct au1xmmc_host *host = (struct au1xmmc_host *) arg; | 836 | static dbdev_tab_t au1xmmc_mem_dbdev = { |
837 | .dev_id = DSCR_CMD0_ALWAYS, | ||
838 | .dev_flags = DEV_FLAGS_ANYUSE, | ||
839 | .dev_tsize = 0, | ||
840 | .dev_devwidth = 8, | ||
841 | .dev_physaddr = 0x00000000, | ||
842 | .dev_intlevel = 0, | ||
843 | .dev_intpolarity = 0, | ||
844 | }; | ||
845 | static int memid; | ||
821 | 846 | ||
822 | int card = au1xmmc_card_inserted(host); | 847 | static void au1xmmc_dbdma_callback(int irq, void *dev_id) |
823 | int controller = (host->flags & HOST_F_ACTIVE) ? 1 : 0; | 848 | { |
849 | struct au1xmmc_host *host = (struct au1xmmc_host *)dev_id; | ||
824 | 850 | ||
825 | if (card != controller) { | 851 | /* Avoid spurious interrupts */ |
826 | host->flags &= ~HOST_F_ACTIVE; | 852 | if (!host->mrq) |
827 | if (card) host->flags |= HOST_F_ACTIVE; | 853 | return; |
828 | mmc_detect_change(host->mmc, 0); | ||
829 | } | ||
830 | 854 | ||
831 | if (host->mrq != NULL) { | 855 | if (host->flags & HOST_F_STOP) |
832 | u32 status = au_readl(HOST_STATUS(host)); | 856 | SEND_STOP(host); |
833 | DBG("PENDING - %8.8x\n", host->id, status); | ||
834 | } | ||
835 | 857 | ||
836 | mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT); | 858 | tasklet_schedule(&host->data_task); |
837 | } | 859 | } |
838 | 860 | ||
839 | static dbdev_tab_t au1xmmc_mem_dbdev = | 861 | static int au1xmmc_dbdma_init(struct au1xmmc_host *host) |
840 | { | ||
841 | DSCR_CMD0_ALWAYS, DEV_FLAGS_ANYUSE, 0, 8, 0x00000000, 0, 0 | ||
842 | }; | ||
843 | |||
844 | static void au1xmmc_init_dma(struct au1xmmc_host *host) | ||
845 | { | 862 | { |
863 | struct resource *res; | ||
864 | int txid, rxid; | ||
865 | |||
866 | res = platform_get_resource(host->pdev, IORESOURCE_DMA, 0); | ||
867 | if (!res) | ||
868 | return -ENODEV; | ||
869 | txid = res->start; | ||
870 | |||
871 | res = platform_get_resource(host->pdev, IORESOURCE_DMA, 1); | ||
872 | if (!res) | ||
873 | return -ENODEV; | ||
874 | rxid = res->start; | ||
875 | |||
876 | if (!memid) | ||
877 | return -ENODEV; | ||
878 | |||
879 | host->tx_chan = au1xxx_dbdma_chan_alloc(memid, txid, | ||
880 | au1xmmc_dbdma_callback, (void *)host); | ||
881 | if (!host->tx_chan) { | ||
882 | dev_err(&host->pdev->dev, "cannot allocate TX DMA\n"); | ||
883 | return -ENODEV; | ||
884 | } | ||
846 | 885 | ||
847 | u32 rxchan, txchan; | 886 | host->rx_chan = au1xxx_dbdma_chan_alloc(rxid, memid, |
848 | 887 | au1xmmc_dbdma_callback, (void *)host); | |
849 | int txid = au1xmmc_card_table[host->id].tx_devid; | 888 | if (!host->rx_chan) { |
850 | int rxid = au1xmmc_card_table[host->id].rx_devid; | 889 | dev_err(&host->pdev->dev, "cannot allocate RX DMA\n"); |
890 | au1xxx_dbdma_chan_free(host->tx_chan); | ||
891 | return -ENODEV; | ||
892 | } | ||
851 | 893 | ||
852 | /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride | 894 | au1xxx_dbdma_set_devwidth(host->tx_chan, 8); |
853 | of 8 bits. And since devices are shared, we need to create | 895 | au1xxx_dbdma_set_devwidth(host->rx_chan, 8); |
854 | our own to avoid freaking out other devices | ||
855 | */ | ||
856 | 896 | ||
857 | int memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev); | 897 | au1xxx_dbdma_ring_alloc(host->tx_chan, AU1XMMC_DESCRIPTOR_COUNT); |
898 | au1xxx_dbdma_ring_alloc(host->rx_chan, AU1XMMC_DESCRIPTOR_COUNT); | ||
858 | 899 | ||
859 | txchan = au1xxx_dbdma_chan_alloc(memid, txid, | 900 | /* DBDMA is good to go */ |
860 | au1xmmc_dma_callback, (void *) host); | 901 | host->flags |= HOST_F_DMA; |
861 | 902 | ||
862 | rxchan = au1xxx_dbdma_chan_alloc(rxid, memid, | 903 | return 0; |
863 | au1xmmc_dma_callback, (void *) host); | 904 | } |
864 | 905 | ||
865 | au1xxx_dbdma_set_devwidth(txchan, 8); | 906 | static void au1xmmc_dbdma_shutdown(struct au1xmmc_host *host) |
866 | au1xxx_dbdma_set_devwidth(rxchan, 8); | 907 | { |
908 | if (host->flags & HOST_F_DMA) { | ||
909 | host->flags &= ~HOST_F_DMA; | ||
910 | au1xxx_dbdma_chan_free(host->tx_chan); | ||
911 | au1xxx_dbdma_chan_free(host->rx_chan); | ||
912 | } | ||
913 | } | ||
914 | #endif | ||
867 | 915 | ||
868 | au1xxx_dbdma_ring_alloc(txchan, AU1XMMC_DESCRIPTOR_COUNT); | 916 | static void au1xmmc_enable_sdio_irq(struct mmc_host *mmc, int en) |
869 | au1xxx_dbdma_ring_alloc(rxchan, AU1XMMC_DESCRIPTOR_COUNT); | 917 | { |
918 | struct au1xmmc_host *host = mmc_priv(mmc); | ||
870 | 919 | ||
871 | host->tx_chan = txchan; | 920 | if (en) |
872 | host->rx_chan = rxchan; | 921 | IRQ_ON(host, SD_CONFIG_SI); |
922 | else | ||
923 | IRQ_OFF(host, SD_CONFIG_SI); | ||
873 | } | 924 | } |
874 | 925 | ||
875 | static const struct mmc_host_ops au1xmmc_ops = { | 926 | static const struct mmc_host_ops au1xmmc_ops = { |
876 | .request = au1xmmc_request, | 927 | .request = au1xmmc_request, |
877 | .set_ios = au1xmmc_set_ios, | 928 | .set_ios = au1xmmc_set_ios, |
878 | .get_ro = au1xmmc_card_readonly, | 929 | .get_ro = au1xmmc_card_readonly, |
930 | .get_cd = au1xmmc_card_inserted, | ||
931 | .enable_sdio_irq = au1xmmc_enable_sdio_irq, | ||
879 | }; | 932 | }; |
880 | 933 | ||
881 | static int __devinit au1xmmc_probe(struct platform_device *pdev) | 934 | static int __devinit au1xmmc_probe(struct platform_device *pdev) |
882 | { | 935 | { |
936 | struct mmc_host *mmc; | ||
937 | struct au1xmmc_host *host; | ||
938 | struct resource *r; | ||
939 | int ret; | ||
940 | |||
941 | mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev); | ||
942 | if (!mmc) { | ||
943 | dev_err(&pdev->dev, "no memory for mmc_host\n"); | ||
944 | ret = -ENOMEM; | ||
945 | goto out0; | ||
946 | } | ||
883 | 947 | ||
884 | int i, ret = 0; | 948 | host = mmc_priv(mmc); |
885 | 949 | host->mmc = mmc; | |
886 | /* THe interrupt is shared among all controllers */ | 950 | host->platdata = pdev->dev.platform_data; |
887 | ret = request_irq(AU1100_SD_IRQ, au1xmmc_irq, IRQF_DISABLED, "MMC", 0); | 951 | host->pdev = pdev; |
888 | 952 | ||
889 | if (ret) { | 953 | ret = -ENODEV; |
890 | printk(DRIVER_NAME "ERROR: Couldn't get int %d: %d\n", | 954 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
891 | AU1100_SD_IRQ, ret); | 955 | if (!r) { |
892 | return -ENXIO; | 956 | dev_err(&pdev->dev, "no mmio defined\n"); |
957 | goto out1; | ||
893 | } | 958 | } |
894 | 959 | ||
895 | disable_irq(AU1100_SD_IRQ); | 960 | host->ioarea = request_mem_region(r->start, r->end - r->start + 1, |
961 | pdev->name); | ||
962 | if (!host->ioarea) { | ||
963 | dev_err(&pdev->dev, "mmio already in use\n"); | ||
964 | goto out1; | ||
965 | } | ||
896 | 966 | ||
897 | for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) { | 967 | host->iobase = (unsigned long)ioremap(r->start, 0x3c); |
898 | struct mmc_host *mmc = mmc_alloc_host(sizeof(struct au1xmmc_host), &pdev->dev); | 968 | if (!host->iobase) { |
899 | struct au1xmmc_host *host = 0; | 969 | dev_err(&pdev->dev, "cannot remap mmio\n"); |
970 | goto out2; | ||
971 | } | ||
900 | 972 | ||
901 | if (!mmc) { | 973 | r = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
902 | printk(DRIVER_NAME "ERROR: no mem for host %d\n", i); | 974 | if (!r) { |
903 | au1xmmc_hosts[i] = 0; | 975 | dev_err(&pdev->dev, "no IRQ defined\n"); |
904 | continue; | 976 | goto out3; |
905 | } | 977 | } |
906 | 978 | ||
907 | mmc->ops = &au1xmmc_ops; | 979 | host->irq = r->start; |
980 | /* IRQ is shared among both SD controllers */ | ||
981 | ret = request_irq(host->irq, au1xmmc_irq, IRQF_SHARED, | ||
982 | DRIVER_NAME, host); | ||
983 | if (ret) { | ||
984 | dev_err(&pdev->dev, "cannot grab IRQ\n"); | ||
985 | goto out3; | ||
986 | } | ||
908 | 987 | ||
909 | mmc->f_min = 450000; | 988 | mmc->ops = &au1xmmc_ops; |
910 | mmc->f_max = 24000000; | ||
911 | 989 | ||
912 | mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE; | 990 | mmc->f_min = 450000; |
913 | mmc->max_phys_segs = AU1XMMC_DESCRIPTOR_COUNT; | 991 | mmc->f_max = 24000000; |
914 | 992 | ||
915 | mmc->max_blk_size = 2048; | 993 | mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE; |
916 | mmc->max_blk_count = 512; | 994 | mmc->max_phys_segs = AU1XMMC_DESCRIPTOR_COUNT; |
917 | 995 | ||
918 | mmc->ocr_avail = AU1XMMC_OCR; | 996 | mmc->max_blk_size = 2048; |
997 | mmc->max_blk_count = 512; | ||
919 | 998 | ||
920 | host = mmc_priv(mmc); | 999 | mmc->ocr_avail = AU1XMMC_OCR; |
921 | host->mmc = mmc; | 1000 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ; |
922 | 1001 | ||
923 | host->id = i; | 1002 | host->status = HOST_S_IDLE; |
924 | host->iobase = au1xmmc_card_table[host->id].iobase; | ||
925 | host->clock = 0; | ||
926 | host->power_mode = MMC_POWER_OFF; | ||
927 | 1003 | ||
928 | host->flags = au1xmmc_card_inserted(host) ? HOST_F_ACTIVE : 0; | 1004 | /* board-specific carddetect setup, if any */ |
929 | host->status = HOST_S_IDLE; | 1005 | if (host->platdata && host->platdata->cd_setup) { |
1006 | ret = host->platdata->cd_setup(mmc, 1); | ||
1007 | if (ret) { | ||
1008 | dev_warn(&pdev->dev, "board CD setup failed\n"); | ||
1009 | mmc->caps |= MMC_CAP_NEEDS_POLL; | ||
1010 | } | ||
1011 | } else | ||
1012 | mmc->caps |= MMC_CAP_NEEDS_POLL; | ||
930 | 1013 | ||
931 | init_timer(&host->timer); | 1014 | tasklet_init(&host->data_task, au1xmmc_tasklet_data, |
1015 | (unsigned long)host); | ||
932 | 1016 | ||
933 | host->timer.function = au1xmmc_poll_event; | 1017 | tasklet_init(&host->finish_task, au1xmmc_tasklet_finish, |
934 | host->timer.data = (unsigned long) host; | 1018 | (unsigned long)host); |
935 | host->timer.expires = jiffies + AU1XMMC_DETECT_TIMEOUT; | ||
936 | 1019 | ||
937 | tasklet_init(&host->data_task, au1xmmc_tasklet_data, | 1020 | #ifdef CONFIG_SOC_AU1200 |
938 | (unsigned long) host); | 1021 | ret = au1xmmc_dbdma_init(host); |
1022 | if (ret) | ||
1023 | printk(KERN_INFO DRIVER_NAME ": DBDMA init failed; using PIO\n"); | ||
1024 | #endif | ||
939 | 1025 | ||
940 | tasklet_init(&host->finish_task, au1xmmc_tasklet_finish, | 1026 | #ifdef CONFIG_LEDS_CLASS |
941 | (unsigned long) host); | 1027 | if (host->platdata && host->platdata->led) { |
1028 | struct led_classdev *led = host->platdata->led; | ||
1029 | led->name = mmc_hostname(mmc); | ||
1030 | led->brightness = LED_OFF; | ||
1031 | led->default_trigger = mmc_hostname(mmc); | ||
1032 | ret = led_classdev_register(mmc_dev(mmc), led); | ||
1033 | if (ret) | ||
1034 | goto out5; | ||
1035 | } | ||
1036 | #endif | ||
942 | 1037 | ||
943 | spin_lock_init(&host->lock); | 1038 | au1xmmc_reset_controller(host); |
944 | 1039 | ||
945 | if (dma != 0) | 1040 | ret = mmc_add_host(mmc); |
946 | au1xmmc_init_dma(host); | 1041 | if (ret) { |
1042 | dev_err(&pdev->dev, "cannot add mmc host\n"); | ||
1043 | goto out6; | ||
1044 | } | ||
947 | 1045 | ||
948 | au1xmmc_reset_controller(host); | 1046 | platform_set_drvdata(pdev, mmc); |
949 | 1047 | ||
950 | mmc_add_host(mmc); | 1048 | printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X" |
951 | au1xmmc_hosts[i] = host; | 1049 | " (mode=%s)\n", pdev->id, host->iobase, |
1050 | host->flags & HOST_F_DMA ? "dma" : "pio"); | ||
952 | 1051 | ||
953 | add_timer(&host->timer); | 1052 | return 0; /* all ok */ |
954 | 1053 | ||
955 | printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X (mode=%s)\n", | 1054 | out6: |
956 | host->id, host->iobase, dma ? "dma" : "pio"); | 1055 | #ifdef CONFIG_LEDS_CLASS |
957 | } | 1056 | if (host->platdata && host->platdata->led) |
1057 | led_classdev_unregister(host->platdata->led); | ||
1058 | out5: | ||
1059 | #endif | ||
1060 | au_writel(0, HOST_ENABLE(host)); | ||
1061 | au_writel(0, HOST_CONFIG(host)); | ||
1062 | au_writel(0, HOST_CONFIG2(host)); | ||
1063 | au_sync(); | ||
958 | 1064 | ||
959 | enable_irq(AU1100_SD_IRQ); | 1065 | #ifdef CONFIG_SOC_AU1200 |
1066 | au1xmmc_dbdma_shutdown(host); | ||
1067 | #endif | ||
960 | 1068 | ||
961 | return 0; | 1069 | tasklet_kill(&host->data_task); |
1070 | tasklet_kill(&host->finish_task); | ||
1071 | |||
1072 | if (host->platdata && host->platdata->cd_setup && | ||
1073 | !(mmc->caps & MMC_CAP_NEEDS_POLL)) | ||
1074 | host->platdata->cd_setup(mmc, 0); | ||
1075 | |||
1076 | free_irq(host->irq, host); | ||
1077 | out3: | ||
1078 | iounmap((void *)host->iobase); | ||
1079 | out2: | ||
1080 | release_resource(host->ioarea); | ||
1081 | kfree(host->ioarea); | ||
1082 | out1: | ||
1083 | mmc_free_host(mmc); | ||
1084 | out0: | ||
1085 | return ret; | ||
962 | } | 1086 | } |
963 | 1087 | ||
964 | static int __devexit au1xmmc_remove(struct platform_device *pdev) | 1088 | static int __devexit au1xmmc_remove(struct platform_device *pdev) |
965 | { | 1089 | { |
1090 | struct mmc_host *mmc = platform_get_drvdata(pdev); | ||
1091 | struct au1xmmc_host *host; | ||
1092 | |||
1093 | if (mmc) { | ||
1094 | host = mmc_priv(mmc); | ||
966 | 1095 | ||
967 | int i; | 1096 | mmc_remove_host(mmc); |
968 | 1097 | ||
969 | disable_irq(AU1100_SD_IRQ); | 1098 | #ifdef CONFIG_LEDS_CLASS |
1099 | if (host->platdata && host->platdata->led) | ||
1100 | led_classdev_unregister(host->platdata->led); | ||
1101 | #endif | ||
970 | 1102 | ||
971 | for(i = 0; i < AU1XMMC_CONTROLLER_COUNT; i++) { | 1103 | if (host->platdata && host->platdata->cd_setup && |
972 | struct au1xmmc_host *host = au1xmmc_hosts[i]; | 1104 | !(mmc->caps & MMC_CAP_NEEDS_POLL)) |
973 | if (!host) continue; | 1105 | host->platdata->cd_setup(mmc, 0); |
1106 | |||
1107 | au_writel(0, HOST_ENABLE(host)); | ||
1108 | au_writel(0, HOST_CONFIG(host)); | ||
1109 | au_writel(0, HOST_CONFIG2(host)); | ||
1110 | au_sync(); | ||
974 | 1111 | ||
975 | tasklet_kill(&host->data_task); | 1112 | tasklet_kill(&host->data_task); |
976 | tasklet_kill(&host->finish_task); | 1113 | tasklet_kill(&host->finish_task); |
977 | 1114 | ||
978 | del_timer_sync(&host->timer); | 1115 | #ifdef CONFIG_SOC_AU1200 |
1116 | au1xmmc_dbdma_shutdown(host); | ||
1117 | #endif | ||
979 | au1xmmc_set_power(host, 0); | 1118 | au1xmmc_set_power(host, 0); |
980 | 1119 | ||
981 | mmc_remove_host(host->mmc); | 1120 | free_irq(host->irq, host); |
982 | 1121 | iounmap((void *)host->iobase); | |
983 | au1xxx_dbdma_chan_free(host->tx_chan); | 1122 | release_resource(host->ioarea); |
984 | au1xxx_dbdma_chan_free(host->rx_chan); | 1123 | kfree(host->ioarea); |
985 | 1124 | ||
986 | au_writel(0x0, HOST_ENABLE(host)); | 1125 | mmc_free_host(mmc); |
987 | au_sync(); | ||
988 | } | 1126 | } |
989 | |||
990 | free_irq(AU1100_SD_IRQ, 0); | ||
991 | return 0; | 1127 | return 0; |
992 | } | 1128 | } |
993 | 1129 | ||
@@ -1004,21 +1140,31 @@ static struct platform_driver au1xmmc_driver = { | |||
1004 | 1140 | ||
1005 | static int __init au1xmmc_init(void) | 1141 | static int __init au1xmmc_init(void) |
1006 | { | 1142 | { |
1143 | #ifdef CONFIG_SOC_AU1200 | ||
1144 | /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride | ||
1145 | * of 8 bits. And since devices are shared, we need to create | ||
1146 | * our own to avoid freaking out other devices. | ||
1147 | */ | ||
1148 | memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev); | ||
1149 | if (!memid) | ||
1150 | printk(KERN_ERR "au1xmmc: cannot add memory dbdma dev\n"); | ||
1151 | #endif | ||
1007 | return platform_driver_register(&au1xmmc_driver); | 1152 | return platform_driver_register(&au1xmmc_driver); |
1008 | } | 1153 | } |
1009 | 1154 | ||
1010 | static void __exit au1xmmc_exit(void) | 1155 | static void __exit au1xmmc_exit(void) |
1011 | { | 1156 | { |
1157 | #ifdef CONFIG_SOC_AU1200 | ||
1158 | if (memid) | ||
1159 | au1xxx_ddma_del_device(memid); | ||
1160 | #endif | ||
1012 | platform_driver_unregister(&au1xmmc_driver); | 1161 | platform_driver_unregister(&au1xmmc_driver); |
1013 | } | 1162 | } |
1014 | 1163 | ||
1015 | module_init(au1xmmc_init); | 1164 | module_init(au1xmmc_init); |
1016 | module_exit(au1xmmc_exit); | 1165 | module_exit(au1xmmc_exit); |
1017 | 1166 | ||
1018 | #ifdef MODULE | ||
1019 | MODULE_AUTHOR("Advanced Micro Devices, Inc"); | 1167 | MODULE_AUTHOR("Advanced Micro Devices, Inc"); |
1020 | MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX"); | 1168 | MODULE_DESCRIPTION("MMC/SD driver for the Alchemy Au1XXX"); |
1021 | MODULE_LICENSE("GPL"); | 1169 | MODULE_LICENSE("GPL"); |
1022 | MODULE_ALIAS("platform:au1xxx-mmc"); | 1170 | MODULE_ALIAS("platform:au1xxx-mmc"); |
1023 | #endif | ||
1024 | |||
diff --git a/drivers/mmc/host/au1xmmc.h b/drivers/mmc/host/au1xmmc.h deleted file mode 100644 index 341cbdf0baca..000000000000 --- a/drivers/mmc/host/au1xmmc.h +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | #ifndef _AU1XMMC_H_ | ||
2 | #define _AU1XMMC_H_ | ||
3 | |||
4 | /* Hardware definitions */ | ||
5 | |||
6 | #define AU1XMMC_DESCRIPTOR_COUNT 1 | ||
7 | #define AU1XMMC_DESCRIPTOR_SIZE 2048 | ||
8 | |||
9 | #define AU1XMMC_OCR ( MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \ | ||
10 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \ | ||
11 | MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36) | ||
12 | |||
13 | /* Easy access macros */ | ||
14 | |||
15 | #define HOST_STATUS(h) ((h)->iobase + SD_STATUS) | ||
16 | #define HOST_CONFIG(h) ((h)->iobase + SD_CONFIG) | ||
17 | #define HOST_ENABLE(h) ((h)->iobase + SD_ENABLE) | ||
18 | #define HOST_TXPORT(h) ((h)->iobase + SD_TXPORT) | ||
19 | #define HOST_RXPORT(h) ((h)->iobase + SD_RXPORT) | ||
20 | #define HOST_CMDARG(h) ((h)->iobase + SD_CMDARG) | ||
21 | #define HOST_BLKSIZE(h) ((h)->iobase + SD_BLKSIZE) | ||
22 | #define HOST_CMD(h) ((h)->iobase + SD_CMD) | ||
23 | #define HOST_CONFIG2(h) ((h)->iobase + SD_CONFIG2) | ||
24 | #define HOST_TIMEOUT(h) ((h)->iobase + SD_TIMEOUT) | ||
25 | #define HOST_DEBUG(h) ((h)->iobase + SD_DEBUG) | ||
26 | |||
27 | #define DMA_CHANNEL(h) \ | ||
28 | ( ((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan) | ||
29 | |||
30 | /* This gives us a hard value for the stop command that we can write directly | ||
31 | * to the command register | ||
32 | */ | ||
33 | |||
34 | #define STOP_CMD (SD_CMD_RT_1B|SD_CMD_CT_7|(0xC << SD_CMD_CI_SHIFT)|SD_CMD_GO) | ||
35 | |||
36 | /* This is the set of interrupts that we configure by default */ | ||
37 | |||
38 | #if 0 | ||
39 | #define AU1XMMC_INTERRUPTS (SD_CONFIG_SC | SD_CONFIG_DT | SD_CONFIG_DD | \ | ||
40 | SD_CONFIG_RAT | SD_CONFIG_CR | SD_CONFIG_I) | ||
41 | #endif | ||
42 | |||
43 | #define AU1XMMC_INTERRUPTS (SD_CONFIG_SC | SD_CONFIG_DT | \ | ||
44 | SD_CONFIG_RAT | SD_CONFIG_CR | SD_CONFIG_I) | ||
45 | /* The poll event (looking for insert/remove events runs twice a second */ | ||
46 | #define AU1XMMC_DETECT_TIMEOUT (HZ/2) | ||
47 | |||
48 | struct au1xmmc_host { | ||
49 | struct mmc_host *mmc; | ||
50 | struct mmc_request *mrq; | ||
51 | |||
52 | u32 id; | ||
53 | |||
54 | u32 flags; | ||
55 | u32 iobase; | ||
56 | u32 clock; | ||
57 | u32 bus_width; | ||
58 | u32 power_mode; | ||
59 | |||
60 | int status; | ||
61 | |||
62 | struct { | ||
63 | int len; | ||
64 | int dir; | ||
65 | } dma; | ||
66 | |||
67 | struct { | ||
68 | int index; | ||
69 | int offset; | ||
70 | int len; | ||
71 | } pio; | ||
72 | |||
73 | u32 tx_chan; | ||
74 | u32 rx_chan; | ||
75 | |||
76 | struct timer_list timer; | ||
77 | struct tasklet_struct finish_task; | ||
78 | struct tasklet_struct data_task; | ||
79 | |||
80 | spinlock_t lock; | ||
81 | }; | ||
82 | |||
83 | /* Status flags used by the host structure */ | ||
84 | |||
85 | #define HOST_F_XMIT 0x0001 | ||
86 | #define HOST_F_RECV 0x0002 | ||
87 | #define HOST_F_DMA 0x0010 | ||
88 | #define HOST_F_ACTIVE 0x0100 | ||
89 | #define HOST_F_STOP 0x1000 | ||
90 | |||
91 | #define HOST_S_IDLE 0x0001 | ||
92 | #define HOST_S_CMD 0x0002 | ||
93 | #define HOST_S_DATA 0x0003 | ||
94 | #define HOST_S_STOP 0x0004 | ||
95 | |||
96 | #endif | ||
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c index eed211b2ac70..5e880c0f1349 100644 --- a/drivers/mmc/host/imxmmc.c +++ b/drivers/mmc/host/imxmmc.c | |||
@@ -892,9 +892,12 @@ static int imxmci_get_ro(struct mmc_host *mmc) | |||
892 | struct imxmci_host *host = mmc_priv(mmc); | 892 | struct imxmci_host *host = mmc_priv(mmc); |
893 | 893 | ||
894 | if (host->pdata && host->pdata->get_ro) | 894 | if (host->pdata && host->pdata->get_ro) |
895 | return host->pdata->get_ro(mmc_dev(mmc)); | 895 | return !!host->pdata->get_ro(mmc_dev(mmc)); |
896 | /* Host doesn't support read only detection so assume writeable */ | 896 | /* |
897 | return 0; | 897 | * Board doesn't support read only detection; let the mmc core |
898 | * decide what to do. | ||
899 | */ | ||
900 | return -ENOSYS; | ||
898 | } | 901 | } |
899 | 902 | ||
900 | 903 | ||
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 35508584ac2a..41cc63360e43 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c | |||
@@ -1126,16 +1126,28 @@ static int mmc_spi_get_ro(struct mmc_host *mmc) | |||
1126 | struct mmc_spi_host *host = mmc_priv(mmc); | 1126 | struct mmc_spi_host *host = mmc_priv(mmc); |
1127 | 1127 | ||
1128 | if (host->pdata && host->pdata->get_ro) | 1128 | if (host->pdata && host->pdata->get_ro) |
1129 | return host->pdata->get_ro(mmc->parent); | 1129 | return !!host->pdata->get_ro(mmc->parent); |
1130 | /* board doesn't support read only detection; assume writeable */ | 1130 | /* |
1131 | return 0; | 1131 | * Board doesn't support read only detection; let the mmc core |
1132 | * decide what to do. | ||
1133 | */ | ||
1134 | return -ENOSYS; | ||
1132 | } | 1135 | } |
1133 | 1136 | ||
1137 | static int mmc_spi_get_cd(struct mmc_host *mmc) | ||
1138 | { | ||
1139 | struct mmc_spi_host *host = mmc_priv(mmc); | ||
1140 | |||
1141 | if (host->pdata && host->pdata->get_cd) | ||
1142 | return !!host->pdata->get_cd(mmc->parent); | ||
1143 | return -ENOSYS; | ||
1144 | } | ||
1134 | 1145 | ||
1135 | static const struct mmc_host_ops mmc_spi_ops = { | 1146 | static const struct mmc_host_ops mmc_spi_ops = { |
1136 | .request = mmc_spi_request, | 1147 | .request = mmc_spi_request, |
1137 | .set_ios = mmc_spi_set_ios, | 1148 | .set_ios = mmc_spi_set_ios, |
1138 | .get_ro = mmc_spi_get_ro, | 1149 | .get_ro = mmc_spi_get_ro, |
1150 | .get_cd = mmc_spi_get_cd, | ||
1139 | }; | 1151 | }; |
1140 | 1152 | ||
1141 | 1153 | ||
@@ -1240,10 +1252,7 @@ static int mmc_spi_probe(struct spi_device *spi) | |||
1240 | mmc->ops = &mmc_spi_ops; | 1252 | mmc->ops = &mmc_spi_ops; |
1241 | mmc->max_blk_size = MMC_SPI_BLOCKSIZE; | 1253 | mmc->max_blk_size = MMC_SPI_BLOCKSIZE; |
1242 | 1254 | ||
1243 | /* As long as we keep track of the number of successfully | 1255 | mmc->caps = MMC_CAP_SPI; |
1244 | * transmitted blocks, we're good for multiwrite. | ||
1245 | */ | ||
1246 | mmc->caps = MMC_CAP_SPI | MMC_CAP_MULTIWRITE; | ||
1247 | 1256 | ||
1248 | /* SPI doesn't need the lowspeed device identification thing for | 1257 | /* SPI doesn't need the lowspeed device identification thing for |
1249 | * MMC or SD cards, since it never comes up in open drain mode. | 1258 | * MMC or SD cards, since it never comes up in open drain mode. |
@@ -1319,17 +1328,23 @@ static int mmc_spi_probe(struct spi_device *spi) | |||
1319 | goto fail_glue_init; | 1328 | goto fail_glue_init; |
1320 | } | 1329 | } |
1321 | 1330 | ||
1331 | /* pass platform capabilities, if any */ | ||
1332 | if (host->pdata) | ||
1333 | mmc->caps |= host->pdata->caps; | ||
1334 | |||
1322 | status = mmc_add_host(mmc); | 1335 | status = mmc_add_host(mmc); |
1323 | if (status != 0) | 1336 | if (status != 0) |
1324 | goto fail_add_host; | 1337 | goto fail_add_host; |
1325 | 1338 | ||
1326 | dev_info(&spi->dev, "SD/MMC host %s%s%s%s\n", | 1339 | dev_info(&spi->dev, "SD/MMC host %s%s%s%s%s\n", |
1327 | mmc->class_dev.bus_id, | 1340 | mmc->class_dev.bus_id, |
1328 | host->dma_dev ? "" : ", no DMA", | 1341 | host->dma_dev ? "" : ", no DMA", |
1329 | (host->pdata && host->pdata->get_ro) | 1342 | (host->pdata && host->pdata->get_ro) |
1330 | ? "" : ", no WP", | 1343 | ? "" : ", no WP", |
1331 | (host->pdata && host->pdata->setpower) | 1344 | (host->pdata && host->pdata->setpower) |
1332 | ? "" : ", no poweroff"); | 1345 | ? "" : ", no poweroff", |
1346 | (mmc->caps & MMC_CAP_NEEDS_POLL) | ||
1347 | ? ", cd polling" : ""); | ||
1333 | return 0; | 1348 | return 0; |
1334 | 1349 | ||
1335 | fail_add_host: | 1350 | fail_add_host: |
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index da5fecad74d9..696cf3647ceb 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c | |||
@@ -535,7 +535,6 @@ static int mmci_probe(struct amba_device *dev, void *id) | |||
535 | mmc->f_min = (host->mclk + 511) / 512; | 535 | mmc->f_min = (host->mclk + 511) / 512; |
536 | mmc->f_max = min(host->mclk, fmax); | 536 | mmc->f_max = min(host->mclk, fmax); |
537 | mmc->ocr_avail = plat->ocr_mask; | 537 | mmc->ocr_avail = plat->ocr_mask; |
538 | mmc->caps = MMC_CAP_MULTIWRITE; | ||
539 | 538 | ||
540 | /* | 539 | /* |
541 | * We can do SGIO | 540 | * We can do SGIO |
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c index 549517c35675..dbc26eb6a89e 100644 --- a/drivers/mmc/host/omap.c +++ b/drivers/mmc/host/omap.c | |||
@@ -1317,7 +1317,7 @@ static int __init mmc_omap_new_slot(struct mmc_omap_host *host, int id) | |||
1317 | 1317 | ||
1318 | host->slots[id] = slot; | 1318 | host->slots[id] = slot; |
1319 | 1319 | ||
1320 | mmc->caps = MMC_CAP_MULTIWRITE; | 1320 | mmc->caps = 0; |
1321 | if (host->pdata->conf.wire4) | 1321 | if (host->pdata->conf.wire4) |
1322 | mmc->caps |= MMC_CAP_4_BIT_DATA; | 1322 | mmc->caps |= MMC_CAP_4_BIT_DATA; |
1323 | 1323 | ||
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c index d89475d36988..d39f59738866 100644 --- a/drivers/mmc/host/pxamci.c +++ b/drivers/mmc/host/pxamci.c | |||
@@ -374,9 +374,12 @@ static int pxamci_get_ro(struct mmc_host *mmc) | |||
374 | struct pxamci_host *host = mmc_priv(mmc); | 374 | struct pxamci_host *host = mmc_priv(mmc); |
375 | 375 | ||
376 | if (host->pdata && host->pdata->get_ro) | 376 | if (host->pdata && host->pdata->get_ro) |
377 | return host->pdata->get_ro(mmc_dev(mmc)); | 377 | return !!host->pdata->get_ro(mmc_dev(mmc)); |
378 | /* Host doesn't support read only detection so assume writeable */ | 378 | /* |
379 | return 0; | 379 | * Board doesn't support read only detection; let the mmc core |
380 | * decide what to do. | ||
381 | */ | ||
382 | return -ENOSYS; | ||
380 | } | 383 | } |
381 | 384 | ||
382 | static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | 385 | static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) |
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c new file mode 100644 index 000000000000..6a1e4994b724 --- /dev/null +++ b/drivers/mmc/host/s3cmci.c | |||
@@ -0,0 +1,1446 @@ | |||
1 | /* | ||
2 | * linux/drivers/mmc/s3cmci.h - Samsung S3C MCI driver | ||
3 | * | ||
4 | * Copyright (C) 2004-2006 maintech GmbH, Thomas Kleffel <tk@maintech.de> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/dma-mapping.h> | ||
13 | #include <linux/clk.h> | ||
14 | #include <linux/mmc/host.h> | ||
15 | #include <linux/platform_device.h> | ||
16 | #include <linux/irq.h> | ||
17 | #include <linux/io.h> | ||
18 | |||
19 | #include <asm/dma.h> | ||
20 | |||
21 | #include <asm/arch/regs-sdi.h> | ||
22 | #include <asm/arch/regs-gpio.h> | ||
23 | |||
24 | #include <asm/plat-s3c24xx/mci.h> | ||
25 | |||
26 | #include "s3cmci.h" | ||
27 | |||
28 | #define DRIVER_NAME "s3c-mci" | ||
29 | |||
30 | enum dbg_channels { | ||
31 | dbg_err = (1 << 0), | ||
32 | dbg_debug = (1 << 1), | ||
33 | dbg_info = (1 << 2), | ||
34 | dbg_irq = (1 << 3), | ||
35 | dbg_sg = (1 << 4), | ||
36 | dbg_dma = (1 << 5), | ||
37 | dbg_pio = (1 << 6), | ||
38 | dbg_fail = (1 << 7), | ||
39 | dbg_conf = (1 << 8), | ||
40 | }; | ||
41 | |||
42 | static const int dbgmap_err = dbg_err | dbg_fail; | ||
43 | static const int dbgmap_info = dbg_info | dbg_conf; | ||
44 | static const int dbgmap_debug = dbg_debug; | ||
45 | |||
46 | #define dbg(host, channels, args...) \ | ||
47 | do { \ | ||
48 | if (dbgmap_err & channels) \ | ||
49 | dev_err(&host->pdev->dev, args); \ | ||
50 | else if (dbgmap_info & channels) \ | ||
51 | dev_info(&host->pdev->dev, args); \ | ||
52 | else if (dbgmap_debug & channels) \ | ||
53 | dev_dbg(&host->pdev->dev, args); \ | ||
54 | } while (0) | ||
55 | |||
56 | #define RESSIZE(ressource) (((ressource)->end - (ressource)->start)+1) | ||
57 | |||
58 | static struct s3c2410_dma_client s3cmci_dma_client = { | ||
59 | .name = "s3c-mci", | ||
60 | }; | ||
61 | |||
62 | static void finalize_request(struct s3cmci_host *host); | ||
63 | static void s3cmci_send_request(struct mmc_host *mmc); | ||
64 | static void s3cmci_reset(struct s3cmci_host *host); | ||
65 | |||
66 | #ifdef CONFIG_MMC_DEBUG | ||
67 | |||
68 | static void dbg_dumpregs(struct s3cmci_host *host, char *prefix) | ||
69 | { | ||
70 | u32 con, pre, cmdarg, cmdcon, cmdsta, r0, r1, r2, r3, timer, bsize; | ||
71 | u32 datcon, datcnt, datsta, fsta, imask; | ||
72 | |||
73 | con = readl(host->base + S3C2410_SDICON); | ||
74 | pre = readl(host->base + S3C2410_SDIPRE); | ||
75 | cmdarg = readl(host->base + S3C2410_SDICMDARG); | ||
76 | cmdcon = readl(host->base + S3C2410_SDICMDCON); | ||
77 | cmdsta = readl(host->base + S3C2410_SDICMDSTAT); | ||
78 | r0 = readl(host->base + S3C2410_SDIRSP0); | ||
79 | r1 = readl(host->base + S3C2410_SDIRSP1); | ||
80 | r2 = readl(host->base + S3C2410_SDIRSP2); | ||
81 | r3 = readl(host->base + S3C2410_SDIRSP3); | ||
82 | timer = readl(host->base + S3C2410_SDITIMER); | ||
83 | bsize = readl(host->base + S3C2410_SDIBSIZE); | ||
84 | datcon = readl(host->base + S3C2410_SDIDCON); | ||
85 | datcnt = readl(host->base + S3C2410_SDIDCNT); | ||
86 | datsta = readl(host->base + S3C2410_SDIDSTA); | ||
87 | fsta = readl(host->base + S3C2410_SDIFSTA); | ||
88 | imask = readl(host->base + host->sdiimsk); | ||
89 | |||
90 | dbg(host, dbg_debug, "%s CON:[%08x] PRE:[%08x] TMR:[%08x]\n", | ||
91 | prefix, con, pre, timer); | ||
92 | |||
93 | dbg(host, dbg_debug, "%s CCON:[%08x] CARG:[%08x] CSTA:[%08x]\n", | ||
94 | prefix, cmdcon, cmdarg, cmdsta); | ||
95 | |||
96 | dbg(host, dbg_debug, "%s DCON:[%08x] FSTA:[%08x]" | ||
97 | " DSTA:[%08x] DCNT:[%08x]\n", | ||
98 | prefix, datcon, fsta, datsta, datcnt); | ||
99 | |||
100 | dbg(host, dbg_debug, "%s R0:[%08x] R1:[%08x]" | ||
101 | " R2:[%08x] R3:[%08x]\n", | ||
102 | prefix, r0, r1, r2, r3); | ||
103 | } | ||
104 | |||
105 | static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd, | ||
106 | int stop) | ||
107 | { | ||
108 | snprintf(host->dbgmsg_cmd, 300, | ||
109 | "#%u%s op:%i arg:0x%08x flags:0x08%x retries:%u", | ||
110 | host->ccnt, (stop ? " (STOP)" : ""), | ||
111 | cmd->opcode, cmd->arg, cmd->flags, cmd->retries); | ||
112 | |||
113 | if (cmd->data) { | ||
114 | snprintf(host->dbgmsg_dat, 300, | ||
115 | "#%u bsize:%u blocks:%u bytes:%u", | ||
116 | host->dcnt, cmd->data->blksz, | ||
117 | cmd->data->blocks, | ||
118 | cmd->data->blocks * cmd->data->blksz); | ||
119 | } else { | ||
120 | host->dbgmsg_dat[0] = '\0'; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | static void dbg_dumpcmd(struct s3cmci_host *host, struct mmc_command *cmd, | ||
125 | int fail) | ||
126 | { | ||
127 | unsigned int dbglvl = fail ? dbg_fail : dbg_debug; | ||
128 | |||
129 | if (!cmd) | ||
130 | return; | ||
131 | |||
132 | if (cmd->error == 0) { | ||
133 | dbg(host, dbglvl, "CMD[OK] %s R0:0x%08x\n", | ||
134 | host->dbgmsg_cmd, cmd->resp[0]); | ||
135 | } else { | ||
136 | dbg(host, dbglvl, "CMD[ERR %i] %s Status:%s\n", | ||
137 | cmd->error, host->dbgmsg_cmd, host->status); | ||
138 | } | ||
139 | |||
140 | if (!cmd->data) | ||
141 | return; | ||
142 | |||
143 | if (cmd->data->error == 0) { | ||
144 | dbg(host, dbglvl, "DAT[OK] %s\n", host->dbgmsg_dat); | ||
145 | } else { | ||
146 | dbg(host, dbglvl, "DAT[ERR %i] %s DCNT:0x%08x\n", | ||
147 | cmd->data->error, host->dbgmsg_dat, | ||
148 | readl(host->base + S3C2410_SDIDCNT)); | ||
149 | } | ||
150 | } | ||
151 | #else | ||
152 | static void dbg_dumpcmd(struct s3cmci_host *host, | ||
153 | struct mmc_command *cmd, int fail) { } | ||
154 | |||
155 | static void prepare_dbgmsg(struct s3cmci_host *host, struct mmc_command *cmd, | ||
156 | int stop) { } | ||
157 | |||
158 | static void dbg_dumpregs(struct s3cmci_host *host, char *prefix) { } | ||
159 | |||
160 | #endif /* CONFIG_MMC_DEBUG */ | ||
161 | |||
162 | static inline u32 enable_imask(struct s3cmci_host *host, u32 imask) | ||
163 | { | ||
164 | u32 newmask; | ||
165 | |||
166 | newmask = readl(host->base + host->sdiimsk); | ||
167 | newmask |= imask; | ||
168 | |||
169 | writel(newmask, host->base + host->sdiimsk); | ||
170 | |||
171 | return newmask; | ||
172 | } | ||
173 | |||
174 | static inline u32 disable_imask(struct s3cmci_host *host, u32 imask) | ||
175 | { | ||
176 | u32 newmask; | ||
177 | |||
178 | newmask = readl(host->base + host->sdiimsk); | ||
179 | newmask &= ~imask; | ||
180 | |||
181 | writel(newmask, host->base + host->sdiimsk); | ||
182 | |||
183 | return newmask; | ||
184 | } | ||
185 | |||
186 | static inline void clear_imask(struct s3cmci_host *host) | ||
187 | { | ||
188 | writel(0, host->base + host->sdiimsk); | ||
189 | } | ||
190 | |||
191 | static inline int get_data_buffer(struct s3cmci_host *host, | ||
192 | u32 *words, u32 **pointer) | ||
193 | { | ||
194 | struct scatterlist *sg; | ||
195 | |||
196 | if (host->pio_active == XFER_NONE) | ||
197 | return -EINVAL; | ||
198 | |||
199 | if ((!host->mrq) || (!host->mrq->data)) | ||
200 | return -EINVAL; | ||
201 | |||
202 | if (host->pio_sgptr >= host->mrq->data->sg_len) { | ||
203 | dbg(host, dbg_debug, "no more buffers (%i/%i)\n", | ||
204 | host->pio_sgptr, host->mrq->data->sg_len); | ||
205 | return -EBUSY; | ||
206 | } | ||
207 | sg = &host->mrq->data->sg[host->pio_sgptr]; | ||
208 | |||
209 | *words = sg->length >> 2; | ||
210 | *pointer = sg_virt(sg); | ||
211 | |||
212 | host->pio_sgptr++; | ||
213 | |||
214 | dbg(host, dbg_sg, "new buffer (%i/%i)\n", | ||
215 | host->pio_sgptr, host->mrq->data->sg_len); | ||
216 | |||
217 | return 0; | ||
218 | } | ||
219 | |||
220 | static inline u32 fifo_count(struct s3cmci_host *host) | ||
221 | { | ||
222 | u32 fifostat = readl(host->base + S3C2410_SDIFSTA); | ||
223 | |||
224 | fifostat &= S3C2410_SDIFSTA_COUNTMASK; | ||
225 | return fifostat >> 2; | ||
226 | } | ||
227 | |||
228 | static inline u32 fifo_free(struct s3cmci_host *host) | ||
229 | { | ||
230 | u32 fifostat = readl(host->base + S3C2410_SDIFSTA); | ||
231 | |||
232 | fifostat &= S3C2410_SDIFSTA_COUNTMASK; | ||
233 | return (63 - fifostat) >> 2; | ||
234 | } | ||
235 | |||
236 | static void do_pio_read(struct s3cmci_host *host) | ||
237 | { | ||
238 | int res; | ||
239 | u32 fifo; | ||
240 | void __iomem *from_ptr; | ||
241 | |||
242 | /* write real prescaler to host, it might be set slow to fix */ | ||
243 | writel(host->prescaler, host->base + S3C2410_SDIPRE); | ||
244 | |||
245 | from_ptr = host->base + host->sdidata; | ||
246 | |||
247 | while ((fifo = fifo_count(host))) { | ||
248 | if (!host->pio_words) { | ||
249 | res = get_data_buffer(host, &host->pio_words, | ||
250 | &host->pio_ptr); | ||
251 | if (res) { | ||
252 | host->pio_active = XFER_NONE; | ||
253 | host->complete_what = COMPLETION_FINALIZE; | ||
254 | |||
255 | dbg(host, dbg_pio, "pio_read(): " | ||
256 | "complete (no more data).\n"); | ||
257 | return; | ||
258 | } | ||
259 | |||
260 | dbg(host, dbg_pio, | ||
261 | "pio_read(): new target: [%i]@[%p]\n", | ||
262 | host->pio_words, host->pio_ptr); | ||
263 | } | ||
264 | |||
265 | dbg(host, dbg_pio, | ||
266 | "pio_read(): fifo:[%02i] buffer:[%03i] dcnt:[%08X]\n", | ||
267 | fifo, host->pio_words, | ||
268 | readl(host->base + S3C2410_SDIDCNT)); | ||
269 | |||
270 | if (fifo > host->pio_words) | ||
271 | fifo = host->pio_words; | ||
272 | |||
273 | host->pio_words -= fifo; | ||
274 | host->pio_count += fifo; | ||
275 | |||
276 | while (fifo--) | ||
277 | *(host->pio_ptr++) = readl(from_ptr); | ||
278 | } | ||
279 | |||
280 | if (!host->pio_words) { | ||
281 | res = get_data_buffer(host, &host->pio_words, &host->pio_ptr); | ||
282 | if (res) { | ||
283 | dbg(host, dbg_pio, | ||
284 | "pio_read(): complete (no more buffers).\n"); | ||
285 | host->pio_active = XFER_NONE; | ||
286 | host->complete_what = COMPLETION_FINALIZE; | ||
287 | |||
288 | return; | ||
289 | } | ||
290 | } | ||
291 | |||
292 | enable_imask(host, | ||
293 | S3C2410_SDIIMSK_RXFIFOHALF | S3C2410_SDIIMSK_RXFIFOLAST); | ||
294 | } | ||
295 | |||
296 | static void do_pio_write(struct s3cmci_host *host) | ||
297 | { | ||
298 | void __iomem *to_ptr; | ||
299 | int res; | ||
300 | u32 fifo; | ||
301 | |||
302 | to_ptr = host->base + host->sdidata; | ||
303 | |||
304 | while ((fifo = fifo_free(host))) { | ||
305 | if (!host->pio_words) { | ||
306 | res = get_data_buffer(host, &host->pio_words, | ||
307 | &host->pio_ptr); | ||
308 | if (res) { | ||
309 | dbg(host, dbg_pio, | ||
310 | "pio_write(): complete (no more data).\n"); | ||
311 | host->pio_active = XFER_NONE; | ||
312 | |||
313 | return; | ||
314 | } | ||
315 | |||
316 | dbg(host, dbg_pio, | ||
317 | "pio_write(): new source: [%i]@[%p]\n", | ||
318 | host->pio_words, host->pio_ptr); | ||
319 | |||
320 | } | ||
321 | |||
322 | if (fifo > host->pio_words) | ||
323 | fifo = host->pio_words; | ||
324 | |||
325 | host->pio_words -= fifo; | ||
326 | host->pio_count += fifo; | ||
327 | |||
328 | while (fifo--) | ||
329 | writel(*(host->pio_ptr++), to_ptr); | ||
330 | } | ||
331 | |||
332 | enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF); | ||
333 | } | ||
334 | |||
335 | static void pio_tasklet(unsigned long data) | ||
336 | { | ||
337 | struct s3cmci_host *host = (struct s3cmci_host *) data; | ||
338 | |||
339 | |||
340 | disable_irq(host->irq); | ||
341 | |||
342 | if (host->pio_active == XFER_WRITE) | ||
343 | do_pio_write(host); | ||
344 | |||
345 | if (host->pio_active == XFER_READ) | ||
346 | do_pio_read(host); | ||
347 | |||
348 | if (host->complete_what == COMPLETION_FINALIZE) { | ||
349 | clear_imask(host); | ||
350 | if (host->pio_active != XFER_NONE) { | ||
351 | dbg(host, dbg_err, "unfinished %s " | ||
352 | "- pio_count:[%u] pio_words:[%u]\n", | ||
353 | (host->pio_active == XFER_READ) ? "read" : "write", | ||
354 | host->pio_count, host->pio_words); | ||
355 | |||
356 | if (host->mrq->data) | ||
357 | host->mrq->data->error = -EINVAL; | ||
358 | } | ||
359 | |||
360 | finalize_request(host); | ||
361 | } else | ||
362 | enable_irq(host->irq); | ||
363 | } | ||
364 | |||
365 | /* | ||
366 | * ISR for SDI Interface IRQ | ||
367 | * Communication between driver and ISR works as follows: | ||
368 | * host->mrq points to current request | ||
369 | * host->complete_what Indicates when the request is considered done | ||
370 | * COMPLETION_CMDSENT when the command was sent | ||
371 | * COMPLETION_RSPFIN when a response was received | ||
372 | * COMPLETION_XFERFINISH when the data transfer is finished | ||
373 | * COMPLETION_XFERFINISH_RSPFIN both of the above. | ||
374 | * host->complete_request is the completion-object the driver waits for | ||
375 | * | ||
376 | * 1) Driver sets up host->mrq and host->complete_what | ||
377 | * 2) Driver prepares the transfer | ||
378 | * 3) Driver enables interrupts | ||
379 | * 4) Driver starts transfer | ||
380 | * 5) Driver waits for host->complete_rquest | ||
381 | * 6) ISR checks for request status (errors and success) | ||
382 | * 6) ISR sets host->mrq->cmd->error and host->mrq->data->error | ||
383 | * 7) ISR completes host->complete_request | ||
384 | * 8) ISR disables interrupts | ||
385 | * 9) Driver wakes up and takes care of the request | ||
386 | * | ||
387 | * Note: "->error"-fields are expected to be set to 0 before the request | ||
388 | * was issued by mmc.c - therefore they are only set, when an error | ||
389 | * contition comes up | ||
390 | */ | ||
391 | |||
392 | static irqreturn_t s3cmci_irq(int irq, void *dev_id) | ||
393 | { | ||
394 | struct s3cmci_host *host = dev_id; | ||
395 | struct mmc_command *cmd; | ||
396 | u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt, mci_imsk; | ||
397 | u32 mci_cclear, mci_dclear; | ||
398 | unsigned long iflags; | ||
399 | |||
400 | spin_lock_irqsave(&host->complete_lock, iflags); | ||
401 | |||
402 | mci_csta = readl(host->base + S3C2410_SDICMDSTAT); | ||
403 | mci_dsta = readl(host->base + S3C2410_SDIDSTA); | ||
404 | mci_dcnt = readl(host->base + S3C2410_SDIDCNT); | ||
405 | mci_fsta = readl(host->base + S3C2410_SDIFSTA); | ||
406 | mci_imsk = readl(host->base + host->sdiimsk); | ||
407 | mci_cclear = 0; | ||
408 | mci_dclear = 0; | ||
409 | |||
410 | if ((host->complete_what == COMPLETION_NONE) || | ||
411 | (host->complete_what == COMPLETION_FINALIZE)) { | ||
412 | host->status = "nothing to complete"; | ||
413 | clear_imask(host); | ||
414 | goto irq_out; | ||
415 | } | ||
416 | |||
417 | if (!host->mrq) { | ||
418 | host->status = "no active mrq"; | ||
419 | clear_imask(host); | ||
420 | goto irq_out; | ||
421 | } | ||
422 | |||
423 | cmd = host->cmd_is_stop ? host->mrq->stop : host->mrq->cmd; | ||
424 | |||
425 | if (!cmd) { | ||
426 | host->status = "no active cmd"; | ||
427 | clear_imask(host); | ||
428 | goto irq_out; | ||
429 | } | ||
430 | |||
431 | if (!host->dodma) { | ||
432 | if ((host->pio_active == XFER_WRITE) && | ||
433 | (mci_fsta & S3C2410_SDIFSTA_TFDET)) { | ||
434 | |||
435 | disable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF); | ||
436 | tasklet_schedule(&host->pio_tasklet); | ||
437 | host->status = "pio tx"; | ||
438 | } | ||
439 | |||
440 | if ((host->pio_active == XFER_READ) && | ||
441 | (mci_fsta & S3C2410_SDIFSTA_RFDET)) { | ||
442 | |||
443 | disable_imask(host, | ||
444 | S3C2410_SDIIMSK_RXFIFOHALF | | ||
445 | S3C2410_SDIIMSK_RXFIFOLAST); | ||
446 | |||
447 | tasklet_schedule(&host->pio_tasklet); | ||
448 | host->status = "pio rx"; | ||
449 | } | ||
450 | } | ||
451 | |||
452 | if (mci_csta & S3C2410_SDICMDSTAT_CMDTIMEOUT) { | ||
453 | dbg(host, dbg_err, "CMDSTAT: error CMDTIMEOUT\n"); | ||
454 | cmd->error = -ETIMEDOUT; | ||
455 | host->status = "error: command timeout"; | ||
456 | goto fail_transfer; | ||
457 | } | ||
458 | |||
459 | if (mci_csta & S3C2410_SDICMDSTAT_CMDSENT) { | ||
460 | if (host->complete_what == COMPLETION_CMDSENT) { | ||
461 | host->status = "ok: command sent"; | ||
462 | goto close_transfer; | ||
463 | } | ||
464 | |||
465 | mci_cclear |= S3C2410_SDICMDSTAT_CMDSENT; | ||
466 | } | ||
467 | |||
468 | if (mci_csta & S3C2410_SDICMDSTAT_CRCFAIL) { | ||
469 | if (cmd->flags & MMC_RSP_CRC) { | ||
470 | if (host->mrq->cmd->flags & MMC_RSP_136) { | ||
471 | dbg(host, dbg_irq, | ||
472 | "fixup: ignore CRC fail with long rsp\n"); | ||
473 | } else { | ||
474 | /* note, we used to fail the transfer | ||
475 | * here, but it seems that this is just | ||
476 | * the hardware getting it wrong. | ||
477 | * | ||
478 | * cmd->error = -EILSEQ; | ||
479 | * host->status = "error: bad command crc"; | ||
480 | * goto fail_transfer; | ||
481 | */ | ||
482 | } | ||
483 | } | ||
484 | |||
485 | mci_cclear |= S3C2410_SDICMDSTAT_CRCFAIL; | ||
486 | } | ||
487 | |||
488 | if (mci_csta & S3C2410_SDICMDSTAT_RSPFIN) { | ||
489 | if (host->complete_what == COMPLETION_RSPFIN) { | ||
490 | host->status = "ok: command response received"; | ||
491 | goto close_transfer; | ||
492 | } | ||
493 | |||
494 | if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN) | ||
495 | host->complete_what = COMPLETION_XFERFINISH; | ||
496 | |||
497 | mci_cclear |= S3C2410_SDICMDSTAT_RSPFIN; | ||
498 | } | ||
499 | |||
500 | /* errors handled after this point are only relevant | ||
501 | when a data transfer is in progress */ | ||
502 | |||
503 | if (!cmd->data) | ||
504 | goto clear_status_bits; | ||
505 | |||
506 | /* Check for FIFO failure */ | ||
507 | if (host->is2440) { | ||
508 | if (mci_fsta & S3C2440_SDIFSTA_FIFOFAIL) { | ||
509 | dbg(host, dbg_err, "FIFO failure\n"); | ||
510 | host->mrq->data->error = -EILSEQ; | ||
511 | host->status = "error: 2440 fifo failure"; | ||
512 | goto fail_transfer; | ||
513 | } | ||
514 | } else { | ||
515 | if (mci_dsta & S3C2410_SDIDSTA_FIFOFAIL) { | ||
516 | dbg(host, dbg_err, "FIFO failure\n"); | ||
517 | cmd->data->error = -EILSEQ; | ||
518 | host->status = "error: fifo failure"; | ||
519 | goto fail_transfer; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | if (mci_dsta & S3C2410_SDIDSTA_RXCRCFAIL) { | ||
524 | dbg(host, dbg_err, "bad data crc (outgoing)\n"); | ||
525 | cmd->data->error = -EILSEQ; | ||
526 | host->status = "error: bad data crc (outgoing)"; | ||
527 | goto fail_transfer; | ||
528 | } | ||
529 | |||
530 | if (mci_dsta & S3C2410_SDIDSTA_CRCFAIL) { | ||
531 | dbg(host, dbg_err, "bad data crc (incoming)\n"); | ||
532 | cmd->data->error = -EILSEQ; | ||
533 | host->status = "error: bad data crc (incoming)"; | ||
534 | goto fail_transfer; | ||
535 | } | ||
536 | |||
537 | if (mci_dsta & S3C2410_SDIDSTA_DATATIMEOUT) { | ||
538 | dbg(host, dbg_err, "data timeout\n"); | ||
539 | cmd->data->error = -ETIMEDOUT; | ||
540 | host->status = "error: data timeout"; | ||
541 | goto fail_transfer; | ||
542 | } | ||
543 | |||
544 | if (mci_dsta & S3C2410_SDIDSTA_XFERFINISH) { | ||
545 | if (host->complete_what == COMPLETION_XFERFINISH) { | ||
546 | host->status = "ok: data transfer completed"; | ||
547 | goto close_transfer; | ||
548 | } | ||
549 | |||
550 | if (host->complete_what == COMPLETION_XFERFINISH_RSPFIN) | ||
551 | host->complete_what = COMPLETION_RSPFIN; | ||
552 | |||
553 | mci_dclear |= S3C2410_SDIDSTA_XFERFINISH; | ||
554 | } | ||
555 | |||
556 | clear_status_bits: | ||
557 | writel(mci_cclear, host->base + S3C2410_SDICMDSTAT); | ||
558 | writel(mci_dclear, host->base + S3C2410_SDIDSTA); | ||
559 | |||
560 | goto irq_out; | ||
561 | |||
562 | fail_transfer: | ||
563 | host->pio_active = XFER_NONE; | ||
564 | |||
565 | close_transfer: | ||
566 | host->complete_what = COMPLETION_FINALIZE; | ||
567 | |||
568 | clear_imask(host); | ||
569 | tasklet_schedule(&host->pio_tasklet); | ||
570 | |||
571 | goto irq_out; | ||
572 | |||
573 | irq_out: | ||
574 | dbg(host, dbg_irq, | ||
575 | "csta:0x%08x dsta:0x%08x fsta:0x%08x dcnt:0x%08x status:%s.\n", | ||
576 | mci_csta, mci_dsta, mci_fsta, mci_dcnt, host->status); | ||
577 | |||
578 | spin_unlock_irqrestore(&host->complete_lock, iflags); | ||
579 | return IRQ_HANDLED; | ||
580 | |||
581 | } | ||
582 | |||
583 | /* | ||
584 | * ISR for the CardDetect Pin | ||
585 | */ | ||
586 | |||
587 | static irqreturn_t s3cmci_irq_cd(int irq, void *dev_id) | ||
588 | { | ||
589 | struct s3cmci_host *host = (struct s3cmci_host *)dev_id; | ||
590 | |||
591 | dbg(host, dbg_irq, "card detect\n"); | ||
592 | |||
593 | mmc_detect_change(host->mmc, msecs_to_jiffies(500)); | ||
594 | |||
595 | return IRQ_HANDLED; | ||
596 | } | ||
597 | |||
598 | void s3cmci_dma_done_callback(struct s3c2410_dma_chan *dma_ch, void *buf_id, | ||
599 | int size, enum s3c2410_dma_buffresult result) | ||
600 | { | ||
601 | struct s3cmci_host *host = buf_id; | ||
602 | unsigned long iflags; | ||
603 | u32 mci_csta, mci_dsta, mci_fsta, mci_dcnt; | ||
604 | |||
605 | mci_csta = readl(host->base + S3C2410_SDICMDSTAT); | ||
606 | mci_dsta = readl(host->base + S3C2410_SDIDSTA); | ||
607 | mci_fsta = readl(host->base + S3C2410_SDIFSTA); | ||
608 | mci_dcnt = readl(host->base + S3C2410_SDIDCNT); | ||
609 | |||
610 | BUG_ON(!host->mrq); | ||
611 | BUG_ON(!host->mrq->data); | ||
612 | BUG_ON(!host->dmatogo); | ||
613 | |||
614 | spin_lock_irqsave(&host->complete_lock, iflags); | ||
615 | |||
616 | if (result != S3C2410_RES_OK) { | ||
617 | dbg(host, dbg_fail, "DMA FAILED: csta=0x%08x dsta=0x%08x " | ||
618 | "fsta=0x%08x dcnt:0x%08x result:0x%08x toGo:%u\n", | ||
619 | mci_csta, mci_dsta, mci_fsta, | ||
620 | mci_dcnt, result, host->dmatogo); | ||
621 | |||
622 | goto fail_request; | ||
623 | } | ||
624 | |||
625 | host->dmatogo--; | ||
626 | if (host->dmatogo) { | ||
627 | dbg(host, dbg_dma, "DMA DONE Size:%i DSTA:[%08x] " | ||
628 | "DCNT:[%08x] toGo:%u\n", | ||
629 | size, mci_dsta, mci_dcnt, host->dmatogo); | ||
630 | |||
631 | goto out; | ||
632 | } | ||
633 | |||
634 | dbg(host, dbg_dma, "DMA FINISHED Size:%i DSTA:%08x DCNT:%08x\n", | ||
635 | size, mci_dsta, mci_dcnt); | ||
636 | |||
637 | host->complete_what = COMPLETION_FINALIZE; | ||
638 | |||
639 | out: | ||
640 | tasklet_schedule(&host->pio_tasklet); | ||
641 | spin_unlock_irqrestore(&host->complete_lock, iflags); | ||
642 | return; | ||
643 | |||
644 | fail_request: | ||
645 | host->mrq->data->error = -EINVAL; | ||
646 | host->complete_what = COMPLETION_FINALIZE; | ||
647 | writel(0, host->base + host->sdiimsk); | ||
648 | goto out; | ||
649 | |||
650 | } | ||
651 | |||
652 | static void finalize_request(struct s3cmci_host *host) | ||
653 | { | ||
654 | struct mmc_request *mrq = host->mrq; | ||
655 | struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd; | ||
656 | int debug_as_failure = 0; | ||
657 | |||
658 | if (host->complete_what != COMPLETION_FINALIZE) | ||
659 | return; | ||
660 | |||
661 | if (!mrq) | ||
662 | return; | ||
663 | |||
664 | if (cmd->data && (cmd->error == 0) && | ||
665 | (cmd->data->error == 0)) { | ||
666 | if (host->dodma && (!host->dma_complete)) { | ||
667 | dbg(host, dbg_dma, "DMA Missing!\n"); | ||
668 | return; | ||
669 | } | ||
670 | } | ||
671 | |||
672 | /* Read response from controller. */ | ||
673 | cmd->resp[0] = readl(host->base + S3C2410_SDIRSP0); | ||
674 | cmd->resp[1] = readl(host->base + S3C2410_SDIRSP1); | ||
675 | cmd->resp[2] = readl(host->base + S3C2410_SDIRSP2); | ||
676 | cmd->resp[3] = readl(host->base + S3C2410_SDIRSP3); | ||
677 | |||
678 | writel(host->prescaler, host->base + S3C2410_SDIPRE); | ||
679 | |||
680 | if (cmd->error) | ||
681 | debug_as_failure = 1; | ||
682 | |||
683 | if (cmd->data && cmd->data->error) | ||
684 | debug_as_failure = 1; | ||
685 | |||
686 | dbg_dumpcmd(host, cmd, debug_as_failure); | ||
687 | |||
688 | /* Cleanup controller */ | ||
689 | writel(0, host->base + S3C2410_SDICMDARG); | ||
690 | writel(S3C2410_SDIDCON_STOP, host->base + S3C2410_SDIDCON); | ||
691 | writel(0, host->base + S3C2410_SDICMDCON); | ||
692 | writel(0, host->base + host->sdiimsk); | ||
693 | |||
694 | if (cmd->data && cmd->error) | ||
695 | cmd->data->error = cmd->error; | ||
696 | |||
697 | if (cmd->data && cmd->data->stop && (!host->cmd_is_stop)) { | ||
698 | host->cmd_is_stop = 1; | ||
699 | s3cmci_send_request(host->mmc); | ||
700 | return; | ||
701 | } | ||
702 | |||
703 | /* If we have no data transfer we are finished here */ | ||
704 | if (!mrq->data) | ||
705 | goto request_done; | ||
706 | |||
707 | /* Calulate the amout of bytes transfer if there was no error */ | ||
708 | if (mrq->data->error == 0) { | ||
709 | mrq->data->bytes_xfered = | ||
710 | (mrq->data->blocks * mrq->data->blksz); | ||
711 | } else { | ||
712 | mrq->data->bytes_xfered = 0; | ||
713 | } | ||
714 | |||
715 | /* If we had an error while transfering data we flush the | ||
716 | * DMA channel and the fifo to clear out any garbage. */ | ||
717 | if (mrq->data->error != 0) { | ||
718 | if (host->dodma) | ||
719 | s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH); | ||
720 | |||
721 | if (host->is2440) { | ||
722 | /* Clear failure register and reset fifo. */ | ||
723 | writel(S3C2440_SDIFSTA_FIFORESET | | ||
724 | S3C2440_SDIFSTA_FIFOFAIL, | ||
725 | host->base + S3C2410_SDIFSTA); | ||
726 | } else { | ||
727 | u32 mci_con; | ||
728 | |||
729 | /* reset fifo */ | ||
730 | mci_con = readl(host->base + S3C2410_SDICON); | ||
731 | mci_con |= S3C2410_SDICON_FIFORESET; | ||
732 | |||
733 | writel(mci_con, host->base + S3C2410_SDICON); | ||
734 | } | ||
735 | } | ||
736 | |||
737 | request_done: | ||
738 | host->complete_what = COMPLETION_NONE; | ||
739 | host->mrq = NULL; | ||
740 | mmc_request_done(host->mmc, mrq); | ||
741 | } | ||
742 | |||
743 | |||
744 | void s3cmci_dma_setup(struct s3cmci_host *host, enum s3c2410_dmasrc source) | ||
745 | { | ||
746 | static enum s3c2410_dmasrc last_source = -1; | ||
747 | static int setup_ok; | ||
748 | |||
749 | if (last_source == source) | ||
750 | return; | ||
751 | |||
752 | last_source = source; | ||
753 | |||
754 | s3c2410_dma_devconfig(host->dma, source, 3, | ||
755 | host->mem->start + host->sdidata); | ||
756 | |||
757 | if (!setup_ok) { | ||
758 | s3c2410_dma_config(host->dma, 4, | ||
759 | (S3C2410_DCON_HWTRIG | S3C2410_DCON_CH0_SDI)); | ||
760 | s3c2410_dma_set_buffdone_fn(host->dma, | ||
761 | s3cmci_dma_done_callback); | ||
762 | s3c2410_dma_setflags(host->dma, S3C2410_DMAF_AUTOSTART); | ||
763 | setup_ok = 1; | ||
764 | } | ||
765 | } | ||
766 | |||
767 | static void s3cmci_send_command(struct s3cmci_host *host, | ||
768 | struct mmc_command *cmd) | ||
769 | { | ||
770 | u32 ccon, imsk; | ||
771 | |||
772 | imsk = S3C2410_SDIIMSK_CRCSTATUS | S3C2410_SDIIMSK_CMDTIMEOUT | | ||
773 | S3C2410_SDIIMSK_RESPONSEND | S3C2410_SDIIMSK_CMDSENT | | ||
774 | S3C2410_SDIIMSK_RESPONSECRC; | ||
775 | |||
776 | enable_imask(host, imsk); | ||
777 | |||
778 | if (cmd->data) | ||
779 | host->complete_what = COMPLETION_XFERFINISH_RSPFIN; | ||
780 | else if (cmd->flags & MMC_RSP_PRESENT) | ||
781 | host->complete_what = COMPLETION_RSPFIN; | ||
782 | else | ||
783 | host->complete_what = COMPLETION_CMDSENT; | ||
784 | |||
785 | writel(cmd->arg, host->base + S3C2410_SDICMDARG); | ||
786 | |||
787 | ccon = cmd->opcode & S3C2410_SDICMDCON_INDEX; | ||
788 | ccon |= S3C2410_SDICMDCON_SENDERHOST | S3C2410_SDICMDCON_CMDSTART; | ||
789 | |||
790 | if (cmd->flags & MMC_RSP_PRESENT) | ||
791 | ccon |= S3C2410_SDICMDCON_WAITRSP; | ||
792 | |||
793 | if (cmd->flags & MMC_RSP_136) | ||
794 | ccon |= S3C2410_SDICMDCON_LONGRSP; | ||
795 | |||
796 | writel(ccon, host->base + S3C2410_SDICMDCON); | ||
797 | } | ||
798 | |||
799 | static int s3cmci_setup_data(struct s3cmci_host *host, struct mmc_data *data) | ||
800 | { | ||
801 | u32 dcon, imsk, stoptries = 3; | ||
802 | |||
803 | /* write DCON register */ | ||
804 | |||
805 | if (!data) { | ||
806 | writel(0, host->base + S3C2410_SDIDCON); | ||
807 | return 0; | ||
808 | } | ||
809 | |||
810 | if ((data->blksz & 3) != 0) { | ||
811 | /* We cannot deal with unaligned blocks with more than | ||
812 | * one block being transfered. */ | ||
813 | |||
814 | if (data->blocks > 1) | ||
815 | return -EINVAL; | ||
816 | |||
817 | /* No support yet for non-word block transfers. */ | ||
818 | return -EINVAL; | ||
819 | } | ||
820 | |||
821 | while (readl(host->base + S3C2410_SDIDSTA) & | ||
822 | (S3C2410_SDIDSTA_TXDATAON | S3C2410_SDIDSTA_RXDATAON)) { | ||
823 | |||
824 | dbg(host, dbg_err, | ||
825 | "mci_setup_data() transfer stillin progress.\n"); | ||
826 | |||
827 | writel(S3C2410_SDIDCON_STOP, host->base + S3C2410_SDIDCON); | ||
828 | s3cmci_reset(host); | ||
829 | |||
830 | if ((stoptries--) == 0) { | ||
831 | dbg_dumpregs(host, "DRF"); | ||
832 | return -EINVAL; | ||
833 | } | ||
834 | } | ||
835 | |||
836 | dcon = data->blocks & S3C2410_SDIDCON_BLKNUM_MASK; | ||
837 | |||
838 | if (host->dodma) | ||
839 | dcon |= S3C2410_SDIDCON_DMAEN; | ||
840 | |||
841 | if (host->bus_width == MMC_BUS_WIDTH_4) | ||
842 | dcon |= S3C2410_SDIDCON_WIDEBUS; | ||
843 | |||
844 | if (!(data->flags & MMC_DATA_STREAM)) | ||
845 | dcon |= S3C2410_SDIDCON_BLOCKMODE; | ||
846 | |||
847 | if (data->flags & MMC_DATA_WRITE) { | ||
848 | dcon |= S3C2410_SDIDCON_TXAFTERRESP; | ||
849 | dcon |= S3C2410_SDIDCON_XFER_TXSTART; | ||
850 | } | ||
851 | |||
852 | if (data->flags & MMC_DATA_READ) { | ||
853 | dcon |= S3C2410_SDIDCON_RXAFTERCMD; | ||
854 | dcon |= S3C2410_SDIDCON_XFER_RXSTART; | ||
855 | } | ||
856 | |||
857 | if (host->is2440) { | ||
858 | dcon |= S3C2440_SDIDCON_DS_WORD; | ||
859 | dcon |= S3C2440_SDIDCON_DATSTART; | ||
860 | } | ||
861 | |||
862 | writel(dcon, host->base + S3C2410_SDIDCON); | ||
863 | |||
864 | /* write BSIZE register */ | ||
865 | |||
866 | writel(data->blksz, host->base + S3C2410_SDIBSIZE); | ||
867 | |||
868 | /* add to IMASK register */ | ||
869 | imsk = S3C2410_SDIIMSK_FIFOFAIL | S3C2410_SDIIMSK_DATACRC | | ||
870 | S3C2410_SDIIMSK_DATATIMEOUT | S3C2410_SDIIMSK_DATAFINISH; | ||
871 | |||
872 | enable_imask(host, imsk); | ||
873 | |||
874 | /* write TIMER register */ | ||
875 | |||
876 | if (host->is2440) { | ||
877 | writel(0x007FFFFF, host->base + S3C2410_SDITIMER); | ||
878 | } else { | ||
879 | writel(0x0000FFFF, host->base + S3C2410_SDITIMER); | ||
880 | |||
881 | /* FIX: set slow clock to prevent timeouts on read */ | ||
882 | if (data->flags & MMC_DATA_READ) | ||
883 | writel(0xFF, host->base + S3C2410_SDIPRE); | ||
884 | } | ||
885 | |||
886 | return 0; | ||
887 | } | ||
888 | |||
889 | #define BOTH_DIR (MMC_DATA_WRITE | MMC_DATA_READ) | ||
890 | |||
891 | static int s3cmci_prepare_pio(struct s3cmci_host *host, struct mmc_data *data) | ||
892 | { | ||
893 | int rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0; | ||
894 | |||
895 | BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR); | ||
896 | |||
897 | host->pio_sgptr = 0; | ||
898 | host->pio_words = 0; | ||
899 | host->pio_count = 0; | ||
900 | host->pio_active = rw ? XFER_WRITE : XFER_READ; | ||
901 | |||
902 | if (rw) { | ||
903 | do_pio_write(host); | ||
904 | enable_imask(host, S3C2410_SDIIMSK_TXFIFOHALF); | ||
905 | } else { | ||
906 | enable_imask(host, S3C2410_SDIIMSK_RXFIFOHALF | ||
907 | | S3C2410_SDIIMSK_RXFIFOLAST); | ||
908 | } | ||
909 | |||
910 | return 0; | ||
911 | } | ||
912 | |||
913 | static int s3cmci_prepare_dma(struct s3cmci_host *host, struct mmc_data *data) | ||
914 | { | ||
915 | int dma_len, i; | ||
916 | int rw = (data->flags & MMC_DATA_WRITE) ? 1 : 0; | ||
917 | |||
918 | BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR); | ||
919 | |||
920 | s3cmci_dma_setup(host, rw ? S3C2410_DMASRC_MEM : S3C2410_DMASRC_HW); | ||
921 | s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH); | ||
922 | |||
923 | dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, | ||
924 | (rw) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); | ||
925 | |||
926 | if (dma_len == 0) | ||
927 | return -ENOMEM; | ||
928 | |||
929 | host->dma_complete = 0; | ||
930 | host->dmatogo = dma_len; | ||
931 | |||
932 | for (i = 0; i < dma_len; i++) { | ||
933 | int res; | ||
934 | |||
935 | dbg(host, dbg_dma, "enqueue %i:%u@%u\n", i, | ||
936 | sg_dma_address(&data->sg[i]), | ||
937 | sg_dma_len(&data->sg[i])); | ||
938 | |||
939 | res = s3c2410_dma_enqueue(host->dma, (void *) host, | ||
940 | sg_dma_address(&data->sg[i]), | ||
941 | sg_dma_len(&data->sg[i])); | ||
942 | |||
943 | if (res) { | ||
944 | s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH); | ||
945 | return -EBUSY; | ||
946 | } | ||
947 | } | ||
948 | |||
949 | s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_START); | ||
950 | |||
951 | return 0; | ||
952 | } | ||
953 | |||
954 | static void s3cmci_send_request(struct mmc_host *mmc) | ||
955 | { | ||
956 | struct s3cmci_host *host = mmc_priv(mmc); | ||
957 | struct mmc_request *mrq = host->mrq; | ||
958 | struct mmc_command *cmd = host->cmd_is_stop ? mrq->stop : mrq->cmd; | ||
959 | |||
960 | host->ccnt++; | ||
961 | prepare_dbgmsg(host, cmd, host->cmd_is_stop); | ||
962 | |||
963 | /* Clear command, data and fifo status registers | ||
964 | Fifo clear only necessary on 2440, but doesn't hurt on 2410 | ||
965 | */ | ||
966 | writel(0xFFFFFFFF, host->base + S3C2410_SDICMDSTAT); | ||
967 | writel(0xFFFFFFFF, host->base + S3C2410_SDIDSTA); | ||
968 | writel(0xFFFFFFFF, host->base + S3C2410_SDIFSTA); | ||
969 | |||
970 | if (cmd->data) { | ||
971 | int res = s3cmci_setup_data(host, cmd->data); | ||
972 | |||
973 | host->dcnt++; | ||
974 | |||
975 | if (res) { | ||
976 | dbg(host, dbg_err, "setup data error %d\n", res); | ||
977 | cmd->error = res; | ||
978 | cmd->data->error = res; | ||
979 | |||
980 | mmc_request_done(mmc, mrq); | ||
981 | return; | ||
982 | } | ||
983 | |||
984 | if (host->dodma) | ||
985 | res = s3cmci_prepare_dma(host, cmd->data); | ||
986 | else | ||
987 | res = s3cmci_prepare_pio(host, cmd->data); | ||
988 | |||
989 | if (res) { | ||
990 | dbg(host, dbg_err, "data prepare error %d\n", res); | ||
991 | cmd->error = res; | ||
992 | cmd->data->error = res; | ||
993 | |||
994 | mmc_request_done(mmc, mrq); | ||
995 | return; | ||
996 | } | ||
997 | } | ||
998 | |||
999 | /* Send command */ | ||
1000 | s3cmci_send_command(host, cmd); | ||
1001 | |||
1002 | /* Enable Interrupt */ | ||
1003 | enable_irq(host->irq); | ||
1004 | } | ||
1005 | |||
1006 | static int s3cmci_card_present(struct s3cmci_host *host) | ||
1007 | { | ||
1008 | struct s3c24xx_mci_pdata *pdata = host->pdata; | ||
1009 | int ret; | ||
1010 | |||
1011 | if (pdata->gpio_detect == 0) | ||
1012 | return -ENOSYS; | ||
1013 | |||
1014 | ret = s3c2410_gpio_getpin(pdata->gpio_detect) ? 0 : 1; | ||
1015 | return ret ^ pdata->detect_invert; | ||
1016 | } | ||
1017 | |||
1018 | static void s3cmci_request(struct mmc_host *mmc, struct mmc_request *mrq) | ||
1019 | { | ||
1020 | struct s3cmci_host *host = mmc_priv(mmc); | ||
1021 | |||
1022 | host->status = "mmc request"; | ||
1023 | host->cmd_is_stop = 0; | ||
1024 | host->mrq = mrq; | ||
1025 | |||
1026 | if (s3cmci_card_present(host) == 0) { | ||
1027 | dbg(host, dbg_err, "%s: no medium present\n", __func__); | ||
1028 | host->mrq->cmd->error = -ENOMEDIUM; | ||
1029 | mmc_request_done(mmc, mrq); | ||
1030 | } else | ||
1031 | s3cmci_send_request(mmc); | ||
1032 | } | ||
1033 | |||
1034 | static void s3cmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | ||
1035 | { | ||
1036 | struct s3cmci_host *host = mmc_priv(mmc); | ||
1037 | u32 mci_psc, mci_con; | ||
1038 | |||
1039 | /* Set the power state */ | ||
1040 | |||
1041 | mci_con = readl(host->base + S3C2410_SDICON); | ||
1042 | |||
1043 | switch (ios->power_mode) { | ||
1044 | case MMC_POWER_ON: | ||
1045 | case MMC_POWER_UP: | ||
1046 | s3c2410_gpio_cfgpin(S3C2410_GPE5, S3C2410_GPE5_SDCLK); | ||
1047 | s3c2410_gpio_cfgpin(S3C2410_GPE6, S3C2410_GPE6_SDCMD); | ||
1048 | s3c2410_gpio_cfgpin(S3C2410_GPE7, S3C2410_GPE7_SDDAT0); | ||
1049 | s3c2410_gpio_cfgpin(S3C2410_GPE8, S3C2410_GPE8_SDDAT1); | ||
1050 | s3c2410_gpio_cfgpin(S3C2410_GPE9, S3C2410_GPE9_SDDAT2); | ||
1051 | s3c2410_gpio_cfgpin(S3C2410_GPE10, S3C2410_GPE10_SDDAT3); | ||
1052 | |||
1053 | if (host->pdata->set_power) | ||
1054 | host->pdata->set_power(ios->power_mode, ios->vdd); | ||
1055 | |||
1056 | if (!host->is2440) | ||
1057 | mci_con |= S3C2410_SDICON_FIFORESET; | ||
1058 | |||
1059 | break; | ||
1060 | |||
1061 | case MMC_POWER_OFF: | ||
1062 | default: | ||
1063 | s3c2410_gpio_setpin(S3C2410_GPE5, 0); | ||
1064 | s3c2410_gpio_cfgpin(S3C2410_GPE5, S3C2410_GPE5_OUTP); | ||
1065 | |||
1066 | if (host->is2440) | ||
1067 | mci_con |= S3C2440_SDICON_SDRESET; | ||
1068 | |||
1069 | if (host->pdata->set_power) | ||
1070 | host->pdata->set_power(ios->power_mode, ios->vdd); | ||
1071 | |||
1072 | break; | ||
1073 | } | ||
1074 | |||
1075 | /* Set clock */ | ||
1076 | for (mci_psc = 0; mci_psc < 255; mci_psc++) { | ||
1077 | host->real_rate = host->clk_rate / (host->clk_div*(mci_psc+1)); | ||
1078 | |||
1079 | if (host->real_rate <= ios->clock) | ||
1080 | break; | ||
1081 | } | ||
1082 | |||
1083 | if (mci_psc > 255) | ||
1084 | mci_psc = 255; | ||
1085 | |||
1086 | host->prescaler = mci_psc; | ||
1087 | writel(host->prescaler, host->base + S3C2410_SDIPRE); | ||
1088 | |||
1089 | /* If requested clock is 0, real_rate will be 0, too */ | ||
1090 | if (ios->clock == 0) | ||
1091 | host->real_rate = 0; | ||
1092 | |||
1093 | /* Set CLOCK_ENABLE */ | ||
1094 | if (ios->clock) | ||
1095 | mci_con |= S3C2410_SDICON_CLOCKTYPE; | ||
1096 | else | ||
1097 | mci_con &= ~S3C2410_SDICON_CLOCKTYPE; | ||
1098 | |||
1099 | writel(mci_con, host->base + S3C2410_SDICON); | ||
1100 | |||
1101 | if ((ios->power_mode == MMC_POWER_ON) || | ||
1102 | (ios->power_mode == MMC_POWER_UP)) { | ||
1103 | dbg(host, dbg_conf, "running at %lukHz (requested: %ukHz).\n", | ||
1104 | host->real_rate/1000, ios->clock/1000); | ||
1105 | } else { | ||
1106 | dbg(host, dbg_conf, "powered down.\n"); | ||
1107 | } | ||
1108 | |||
1109 | host->bus_width = ios->bus_width; | ||
1110 | } | ||
1111 | |||
1112 | static void s3cmci_reset(struct s3cmci_host *host) | ||
1113 | { | ||
1114 | u32 con = readl(host->base + S3C2410_SDICON); | ||
1115 | |||
1116 | con |= S3C2440_SDICON_SDRESET; | ||
1117 | writel(con, host->base + S3C2410_SDICON); | ||
1118 | } | ||
1119 | |||
1120 | static int s3cmci_get_ro(struct mmc_host *mmc) | ||
1121 | { | ||
1122 | struct s3cmci_host *host = mmc_priv(mmc); | ||
1123 | struct s3c24xx_mci_pdata *pdata = host->pdata; | ||
1124 | int ret; | ||
1125 | |||
1126 | if (pdata->gpio_wprotect == 0) | ||
1127 | return 0; | ||
1128 | |||
1129 | ret = s3c2410_gpio_getpin(pdata->gpio_wprotect); | ||
1130 | |||
1131 | if (pdata->wprotect_invert) | ||
1132 | ret = !ret; | ||
1133 | |||
1134 | return ret; | ||
1135 | } | ||
1136 | |||
1137 | static struct mmc_host_ops s3cmci_ops = { | ||
1138 | .request = s3cmci_request, | ||
1139 | .set_ios = s3cmci_set_ios, | ||
1140 | .get_ro = s3cmci_get_ro, | ||
1141 | }; | ||
1142 | |||
1143 | static struct s3c24xx_mci_pdata s3cmci_def_pdata = { | ||
1144 | /* This is currently here to avoid a number of if (host->pdata) | ||
1145 | * checks. Any zero fields to ensure reaonable defaults are picked. */ | ||
1146 | }; | ||
1147 | |||
1148 | static int __devinit s3cmci_probe(struct platform_device *pdev, int is2440) | ||
1149 | { | ||
1150 | struct s3cmci_host *host; | ||
1151 | struct mmc_host *mmc; | ||
1152 | int ret; | ||
1153 | |||
1154 | mmc = mmc_alloc_host(sizeof(struct s3cmci_host), &pdev->dev); | ||
1155 | if (!mmc) { | ||
1156 | ret = -ENOMEM; | ||
1157 | goto probe_out; | ||
1158 | } | ||
1159 | |||
1160 | host = mmc_priv(mmc); | ||
1161 | host->mmc = mmc; | ||
1162 | host->pdev = pdev; | ||
1163 | host->is2440 = is2440; | ||
1164 | |||
1165 | host->pdata = pdev->dev.platform_data; | ||
1166 | if (!host->pdata) { | ||
1167 | pdev->dev.platform_data = &s3cmci_def_pdata; | ||
1168 | host->pdata = &s3cmci_def_pdata; | ||
1169 | } | ||
1170 | |||
1171 | spin_lock_init(&host->complete_lock); | ||
1172 | tasklet_init(&host->pio_tasklet, pio_tasklet, (unsigned long) host); | ||
1173 | |||
1174 | if (is2440) { | ||
1175 | host->sdiimsk = S3C2440_SDIIMSK; | ||
1176 | host->sdidata = S3C2440_SDIDATA; | ||
1177 | host->clk_div = 1; | ||
1178 | } else { | ||
1179 | host->sdiimsk = S3C2410_SDIIMSK; | ||
1180 | host->sdidata = S3C2410_SDIDATA; | ||
1181 | host->clk_div = 2; | ||
1182 | } | ||
1183 | |||
1184 | host->dodma = 0; | ||
1185 | host->complete_what = COMPLETION_NONE; | ||
1186 | host->pio_active = XFER_NONE; | ||
1187 | |||
1188 | host->dma = S3CMCI_DMA; | ||
1189 | |||
1190 | host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
1191 | if (!host->mem) { | ||
1192 | dev_err(&pdev->dev, | ||
1193 | "failed to get io memory region resouce.\n"); | ||
1194 | |||
1195 | ret = -ENOENT; | ||
1196 | goto probe_free_host; | ||
1197 | } | ||
1198 | |||
1199 | host->mem = request_mem_region(host->mem->start, | ||
1200 | RESSIZE(host->mem), pdev->name); | ||
1201 | |||
1202 | if (!host->mem) { | ||
1203 | dev_err(&pdev->dev, "failed to request io memory region.\n"); | ||
1204 | ret = -ENOENT; | ||
1205 | goto probe_free_host; | ||
1206 | } | ||
1207 | |||
1208 | host->base = ioremap(host->mem->start, RESSIZE(host->mem)); | ||
1209 | if (host->base == 0) { | ||
1210 | dev_err(&pdev->dev, "failed to ioremap() io memory region.\n"); | ||
1211 | ret = -EINVAL; | ||
1212 | goto probe_free_mem_region; | ||
1213 | } | ||
1214 | |||
1215 | host->irq = platform_get_irq(pdev, 0); | ||
1216 | if (host->irq == 0) { | ||
1217 | dev_err(&pdev->dev, "failed to get interrupt resouce.\n"); | ||
1218 | ret = -EINVAL; | ||
1219 | goto probe_iounmap; | ||
1220 | } | ||
1221 | |||
1222 | if (request_irq(host->irq, s3cmci_irq, 0, DRIVER_NAME, host)) { | ||
1223 | dev_err(&pdev->dev, "failed to request mci interrupt.\n"); | ||
1224 | ret = -ENOENT; | ||
1225 | goto probe_iounmap; | ||
1226 | } | ||
1227 | |||
1228 | /* We get spurious interrupts even when we have set the IMSK | ||
1229 | * register to ignore everything, so use disable_irq() to make | ||
1230 | * ensure we don't lock the system with un-serviceable requests. */ | ||
1231 | |||
1232 | disable_irq(host->irq); | ||
1233 | |||
1234 | host->irq_cd = s3c2410_gpio_getirq(host->pdata->gpio_detect); | ||
1235 | |||
1236 | if (host->irq_cd >= 0) { | ||
1237 | if (request_irq(host->irq_cd, s3cmci_irq_cd, | ||
1238 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | ||
1239 | DRIVER_NAME, host)) { | ||
1240 | dev_err(&pdev->dev, "can't get card detect irq.\n"); | ||
1241 | ret = -ENOENT; | ||
1242 | goto probe_free_irq; | ||
1243 | } | ||
1244 | } else { | ||
1245 | dev_warn(&pdev->dev, "host detect has no irq available\n"); | ||
1246 | s3c2410_gpio_cfgpin(host->pdata->gpio_detect, | ||
1247 | S3C2410_GPIO_INPUT); | ||
1248 | } | ||
1249 | |||
1250 | if (host->pdata->gpio_wprotect) | ||
1251 | s3c2410_gpio_cfgpin(host->pdata->gpio_wprotect, | ||
1252 | S3C2410_GPIO_INPUT); | ||
1253 | |||
1254 | if (s3c2410_dma_request(S3CMCI_DMA, &s3cmci_dma_client, NULL) < 0) { | ||
1255 | dev_err(&pdev->dev, "unable to get DMA channel.\n"); | ||
1256 | ret = -EBUSY; | ||
1257 | goto probe_free_irq_cd; | ||
1258 | } | ||
1259 | |||
1260 | host->clk = clk_get(&pdev->dev, "sdi"); | ||
1261 | if (IS_ERR(host->clk)) { | ||
1262 | dev_err(&pdev->dev, "failed to find clock source.\n"); | ||
1263 | ret = PTR_ERR(host->clk); | ||
1264 | host->clk = NULL; | ||
1265 | goto probe_free_host; | ||
1266 | } | ||
1267 | |||
1268 | ret = clk_enable(host->clk); | ||
1269 | if (ret) { | ||
1270 | dev_err(&pdev->dev, "failed to enable clock source.\n"); | ||
1271 | goto clk_free; | ||
1272 | } | ||
1273 | |||
1274 | host->clk_rate = clk_get_rate(host->clk); | ||
1275 | |||
1276 | mmc->ops = &s3cmci_ops; | ||
1277 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | ||
1278 | mmc->caps = MMC_CAP_4_BIT_DATA; | ||
1279 | mmc->f_min = host->clk_rate / (host->clk_div * 256); | ||
1280 | mmc->f_max = host->clk_rate / host->clk_div; | ||
1281 | |||
1282 | if (host->pdata->ocr_avail) | ||
1283 | mmc->ocr_avail = host->pdata->ocr_avail; | ||
1284 | |||
1285 | mmc->max_blk_count = 4095; | ||
1286 | mmc->max_blk_size = 4095; | ||
1287 | mmc->max_req_size = 4095 * 512; | ||
1288 | mmc->max_seg_size = mmc->max_req_size; | ||
1289 | |||
1290 | mmc->max_phys_segs = 128; | ||
1291 | mmc->max_hw_segs = 128; | ||
1292 | |||
1293 | dbg(host, dbg_debug, | ||
1294 | "probe: mode:%s mapped mci_base:%p irq:%u irq_cd:%u dma:%u.\n", | ||
1295 | (host->is2440?"2440":""), | ||
1296 | host->base, host->irq, host->irq_cd, host->dma); | ||
1297 | |||
1298 | ret = mmc_add_host(mmc); | ||
1299 | if (ret) { | ||
1300 | dev_err(&pdev->dev, "failed to add mmc host.\n"); | ||
1301 | goto free_dmabuf; | ||
1302 | } | ||
1303 | |||
1304 | platform_set_drvdata(pdev, mmc); | ||
1305 | dev_info(&pdev->dev, "initialisation done.\n"); | ||
1306 | |||
1307 | return 0; | ||
1308 | |||
1309 | free_dmabuf: | ||
1310 | clk_disable(host->clk); | ||
1311 | |||
1312 | clk_free: | ||
1313 | clk_put(host->clk); | ||
1314 | |||
1315 | probe_free_irq_cd: | ||
1316 | if (host->irq_cd >= 0) | ||
1317 | free_irq(host->irq_cd, host); | ||
1318 | |||
1319 | probe_free_irq: | ||
1320 | free_irq(host->irq, host); | ||
1321 | |||
1322 | probe_iounmap: | ||
1323 | iounmap(host->base); | ||
1324 | |||
1325 | probe_free_mem_region: | ||
1326 | release_mem_region(host->mem->start, RESSIZE(host->mem)); | ||
1327 | |||
1328 | probe_free_host: | ||
1329 | mmc_free_host(mmc); | ||
1330 | probe_out: | ||
1331 | return ret; | ||
1332 | } | ||
1333 | |||
1334 | static int __devexit s3cmci_remove(struct platform_device *pdev) | ||
1335 | { | ||
1336 | struct mmc_host *mmc = platform_get_drvdata(pdev); | ||
1337 | struct s3cmci_host *host = mmc_priv(mmc); | ||
1338 | |||
1339 | mmc_remove_host(mmc); | ||
1340 | |||
1341 | clk_disable(host->clk); | ||
1342 | clk_put(host->clk); | ||
1343 | |||
1344 | tasklet_disable(&host->pio_tasklet); | ||
1345 | s3c2410_dma_free(S3CMCI_DMA, &s3cmci_dma_client); | ||
1346 | |||
1347 | if (host->irq_cd >= 0) | ||
1348 | free_irq(host->irq_cd, host); | ||
1349 | free_irq(host->irq, host); | ||
1350 | |||
1351 | iounmap(host->base); | ||
1352 | release_mem_region(host->mem->start, RESSIZE(host->mem)); | ||
1353 | |||
1354 | mmc_free_host(mmc); | ||
1355 | return 0; | ||
1356 | } | ||
1357 | |||
1358 | static int __devinit s3cmci_probe_2410(struct platform_device *dev) | ||
1359 | { | ||
1360 | return s3cmci_probe(dev, 0); | ||
1361 | } | ||
1362 | |||
1363 | static int __devinit s3cmci_probe_2412(struct platform_device *dev) | ||
1364 | { | ||
1365 | return s3cmci_probe(dev, 1); | ||
1366 | } | ||
1367 | |||
1368 | static int __devinit s3cmci_probe_2440(struct platform_device *dev) | ||
1369 | { | ||
1370 | return s3cmci_probe(dev, 1); | ||
1371 | } | ||
1372 | |||
1373 | #ifdef CONFIG_PM | ||
1374 | |||
1375 | static int s3cmci_suspend(struct platform_device *dev, pm_message_t state) | ||
1376 | { | ||
1377 | struct mmc_host *mmc = platform_get_drvdata(dev); | ||
1378 | |||
1379 | return mmc_suspend_host(mmc, state); | ||
1380 | } | ||
1381 | |||
1382 | static int s3cmci_resume(struct platform_device *dev) | ||
1383 | { | ||
1384 | struct mmc_host *mmc = platform_get_drvdata(dev); | ||
1385 | |||
1386 | return mmc_resume_host(mmc); | ||
1387 | } | ||
1388 | |||
1389 | #else /* CONFIG_PM */ | ||
1390 | #define s3cmci_suspend NULL | ||
1391 | #define s3cmci_resume NULL | ||
1392 | #endif /* CONFIG_PM */ | ||
1393 | |||
1394 | |||
1395 | static struct platform_driver s3cmci_driver_2410 = { | ||
1396 | .driver.name = "s3c2410-sdi", | ||
1397 | .driver.owner = THIS_MODULE, | ||
1398 | .probe = s3cmci_probe_2410, | ||
1399 | .remove = __devexit_p(s3cmci_remove), | ||
1400 | .suspend = s3cmci_suspend, | ||
1401 | .resume = s3cmci_resume, | ||
1402 | }; | ||
1403 | |||
1404 | static struct platform_driver s3cmci_driver_2412 = { | ||
1405 | .driver.name = "s3c2412-sdi", | ||
1406 | .driver.owner = THIS_MODULE, | ||
1407 | .probe = s3cmci_probe_2412, | ||
1408 | .remove = __devexit_p(s3cmci_remove), | ||
1409 | .suspend = s3cmci_suspend, | ||
1410 | .resume = s3cmci_resume, | ||
1411 | }; | ||
1412 | |||
1413 | static struct platform_driver s3cmci_driver_2440 = { | ||
1414 | .driver.name = "s3c2440-sdi", | ||
1415 | .driver.owner = THIS_MODULE, | ||
1416 | .probe = s3cmci_probe_2440, | ||
1417 | .remove = __devexit_p(s3cmci_remove), | ||
1418 | .suspend = s3cmci_suspend, | ||
1419 | .resume = s3cmci_resume, | ||
1420 | }; | ||
1421 | |||
1422 | |||
1423 | static int __init s3cmci_init(void) | ||
1424 | { | ||
1425 | platform_driver_register(&s3cmci_driver_2410); | ||
1426 | platform_driver_register(&s3cmci_driver_2412); | ||
1427 | platform_driver_register(&s3cmci_driver_2440); | ||
1428 | return 0; | ||
1429 | } | ||
1430 | |||
1431 | static void __exit s3cmci_exit(void) | ||
1432 | { | ||
1433 | platform_driver_unregister(&s3cmci_driver_2410); | ||
1434 | platform_driver_unregister(&s3cmci_driver_2412); | ||
1435 | platform_driver_unregister(&s3cmci_driver_2440); | ||
1436 | } | ||
1437 | |||
1438 | module_init(s3cmci_init); | ||
1439 | module_exit(s3cmci_exit); | ||
1440 | |||
1441 | MODULE_DESCRIPTION("Samsung S3C MMC/SD Card Interface driver"); | ||
1442 | MODULE_LICENSE("GPL v2"); | ||
1443 | MODULE_AUTHOR("Thomas Kleffel <tk@maintech.de>"); | ||
1444 | MODULE_ALIAS("platform:s3c2410-sdi"); | ||
1445 | MODULE_ALIAS("platform:s3c2412-sdi"); | ||
1446 | MODULE_ALIAS("platform:s3c2440-sdi"); | ||
diff --git a/drivers/mmc/host/s3cmci.h b/drivers/mmc/host/s3cmci.h new file mode 100644 index 000000000000..37d9c60010c9 --- /dev/null +++ b/drivers/mmc/host/s3cmci.h | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * linux/drivers/mmc/s3cmci.h - Samsung S3C MCI driver | ||
3 | * | ||
4 | * Copyright (C) 2004-2006 Thomas Kleffel, All Rights Reserved. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | /* FIXME: DMA Resource management ?! */ | ||
12 | #define S3CMCI_DMA 0 | ||
13 | |||
14 | enum s3cmci_waitfor { | ||
15 | COMPLETION_NONE, | ||
16 | COMPLETION_FINALIZE, | ||
17 | COMPLETION_CMDSENT, | ||
18 | COMPLETION_RSPFIN, | ||
19 | COMPLETION_XFERFINISH, | ||
20 | COMPLETION_XFERFINISH_RSPFIN, | ||
21 | }; | ||
22 | |||
23 | struct s3cmci_host { | ||
24 | struct platform_device *pdev; | ||
25 | struct s3c24xx_mci_pdata *pdata; | ||
26 | struct mmc_host *mmc; | ||
27 | struct resource *mem; | ||
28 | struct clk *clk; | ||
29 | void __iomem *base; | ||
30 | int irq; | ||
31 | int irq_cd; | ||
32 | int dma; | ||
33 | |||
34 | unsigned long clk_rate; | ||
35 | unsigned long clk_div; | ||
36 | unsigned long real_rate; | ||
37 | u8 prescaler; | ||
38 | |||
39 | int is2440; | ||
40 | unsigned sdiimsk; | ||
41 | unsigned sdidata; | ||
42 | int dodma; | ||
43 | int dmatogo; | ||
44 | |||
45 | struct mmc_request *mrq; | ||
46 | int cmd_is_stop; | ||
47 | |||
48 | spinlock_t complete_lock; | ||
49 | enum s3cmci_waitfor complete_what; | ||
50 | |||
51 | int dma_complete; | ||
52 | |||
53 | u32 pio_sgptr; | ||
54 | u32 pio_words; | ||
55 | u32 pio_count; | ||
56 | u32 *pio_ptr; | ||
57 | #define XFER_NONE 0 | ||
58 | #define XFER_READ 1 | ||
59 | #define XFER_WRITE 2 | ||
60 | u32 pio_active; | ||
61 | |||
62 | int bus_width; | ||
63 | |||
64 | char dbgmsg_cmd[301]; | ||
65 | char dbgmsg_dat[301]; | ||
66 | char *status; | ||
67 | |||
68 | unsigned int ccnt, dcnt; | ||
69 | struct tasklet_struct pio_tasklet; | ||
70 | }; | ||
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c new file mode 100644 index 000000000000..deb607c52c0d --- /dev/null +++ b/drivers/mmc/host/sdhci-pci.c | |||
@@ -0,0 +1,732 @@ | |||
1 | /* linux/drivers/mmc/host/sdhci-pci.c - SDHCI on PCI bus interface | ||
2 | * | ||
3 | * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved. | ||
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 (at | ||
8 | * your option) any later version. | ||
9 | * | ||
10 | * Thanks to the following companies for their support: | ||
11 | * | ||
12 | * - JMicron (hardware and technical support) | ||
13 | */ | ||
14 | |||
15 | #include <linux/delay.h> | ||
16 | #include <linux/highmem.h> | ||
17 | #include <linux/pci.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | |||
20 | #include <linux/mmc/host.h> | ||
21 | |||
22 | #include <asm/scatterlist.h> | ||
23 | #include <asm/io.h> | ||
24 | |||
25 | #include "sdhci.h" | ||
26 | |||
27 | /* | ||
28 | * PCI registers | ||
29 | */ | ||
30 | |||
31 | #define PCI_SDHCI_IFPIO 0x00 | ||
32 | #define PCI_SDHCI_IFDMA 0x01 | ||
33 | #define PCI_SDHCI_IFVENDOR 0x02 | ||
34 | |||
35 | #define PCI_SLOT_INFO 0x40 /* 8 bits */ | ||
36 | #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7) | ||
37 | #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07 | ||
38 | |||
39 | #define MAX_SLOTS 8 | ||
40 | |||
41 | struct sdhci_pci_chip; | ||
42 | struct sdhci_pci_slot; | ||
43 | |||
44 | struct sdhci_pci_fixes { | ||
45 | unsigned int quirks; | ||
46 | |||
47 | int (*probe)(struct sdhci_pci_chip*); | ||
48 | |||
49 | int (*probe_slot)(struct sdhci_pci_slot*); | ||
50 | void (*remove_slot)(struct sdhci_pci_slot*, int); | ||
51 | |||
52 | int (*suspend)(struct sdhci_pci_chip*, | ||
53 | pm_message_t); | ||
54 | int (*resume)(struct sdhci_pci_chip*); | ||
55 | }; | ||
56 | |||
57 | struct sdhci_pci_slot { | ||
58 | struct sdhci_pci_chip *chip; | ||
59 | struct sdhci_host *host; | ||
60 | |||
61 | int pci_bar; | ||
62 | }; | ||
63 | |||
64 | struct sdhci_pci_chip { | ||
65 | struct pci_dev *pdev; | ||
66 | |||
67 | unsigned int quirks; | ||
68 | const struct sdhci_pci_fixes *fixes; | ||
69 | |||
70 | int num_slots; /* Slots on controller */ | ||
71 | struct sdhci_pci_slot *slots[MAX_SLOTS]; /* Pointers to host slots */ | ||
72 | }; | ||
73 | |||
74 | |||
75 | /*****************************************************************************\ | ||
76 | * * | ||
77 | * Hardware specific quirk handling * | ||
78 | * * | ||
79 | \*****************************************************************************/ | ||
80 | |||
81 | static int ricoh_probe(struct sdhci_pci_chip *chip) | ||
82 | { | ||
83 | if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) | ||
84 | chip->quirks |= SDHCI_QUIRK_CLOCK_BEFORE_RESET; | ||
85 | |||
86 | if (chip->pdev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG) | ||
87 | chip->quirks |= SDHCI_QUIRK_NO_CARD_NO_RESET; | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | static const struct sdhci_pci_fixes sdhci_ricoh = { | ||
93 | .probe = ricoh_probe, | ||
94 | .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR, | ||
95 | }; | ||
96 | |||
97 | static const struct sdhci_pci_fixes sdhci_ene_712 = { | ||
98 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | | ||
99 | SDHCI_QUIRK_BROKEN_DMA, | ||
100 | }; | ||
101 | |||
102 | static const struct sdhci_pci_fixes sdhci_ene_714 = { | ||
103 | .quirks = SDHCI_QUIRK_SINGLE_POWER_WRITE | | ||
104 | SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS | | ||
105 | SDHCI_QUIRK_BROKEN_DMA, | ||
106 | }; | ||
107 | |||
108 | static const struct sdhci_pci_fixes sdhci_cafe = { | ||
109 | .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | | ||
110 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, | ||
111 | }; | ||
112 | |||
113 | static int jmicron_pmos(struct sdhci_pci_chip *chip, int on) | ||
114 | { | ||
115 | u8 scratch; | ||
116 | int ret; | ||
117 | |||
118 | ret = pci_read_config_byte(chip->pdev, 0xAE, &scratch); | ||
119 | if (ret) | ||
120 | return ret; | ||
121 | |||
122 | /* | ||
123 | * Turn PMOS on [bit 0], set over current detection to 2.4 V | ||
124 | * [bit 1:2] and enable over current debouncing [bit 6]. | ||
125 | */ | ||
126 | if (on) | ||
127 | scratch |= 0x47; | ||
128 | else | ||
129 | scratch &= ~0x47; | ||
130 | |||
131 | ret = pci_write_config_byte(chip->pdev, 0xAE, scratch); | ||
132 | if (ret) | ||
133 | return ret; | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | static int jmicron_probe(struct sdhci_pci_chip *chip) | ||
139 | { | ||
140 | int ret; | ||
141 | |||
142 | if (chip->pdev->revision == 0) { | ||
143 | chip->quirks |= SDHCI_QUIRK_32BIT_DMA_ADDR | | ||
144 | SDHCI_QUIRK_32BIT_DMA_SIZE | | ||
145 | SDHCI_QUIRK_32BIT_ADMA_SIZE | | ||
146 | SDHCI_QUIRK_RESET_AFTER_REQUEST; | ||
147 | } | ||
148 | |||
149 | /* | ||
150 | * JMicron chips can have two interfaces to the same hardware | ||
151 | * in order to work around limitations in Microsoft's driver. | ||
152 | * We need to make sure we only bind to one of them. | ||
153 | * | ||
154 | * This code assumes two things: | ||
155 | * | ||
156 | * 1. The PCI code adds subfunctions in order. | ||
157 | * | ||
158 | * 2. The MMC interface has a lower subfunction number | ||
159 | * than the SD interface. | ||
160 | */ | ||
161 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_SD) { | ||
162 | struct pci_dev *sd_dev; | ||
163 | |||
164 | sd_dev = NULL; | ||
165 | while ((sd_dev = pci_get_device(PCI_VENDOR_ID_JMICRON, | ||
166 | PCI_DEVICE_ID_JMICRON_JMB38X_MMC, sd_dev)) != NULL) { | ||
167 | if ((PCI_SLOT(chip->pdev->devfn) == | ||
168 | PCI_SLOT(sd_dev->devfn)) && | ||
169 | (chip->pdev->bus == sd_dev->bus)) | ||
170 | break; | ||
171 | } | ||
172 | |||
173 | if (sd_dev) { | ||
174 | pci_dev_put(sd_dev); | ||
175 | dev_info(&chip->pdev->dev, "Refusing to bind to " | ||
176 | "secondary interface.\n"); | ||
177 | return -ENODEV; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | /* | ||
182 | * JMicron chips need a bit of a nudge to enable the power | ||
183 | * output pins. | ||
184 | */ | ||
185 | ret = jmicron_pmos(chip, 1); | ||
186 | if (ret) { | ||
187 | dev_err(&chip->pdev->dev, "Failure enabling card power\n"); | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | static void jmicron_enable_mmc(struct sdhci_host *host, int on) | ||
195 | { | ||
196 | u8 scratch; | ||
197 | |||
198 | scratch = readb(host->ioaddr + 0xC0); | ||
199 | |||
200 | if (on) | ||
201 | scratch |= 0x01; | ||
202 | else | ||
203 | scratch &= ~0x01; | ||
204 | |||
205 | writeb(scratch, host->ioaddr + 0xC0); | ||
206 | } | ||
207 | |||
208 | static int jmicron_probe_slot(struct sdhci_pci_slot *slot) | ||
209 | { | ||
210 | if (slot->chip->pdev->revision == 0) { | ||
211 | u16 version; | ||
212 | |||
213 | version = readl(slot->host->ioaddr + SDHCI_HOST_VERSION); | ||
214 | version = (version & SDHCI_VENDOR_VER_MASK) >> | ||
215 | SDHCI_VENDOR_VER_SHIFT; | ||
216 | |||
217 | /* | ||
218 | * Older versions of the chip have lots of nasty glitches | ||
219 | * in the ADMA engine. It's best just to avoid it | ||
220 | * completely. | ||
221 | */ | ||
222 | if (version < 0xAC) | ||
223 | slot->host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; | ||
224 | } | ||
225 | |||
226 | /* | ||
227 | * The secondary interface requires a bit set to get the | ||
228 | * interrupts. | ||
229 | */ | ||
230 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) | ||
231 | jmicron_enable_mmc(slot->host, 1); | ||
232 | |||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead) | ||
237 | { | ||
238 | if (dead) | ||
239 | return; | ||
240 | |||
241 | if (slot->chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) | ||
242 | jmicron_enable_mmc(slot->host, 0); | ||
243 | } | ||
244 | |||
245 | static int jmicron_suspend(struct sdhci_pci_chip *chip, pm_message_t state) | ||
246 | { | ||
247 | int i; | ||
248 | |||
249 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) { | ||
250 | for (i = 0;i < chip->num_slots;i++) | ||
251 | jmicron_enable_mmc(chip->slots[i]->host, 0); | ||
252 | } | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | static int jmicron_resume(struct sdhci_pci_chip *chip) | ||
258 | { | ||
259 | int ret, i; | ||
260 | |||
261 | if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC) { | ||
262 | for (i = 0;i < chip->num_slots;i++) | ||
263 | jmicron_enable_mmc(chip->slots[i]->host, 1); | ||
264 | } | ||
265 | |||
266 | ret = jmicron_pmos(chip, 1); | ||
267 | if (ret) { | ||
268 | dev_err(&chip->pdev->dev, "Failure enabling card power\n"); | ||
269 | return ret; | ||
270 | } | ||
271 | |||
272 | return 0; | ||
273 | } | ||
274 | |||
275 | static const struct sdhci_pci_fixes sdhci_jmicron = { | ||
276 | .probe = jmicron_probe, | ||
277 | |||
278 | .probe_slot = jmicron_probe_slot, | ||
279 | .remove_slot = jmicron_remove_slot, | ||
280 | |||
281 | .suspend = jmicron_suspend, | ||
282 | .resume = jmicron_resume, | ||
283 | }; | ||
284 | |||
285 | static const struct pci_device_id pci_ids[] __devinitdata = { | ||
286 | { | ||
287 | .vendor = PCI_VENDOR_ID_RICOH, | ||
288 | .device = PCI_DEVICE_ID_RICOH_R5C822, | ||
289 | .subvendor = PCI_ANY_ID, | ||
290 | .subdevice = PCI_ANY_ID, | ||
291 | .driver_data = (kernel_ulong_t)&sdhci_ricoh, | ||
292 | }, | ||
293 | |||
294 | { | ||
295 | .vendor = PCI_VENDOR_ID_ENE, | ||
296 | .device = PCI_DEVICE_ID_ENE_CB712_SD, | ||
297 | .subvendor = PCI_ANY_ID, | ||
298 | .subdevice = PCI_ANY_ID, | ||
299 | .driver_data = (kernel_ulong_t)&sdhci_ene_712, | ||
300 | }, | ||
301 | |||
302 | { | ||
303 | .vendor = PCI_VENDOR_ID_ENE, | ||
304 | .device = PCI_DEVICE_ID_ENE_CB712_SD_2, | ||
305 | .subvendor = PCI_ANY_ID, | ||
306 | .subdevice = PCI_ANY_ID, | ||
307 | .driver_data = (kernel_ulong_t)&sdhci_ene_712, | ||
308 | }, | ||
309 | |||
310 | { | ||
311 | .vendor = PCI_VENDOR_ID_ENE, | ||
312 | .device = PCI_DEVICE_ID_ENE_CB714_SD, | ||
313 | .subvendor = PCI_ANY_ID, | ||
314 | .subdevice = PCI_ANY_ID, | ||
315 | .driver_data = (kernel_ulong_t)&sdhci_ene_714, | ||
316 | }, | ||
317 | |||
318 | { | ||
319 | .vendor = PCI_VENDOR_ID_ENE, | ||
320 | .device = PCI_DEVICE_ID_ENE_CB714_SD_2, | ||
321 | .subvendor = PCI_ANY_ID, | ||
322 | .subdevice = PCI_ANY_ID, | ||
323 | .driver_data = (kernel_ulong_t)&sdhci_ene_714, | ||
324 | }, | ||
325 | |||
326 | { | ||
327 | .vendor = PCI_VENDOR_ID_MARVELL, | ||
328 | .device = PCI_DEVICE_ID_MARVELL_CAFE_SD, | ||
329 | .subvendor = PCI_ANY_ID, | ||
330 | .subdevice = PCI_ANY_ID, | ||
331 | .driver_data = (kernel_ulong_t)&sdhci_cafe, | ||
332 | }, | ||
333 | |||
334 | { | ||
335 | .vendor = PCI_VENDOR_ID_JMICRON, | ||
336 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD, | ||
337 | .subvendor = PCI_ANY_ID, | ||
338 | .subdevice = PCI_ANY_ID, | ||
339 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, | ||
340 | }, | ||
341 | |||
342 | { | ||
343 | .vendor = PCI_VENDOR_ID_JMICRON, | ||
344 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_MMC, | ||
345 | .subvendor = PCI_ANY_ID, | ||
346 | .subdevice = PCI_ANY_ID, | ||
347 | .driver_data = (kernel_ulong_t)&sdhci_jmicron, | ||
348 | }, | ||
349 | |||
350 | { /* Generic SD host controller */ | ||
351 | PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) | ||
352 | }, | ||
353 | |||
354 | { /* end: all zeroes */ }, | ||
355 | }; | ||
356 | |||
357 | MODULE_DEVICE_TABLE(pci, pci_ids); | ||
358 | |||
359 | /*****************************************************************************\ | ||
360 | * * | ||
361 | * SDHCI core callbacks * | ||
362 | * * | ||
363 | \*****************************************************************************/ | ||
364 | |||
365 | static int sdhci_pci_enable_dma(struct sdhci_host *host) | ||
366 | { | ||
367 | struct sdhci_pci_slot *slot; | ||
368 | struct pci_dev *pdev; | ||
369 | int ret; | ||
370 | |||
371 | slot = sdhci_priv(host); | ||
372 | pdev = slot->chip->pdev; | ||
373 | |||
374 | if (((pdev->class & 0xFFFF00) == (PCI_CLASS_SYSTEM_SDHCI << 8)) && | ||
375 | ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) && | ||
376 | (host->flags & SDHCI_USE_DMA)) { | ||
377 | dev_warn(&pdev->dev, "Will use DMA mode even though HW " | ||
378 | "doesn't fully claim to support it.\n"); | ||
379 | } | ||
380 | |||
381 | ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK); | ||
382 | if (ret) | ||
383 | return ret; | ||
384 | |||
385 | pci_set_master(pdev); | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | static struct sdhci_ops sdhci_pci_ops = { | ||
391 | .enable_dma = sdhci_pci_enable_dma, | ||
392 | }; | ||
393 | |||
394 | /*****************************************************************************\ | ||
395 | * * | ||
396 | * Suspend/resume * | ||
397 | * * | ||
398 | \*****************************************************************************/ | ||
399 | |||
400 | #ifdef CONFIG_PM | ||
401 | |||
402 | static int sdhci_pci_suspend (struct pci_dev *pdev, pm_message_t state) | ||
403 | { | ||
404 | struct sdhci_pci_chip *chip; | ||
405 | struct sdhci_pci_slot *slot; | ||
406 | int i, ret; | ||
407 | |||
408 | chip = pci_get_drvdata(pdev); | ||
409 | if (!chip) | ||
410 | return 0; | ||
411 | |||
412 | for (i = 0;i < chip->num_slots;i++) { | ||
413 | slot = chip->slots[i]; | ||
414 | if (!slot) | ||
415 | continue; | ||
416 | |||
417 | ret = sdhci_suspend_host(slot->host, state); | ||
418 | |||
419 | if (ret) { | ||
420 | for (i--;i >= 0;i--) | ||
421 | sdhci_resume_host(chip->slots[i]->host); | ||
422 | return ret; | ||
423 | } | ||
424 | } | ||
425 | |||
426 | if (chip->fixes && chip->fixes->suspend) { | ||
427 | ret = chip->fixes->suspend(chip, state); | ||
428 | if (ret) { | ||
429 | for (i = chip->num_slots - 1;i >= 0;i--) | ||
430 | sdhci_resume_host(chip->slots[i]->host); | ||
431 | return ret; | ||
432 | } | ||
433 | } | ||
434 | |||
435 | pci_save_state(pdev); | ||
436 | pci_enable_wake(pdev, pci_choose_state(pdev, state), 0); | ||
437 | pci_disable_device(pdev); | ||
438 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | ||
439 | |||
440 | return 0; | ||
441 | } | ||
442 | |||
443 | static int sdhci_pci_resume (struct pci_dev *pdev) | ||
444 | { | ||
445 | struct sdhci_pci_chip *chip; | ||
446 | struct sdhci_pci_slot *slot; | ||
447 | int i, ret; | ||
448 | |||
449 | chip = pci_get_drvdata(pdev); | ||
450 | if (!chip) | ||
451 | return 0; | ||
452 | |||
453 | pci_set_power_state(pdev, PCI_D0); | ||
454 | pci_restore_state(pdev); | ||
455 | ret = pci_enable_device(pdev); | ||
456 | if (ret) | ||
457 | return ret; | ||
458 | |||
459 | if (chip->fixes && chip->fixes->resume) { | ||
460 | ret = chip->fixes->resume(chip); | ||
461 | if (ret) | ||
462 | return ret; | ||
463 | } | ||
464 | |||
465 | for (i = 0;i < chip->num_slots;i++) { | ||
466 | slot = chip->slots[i]; | ||
467 | if (!slot) | ||
468 | continue; | ||
469 | |||
470 | ret = sdhci_resume_host(slot->host); | ||
471 | if (ret) | ||
472 | return ret; | ||
473 | } | ||
474 | |||
475 | return 0; | ||
476 | } | ||
477 | |||
478 | #else /* CONFIG_PM */ | ||
479 | |||
480 | #define sdhci_pci_suspend NULL | ||
481 | #define sdhci_pci_resume NULL | ||
482 | |||
483 | #endif /* CONFIG_PM */ | ||
484 | |||
485 | /*****************************************************************************\ | ||
486 | * * | ||
487 | * Device probing/removal * | ||
488 | * * | ||
489 | \*****************************************************************************/ | ||
490 | |||
491 | static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot( | ||
492 | struct pci_dev *pdev, struct sdhci_pci_chip *chip, int bar) | ||
493 | { | ||
494 | struct sdhci_pci_slot *slot; | ||
495 | struct sdhci_host *host; | ||
496 | |||
497 | resource_size_t addr; | ||
498 | |||
499 | int ret; | ||
500 | |||
501 | if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) { | ||
502 | dev_err(&pdev->dev, "BAR %d is not iomem. Aborting.\n", bar); | ||
503 | return ERR_PTR(-ENODEV); | ||
504 | } | ||
505 | |||
506 | if (pci_resource_len(pdev, bar) != 0x100) { | ||
507 | dev_err(&pdev->dev, "Invalid iomem size. You may " | ||
508 | "experience problems.\n"); | ||
509 | } | ||
510 | |||
511 | if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { | ||
512 | dev_err(&pdev->dev, "Vendor specific interface. Aborting.\n"); | ||
513 | return ERR_PTR(-ENODEV); | ||
514 | } | ||
515 | |||
516 | if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) { | ||
517 | dev_err(&pdev->dev, "Unknown interface. Aborting.\n"); | ||
518 | return ERR_PTR(-ENODEV); | ||
519 | } | ||
520 | |||
521 | host = sdhci_alloc_host(&pdev->dev, sizeof(struct sdhci_pci_slot)); | ||
522 | if (IS_ERR(host)) { | ||
523 | ret = PTR_ERR(host); | ||
524 | goto unmap; | ||
525 | } | ||
526 | |||
527 | slot = sdhci_priv(host); | ||
528 | |||
529 | slot->chip = chip; | ||
530 | slot->host = host; | ||
531 | slot->pci_bar = bar; | ||
532 | |||
533 | host->hw_name = "PCI"; | ||
534 | host->ops = &sdhci_pci_ops; | ||
535 | host->quirks = chip->quirks; | ||
536 | |||
537 | host->irq = pdev->irq; | ||
538 | |||
539 | ret = pci_request_region(pdev, bar, mmc_hostname(host->mmc)); | ||
540 | if (ret) { | ||
541 | dev_err(&pdev->dev, "cannot request region\n"); | ||
542 | return ERR_PTR(ret); | ||
543 | } | ||
544 | |||
545 | addr = pci_resource_start(pdev, bar); | ||
546 | host->ioaddr = ioremap_nocache(addr, pci_resource_len(pdev, bar)); | ||
547 | if (!host->ioaddr) { | ||
548 | dev_err(&pdev->dev, "failed to remap registers\n"); | ||
549 | goto release; | ||
550 | } | ||
551 | |||
552 | if (chip->fixes && chip->fixes->probe_slot) { | ||
553 | ret = chip->fixes->probe_slot(slot); | ||
554 | if (ret) | ||
555 | goto unmap; | ||
556 | } | ||
557 | |||
558 | ret = sdhci_add_host(host); | ||
559 | if (ret) | ||
560 | goto remove; | ||
561 | |||
562 | return slot; | ||
563 | |||
564 | remove: | ||
565 | if (chip->fixes && chip->fixes->remove_slot) | ||
566 | chip->fixes->remove_slot(slot, 0); | ||
567 | |||
568 | unmap: | ||
569 | iounmap(host->ioaddr); | ||
570 | |||
571 | release: | ||
572 | pci_release_region(pdev, bar); | ||
573 | sdhci_free_host(host); | ||
574 | |||
575 | return ERR_PTR(ret); | ||
576 | } | ||
577 | |||
578 | static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot) | ||
579 | { | ||
580 | int dead; | ||
581 | u32 scratch; | ||
582 | |||
583 | dead = 0; | ||
584 | scratch = readl(slot->host->ioaddr + SDHCI_INT_STATUS); | ||
585 | if (scratch == (u32)-1) | ||
586 | dead = 1; | ||
587 | |||
588 | sdhci_remove_host(slot->host, dead); | ||
589 | |||
590 | if (slot->chip->fixes && slot->chip->fixes->remove_slot) | ||
591 | slot->chip->fixes->remove_slot(slot, dead); | ||
592 | |||
593 | pci_release_region(slot->chip->pdev, slot->pci_bar); | ||
594 | |||
595 | sdhci_free_host(slot->host); | ||
596 | } | ||
597 | |||
598 | static int __devinit sdhci_pci_probe(struct pci_dev *pdev, | ||
599 | const struct pci_device_id *ent) | ||
600 | { | ||
601 | struct sdhci_pci_chip *chip; | ||
602 | struct sdhci_pci_slot *slot; | ||
603 | |||
604 | u8 slots, rev, first_bar; | ||
605 | int ret, i; | ||
606 | |||
607 | BUG_ON(pdev == NULL); | ||
608 | BUG_ON(ent == NULL); | ||
609 | |||
610 | pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev); | ||
611 | |||
612 | dev_info(&pdev->dev, "SDHCI controller found [%04x:%04x] (rev %x)\n", | ||
613 | (int)pdev->vendor, (int)pdev->device, (int)rev); | ||
614 | |||
615 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots); | ||
616 | if (ret) | ||
617 | return ret; | ||
618 | |||
619 | slots = PCI_SLOT_INFO_SLOTS(slots) + 1; | ||
620 | dev_dbg(&pdev->dev, "found %d slot(s)\n", slots); | ||
621 | if (slots == 0) | ||
622 | return -ENODEV; | ||
623 | |||
624 | BUG_ON(slots > MAX_SLOTS); | ||
625 | |||
626 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar); | ||
627 | if (ret) | ||
628 | return ret; | ||
629 | |||
630 | first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK; | ||
631 | |||
632 | if (first_bar > 5) { | ||
633 | dev_err(&pdev->dev, "Invalid first BAR. Aborting.\n"); | ||
634 | return -ENODEV; | ||
635 | } | ||
636 | |||
637 | ret = pci_enable_device(pdev); | ||
638 | if (ret) | ||
639 | return ret; | ||
640 | |||
641 | chip = kzalloc(sizeof(struct sdhci_pci_chip), GFP_KERNEL); | ||
642 | if (!chip) { | ||
643 | ret = -ENOMEM; | ||
644 | goto err; | ||
645 | } | ||
646 | |||
647 | chip->pdev = pdev; | ||
648 | chip->fixes = (const struct sdhci_pci_fixes*)ent->driver_data; | ||
649 | if (chip->fixes) | ||
650 | chip->quirks = chip->fixes->quirks; | ||
651 | chip->num_slots = slots; | ||
652 | |||
653 | pci_set_drvdata(pdev, chip); | ||
654 | |||
655 | if (chip->fixes && chip->fixes->probe) { | ||
656 | ret = chip->fixes->probe(chip); | ||
657 | if (ret) | ||
658 | goto free; | ||
659 | } | ||
660 | |||
661 | for (i = 0;i < slots;i++) { | ||
662 | slot = sdhci_pci_probe_slot(pdev, chip, first_bar + i); | ||
663 | if (IS_ERR(slot)) { | ||
664 | for (i--;i >= 0;i--) | ||
665 | sdhci_pci_remove_slot(chip->slots[i]); | ||
666 | ret = PTR_ERR(slot); | ||
667 | goto free; | ||
668 | } | ||
669 | |||
670 | chip->slots[i] = slot; | ||
671 | } | ||
672 | |||
673 | return 0; | ||
674 | |||
675 | free: | ||
676 | pci_set_drvdata(pdev, NULL); | ||
677 | kfree(chip); | ||
678 | |||
679 | err: | ||
680 | pci_disable_device(pdev); | ||
681 | return ret; | ||
682 | } | ||
683 | |||
684 | static void __devexit sdhci_pci_remove(struct pci_dev *pdev) | ||
685 | { | ||
686 | int i; | ||
687 | struct sdhci_pci_chip *chip; | ||
688 | |||
689 | chip = pci_get_drvdata(pdev); | ||
690 | |||
691 | if (chip) { | ||
692 | for (i = 0;i < chip->num_slots; i++) | ||
693 | sdhci_pci_remove_slot(chip->slots[i]); | ||
694 | |||
695 | pci_set_drvdata(pdev, NULL); | ||
696 | kfree(chip); | ||
697 | } | ||
698 | |||
699 | pci_disable_device(pdev); | ||
700 | } | ||
701 | |||
702 | static struct pci_driver sdhci_driver = { | ||
703 | .name = "sdhci-pci", | ||
704 | .id_table = pci_ids, | ||
705 | .probe = sdhci_pci_probe, | ||
706 | .remove = __devexit_p(sdhci_pci_remove), | ||
707 | .suspend = sdhci_pci_suspend, | ||
708 | .resume = sdhci_pci_resume, | ||
709 | }; | ||
710 | |||
711 | /*****************************************************************************\ | ||
712 | * * | ||
713 | * Driver init/exit * | ||
714 | * * | ||
715 | \*****************************************************************************/ | ||
716 | |||
717 | static int __init sdhci_drv_init(void) | ||
718 | { | ||
719 | return pci_register_driver(&sdhci_driver); | ||
720 | } | ||
721 | |||
722 | static void __exit sdhci_drv_exit(void) | ||
723 | { | ||
724 | pci_unregister_driver(&sdhci_driver); | ||
725 | } | ||
726 | |||
727 | module_init(sdhci_drv_init); | ||
728 | module_exit(sdhci_drv_exit); | ||
729 | |||
730 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); | ||
731 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface PCI driver"); | ||
732 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index b413aa6c246b..17701c3da733 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/highmem.h> | 17 | #include <linux/highmem.h> |
18 | #include <linux/pci.h> | 18 | #include <linux/io.h> |
19 | #include <linux/dma-mapping.h> | 19 | #include <linux/dma-mapping.h> |
20 | #include <linux/scatterlist.h> | 20 | #include <linux/scatterlist.h> |
21 | 21 | ||
@@ -32,135 +32,6 @@ | |||
32 | 32 | ||
33 | static unsigned int debug_quirks = 0; | 33 | static unsigned int debug_quirks = 0; |
34 | 34 | ||
35 | /* | ||
36 | * Different quirks to handle when the hardware deviates from a strict | ||
37 | * interpretation of the SDHCI specification. | ||
38 | */ | ||
39 | |||
40 | /* Controller doesn't honor resets unless we touch the clock register */ | ||
41 | #define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0) | ||
42 | /* Controller has bad caps bits, but really supports DMA */ | ||
43 | #define SDHCI_QUIRK_FORCE_DMA (1<<1) | ||
44 | /* Controller doesn't like to be reset when there is no card inserted. */ | ||
45 | #define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2) | ||
46 | /* Controller doesn't like clearing the power reg before a change */ | ||
47 | #define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) | ||
48 | /* Controller has flaky internal state so reset it on each ios change */ | ||
49 | #define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4) | ||
50 | /* Controller has an unusable DMA engine */ | ||
51 | #define SDHCI_QUIRK_BROKEN_DMA (1<<5) | ||
52 | /* Controller can only DMA from 32-bit aligned addresses */ | ||
53 | #define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<6) | ||
54 | /* Controller can only DMA chunk sizes that are a multiple of 32 bits */ | ||
55 | #define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<7) | ||
56 | /* Controller needs to be reset after each request to stay stable */ | ||
57 | #define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<8) | ||
58 | /* Controller needs voltage and power writes to happen separately */ | ||
59 | #define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<9) | ||
60 | /* Controller has an off-by-one issue with timeout value */ | ||
61 | #define SDHCI_QUIRK_INCR_TIMEOUT_CONTROL (1<<10) | ||
62 | |||
63 | static const struct pci_device_id pci_ids[] __devinitdata = { | ||
64 | { | ||
65 | .vendor = PCI_VENDOR_ID_RICOH, | ||
66 | .device = PCI_DEVICE_ID_RICOH_R5C822, | ||
67 | .subvendor = PCI_VENDOR_ID_IBM, | ||
68 | .subdevice = PCI_ANY_ID, | ||
69 | .driver_data = SDHCI_QUIRK_CLOCK_BEFORE_RESET | | ||
70 | SDHCI_QUIRK_FORCE_DMA, | ||
71 | }, | ||
72 | |||
73 | { | ||
74 | .vendor = PCI_VENDOR_ID_RICOH, | ||
75 | .device = PCI_DEVICE_ID_RICOH_R5C822, | ||
76 | .subvendor = PCI_VENDOR_ID_SAMSUNG, | ||
77 | .subdevice = PCI_ANY_ID, | ||
78 | .driver_data = SDHCI_QUIRK_FORCE_DMA | | ||
79 | SDHCI_QUIRK_NO_CARD_NO_RESET, | ||
80 | }, | ||
81 | |||
82 | { | ||
83 | .vendor = PCI_VENDOR_ID_RICOH, | ||
84 | .device = PCI_DEVICE_ID_RICOH_R5C822, | ||
85 | .subvendor = PCI_ANY_ID, | ||
86 | .subdevice = PCI_ANY_ID, | ||
87 | .driver_data = SDHCI_QUIRK_FORCE_DMA, | ||
88 | }, | ||
89 | |||
90 | { | ||
91 | .vendor = PCI_VENDOR_ID_TI, | ||
92 | .device = PCI_DEVICE_ID_TI_XX21_XX11_SD, | ||
93 | .subvendor = PCI_ANY_ID, | ||
94 | .subdevice = PCI_ANY_ID, | ||
95 | .driver_data = SDHCI_QUIRK_FORCE_DMA, | ||
96 | }, | ||
97 | |||
98 | { | ||
99 | .vendor = PCI_VENDOR_ID_ENE, | ||
100 | .device = PCI_DEVICE_ID_ENE_CB712_SD, | ||
101 | .subvendor = PCI_ANY_ID, | ||
102 | .subdevice = PCI_ANY_ID, | ||
103 | .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE | | ||
104 | SDHCI_QUIRK_BROKEN_DMA, | ||
105 | }, | ||
106 | |||
107 | { | ||
108 | .vendor = PCI_VENDOR_ID_ENE, | ||
109 | .device = PCI_DEVICE_ID_ENE_CB712_SD_2, | ||
110 | .subvendor = PCI_ANY_ID, | ||
111 | .subdevice = PCI_ANY_ID, | ||
112 | .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE | | ||
113 | SDHCI_QUIRK_BROKEN_DMA, | ||
114 | }, | ||
115 | |||
116 | { | ||
117 | .vendor = PCI_VENDOR_ID_ENE, | ||
118 | .device = PCI_DEVICE_ID_ENE_CB714_SD, | ||
119 | .subvendor = PCI_ANY_ID, | ||
120 | .subdevice = PCI_ANY_ID, | ||
121 | .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE | | ||
122 | SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS | | ||
123 | SDHCI_QUIRK_BROKEN_DMA, | ||
124 | }, | ||
125 | |||
126 | { | ||
127 | .vendor = PCI_VENDOR_ID_ENE, | ||
128 | .device = PCI_DEVICE_ID_ENE_CB714_SD_2, | ||
129 | .subvendor = PCI_ANY_ID, | ||
130 | .subdevice = PCI_ANY_ID, | ||
131 | .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE | | ||
132 | SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS | | ||
133 | SDHCI_QUIRK_BROKEN_DMA, | ||
134 | }, | ||
135 | |||
136 | { | ||
137 | .vendor = PCI_VENDOR_ID_MARVELL, | ||
138 | .device = PCI_DEVICE_ID_MARVELL_CAFE_SD, | ||
139 | .subvendor = PCI_ANY_ID, | ||
140 | .subdevice = PCI_ANY_ID, | ||
141 | .driver_data = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | | ||
142 | SDHCI_QUIRK_INCR_TIMEOUT_CONTROL, | ||
143 | }, | ||
144 | |||
145 | { | ||
146 | .vendor = PCI_VENDOR_ID_JMICRON, | ||
147 | .device = PCI_DEVICE_ID_JMICRON_JMB38X_SD, | ||
148 | .subvendor = PCI_ANY_ID, | ||
149 | .subdevice = PCI_ANY_ID, | ||
150 | .driver_data = SDHCI_QUIRK_32BIT_DMA_ADDR | | ||
151 | SDHCI_QUIRK_32BIT_DMA_SIZE | | ||
152 | SDHCI_QUIRK_RESET_AFTER_REQUEST, | ||
153 | }, | ||
154 | |||
155 | { /* Generic SD host controller */ | ||
156 | PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) | ||
157 | }, | ||
158 | |||
159 | { /* end: all zeroes */ }, | ||
160 | }; | ||
161 | |||
162 | MODULE_DEVICE_TABLE(pci, pci_ids); | ||
163 | |||
164 | static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *); | 35 | static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *); |
165 | static void sdhci_finish_data(struct sdhci_host *); | 36 | static void sdhci_finish_data(struct sdhci_host *); |
166 | 37 | ||
@@ -215,7 +86,7 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask) | |||
215 | { | 86 | { |
216 | unsigned long timeout; | 87 | unsigned long timeout; |
217 | 88 | ||
218 | if (host->chip->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { | 89 | if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { |
219 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & | 90 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & |
220 | SDHCI_CARD_PRESENT)) | 91 | SDHCI_CARD_PRESENT)) |
221 | return; | 92 | return; |
@@ -253,7 +124,8 @@ static void sdhci_init(struct sdhci_host *host) | |||
253 | SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT | | 124 | SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT | |
254 | SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT | | 125 | SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT | |
255 | SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | | 126 | SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL | |
256 | SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE; | 127 | SDHCI_INT_DMA_END | SDHCI_INT_DATA_END | SDHCI_INT_RESPONSE | |
128 | SDHCI_INT_ADMA_ERROR; | ||
257 | 129 | ||
258 | writel(intmask, host->ioaddr + SDHCI_INT_ENABLE); | 130 | writel(intmask, host->ioaddr + SDHCI_INT_ENABLE); |
259 | writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE); | 131 | writel(intmask, host->ioaddr + SDHCI_SIGNAL_ENABLE); |
@@ -443,23 +315,226 @@ static void sdhci_transfer_pio(struct sdhci_host *host) | |||
443 | DBG("PIO transfer complete.\n"); | 315 | DBG("PIO transfer complete.\n"); |
444 | } | 316 | } |
445 | 317 | ||
446 | static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) | 318 | static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags) |
447 | { | 319 | { |
448 | u8 count; | 320 | local_irq_save(*flags); |
449 | unsigned target_timeout, current_timeout; | 321 | return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset; |
322 | } | ||
450 | 323 | ||
451 | WARN_ON(host->data); | 324 | static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags) |
325 | { | ||
326 | kunmap_atomic(buffer, KM_BIO_SRC_IRQ); | ||
327 | local_irq_restore(*flags); | ||
328 | } | ||
452 | 329 | ||
453 | if (data == NULL) | 330 | static int sdhci_adma_table_pre(struct sdhci_host *host, |
454 | return; | 331 | struct mmc_data *data) |
332 | { | ||
333 | int direction; | ||
455 | 334 | ||
456 | /* Sanity checks */ | 335 | u8 *desc; |
457 | BUG_ON(data->blksz * data->blocks > 524288); | 336 | u8 *align; |
458 | BUG_ON(data->blksz > host->mmc->max_blk_size); | 337 | dma_addr_t addr; |
459 | BUG_ON(data->blocks > 65535); | 338 | dma_addr_t align_addr; |
339 | int len, offset; | ||
460 | 340 | ||
461 | host->data = data; | 341 | struct scatterlist *sg; |
462 | host->data_early = 0; | 342 | int i; |
343 | char *buffer; | ||
344 | unsigned long flags; | ||
345 | |||
346 | /* | ||
347 | * The spec does not specify endianness of descriptor table. | ||
348 | * We currently guess that it is LE. | ||
349 | */ | ||
350 | |||
351 | if (data->flags & MMC_DATA_READ) | ||
352 | direction = DMA_FROM_DEVICE; | ||
353 | else | ||
354 | direction = DMA_TO_DEVICE; | ||
355 | |||
356 | /* | ||
357 | * The ADMA descriptor table is mapped further down as we | ||
358 | * need to fill it with data first. | ||
359 | */ | ||
360 | |||
361 | host->align_addr = dma_map_single(mmc_dev(host->mmc), | ||
362 | host->align_buffer, 128 * 4, direction); | ||
363 | if (dma_mapping_error(host->align_addr)) | ||
364 | goto fail; | ||
365 | BUG_ON(host->align_addr & 0x3); | ||
366 | |||
367 | host->sg_count = dma_map_sg(mmc_dev(host->mmc), | ||
368 | data->sg, data->sg_len, direction); | ||
369 | if (host->sg_count == 0) | ||
370 | goto unmap_align; | ||
371 | |||
372 | desc = host->adma_desc; | ||
373 | align = host->align_buffer; | ||
374 | |||
375 | align_addr = host->align_addr; | ||
376 | |||
377 | for_each_sg(data->sg, sg, host->sg_count, i) { | ||
378 | addr = sg_dma_address(sg); | ||
379 | len = sg_dma_len(sg); | ||
380 | |||
381 | /* | ||
382 | * The SDHCI specification states that ADMA | ||
383 | * addresses must be 32-bit aligned. If they | ||
384 | * aren't, then we use a bounce buffer for | ||
385 | * the (up to three) bytes that screw up the | ||
386 | * alignment. | ||
387 | */ | ||
388 | offset = (4 - (addr & 0x3)) & 0x3; | ||
389 | if (offset) { | ||
390 | if (data->flags & MMC_DATA_WRITE) { | ||
391 | buffer = sdhci_kmap_atomic(sg, &flags); | ||
392 | memcpy(align, buffer, offset); | ||
393 | sdhci_kunmap_atomic(buffer, &flags); | ||
394 | } | ||
395 | |||
396 | desc[7] = (align_addr >> 24) & 0xff; | ||
397 | desc[6] = (align_addr >> 16) & 0xff; | ||
398 | desc[5] = (align_addr >> 8) & 0xff; | ||
399 | desc[4] = (align_addr >> 0) & 0xff; | ||
400 | |||
401 | BUG_ON(offset > 65536); | ||
402 | |||
403 | desc[3] = (offset >> 8) & 0xff; | ||
404 | desc[2] = (offset >> 0) & 0xff; | ||
405 | |||
406 | desc[1] = 0x00; | ||
407 | desc[0] = 0x21; /* tran, valid */ | ||
408 | |||
409 | align += 4; | ||
410 | align_addr += 4; | ||
411 | |||
412 | desc += 8; | ||
413 | |||
414 | addr += offset; | ||
415 | len -= offset; | ||
416 | } | ||
417 | |||
418 | desc[7] = (addr >> 24) & 0xff; | ||
419 | desc[6] = (addr >> 16) & 0xff; | ||
420 | desc[5] = (addr >> 8) & 0xff; | ||
421 | desc[4] = (addr >> 0) & 0xff; | ||
422 | |||
423 | BUG_ON(len > 65536); | ||
424 | |||
425 | desc[3] = (len >> 8) & 0xff; | ||
426 | desc[2] = (len >> 0) & 0xff; | ||
427 | |||
428 | desc[1] = 0x00; | ||
429 | desc[0] = 0x21; /* tran, valid */ | ||
430 | |||
431 | desc += 8; | ||
432 | |||
433 | /* | ||
434 | * If this triggers then we have a calculation bug | ||
435 | * somewhere. :/ | ||
436 | */ | ||
437 | WARN_ON((desc - host->adma_desc) > (128 * 2 + 1) * 4); | ||
438 | } | ||
439 | |||
440 | /* | ||
441 | * Add a terminating entry. | ||
442 | */ | ||
443 | desc[7] = 0; | ||
444 | desc[6] = 0; | ||
445 | desc[5] = 0; | ||
446 | desc[4] = 0; | ||
447 | |||
448 | desc[3] = 0; | ||
449 | desc[2] = 0; | ||
450 | |||
451 | desc[1] = 0x00; | ||
452 | desc[0] = 0x03; /* nop, end, valid */ | ||
453 | |||
454 | /* | ||
455 | * Resync align buffer as we might have changed it. | ||
456 | */ | ||
457 | if (data->flags & MMC_DATA_WRITE) { | ||
458 | dma_sync_single_for_device(mmc_dev(host->mmc), | ||
459 | host->align_addr, 128 * 4, direction); | ||
460 | } | ||
461 | |||
462 | host->adma_addr = dma_map_single(mmc_dev(host->mmc), | ||
463 | host->adma_desc, (128 * 2 + 1) * 4, DMA_TO_DEVICE); | ||
464 | if (dma_mapping_error(host->align_addr)) | ||
465 | goto unmap_entries; | ||
466 | BUG_ON(host->adma_addr & 0x3); | ||
467 | |||
468 | return 0; | ||
469 | |||
470 | unmap_entries: | ||
471 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, | ||
472 | data->sg_len, direction); | ||
473 | unmap_align: | ||
474 | dma_unmap_single(mmc_dev(host->mmc), host->align_addr, | ||
475 | 128 * 4, direction); | ||
476 | fail: | ||
477 | return -EINVAL; | ||
478 | } | ||
479 | |||
480 | static void sdhci_adma_table_post(struct sdhci_host *host, | ||
481 | struct mmc_data *data) | ||
482 | { | ||
483 | int direction; | ||
484 | |||
485 | struct scatterlist *sg; | ||
486 | int i, size; | ||
487 | u8 *align; | ||
488 | char *buffer; | ||
489 | unsigned long flags; | ||
490 | |||
491 | if (data->flags & MMC_DATA_READ) | ||
492 | direction = DMA_FROM_DEVICE; | ||
493 | else | ||
494 | direction = DMA_TO_DEVICE; | ||
495 | |||
496 | dma_unmap_single(mmc_dev(host->mmc), host->adma_addr, | ||
497 | (128 * 2 + 1) * 4, DMA_TO_DEVICE); | ||
498 | |||
499 | dma_unmap_single(mmc_dev(host->mmc), host->align_addr, | ||
500 | 128 * 4, direction); | ||
501 | |||
502 | if (data->flags & MMC_DATA_READ) { | ||
503 | dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg, | ||
504 | data->sg_len, direction); | ||
505 | |||
506 | align = host->align_buffer; | ||
507 | |||
508 | for_each_sg(data->sg, sg, host->sg_count, i) { | ||
509 | if (sg_dma_address(sg) & 0x3) { | ||
510 | size = 4 - (sg_dma_address(sg) & 0x3); | ||
511 | |||
512 | buffer = sdhci_kmap_atomic(sg, &flags); | ||
513 | memcpy(buffer, align, size); | ||
514 | sdhci_kunmap_atomic(buffer, &flags); | ||
515 | |||
516 | align += 4; | ||
517 | } | ||
518 | } | ||
519 | } | ||
520 | |||
521 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, | ||
522 | data->sg_len, direction); | ||
523 | } | ||
524 | |||
525 | static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_data *data) | ||
526 | { | ||
527 | u8 count; | ||
528 | unsigned target_timeout, current_timeout; | ||
529 | |||
530 | /* | ||
531 | * If the host controller provides us with an incorrect timeout | ||
532 | * value, just skip the check and use 0xE. The hardware may take | ||
533 | * longer to time out, but that's much better than having a too-short | ||
534 | * timeout value. | ||
535 | */ | ||
536 | if ((host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL)) | ||
537 | return 0xE; | ||
463 | 538 | ||
464 | /* timeout in us */ | 539 | /* timeout in us */ |
465 | target_timeout = data->timeout_ns / 1000 + | 540 | target_timeout = data->timeout_ns / 1000 + |
@@ -484,52 +559,158 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) | |||
484 | break; | 559 | break; |
485 | } | 560 | } |
486 | 561 | ||
487 | /* | ||
488 | * Compensate for an off-by-one error in the CaFe hardware; otherwise, | ||
489 | * a too-small count gives us interrupt timeouts. | ||
490 | */ | ||
491 | if ((host->chip->quirks & SDHCI_QUIRK_INCR_TIMEOUT_CONTROL)) | ||
492 | count++; | ||
493 | |||
494 | if (count >= 0xF) { | 562 | if (count >= 0xF) { |
495 | printk(KERN_WARNING "%s: Too large timeout requested!\n", | 563 | printk(KERN_WARNING "%s: Too large timeout requested!\n", |
496 | mmc_hostname(host->mmc)); | 564 | mmc_hostname(host->mmc)); |
497 | count = 0xE; | 565 | count = 0xE; |
498 | } | 566 | } |
499 | 567 | ||
568 | return count; | ||
569 | } | ||
570 | |||
571 | static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_data *data) | ||
572 | { | ||
573 | u8 count; | ||
574 | u8 ctrl; | ||
575 | int ret; | ||
576 | |||
577 | WARN_ON(host->data); | ||
578 | |||
579 | if (data == NULL) | ||
580 | return; | ||
581 | |||
582 | /* Sanity checks */ | ||
583 | BUG_ON(data->blksz * data->blocks > 524288); | ||
584 | BUG_ON(data->blksz > host->mmc->max_blk_size); | ||
585 | BUG_ON(data->blocks > 65535); | ||
586 | |||
587 | host->data = data; | ||
588 | host->data_early = 0; | ||
589 | |||
590 | count = sdhci_calc_timeout(host, data); | ||
500 | writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL); | 591 | writeb(count, host->ioaddr + SDHCI_TIMEOUT_CONTROL); |
501 | 592 | ||
502 | if (host->flags & SDHCI_USE_DMA) | 593 | if (host->flags & SDHCI_USE_DMA) |
503 | host->flags |= SDHCI_REQ_USE_DMA; | 594 | host->flags |= SDHCI_REQ_USE_DMA; |
504 | 595 | ||
505 | if (unlikely((host->flags & SDHCI_REQ_USE_DMA) && | 596 | /* |
506 | (host->chip->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) && | 597 | * FIXME: This doesn't account for merging when mapping the |
507 | ((data->blksz * data->blocks) & 0x3))) { | 598 | * scatterlist. |
508 | DBG("Reverting to PIO because of transfer size (%d)\n", | 599 | */ |
509 | data->blksz * data->blocks); | 600 | if (host->flags & SDHCI_REQ_USE_DMA) { |
510 | host->flags &= ~SDHCI_REQ_USE_DMA; | 601 | int broken, i; |
602 | struct scatterlist *sg; | ||
603 | |||
604 | broken = 0; | ||
605 | if (host->flags & SDHCI_USE_ADMA) { | ||
606 | if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) | ||
607 | broken = 1; | ||
608 | } else { | ||
609 | if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) | ||
610 | broken = 1; | ||
611 | } | ||
612 | |||
613 | if (unlikely(broken)) { | ||
614 | for_each_sg(data->sg, sg, data->sg_len, i) { | ||
615 | if (sg->length & 0x3) { | ||
616 | DBG("Reverting to PIO because of " | ||
617 | "transfer size (%d)\n", | ||
618 | sg->length); | ||
619 | host->flags &= ~SDHCI_REQ_USE_DMA; | ||
620 | break; | ||
621 | } | ||
622 | } | ||
623 | } | ||
511 | } | 624 | } |
512 | 625 | ||
513 | /* | 626 | /* |
514 | * The assumption here being that alignment is the same after | 627 | * The assumption here being that alignment is the same after |
515 | * translation to device address space. | 628 | * translation to device address space. |
516 | */ | 629 | */ |
517 | if (unlikely((host->flags & SDHCI_REQ_USE_DMA) && | 630 | if (host->flags & SDHCI_REQ_USE_DMA) { |
518 | (host->chip->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && | 631 | int broken, i; |
519 | (data->sg->offset & 0x3))) { | 632 | struct scatterlist *sg; |
520 | DBG("Reverting to PIO because of bad alignment\n"); | 633 | |
521 | host->flags &= ~SDHCI_REQ_USE_DMA; | 634 | broken = 0; |
635 | if (host->flags & SDHCI_USE_ADMA) { | ||
636 | /* | ||
637 | * As we use 3 byte chunks to work around | ||
638 | * alignment problems, we need to check this | ||
639 | * quirk. | ||
640 | */ | ||
641 | if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) | ||
642 | broken = 1; | ||
643 | } else { | ||
644 | if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) | ||
645 | broken = 1; | ||
646 | } | ||
647 | |||
648 | if (unlikely(broken)) { | ||
649 | for_each_sg(data->sg, sg, data->sg_len, i) { | ||
650 | if (sg->offset & 0x3) { | ||
651 | DBG("Reverting to PIO because of " | ||
652 | "bad alignment\n"); | ||
653 | host->flags &= ~SDHCI_REQ_USE_DMA; | ||
654 | break; | ||
655 | } | ||
656 | } | ||
657 | } | ||
522 | } | 658 | } |
523 | 659 | ||
524 | if (host->flags & SDHCI_REQ_USE_DMA) { | 660 | if (host->flags & SDHCI_REQ_USE_DMA) { |
525 | int count; | 661 | if (host->flags & SDHCI_USE_ADMA) { |
662 | ret = sdhci_adma_table_pre(host, data); | ||
663 | if (ret) { | ||
664 | /* | ||
665 | * This only happens when someone fed | ||
666 | * us an invalid request. | ||
667 | */ | ||
668 | WARN_ON(1); | ||
669 | host->flags &= ~SDHCI_USE_DMA; | ||
670 | } else { | ||
671 | writel(host->adma_addr, | ||
672 | host->ioaddr + SDHCI_ADMA_ADDRESS); | ||
673 | } | ||
674 | } else { | ||
675 | int sg_cnt; | ||
676 | |||
677 | sg_cnt = dma_map_sg(mmc_dev(host->mmc), | ||
678 | data->sg, data->sg_len, | ||
679 | (data->flags & MMC_DATA_READ) ? | ||
680 | DMA_FROM_DEVICE : | ||
681 | DMA_TO_DEVICE); | ||
682 | if (sg_cnt == 0) { | ||
683 | /* | ||
684 | * This only happens when someone fed | ||
685 | * us an invalid request. | ||
686 | */ | ||
687 | WARN_ON(1); | ||
688 | host->flags &= ~SDHCI_USE_DMA; | ||
689 | } else { | ||
690 | WARN_ON(count != 1); | ||
691 | writel(sg_dma_address(data->sg), | ||
692 | host->ioaddr + SDHCI_DMA_ADDRESS); | ||
693 | } | ||
694 | } | ||
695 | } | ||
526 | 696 | ||
527 | count = pci_map_sg(host->chip->pdev, data->sg, data->sg_len, | 697 | /* |
528 | (data->flags & MMC_DATA_READ)?PCI_DMA_FROMDEVICE:PCI_DMA_TODEVICE); | 698 | * Always adjust the DMA selection as some controllers |
529 | BUG_ON(count != 1); | 699 | * (e.g. JMicron) can't do PIO properly when the selection |
700 | * is ADMA. | ||
701 | */ | ||
702 | if (host->version >= SDHCI_SPEC_200) { | ||
703 | ctrl = readb(host->ioaddr + SDHCI_HOST_CONTROL); | ||
704 | ctrl &= ~SDHCI_CTRL_DMA_MASK; | ||
705 | if ((host->flags & SDHCI_REQ_USE_DMA) && | ||
706 | (host->flags & SDHCI_USE_ADMA)) | ||
707 | ctrl |= SDHCI_CTRL_ADMA32; | ||
708 | else | ||
709 | ctrl |= SDHCI_CTRL_SDMA; | ||
710 | writeb(ctrl, host->ioaddr + SDHCI_HOST_CONTROL); | ||
711 | } | ||
530 | 712 | ||
531 | writel(sg_dma_address(data->sg), host->ioaddr + SDHCI_DMA_ADDRESS); | 713 | if (!(host->flags & SDHCI_REQ_USE_DMA)) { |
532 | } else { | ||
533 | host->cur_sg = data->sg; | 714 | host->cur_sg = data->sg; |
534 | host->num_sg = data->sg_len; | 715 | host->num_sg = data->sg_len; |
535 | 716 | ||
@@ -567,7 +748,6 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host, | |||
567 | static void sdhci_finish_data(struct sdhci_host *host) | 748 | static void sdhci_finish_data(struct sdhci_host *host) |
568 | { | 749 | { |
569 | struct mmc_data *data; | 750 | struct mmc_data *data; |
570 | u16 blocks; | ||
571 | 751 | ||
572 | BUG_ON(!host->data); | 752 | BUG_ON(!host->data); |
573 | 753 | ||
@@ -575,25 +755,26 @@ static void sdhci_finish_data(struct sdhci_host *host) | |||
575 | host->data = NULL; | 755 | host->data = NULL; |
576 | 756 | ||
577 | if (host->flags & SDHCI_REQ_USE_DMA) { | 757 | if (host->flags & SDHCI_REQ_USE_DMA) { |
578 | pci_unmap_sg(host->chip->pdev, data->sg, data->sg_len, | 758 | if (host->flags & SDHCI_USE_ADMA) |
579 | (data->flags & MMC_DATA_READ)?PCI_DMA_FROMDEVICE:PCI_DMA_TODEVICE); | 759 | sdhci_adma_table_post(host, data); |
760 | else { | ||
761 | dma_unmap_sg(mmc_dev(host->mmc), data->sg, | ||
762 | data->sg_len, (data->flags & MMC_DATA_READ) ? | ||
763 | DMA_FROM_DEVICE : DMA_TO_DEVICE); | ||
764 | } | ||
580 | } | 765 | } |
581 | 766 | ||
582 | /* | 767 | /* |
583 | * Controller doesn't count down when in single block mode. | 768 | * The specification states that the block count register must |
769 | * be updated, but it does not specify at what point in the | ||
770 | * data flow. That makes the register entirely useless to read | ||
771 | * back so we have to assume that nothing made it to the card | ||
772 | * in the event of an error. | ||
584 | */ | 773 | */ |
585 | if (data->blocks == 1) | 774 | if (data->error) |
586 | blocks = (data->error == 0) ? 0 : 1; | 775 | data->bytes_xfered = 0; |
587 | else | 776 | else |
588 | blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT); | 777 | data->bytes_xfered = data->blksz * data->blocks; |
589 | data->bytes_xfered = data->blksz * (data->blocks - blocks); | ||
590 | |||
591 | if (!data->error && blocks) { | ||
592 | printk(KERN_ERR "%s: Controller signalled completion even " | ||
593 | "though there were blocks left.\n", | ||
594 | mmc_hostname(host->mmc)); | ||
595 | data->error = -EIO; | ||
596 | } | ||
597 | 778 | ||
598 | if (data->stop) { | 779 | if (data->stop) { |
599 | /* | 780 | /* |
@@ -775,7 +956,7 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power) | |||
775 | * Spec says that we should clear the power reg before setting | 956 | * Spec says that we should clear the power reg before setting |
776 | * a new value. Some controllers don't seem to like this though. | 957 | * a new value. Some controllers don't seem to like this though. |
777 | */ | 958 | */ |
778 | if (!(host->chip->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) | 959 | if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) |
779 | writeb(0, host->ioaddr + SDHCI_POWER_CONTROL); | 960 | writeb(0, host->ioaddr + SDHCI_POWER_CONTROL); |
780 | 961 | ||
781 | pwr = SDHCI_POWER_ON; | 962 | pwr = SDHCI_POWER_ON; |
@@ -797,10 +978,10 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power) | |||
797 | } | 978 | } |
798 | 979 | ||
799 | /* | 980 | /* |
800 | * At least the CaFe chip gets confused if we set the voltage | 981 | * At least the Marvell CaFe chip gets confused if we set the voltage |
801 | * and set turn on power at the same time, so set the voltage first. | 982 | * and set turn on power at the same time, so set the voltage first. |
802 | */ | 983 | */ |
803 | if ((host->chip->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER)) | 984 | if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER)) |
804 | writeb(pwr & ~SDHCI_POWER_ON, | 985 | writeb(pwr & ~SDHCI_POWER_ON, |
805 | host->ioaddr + SDHCI_POWER_CONTROL); | 986 | host->ioaddr + SDHCI_POWER_CONTROL); |
806 | 987 | ||
@@ -833,7 +1014,8 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq) | |||
833 | 1014 | ||
834 | host->mrq = mrq; | 1015 | host->mrq = mrq; |
835 | 1016 | ||
836 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { | 1017 | if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT) |
1018 | || (host->flags & SDHCI_DEVICE_DEAD)) { | ||
837 | host->mrq->cmd->error = -ENOMEDIUM; | 1019 | host->mrq->cmd->error = -ENOMEDIUM; |
838 | tasklet_schedule(&host->finish_tasklet); | 1020 | tasklet_schedule(&host->finish_tasklet); |
839 | } else | 1021 | } else |
@@ -853,6 +1035,9 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
853 | 1035 | ||
854 | spin_lock_irqsave(&host->lock, flags); | 1036 | spin_lock_irqsave(&host->lock, flags); |
855 | 1037 | ||
1038 | if (host->flags & SDHCI_DEVICE_DEAD) | ||
1039 | goto out; | ||
1040 | |||
856 | /* | 1041 | /* |
857 | * Reset the chip on each power off. | 1042 | * Reset the chip on each power off. |
858 | * Should clear out any weird states. | 1043 | * Should clear out any weird states. |
@@ -888,9 +1073,10 @@ static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | |||
888 | * signalling timeout and CRC errors even on CMD0. Resetting | 1073 | * signalling timeout and CRC errors even on CMD0. Resetting |
889 | * it on each ios seems to solve the problem. | 1074 | * it on each ios seems to solve the problem. |
890 | */ | 1075 | */ |
891 | if(host->chip->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS) | 1076 | if(host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS) |
892 | sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); | 1077 | sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); |
893 | 1078 | ||
1079 | out: | ||
894 | mmiowb(); | 1080 | mmiowb(); |
895 | spin_unlock_irqrestore(&host->lock, flags); | 1081 | spin_unlock_irqrestore(&host->lock, flags); |
896 | } | 1082 | } |
@@ -905,7 +1091,10 @@ static int sdhci_get_ro(struct mmc_host *mmc) | |||
905 | 1091 | ||
906 | spin_lock_irqsave(&host->lock, flags); | 1092 | spin_lock_irqsave(&host->lock, flags); |
907 | 1093 | ||
908 | present = readl(host->ioaddr + SDHCI_PRESENT_STATE); | 1094 | if (host->flags & SDHCI_DEVICE_DEAD) |
1095 | present = 0; | ||
1096 | else | ||
1097 | present = readl(host->ioaddr + SDHCI_PRESENT_STATE); | ||
909 | 1098 | ||
910 | spin_unlock_irqrestore(&host->lock, flags); | 1099 | spin_unlock_irqrestore(&host->lock, flags); |
911 | 1100 | ||
@@ -922,6 +1111,9 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) | |||
922 | 1111 | ||
923 | spin_lock_irqsave(&host->lock, flags); | 1112 | spin_lock_irqsave(&host->lock, flags); |
924 | 1113 | ||
1114 | if (host->flags & SDHCI_DEVICE_DEAD) | ||
1115 | goto out; | ||
1116 | |||
925 | ier = readl(host->ioaddr + SDHCI_INT_ENABLE); | 1117 | ier = readl(host->ioaddr + SDHCI_INT_ENABLE); |
926 | 1118 | ||
927 | ier &= ~SDHCI_INT_CARD_INT; | 1119 | ier &= ~SDHCI_INT_CARD_INT; |
@@ -931,6 +1123,7 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) | |||
931 | writel(ier, host->ioaddr + SDHCI_INT_ENABLE); | 1123 | writel(ier, host->ioaddr + SDHCI_INT_ENABLE); |
932 | writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE); | 1124 | writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE); |
933 | 1125 | ||
1126 | out: | ||
934 | mmiowb(); | 1127 | mmiowb(); |
935 | 1128 | ||
936 | spin_unlock_irqrestore(&host->lock, flags); | 1129 | spin_unlock_irqrestore(&host->lock, flags); |
@@ -996,13 +1189,14 @@ static void sdhci_tasklet_finish(unsigned long param) | |||
996 | * The controller needs a reset of internal state machines | 1189 | * The controller needs a reset of internal state machines |
997 | * upon error conditions. | 1190 | * upon error conditions. |
998 | */ | 1191 | */ |
999 | if (mrq->cmd->error || | 1192 | if (!(host->flags & SDHCI_DEVICE_DEAD) && |
1000 | (mrq->data && (mrq->data->error || | 1193 | (mrq->cmd->error || |
1001 | (mrq->data->stop && mrq->data->stop->error))) || | 1194 | (mrq->data && (mrq->data->error || |
1002 | (host->chip->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST)) { | 1195 | (mrq->data->stop && mrq->data->stop->error))) || |
1196 | (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) { | ||
1003 | 1197 | ||
1004 | /* Some controllers need this kick or reset won't work here */ | 1198 | /* Some controllers need this kick or reset won't work here */ |
1005 | if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) { | 1199 | if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) { |
1006 | unsigned int clock; | 1200 | unsigned int clock; |
1007 | 1201 | ||
1008 | /* This is to force an update */ | 1202 | /* This is to force an update */ |
@@ -1116,6 +1310,8 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) | |||
1116 | host->data->error = -ETIMEDOUT; | 1310 | host->data->error = -ETIMEDOUT; |
1117 | else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT)) | 1311 | else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT)) |
1118 | host->data->error = -EILSEQ; | 1312 | host->data->error = -EILSEQ; |
1313 | else if (intmask & SDHCI_INT_ADMA_ERROR) | ||
1314 | host->data->error = -EIO; | ||
1119 | 1315 | ||
1120 | if (host->data->error) | 1316 | if (host->data->error) |
1121 | sdhci_finish_data(host); | 1317 | sdhci_finish_data(host); |
@@ -1234,218 +1430,167 @@ out: | |||
1234 | 1430 | ||
1235 | #ifdef CONFIG_PM | 1431 | #ifdef CONFIG_PM |
1236 | 1432 | ||
1237 | static int sdhci_suspend (struct pci_dev *pdev, pm_message_t state) | 1433 | int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state) |
1238 | { | 1434 | { |
1239 | struct sdhci_chip *chip; | 1435 | int ret; |
1240 | int i, ret; | ||
1241 | |||
1242 | chip = pci_get_drvdata(pdev); | ||
1243 | if (!chip) | ||
1244 | return 0; | ||
1245 | |||
1246 | DBG("Suspending...\n"); | ||
1247 | |||
1248 | for (i = 0;i < chip->num_slots;i++) { | ||
1249 | if (!chip->hosts[i]) | ||
1250 | continue; | ||
1251 | ret = mmc_suspend_host(chip->hosts[i]->mmc, state); | ||
1252 | if (ret) { | ||
1253 | for (i--;i >= 0;i--) | ||
1254 | mmc_resume_host(chip->hosts[i]->mmc); | ||
1255 | return ret; | ||
1256 | } | ||
1257 | } | ||
1258 | |||
1259 | pci_save_state(pdev); | ||
1260 | pci_enable_wake(pdev, pci_choose_state(pdev, state), 0); | ||
1261 | 1436 | ||
1262 | for (i = 0;i < chip->num_slots;i++) { | 1437 | ret = mmc_suspend_host(host->mmc, state); |
1263 | if (!chip->hosts[i]) | 1438 | if (ret) |
1264 | continue; | 1439 | return ret; |
1265 | free_irq(chip->hosts[i]->irq, chip->hosts[i]); | ||
1266 | } | ||
1267 | 1440 | ||
1268 | pci_disable_device(pdev); | 1441 | free_irq(host->irq, host); |
1269 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | ||
1270 | 1442 | ||
1271 | return 0; | 1443 | return 0; |
1272 | } | 1444 | } |
1273 | 1445 | ||
1274 | static int sdhci_resume (struct pci_dev *pdev) | 1446 | EXPORT_SYMBOL_GPL(sdhci_suspend_host); |
1275 | { | ||
1276 | struct sdhci_chip *chip; | ||
1277 | int i, ret; | ||
1278 | 1447 | ||
1279 | chip = pci_get_drvdata(pdev); | 1448 | int sdhci_resume_host(struct sdhci_host *host) |
1280 | if (!chip) | 1449 | { |
1281 | return 0; | 1450 | int ret; |
1282 | 1451 | ||
1283 | DBG("Resuming...\n"); | 1452 | if (host->flags & SDHCI_USE_DMA) { |
1453 | if (host->ops->enable_dma) | ||
1454 | host->ops->enable_dma(host); | ||
1455 | } | ||
1284 | 1456 | ||
1285 | pci_set_power_state(pdev, PCI_D0); | 1457 | ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, |
1286 | pci_restore_state(pdev); | 1458 | mmc_hostname(host->mmc), host); |
1287 | ret = pci_enable_device(pdev); | ||
1288 | if (ret) | 1459 | if (ret) |
1289 | return ret; | 1460 | return ret; |
1290 | 1461 | ||
1291 | for (i = 0;i < chip->num_slots;i++) { | 1462 | sdhci_init(host); |
1292 | if (!chip->hosts[i]) | 1463 | mmiowb(); |
1293 | continue; | 1464 | |
1294 | if (chip->hosts[i]->flags & SDHCI_USE_DMA) | 1465 | ret = mmc_resume_host(host->mmc); |
1295 | pci_set_master(pdev); | 1466 | if (ret) |
1296 | ret = request_irq(chip->hosts[i]->irq, sdhci_irq, | 1467 | return ret; |
1297 | IRQF_SHARED, mmc_hostname(chip->hosts[i]->mmc), | ||
1298 | chip->hosts[i]); | ||
1299 | if (ret) | ||
1300 | return ret; | ||
1301 | sdhci_init(chip->hosts[i]); | ||
1302 | mmiowb(); | ||
1303 | ret = mmc_resume_host(chip->hosts[i]->mmc); | ||
1304 | if (ret) | ||
1305 | return ret; | ||
1306 | } | ||
1307 | 1468 | ||
1308 | return 0; | 1469 | return 0; |
1309 | } | 1470 | } |
1310 | 1471 | ||
1311 | #else /* CONFIG_PM */ | 1472 | EXPORT_SYMBOL_GPL(sdhci_resume_host); |
1312 | |||
1313 | #define sdhci_suspend NULL | ||
1314 | #define sdhci_resume NULL | ||
1315 | 1473 | ||
1316 | #endif /* CONFIG_PM */ | 1474 | #endif /* CONFIG_PM */ |
1317 | 1475 | ||
1318 | /*****************************************************************************\ | 1476 | /*****************************************************************************\ |
1319 | * * | 1477 | * * |
1320 | * Device probing/removal * | 1478 | * Device allocation/registration * |
1321 | * * | 1479 | * * |
1322 | \*****************************************************************************/ | 1480 | \*****************************************************************************/ |
1323 | 1481 | ||
1324 | static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | 1482 | struct sdhci_host *sdhci_alloc_host(struct device *dev, |
1483 | size_t priv_size) | ||
1325 | { | 1484 | { |
1326 | int ret; | ||
1327 | unsigned int version; | ||
1328 | struct sdhci_chip *chip; | ||
1329 | struct mmc_host *mmc; | 1485 | struct mmc_host *mmc; |
1330 | struct sdhci_host *host; | 1486 | struct sdhci_host *host; |
1331 | 1487 | ||
1332 | u8 first_bar; | 1488 | WARN_ON(dev == NULL); |
1333 | unsigned int caps; | ||
1334 | |||
1335 | chip = pci_get_drvdata(pdev); | ||
1336 | BUG_ON(!chip); | ||
1337 | |||
1338 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &first_bar); | ||
1339 | if (ret) | ||
1340 | return ret; | ||
1341 | |||
1342 | first_bar &= PCI_SLOT_INFO_FIRST_BAR_MASK; | ||
1343 | |||
1344 | if (first_bar > 5) { | ||
1345 | printk(KERN_ERR DRIVER_NAME ": Invalid first BAR. Aborting.\n"); | ||
1346 | return -ENODEV; | ||
1347 | } | ||
1348 | |||
1349 | if (!(pci_resource_flags(pdev, first_bar + slot) & IORESOURCE_MEM)) { | ||
1350 | printk(KERN_ERR DRIVER_NAME ": BAR is not iomem. Aborting.\n"); | ||
1351 | return -ENODEV; | ||
1352 | } | ||
1353 | |||
1354 | if (pci_resource_len(pdev, first_bar + slot) != 0x100) { | ||
1355 | printk(KERN_ERR DRIVER_NAME ": Invalid iomem size. " | ||
1356 | "You may experience problems.\n"); | ||
1357 | } | ||
1358 | |||
1359 | if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { | ||
1360 | printk(KERN_ERR DRIVER_NAME ": Vendor specific interface. Aborting.\n"); | ||
1361 | return -ENODEV; | ||
1362 | } | ||
1363 | |||
1364 | if ((pdev->class & 0x0000FF) > PCI_SDHCI_IFVENDOR) { | ||
1365 | printk(KERN_ERR DRIVER_NAME ": Unknown interface. Aborting.\n"); | ||
1366 | return -ENODEV; | ||
1367 | } | ||
1368 | 1489 | ||
1369 | mmc = mmc_alloc_host(sizeof(struct sdhci_host), &pdev->dev); | 1490 | mmc = mmc_alloc_host(sizeof(struct sdhci_host) + priv_size, dev); |
1370 | if (!mmc) | 1491 | if (!mmc) |
1371 | return -ENOMEM; | 1492 | return ERR_PTR(-ENOMEM); |
1372 | 1493 | ||
1373 | host = mmc_priv(mmc); | 1494 | host = mmc_priv(mmc); |
1374 | host->mmc = mmc; | 1495 | host->mmc = mmc; |
1375 | 1496 | ||
1376 | host->chip = chip; | 1497 | return host; |
1377 | chip->hosts[slot] = host; | 1498 | } |
1378 | 1499 | ||
1379 | host->bar = first_bar + slot; | 1500 | EXPORT_SYMBOL_GPL(sdhci_alloc_host); |
1380 | 1501 | ||
1381 | host->addr = pci_resource_start(pdev, host->bar); | 1502 | int sdhci_add_host(struct sdhci_host *host) |
1382 | host->irq = pdev->irq; | 1503 | { |
1504 | struct mmc_host *mmc; | ||
1505 | unsigned int caps; | ||
1506 | int ret; | ||
1383 | 1507 | ||
1384 | DBG("slot %d at 0x%08lx, irq %d\n", slot, host->addr, host->irq); | 1508 | WARN_ON(host == NULL); |
1509 | if (host == NULL) | ||
1510 | return -EINVAL; | ||
1385 | 1511 | ||
1386 | ret = pci_request_region(pdev, host->bar, mmc_hostname(mmc)); | 1512 | mmc = host->mmc; |
1387 | if (ret) | ||
1388 | goto free; | ||
1389 | 1513 | ||
1390 | host->ioaddr = ioremap_nocache(host->addr, | 1514 | if (debug_quirks) |
1391 | pci_resource_len(pdev, host->bar)); | 1515 | host->quirks = debug_quirks; |
1392 | if (!host->ioaddr) { | ||
1393 | ret = -ENOMEM; | ||
1394 | goto release; | ||
1395 | } | ||
1396 | 1516 | ||
1397 | sdhci_reset(host, SDHCI_RESET_ALL); | 1517 | sdhci_reset(host, SDHCI_RESET_ALL); |
1398 | 1518 | ||
1399 | version = readw(host->ioaddr + SDHCI_HOST_VERSION); | 1519 | host->version = readw(host->ioaddr + SDHCI_HOST_VERSION); |
1400 | version = (version & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; | 1520 | host->version = (host->version & SDHCI_SPEC_VER_MASK) |
1401 | if (version > 1) { | 1521 | >> SDHCI_SPEC_VER_SHIFT; |
1522 | if (host->version > SDHCI_SPEC_200) { | ||
1402 | printk(KERN_ERR "%s: Unknown controller version (%d). " | 1523 | printk(KERN_ERR "%s: Unknown controller version (%d). " |
1403 | "You may experience problems.\n", mmc_hostname(mmc), | 1524 | "You may experience problems.\n", mmc_hostname(mmc), |
1404 | version); | 1525 | host->version); |
1405 | } | 1526 | } |
1406 | 1527 | ||
1407 | caps = readl(host->ioaddr + SDHCI_CAPABILITIES); | 1528 | caps = readl(host->ioaddr + SDHCI_CAPABILITIES); |
1408 | 1529 | ||
1409 | if (chip->quirks & SDHCI_QUIRK_FORCE_DMA) | 1530 | if (host->quirks & SDHCI_QUIRK_FORCE_DMA) |
1410 | host->flags |= SDHCI_USE_DMA; | 1531 | host->flags |= SDHCI_USE_DMA; |
1411 | else if (!(caps & SDHCI_CAN_DO_DMA)) | 1532 | else if (!(caps & SDHCI_CAN_DO_DMA)) |
1412 | DBG("Controller doesn't have DMA capability\n"); | 1533 | DBG("Controller doesn't have DMA capability\n"); |
1413 | else | 1534 | else |
1414 | host->flags |= SDHCI_USE_DMA; | 1535 | host->flags |= SDHCI_USE_DMA; |
1415 | 1536 | ||
1416 | if ((chip->quirks & SDHCI_QUIRK_BROKEN_DMA) && | 1537 | if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) && |
1417 | (host->flags & SDHCI_USE_DMA)) { | 1538 | (host->flags & SDHCI_USE_DMA)) { |
1418 | DBG("Disabling DMA as it is marked broken\n"); | 1539 | DBG("Disabling DMA as it is marked broken\n"); |
1419 | host->flags &= ~SDHCI_USE_DMA; | 1540 | host->flags &= ~SDHCI_USE_DMA; |
1420 | } | 1541 | } |
1421 | 1542 | ||
1422 | if (((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) && | 1543 | if (host->flags & SDHCI_USE_DMA) { |
1423 | (host->flags & SDHCI_USE_DMA)) { | 1544 | if ((host->version >= SDHCI_SPEC_200) && |
1424 | printk(KERN_WARNING "%s: Will use DMA " | 1545 | (caps & SDHCI_CAN_DO_ADMA2)) |
1425 | "mode even though HW doesn't fully " | 1546 | host->flags |= SDHCI_USE_ADMA; |
1426 | "claim to support it.\n", mmc_hostname(mmc)); | 1547 | } |
1548 | |||
1549 | if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && | ||
1550 | (host->flags & SDHCI_USE_ADMA)) { | ||
1551 | DBG("Disabling ADMA as it is marked broken\n"); | ||
1552 | host->flags &= ~SDHCI_USE_ADMA; | ||
1427 | } | 1553 | } |
1428 | 1554 | ||
1429 | if (host->flags & SDHCI_USE_DMA) { | 1555 | if (host->flags & SDHCI_USE_DMA) { |
1430 | if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { | 1556 | if (host->ops->enable_dma) { |
1431 | printk(KERN_WARNING "%s: No suitable DMA available. " | 1557 | if (host->ops->enable_dma(host)) { |
1432 | "Falling back to PIO.\n", mmc_hostname(mmc)); | 1558 | printk(KERN_WARNING "%s: No suitable DMA " |
1433 | host->flags &= ~SDHCI_USE_DMA; | 1559 | "available. Falling back to PIO.\n", |
1560 | mmc_hostname(mmc)); | ||
1561 | host->flags &= ~(SDHCI_USE_DMA | SDHCI_USE_ADMA); | ||
1562 | } | ||
1434 | } | 1563 | } |
1435 | } | 1564 | } |
1436 | 1565 | ||
1437 | if (host->flags & SDHCI_USE_DMA) | 1566 | if (host->flags & SDHCI_USE_ADMA) { |
1438 | pci_set_master(pdev); | 1567 | /* |
1439 | else /* XXX: Hack to get MMC layer to avoid highmem */ | 1568 | * We need to allocate descriptors for all sg entries |
1440 | pdev->dma_mask = 0; | 1569 | * (128) and potentially one alignment transfer for |
1570 | * each of those entries. | ||
1571 | */ | ||
1572 | host->adma_desc = kmalloc((128 * 2 + 1) * 4, GFP_KERNEL); | ||
1573 | host->align_buffer = kmalloc(128 * 4, GFP_KERNEL); | ||
1574 | if (!host->adma_desc || !host->align_buffer) { | ||
1575 | kfree(host->adma_desc); | ||
1576 | kfree(host->align_buffer); | ||
1577 | printk(KERN_WARNING "%s: Unable to allocate ADMA " | ||
1578 | "buffers. Falling back to standard DMA.\n", | ||
1579 | mmc_hostname(mmc)); | ||
1580 | host->flags &= ~SDHCI_USE_ADMA; | ||
1581 | } | ||
1582 | } | ||
1583 | |||
1584 | /* XXX: Hack to get MMC layer to avoid highmem */ | ||
1585 | if (!(host->flags & SDHCI_USE_DMA)) | ||
1586 | mmc_dev(host->mmc)->dma_mask = NULL; | ||
1441 | 1587 | ||
1442 | host->max_clk = | 1588 | host->max_clk = |
1443 | (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT; | 1589 | (caps & SDHCI_CLOCK_BASE_MASK) >> SDHCI_CLOCK_BASE_SHIFT; |
1444 | if (host->max_clk == 0) { | 1590 | if (host->max_clk == 0) { |
1445 | printk(KERN_ERR "%s: Hardware doesn't specify base clock " | 1591 | printk(KERN_ERR "%s: Hardware doesn't specify base clock " |
1446 | "frequency.\n", mmc_hostname(mmc)); | 1592 | "frequency.\n", mmc_hostname(mmc)); |
1447 | ret = -ENODEV; | 1593 | return -ENODEV; |
1448 | goto unmap; | ||
1449 | } | 1594 | } |
1450 | host->max_clk *= 1000000; | 1595 | host->max_clk *= 1000000; |
1451 | 1596 | ||
@@ -1454,8 +1599,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1454 | if (host->timeout_clk == 0) { | 1599 | if (host->timeout_clk == 0) { |
1455 | printk(KERN_ERR "%s: Hardware doesn't specify timeout clock " | 1600 | printk(KERN_ERR "%s: Hardware doesn't specify timeout clock " |
1456 | "frequency.\n", mmc_hostname(mmc)); | 1601 | "frequency.\n", mmc_hostname(mmc)); |
1457 | ret = -ENODEV; | 1602 | return -ENODEV; |
1458 | goto unmap; | ||
1459 | } | 1603 | } |
1460 | if (caps & SDHCI_TIMEOUT_CLK_UNIT) | 1604 | if (caps & SDHCI_TIMEOUT_CLK_UNIT) |
1461 | host->timeout_clk *= 1000; | 1605 | host->timeout_clk *= 1000; |
@@ -1466,7 +1610,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1466 | mmc->ops = &sdhci_ops; | 1610 | mmc->ops = &sdhci_ops; |
1467 | mmc->f_min = host->max_clk / 256; | 1611 | mmc->f_min = host->max_clk / 256; |
1468 | mmc->f_max = host->max_clk; | 1612 | mmc->f_max = host->max_clk; |
1469 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_SDIO_IRQ; | 1613 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ; |
1470 | 1614 | ||
1471 | if (caps & SDHCI_CAN_DO_HISPD) | 1615 | if (caps & SDHCI_CAN_DO_HISPD) |
1472 | mmc->caps |= MMC_CAP_SD_HIGHSPEED; | 1616 | mmc->caps |= MMC_CAP_SD_HIGHSPEED; |
@@ -1482,20 +1626,22 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1482 | if (mmc->ocr_avail == 0) { | 1626 | if (mmc->ocr_avail == 0) { |
1483 | printk(KERN_ERR "%s: Hardware doesn't report any " | 1627 | printk(KERN_ERR "%s: Hardware doesn't report any " |
1484 | "support voltages.\n", mmc_hostname(mmc)); | 1628 | "support voltages.\n", mmc_hostname(mmc)); |
1485 | ret = -ENODEV; | 1629 | return -ENODEV; |
1486 | goto unmap; | ||
1487 | } | 1630 | } |
1488 | 1631 | ||
1489 | spin_lock_init(&host->lock); | 1632 | spin_lock_init(&host->lock); |
1490 | 1633 | ||
1491 | /* | 1634 | /* |
1492 | * Maximum number of segments. Hardware cannot do scatter lists. | 1635 | * Maximum number of segments. Depends on if the hardware |
1636 | * can do scatter/gather or not. | ||
1493 | */ | 1637 | */ |
1494 | if (host->flags & SDHCI_USE_DMA) | 1638 | if (host->flags & SDHCI_USE_ADMA) |
1639 | mmc->max_hw_segs = 128; | ||
1640 | else if (host->flags & SDHCI_USE_DMA) | ||
1495 | mmc->max_hw_segs = 1; | 1641 | mmc->max_hw_segs = 1; |
1496 | else | 1642 | else /* PIO */ |
1497 | mmc->max_hw_segs = 16; | 1643 | mmc->max_hw_segs = 128; |
1498 | mmc->max_phys_segs = 16; | 1644 | mmc->max_phys_segs = 128; |
1499 | 1645 | ||
1500 | /* | 1646 | /* |
1501 | * Maximum number of sectors in one transfer. Limited by DMA boundary | 1647 | * Maximum number of sectors in one transfer. Limited by DMA boundary |
@@ -1505,9 +1651,13 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1505 | 1651 | ||
1506 | /* | 1652 | /* |
1507 | * Maximum segment size. Could be one segment with the maximum number | 1653 | * Maximum segment size. Could be one segment with the maximum number |
1508 | * of bytes. | 1654 | * of bytes. When doing hardware scatter/gather, each entry cannot |
1655 | * be larger than 64 KiB though. | ||
1509 | */ | 1656 | */ |
1510 | mmc->max_seg_size = mmc->max_req_size; | 1657 | if (host->flags & SDHCI_USE_ADMA) |
1658 | mmc->max_seg_size = 65536; | ||
1659 | else | ||
1660 | mmc->max_seg_size = mmc->max_req_size; | ||
1511 | 1661 | ||
1512 | /* | 1662 | /* |
1513 | * Maximum block size. This varies from controller to controller and | 1663 | * Maximum block size. This varies from controller to controller and |
@@ -1553,7 +1703,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1553 | host->led.default_trigger = mmc_hostname(mmc); | 1703 | host->led.default_trigger = mmc_hostname(mmc); |
1554 | host->led.brightness_set = sdhci_led_control; | 1704 | host->led.brightness_set = sdhci_led_control; |
1555 | 1705 | ||
1556 | ret = led_classdev_register(&pdev->dev, &host->led); | 1706 | ret = led_classdev_register(mmc_dev(mmc), &host->led); |
1557 | if (ret) | 1707 | if (ret) |
1558 | goto reset; | 1708 | goto reset; |
1559 | #endif | 1709 | #endif |
@@ -1562,8 +1712,9 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) | |||
1562 | 1712 | ||
1563 | mmc_add_host(mmc); | 1713 | mmc_add_host(mmc); |
1564 | 1714 | ||
1565 | printk(KERN_INFO "%s: SDHCI at 0x%08lx irq %d %s\n", | 1715 | printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s%s\n", |
1566 | mmc_hostname(mmc), host->addr, host->irq, | 1716 | mmc_hostname(mmc), host->hw_name, mmc_dev(mmc)->bus_id, |
1717 | (host->flags & SDHCI_USE_ADMA)?"A":"", | ||
1567 | (host->flags & SDHCI_USE_DMA)?"DMA":"PIO"); | 1718 | (host->flags & SDHCI_USE_DMA)?"DMA":"PIO"); |
1568 | 1719 | ||
1569 | return 0; | 1720 | return 0; |
@@ -1576,35 +1727,40 @@ reset: | |||
1576 | untasklet: | 1727 | untasklet: |
1577 | tasklet_kill(&host->card_tasklet); | 1728 | tasklet_kill(&host->card_tasklet); |
1578 | tasklet_kill(&host->finish_tasklet); | 1729 | tasklet_kill(&host->finish_tasklet); |
1579 | unmap: | ||
1580 | iounmap(host->ioaddr); | ||
1581 | release: | ||
1582 | pci_release_region(pdev, host->bar); | ||
1583 | free: | ||
1584 | mmc_free_host(mmc); | ||
1585 | 1730 | ||
1586 | return ret; | 1731 | return ret; |
1587 | } | 1732 | } |
1588 | 1733 | ||
1589 | static void sdhci_remove_slot(struct pci_dev *pdev, int slot) | 1734 | EXPORT_SYMBOL_GPL(sdhci_add_host); |
1735 | |||
1736 | void sdhci_remove_host(struct sdhci_host *host, int dead) | ||
1590 | { | 1737 | { |
1591 | struct sdhci_chip *chip; | 1738 | unsigned long flags; |
1592 | struct mmc_host *mmc; | ||
1593 | struct sdhci_host *host; | ||
1594 | 1739 | ||
1595 | chip = pci_get_drvdata(pdev); | 1740 | if (dead) { |
1596 | host = chip->hosts[slot]; | 1741 | spin_lock_irqsave(&host->lock, flags); |
1597 | mmc = host->mmc; | 1742 | |
1743 | host->flags |= SDHCI_DEVICE_DEAD; | ||
1744 | |||
1745 | if (host->mrq) { | ||
1746 | printk(KERN_ERR "%s: Controller removed during " | ||
1747 | " transfer!\n", mmc_hostname(host->mmc)); | ||
1598 | 1748 | ||
1599 | chip->hosts[slot] = NULL; | 1749 | host->mrq->cmd->error = -ENOMEDIUM; |
1750 | tasklet_schedule(&host->finish_tasklet); | ||
1751 | } | ||
1752 | |||
1753 | spin_unlock_irqrestore(&host->lock, flags); | ||
1754 | } | ||
1600 | 1755 | ||
1601 | mmc_remove_host(mmc); | 1756 | mmc_remove_host(host->mmc); |
1602 | 1757 | ||
1603 | #ifdef CONFIG_LEDS_CLASS | 1758 | #ifdef CONFIG_LEDS_CLASS |
1604 | led_classdev_unregister(&host->led); | 1759 | led_classdev_unregister(&host->led); |
1605 | #endif | 1760 | #endif |
1606 | 1761 | ||
1607 | sdhci_reset(host, SDHCI_RESET_ALL); | 1762 | if (!dead) |
1763 | sdhci_reset(host, SDHCI_RESET_ALL); | ||
1608 | 1764 | ||
1609 | free_irq(host->irq, host); | 1765 | free_irq(host->irq, host); |
1610 | 1766 | ||
@@ -1613,106 +1769,21 @@ static void sdhci_remove_slot(struct pci_dev *pdev, int slot) | |||
1613 | tasklet_kill(&host->card_tasklet); | 1769 | tasklet_kill(&host->card_tasklet); |
1614 | tasklet_kill(&host->finish_tasklet); | 1770 | tasklet_kill(&host->finish_tasklet); |
1615 | 1771 | ||
1616 | iounmap(host->ioaddr); | 1772 | kfree(host->adma_desc); |
1617 | 1773 | kfree(host->align_buffer); | |
1618 | pci_release_region(pdev, host->bar); | ||
1619 | 1774 | ||
1620 | mmc_free_host(mmc); | 1775 | host->adma_desc = NULL; |
1776 | host->align_buffer = NULL; | ||
1621 | } | 1777 | } |
1622 | 1778 | ||
1623 | static int __devinit sdhci_probe(struct pci_dev *pdev, | 1779 | EXPORT_SYMBOL_GPL(sdhci_remove_host); |
1624 | const struct pci_device_id *ent) | ||
1625 | { | ||
1626 | int ret, i; | ||
1627 | u8 slots, rev; | ||
1628 | struct sdhci_chip *chip; | ||
1629 | |||
1630 | BUG_ON(pdev == NULL); | ||
1631 | BUG_ON(ent == NULL); | ||
1632 | 1780 | ||
1633 | pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev); | 1781 | void sdhci_free_host(struct sdhci_host *host) |
1634 | |||
1635 | printk(KERN_INFO DRIVER_NAME | ||
1636 | ": SDHCI controller found at %s [%04x:%04x] (rev %x)\n", | ||
1637 | pci_name(pdev), (int)pdev->vendor, (int)pdev->device, | ||
1638 | (int)rev); | ||
1639 | |||
1640 | ret = pci_read_config_byte(pdev, PCI_SLOT_INFO, &slots); | ||
1641 | if (ret) | ||
1642 | return ret; | ||
1643 | |||
1644 | slots = PCI_SLOT_INFO_SLOTS(slots) + 1; | ||
1645 | DBG("found %d slot(s)\n", slots); | ||
1646 | if (slots == 0) | ||
1647 | return -ENODEV; | ||
1648 | |||
1649 | ret = pci_enable_device(pdev); | ||
1650 | if (ret) | ||
1651 | return ret; | ||
1652 | |||
1653 | chip = kzalloc(sizeof(struct sdhci_chip) + | ||
1654 | sizeof(struct sdhci_host*) * slots, GFP_KERNEL); | ||
1655 | if (!chip) { | ||
1656 | ret = -ENOMEM; | ||
1657 | goto err; | ||
1658 | } | ||
1659 | |||
1660 | chip->pdev = pdev; | ||
1661 | chip->quirks = ent->driver_data; | ||
1662 | |||
1663 | if (debug_quirks) | ||
1664 | chip->quirks = debug_quirks; | ||
1665 | |||
1666 | chip->num_slots = slots; | ||
1667 | pci_set_drvdata(pdev, chip); | ||
1668 | |||
1669 | for (i = 0;i < slots;i++) { | ||
1670 | ret = sdhci_probe_slot(pdev, i); | ||
1671 | if (ret) { | ||
1672 | for (i--;i >= 0;i--) | ||
1673 | sdhci_remove_slot(pdev, i); | ||
1674 | goto free; | ||
1675 | } | ||
1676 | } | ||
1677 | |||
1678 | return 0; | ||
1679 | |||
1680 | free: | ||
1681 | pci_set_drvdata(pdev, NULL); | ||
1682 | kfree(chip); | ||
1683 | |||
1684 | err: | ||
1685 | pci_disable_device(pdev); | ||
1686 | return ret; | ||
1687 | } | ||
1688 | |||
1689 | static void __devexit sdhci_remove(struct pci_dev *pdev) | ||
1690 | { | 1782 | { |
1691 | int i; | 1783 | mmc_free_host(host->mmc); |
1692 | struct sdhci_chip *chip; | ||
1693 | |||
1694 | chip = pci_get_drvdata(pdev); | ||
1695 | |||
1696 | if (chip) { | ||
1697 | for (i = 0;i < chip->num_slots;i++) | ||
1698 | sdhci_remove_slot(pdev, i); | ||
1699 | |||
1700 | pci_set_drvdata(pdev, NULL); | ||
1701 | |||
1702 | kfree(chip); | ||
1703 | } | ||
1704 | |||
1705 | pci_disable_device(pdev); | ||
1706 | } | 1784 | } |
1707 | 1785 | ||
1708 | static struct pci_driver sdhci_driver = { | 1786 | EXPORT_SYMBOL_GPL(sdhci_free_host); |
1709 | .name = DRIVER_NAME, | ||
1710 | .id_table = pci_ids, | ||
1711 | .probe = sdhci_probe, | ||
1712 | .remove = __devexit_p(sdhci_remove), | ||
1713 | .suspend = sdhci_suspend, | ||
1714 | .resume = sdhci_resume, | ||
1715 | }; | ||
1716 | 1787 | ||
1717 | /*****************************************************************************\ | 1788 | /*****************************************************************************\ |
1718 | * * | 1789 | * * |
@@ -1726,14 +1797,11 @@ static int __init sdhci_drv_init(void) | |||
1726 | ": Secure Digital Host Controller Interface driver\n"); | 1797 | ": Secure Digital Host Controller Interface driver\n"); |
1727 | printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); | 1798 | printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); |
1728 | 1799 | ||
1729 | return pci_register_driver(&sdhci_driver); | 1800 | return 0; |
1730 | } | 1801 | } |
1731 | 1802 | ||
1732 | static void __exit sdhci_drv_exit(void) | 1803 | static void __exit sdhci_drv_exit(void) |
1733 | { | 1804 | { |
1734 | DBG("Exiting\n"); | ||
1735 | |||
1736 | pci_unregister_driver(&sdhci_driver); | ||
1737 | } | 1805 | } |
1738 | 1806 | ||
1739 | module_init(sdhci_drv_init); | 1807 | module_init(sdhci_drv_init); |
@@ -1742,7 +1810,7 @@ module_exit(sdhci_drv_exit); | |||
1742 | module_param(debug_quirks, uint, 0444); | 1810 | module_param(debug_quirks, uint, 0444); |
1743 | 1811 | ||
1744 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); | 1812 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); |
1745 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver"); | 1813 | MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver"); |
1746 | MODULE_LICENSE("GPL"); | 1814 | MODULE_LICENSE("GPL"); |
1747 | 1815 | ||
1748 | MODULE_PARM_DESC(debug_quirks, "Force certain quirks."); | 1816 | MODULE_PARM_DESC(debug_quirks, "Force certain quirks."); |
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 299118de8933..5bb355281765 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h | |||
@@ -10,18 +10,6 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | /* | 12 | /* |
13 | * PCI registers | ||
14 | */ | ||
15 | |||
16 | #define PCI_SDHCI_IFPIO 0x00 | ||
17 | #define PCI_SDHCI_IFDMA 0x01 | ||
18 | #define PCI_SDHCI_IFVENDOR 0x02 | ||
19 | |||
20 | #define PCI_SLOT_INFO 0x40 /* 8 bits */ | ||
21 | #define PCI_SLOT_INFO_SLOTS(x) ((x >> 4) & 7) | ||
22 | #define PCI_SLOT_INFO_FIRST_BAR_MASK 0x07 | ||
23 | |||
24 | /* | ||
25 | * Controller registers | 13 | * Controller registers |
26 | */ | 14 | */ |
27 | 15 | ||
@@ -72,6 +60,11 @@ | |||
72 | #define SDHCI_CTRL_LED 0x01 | 60 | #define SDHCI_CTRL_LED 0x01 |
73 | #define SDHCI_CTRL_4BITBUS 0x02 | 61 | #define SDHCI_CTRL_4BITBUS 0x02 |
74 | #define SDHCI_CTRL_HISPD 0x04 | 62 | #define SDHCI_CTRL_HISPD 0x04 |
63 | #define SDHCI_CTRL_DMA_MASK 0x18 | ||
64 | #define SDHCI_CTRL_SDMA 0x00 | ||
65 | #define SDHCI_CTRL_ADMA1 0x08 | ||
66 | #define SDHCI_CTRL_ADMA32 0x10 | ||
67 | #define SDHCI_CTRL_ADMA64 0x18 | ||
75 | 68 | ||
76 | #define SDHCI_POWER_CONTROL 0x29 | 69 | #define SDHCI_POWER_CONTROL 0x29 |
77 | #define SDHCI_POWER_ON 0x01 | 70 | #define SDHCI_POWER_ON 0x01 |
@@ -117,6 +110,7 @@ | |||
117 | #define SDHCI_INT_DATA_END_BIT 0x00400000 | 110 | #define SDHCI_INT_DATA_END_BIT 0x00400000 |
118 | #define SDHCI_INT_BUS_POWER 0x00800000 | 111 | #define SDHCI_INT_BUS_POWER 0x00800000 |
119 | #define SDHCI_INT_ACMD12ERR 0x01000000 | 112 | #define SDHCI_INT_ACMD12ERR 0x01000000 |
113 | #define SDHCI_INT_ADMA_ERROR 0x02000000 | ||
120 | 114 | ||
121 | #define SDHCI_INT_NORMAL_MASK 0x00007FFF | 115 | #define SDHCI_INT_NORMAL_MASK 0x00007FFF |
122 | #define SDHCI_INT_ERROR_MASK 0xFFFF8000 | 116 | #define SDHCI_INT_ERROR_MASK 0xFFFF8000 |
@@ -140,11 +134,14 @@ | |||
140 | #define SDHCI_CLOCK_BASE_SHIFT 8 | 134 | #define SDHCI_CLOCK_BASE_SHIFT 8 |
141 | #define SDHCI_MAX_BLOCK_MASK 0x00030000 | 135 | #define SDHCI_MAX_BLOCK_MASK 0x00030000 |
142 | #define SDHCI_MAX_BLOCK_SHIFT 16 | 136 | #define SDHCI_MAX_BLOCK_SHIFT 16 |
137 | #define SDHCI_CAN_DO_ADMA2 0x00080000 | ||
138 | #define SDHCI_CAN_DO_ADMA1 0x00100000 | ||
143 | #define SDHCI_CAN_DO_HISPD 0x00200000 | 139 | #define SDHCI_CAN_DO_HISPD 0x00200000 |
144 | #define SDHCI_CAN_DO_DMA 0x00400000 | 140 | #define SDHCI_CAN_DO_DMA 0x00400000 |
145 | #define SDHCI_CAN_VDD_330 0x01000000 | 141 | #define SDHCI_CAN_VDD_330 0x01000000 |
146 | #define SDHCI_CAN_VDD_300 0x02000000 | 142 | #define SDHCI_CAN_VDD_300 0x02000000 |
147 | #define SDHCI_CAN_VDD_180 0x04000000 | 143 | #define SDHCI_CAN_VDD_180 0x04000000 |
144 | #define SDHCI_CAN_64BIT 0x10000000 | ||
148 | 145 | ||
149 | /* 44-47 reserved for more caps */ | 146 | /* 44-47 reserved for more caps */ |
150 | 147 | ||
@@ -152,7 +149,16 @@ | |||
152 | 149 | ||
153 | /* 4C-4F reserved for more max current */ | 150 | /* 4C-4F reserved for more max current */ |
154 | 151 | ||
155 | /* 50-FB reserved */ | 152 | #define SDHCI_SET_ACMD12_ERROR 0x50 |
153 | #define SDHCI_SET_INT_ERROR 0x52 | ||
154 | |||
155 | #define SDHCI_ADMA_ERROR 0x54 | ||
156 | |||
157 | /* 55-57 reserved */ | ||
158 | |||
159 | #define SDHCI_ADMA_ADDRESS 0x58 | ||
160 | |||
161 | /* 60-FB reserved */ | ||
156 | 162 | ||
157 | #define SDHCI_SLOT_INT_STATUS 0xFC | 163 | #define SDHCI_SLOT_INT_STATUS 0xFC |
158 | 164 | ||
@@ -161,11 +167,50 @@ | |||
161 | #define SDHCI_VENDOR_VER_SHIFT 8 | 167 | #define SDHCI_VENDOR_VER_SHIFT 8 |
162 | #define SDHCI_SPEC_VER_MASK 0x00FF | 168 | #define SDHCI_SPEC_VER_MASK 0x00FF |
163 | #define SDHCI_SPEC_VER_SHIFT 0 | 169 | #define SDHCI_SPEC_VER_SHIFT 0 |
170 | #define SDHCI_SPEC_100 0 | ||
171 | #define SDHCI_SPEC_200 1 | ||
164 | 172 | ||
165 | struct sdhci_chip; | 173 | struct sdhci_ops; |
166 | 174 | ||
167 | struct sdhci_host { | 175 | struct sdhci_host { |
168 | struct sdhci_chip *chip; | 176 | /* Data set by hardware interface driver */ |
177 | const char *hw_name; /* Hardware bus name */ | ||
178 | |||
179 | unsigned int quirks; /* Deviations from spec. */ | ||
180 | |||
181 | /* Controller doesn't honor resets unless we touch the clock register */ | ||
182 | #define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0) | ||
183 | /* Controller has bad caps bits, but really supports DMA */ | ||
184 | #define SDHCI_QUIRK_FORCE_DMA (1<<1) | ||
185 | /* Controller doesn't like to be reset when there is no card inserted. */ | ||
186 | #define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2) | ||
187 | /* Controller doesn't like clearing the power reg before a change */ | ||
188 | #define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) | ||
189 | /* Controller has flaky internal state so reset it on each ios change */ | ||
190 | #define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4) | ||
191 | /* Controller has an unusable DMA engine */ | ||
192 | #define SDHCI_QUIRK_BROKEN_DMA (1<<5) | ||
193 | /* Controller has an unusable ADMA engine */ | ||
194 | #define SDHCI_QUIRK_BROKEN_ADMA (1<<6) | ||
195 | /* Controller can only DMA from 32-bit aligned addresses */ | ||
196 | #define SDHCI_QUIRK_32BIT_DMA_ADDR (1<<7) | ||
197 | /* Controller can only DMA chunk sizes that are a multiple of 32 bits */ | ||
198 | #define SDHCI_QUIRK_32BIT_DMA_SIZE (1<<8) | ||
199 | /* Controller can only ADMA chunks that are a multiple of 32 bits */ | ||
200 | #define SDHCI_QUIRK_32BIT_ADMA_SIZE (1<<9) | ||
201 | /* Controller needs to be reset after each request to stay stable */ | ||
202 | #define SDHCI_QUIRK_RESET_AFTER_REQUEST (1<<10) | ||
203 | /* Controller needs voltage and power writes to happen separately */ | ||
204 | #define SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER (1<<11) | ||
205 | /* Controller provides an incorrect timeout value for transfers */ | ||
206 | #define SDHCI_QUIRK_BROKEN_TIMEOUT_VAL (1<<12) | ||
207 | |||
208 | int irq; /* Device IRQ */ | ||
209 | void __iomem * ioaddr; /* Mapped address */ | ||
210 | |||
211 | const struct sdhci_ops *ops; /* Low level hw interface */ | ||
212 | |||
213 | /* Internal data */ | ||
169 | struct mmc_host *mmc; /* MMC structure */ | 214 | struct mmc_host *mmc; /* MMC structure */ |
170 | 215 | ||
171 | #ifdef CONFIG_LEDS_CLASS | 216 | #ifdef CONFIG_LEDS_CLASS |
@@ -176,7 +221,11 @@ struct sdhci_host { | |||
176 | 221 | ||
177 | int flags; /* Host attributes */ | 222 | int flags; /* Host attributes */ |
178 | #define SDHCI_USE_DMA (1<<0) /* Host is DMA capable */ | 223 | #define SDHCI_USE_DMA (1<<0) /* Host is DMA capable */ |
179 | #define SDHCI_REQ_USE_DMA (1<<1) /* Use DMA for this req. */ | 224 | #define SDHCI_USE_ADMA (1<<1) /* Host is ADMA capable */ |
225 | #define SDHCI_REQ_USE_DMA (1<<2) /* Use DMA for this req. */ | ||
226 | #define SDHCI_DEVICE_DEAD (1<<3) /* Device unresponsive */ | ||
227 | |||
228 | unsigned int version; /* SDHCI spec. version */ | ||
180 | 229 | ||
181 | unsigned int max_clk; /* Max possible freq (MHz) */ | 230 | unsigned int max_clk; /* Max possible freq (MHz) */ |
182 | unsigned int timeout_clk; /* Timeout freq (KHz) */ | 231 | unsigned int timeout_clk; /* Timeout freq (KHz) */ |
@@ -194,22 +243,41 @@ struct sdhci_host { | |||
194 | int offset; /* Offset into current sg */ | 243 | int offset; /* Offset into current sg */ |
195 | int remain; /* Bytes left in current */ | 244 | int remain; /* Bytes left in current */ |
196 | 245 | ||
197 | int irq; /* Device IRQ */ | 246 | int sg_count; /* Mapped sg entries */ |
198 | int bar; /* PCI BAR index */ | 247 | |
199 | unsigned long addr; /* Bus address */ | 248 | u8 *adma_desc; /* ADMA descriptor table */ |
200 | void __iomem * ioaddr; /* Mapped address */ | 249 | u8 *align_buffer; /* Bounce buffer */ |
250 | |||
251 | dma_addr_t adma_addr; /* Mapped ADMA descr. table */ | ||
252 | dma_addr_t align_addr; /* Mapped bounce buffer */ | ||
201 | 253 | ||
202 | struct tasklet_struct card_tasklet; /* Tasklet structures */ | 254 | struct tasklet_struct card_tasklet; /* Tasklet structures */ |
203 | struct tasklet_struct finish_tasklet; | 255 | struct tasklet_struct finish_tasklet; |
204 | 256 | ||
205 | struct timer_list timer; /* Timer for timeouts */ | 257 | struct timer_list timer; /* Timer for timeouts */ |
206 | }; | ||
207 | 258 | ||
208 | struct sdhci_chip { | 259 | unsigned long private[0] ____cacheline_aligned; |
209 | struct pci_dev *pdev; | 260 | }; |
210 | 261 | ||
211 | unsigned long quirks; | ||
212 | 262 | ||
213 | int num_slots; /* Slots on controller */ | 263 | struct sdhci_ops { |
214 | struct sdhci_host *hosts[0]; /* Pointers to hosts */ | 264 | int (*enable_dma)(struct sdhci_host *host); |
215 | }; | 265 | }; |
266 | |||
267 | |||
268 | extern struct sdhci_host *sdhci_alloc_host(struct device *dev, | ||
269 | size_t priv_size); | ||
270 | extern void sdhci_free_host(struct sdhci_host *host); | ||
271 | |||
272 | static inline void *sdhci_priv(struct sdhci_host *host) | ||
273 | { | ||
274 | return (void *)host->private; | ||
275 | } | ||
276 | |||
277 | extern int sdhci_add_host(struct sdhci_host *host); | ||
278 | extern void sdhci_remove_host(struct sdhci_host *host, int dead); | ||
279 | |||
280 | #ifdef CONFIG_PM | ||
281 | extern int sdhci_suspend_host(struct sdhci_host *host, pm_message_t state); | ||
282 | extern int sdhci_resume_host(struct sdhci_host *host); | ||
283 | #endif | ||
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c new file mode 100644 index 000000000000..f99e9f721629 --- /dev/null +++ b/drivers/mmc/host/sdricoh_cs.c | |||
@@ -0,0 +1,575 @@ | |||
1 | /* | ||
2 | * sdricoh_cs.c - driver for Ricoh Secure Digital Card Readers that can be | ||
3 | * found on some Ricoh RL5c476 II cardbus bridge | ||
4 | * | ||
5 | * Copyright (C) 2006 - 2008 Sascha Sommer <saschasommer@freenet.de> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | #define DEBUG | ||
25 | #define VERBOSE_DEBUG | ||
26 | */ | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/highmem.h> | ||
29 | #include <linux/pci.h> | ||
30 | #include <linux/ioport.h> | ||
31 | #include <linux/scatterlist.h> | ||
32 | #include <linux/version.h> | ||
33 | |||
34 | #include <pcmcia/cs_types.h> | ||
35 | #include <pcmcia/cs.h> | ||
36 | #include <pcmcia/cistpl.h> | ||
37 | #include <pcmcia/ds.h> | ||
38 | #include <linux/io.h> | ||
39 | |||
40 | #include <linux/mmc/host.h> | ||
41 | |||
42 | #define DRIVER_NAME "sdricoh_cs" | ||
43 | |||
44 | static unsigned int switchlocked; | ||
45 | |||
46 | /* i/o region */ | ||
47 | #define SDRICOH_PCI_REGION 0 | ||
48 | #define SDRICOH_PCI_REGION_SIZE 0x1000 | ||
49 | |||
50 | /* registers */ | ||
51 | #define R104_VERSION 0x104 | ||
52 | #define R200_CMD 0x200 | ||
53 | #define R204_CMD_ARG 0x204 | ||
54 | #define R208_DATAIO 0x208 | ||
55 | #define R20C_RESP 0x20c | ||
56 | #define R21C_STATUS 0x21c | ||
57 | #define R2E0_INIT 0x2e0 | ||
58 | #define R2E4_STATUS_RESP 0x2e4 | ||
59 | #define R2F0_RESET 0x2f0 | ||
60 | #define R224_MODE 0x224 | ||
61 | #define R226_BLOCKSIZE 0x226 | ||
62 | #define R228_POWER 0x228 | ||
63 | #define R230_DATA 0x230 | ||
64 | |||
65 | /* flags for the R21C_STATUS register */ | ||
66 | #define STATUS_CMD_FINISHED 0x00000001 | ||
67 | #define STATUS_TRANSFER_FINISHED 0x00000004 | ||
68 | #define STATUS_CARD_INSERTED 0x00000020 | ||
69 | #define STATUS_CARD_LOCKED 0x00000080 | ||
70 | #define STATUS_CMD_TIMEOUT 0x00400000 | ||
71 | #define STATUS_READY_TO_READ 0x01000000 | ||
72 | #define STATUS_READY_TO_WRITE 0x02000000 | ||
73 | #define STATUS_BUSY 0x40000000 | ||
74 | |||
75 | /* timeouts */ | ||
76 | #define INIT_TIMEOUT 100 | ||
77 | #define CMD_TIMEOUT 100000 | ||
78 | #define TRANSFER_TIMEOUT 100000 | ||
79 | #define BUSY_TIMEOUT 32767 | ||
80 | |||
81 | /* list of supported pcmcia devices */ | ||
82 | static struct pcmcia_device_id pcmcia_ids[] = { | ||
83 | /* vendor and device strings followed by their crc32 hashes */ | ||
84 | PCMCIA_DEVICE_PROD_ID12("RICOH", "Bay1Controller", 0xd9f522ed, | ||
85 | 0xc3901202), | ||
86 | PCMCIA_DEVICE_NULL, | ||
87 | }; | ||
88 | |||
89 | MODULE_DEVICE_TABLE(pcmcia, pcmcia_ids); | ||
90 | |||
91 | /* mmc privdata */ | ||
92 | struct sdricoh_host { | ||
93 | struct device *dev; | ||
94 | struct mmc_host *mmc; /* MMC structure */ | ||
95 | unsigned char __iomem *iobase; | ||
96 | struct pci_dev *pci_dev; | ||
97 | int app_cmd; | ||
98 | }; | ||
99 | |||
100 | /***************** register i/o helper functions *****************************/ | ||
101 | |||
102 | static inline unsigned int sdricoh_readl(struct sdricoh_host *host, | ||
103 | unsigned int reg) | ||
104 | { | ||
105 | unsigned int value = readl(host->iobase + reg); | ||
106 | dev_vdbg(host->dev, "rl %x 0x%x\n", reg, value); | ||
107 | return value; | ||
108 | } | ||
109 | |||
110 | static inline void sdricoh_writel(struct sdricoh_host *host, unsigned int reg, | ||
111 | unsigned int value) | ||
112 | { | ||
113 | writel(value, host->iobase + reg); | ||
114 | dev_vdbg(host->dev, "wl %x 0x%x\n", reg, value); | ||
115 | |||
116 | } | ||
117 | |||
118 | static inline unsigned int sdricoh_readw(struct sdricoh_host *host, | ||
119 | unsigned int reg) | ||
120 | { | ||
121 | unsigned int value = readw(host->iobase + reg); | ||
122 | dev_vdbg(host->dev, "rb %x 0x%x\n", reg, value); | ||
123 | return value; | ||
124 | } | ||
125 | |||
126 | static inline void sdricoh_writew(struct sdricoh_host *host, unsigned int reg, | ||
127 | unsigned short value) | ||
128 | { | ||
129 | writew(value, host->iobase + reg); | ||
130 | dev_vdbg(host->dev, "ww %x 0x%x\n", reg, value); | ||
131 | } | ||
132 | |||
133 | static inline unsigned int sdricoh_readb(struct sdricoh_host *host, | ||
134 | unsigned int reg) | ||
135 | { | ||
136 | unsigned int value = readb(host->iobase + reg); | ||
137 | dev_vdbg(host->dev, "rb %x 0x%x\n", reg, value); | ||
138 | return value; | ||
139 | } | ||
140 | |||
141 | static int sdricoh_query_status(struct sdricoh_host *host, unsigned int wanted, | ||
142 | unsigned int timeout){ | ||
143 | unsigned int loop; | ||
144 | unsigned int status = 0; | ||
145 | struct device *dev = host->dev; | ||
146 | for (loop = 0; loop < timeout; loop++) { | ||
147 | status = sdricoh_readl(host, R21C_STATUS); | ||
148 | sdricoh_writel(host, R2E4_STATUS_RESP, status); | ||
149 | if (status & wanted) | ||
150 | break; | ||
151 | } | ||
152 | |||
153 | if (loop == timeout) { | ||
154 | dev_err(dev, "query_status: timeout waiting for %x\n", wanted); | ||
155 | return -ETIMEDOUT; | ||
156 | } | ||
157 | |||
158 | /* do not do this check in the loop as some commands fail otherwise */ | ||
159 | if (status & 0x7F0000) { | ||
160 | dev_err(dev, "waiting for status bit %x failed\n", wanted); | ||
161 | return -EINVAL; | ||
162 | } | ||
163 | return 0; | ||
164 | |||
165 | } | ||
166 | |||
167 | static int sdricoh_mmc_cmd(struct sdricoh_host *host, unsigned char opcode, | ||
168 | unsigned int arg) | ||
169 | { | ||
170 | unsigned int status; | ||
171 | int result = 0; | ||
172 | unsigned int loop = 0; | ||
173 | /* reset status reg? */ | ||
174 | sdricoh_writel(host, R21C_STATUS, 0x18); | ||
175 | /* fill parameters */ | ||
176 | sdricoh_writel(host, R204_CMD_ARG, arg); | ||
177 | sdricoh_writel(host, R200_CMD, (0x10000 << 8) | opcode); | ||
178 | /* wait for command completion */ | ||
179 | if (opcode) { | ||
180 | for (loop = 0; loop < CMD_TIMEOUT; loop++) { | ||
181 | status = sdricoh_readl(host, R21C_STATUS); | ||
182 | sdricoh_writel(host, R2E4_STATUS_RESP, status); | ||
183 | if (status & STATUS_CMD_FINISHED) | ||
184 | break; | ||
185 | } | ||
186 | /* don't check for timeout in the loop it is not always | ||
187 | reset correctly | ||
188 | */ | ||
189 | if (loop == CMD_TIMEOUT || status & STATUS_CMD_TIMEOUT) | ||
190 | result = -ETIMEDOUT; | ||
191 | |||
192 | } | ||
193 | |||
194 | return result; | ||
195 | |||
196 | } | ||
197 | |||
198 | static int sdricoh_reset(struct sdricoh_host *host) | ||
199 | { | ||
200 | dev_dbg(host->dev, "reset\n"); | ||
201 | sdricoh_writel(host, R2F0_RESET, 0x10001); | ||
202 | sdricoh_writel(host, R2E0_INIT, 0x10000); | ||
203 | if (sdricoh_readl(host, R2E0_INIT) != 0x10000) | ||
204 | return -EIO; | ||
205 | sdricoh_writel(host, R2E0_INIT, 0x10007); | ||
206 | |||
207 | sdricoh_writel(host, R224_MODE, 0x2000000); | ||
208 | sdricoh_writel(host, R228_POWER, 0xe0); | ||
209 | |||
210 | |||
211 | /* status register ? */ | ||
212 | sdricoh_writel(host, R21C_STATUS, 0x18); | ||
213 | |||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | static int sdricoh_blockio(struct sdricoh_host *host, int read, | ||
218 | u8 *buf, int len) | ||
219 | { | ||
220 | int size; | ||
221 | u32 data = 0; | ||
222 | /* wait until the data is available */ | ||
223 | if (read) { | ||
224 | if (sdricoh_query_status(host, STATUS_READY_TO_READ, | ||
225 | TRANSFER_TIMEOUT)) | ||
226 | return -ETIMEDOUT; | ||
227 | sdricoh_writel(host, R21C_STATUS, 0x18); | ||
228 | /* read data */ | ||
229 | while (len) { | ||
230 | data = sdricoh_readl(host, R230_DATA); | ||
231 | size = min(len, 4); | ||
232 | len -= size; | ||
233 | while (size) { | ||
234 | *buf = data & 0xFF; | ||
235 | buf++; | ||
236 | data >>= 8; | ||
237 | size--; | ||
238 | } | ||
239 | } | ||
240 | } else { | ||
241 | if (sdricoh_query_status(host, STATUS_READY_TO_WRITE, | ||
242 | TRANSFER_TIMEOUT)) | ||
243 | return -ETIMEDOUT; | ||
244 | sdricoh_writel(host, R21C_STATUS, 0x18); | ||
245 | /* write data */ | ||
246 | while (len) { | ||
247 | size = min(len, 4); | ||
248 | len -= size; | ||
249 | while (size) { | ||
250 | data >>= 8; | ||
251 | data |= (u32)*buf << 24; | ||
252 | buf++; | ||
253 | size--; | ||
254 | } | ||
255 | sdricoh_writel(host, R230_DATA, data); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | if (len) | ||
260 | return -EIO; | ||
261 | |||
262 | return 0; | ||
263 | } | ||
264 | |||
265 | static void sdricoh_request(struct mmc_host *mmc, struct mmc_request *mrq) | ||
266 | { | ||
267 | struct sdricoh_host *host = mmc_priv(mmc); | ||
268 | struct mmc_command *cmd = mrq->cmd; | ||
269 | struct mmc_data *data = cmd->data; | ||
270 | struct device *dev = host->dev; | ||
271 | unsigned char opcode = cmd->opcode; | ||
272 | int i; | ||
273 | |||
274 | dev_dbg(dev, "=============================\n"); | ||
275 | dev_dbg(dev, "sdricoh_request opcode=%i\n", opcode); | ||
276 | |||
277 | sdricoh_writel(host, R21C_STATUS, 0x18); | ||
278 | |||
279 | /* MMC_APP_CMDs need some special handling */ | ||
280 | if (host->app_cmd) { | ||
281 | opcode |= 64; | ||
282 | host->app_cmd = 0; | ||
283 | } else if (opcode == 55) | ||
284 | host->app_cmd = 1; | ||
285 | |||
286 | /* read/write commands seem to require this */ | ||
287 | if (data) { | ||
288 | sdricoh_writew(host, R226_BLOCKSIZE, data->blksz); | ||
289 | sdricoh_writel(host, R208_DATAIO, 0); | ||
290 | } | ||
291 | |||
292 | cmd->error = sdricoh_mmc_cmd(host, opcode, cmd->arg); | ||
293 | |||
294 | /* read response buffer */ | ||
295 | if (cmd->flags & MMC_RSP_PRESENT) { | ||
296 | if (cmd->flags & MMC_RSP_136) { | ||
297 | /* CRC is stripped so we need to do some shifting. */ | ||
298 | for (i = 0; i < 4; i++) { | ||
299 | cmd->resp[i] = | ||
300 | sdricoh_readl(host, | ||
301 | R20C_RESP + (3 - i) * 4) << 8; | ||
302 | if (i != 3) | ||
303 | cmd->resp[i] |= | ||
304 | sdricoh_readb(host, R20C_RESP + | ||
305 | (3 - i) * 4 - 1); | ||
306 | } | ||
307 | } else | ||
308 | cmd->resp[0] = sdricoh_readl(host, R20C_RESP); | ||
309 | } | ||
310 | |||
311 | /* transfer data */ | ||
312 | if (data && cmd->error == 0) { | ||
313 | dev_dbg(dev, "transfer: blksz %i blocks %i sg_len %i " | ||
314 | "sg length %i\n", data->blksz, data->blocks, | ||
315 | data->sg_len, data->sg->length); | ||
316 | |||
317 | /* enter data reading mode */ | ||
318 | sdricoh_writel(host, R21C_STATUS, 0x837f031e); | ||
319 | for (i = 0; i < data->blocks; i++) { | ||
320 | size_t len = data->blksz; | ||
321 | u8 *buf; | ||
322 | struct page *page; | ||
323 | int result; | ||
324 | page = sg_page(data->sg); | ||
325 | |||
326 | buf = kmap(page) + data->sg->offset + (len * i); | ||
327 | result = | ||
328 | sdricoh_blockio(host, | ||
329 | data->flags & MMC_DATA_READ, buf, len); | ||
330 | kunmap(page); | ||
331 | flush_dcache_page(page); | ||
332 | if (result) { | ||
333 | dev_err(dev, "sdricoh_request: cmd %i " | ||
334 | "block transfer failed\n", cmd->opcode); | ||
335 | cmd->error = result; | ||
336 | break; | ||
337 | } else | ||
338 | data->bytes_xfered += len; | ||
339 | } | ||
340 | |||
341 | sdricoh_writel(host, R208_DATAIO, 1); | ||
342 | |||
343 | if (sdricoh_query_status(host, STATUS_TRANSFER_FINISHED, | ||
344 | TRANSFER_TIMEOUT)) { | ||
345 | dev_err(dev, "sdricoh_request: transfer end error\n"); | ||
346 | cmd->error = -EINVAL; | ||
347 | } | ||
348 | } | ||
349 | /* FIXME check busy flag */ | ||
350 | |||
351 | mmc_request_done(mmc, mrq); | ||
352 | dev_dbg(dev, "=============================\n"); | ||
353 | } | ||
354 | |||
355 | static void sdricoh_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) | ||
356 | { | ||
357 | struct sdricoh_host *host = mmc_priv(mmc); | ||
358 | dev_dbg(host->dev, "set_ios\n"); | ||
359 | |||
360 | if (ios->power_mode == MMC_POWER_ON) { | ||
361 | sdricoh_writel(host, R228_POWER, 0xc0e0); | ||
362 | |||
363 | if (ios->bus_width == MMC_BUS_WIDTH_4) { | ||
364 | sdricoh_writel(host, R224_MODE, 0x2000300); | ||
365 | sdricoh_writel(host, R228_POWER, 0x40e0); | ||
366 | } else { | ||
367 | sdricoh_writel(host, R224_MODE, 0x2000340); | ||
368 | } | ||
369 | |||
370 | } else if (ios->power_mode == MMC_POWER_UP) { | ||
371 | sdricoh_writel(host, R224_MODE, 0x2000320); | ||
372 | sdricoh_writel(host, R228_POWER, 0xe0); | ||
373 | } | ||
374 | } | ||
375 | |||
376 | static int sdricoh_get_ro(struct mmc_host *mmc) | ||
377 | { | ||
378 | struct sdricoh_host *host = mmc_priv(mmc); | ||
379 | unsigned int status; | ||
380 | |||
381 | status = sdricoh_readl(host, R21C_STATUS); | ||
382 | sdricoh_writel(host, R2E4_STATUS_RESP, status); | ||
383 | |||
384 | /* some notebooks seem to have the locked flag switched */ | ||
385 | if (switchlocked) | ||
386 | return !(status & STATUS_CARD_LOCKED); | ||
387 | |||
388 | return (status & STATUS_CARD_LOCKED); | ||
389 | } | ||
390 | |||
391 | static struct mmc_host_ops sdricoh_ops = { | ||
392 | .request = sdricoh_request, | ||
393 | .set_ios = sdricoh_set_ios, | ||
394 | .get_ro = sdricoh_get_ro, | ||
395 | }; | ||
396 | |||
397 | /* initialize the control and register it to the mmc framework */ | ||
398 | static int sdricoh_init_mmc(struct pci_dev *pci_dev, | ||
399 | struct pcmcia_device *pcmcia_dev) | ||
400 | { | ||
401 | int result = 0; | ||
402 | void __iomem *iobase = NULL; | ||
403 | struct mmc_host *mmc = NULL; | ||
404 | struct sdricoh_host *host = NULL; | ||
405 | struct device *dev = &pcmcia_dev->dev; | ||
406 | /* map iomem */ | ||
407 | if (pci_resource_len(pci_dev, SDRICOH_PCI_REGION) != | ||
408 | SDRICOH_PCI_REGION_SIZE) { | ||
409 | dev_dbg(dev, "unexpected pci resource len\n"); | ||
410 | return -ENODEV; | ||
411 | } | ||
412 | iobase = | ||
413 | pci_iomap(pci_dev, SDRICOH_PCI_REGION, SDRICOH_PCI_REGION_SIZE); | ||
414 | if (!iobase) { | ||
415 | dev_err(dev, "unable to map iobase\n"); | ||
416 | return -ENODEV; | ||
417 | } | ||
418 | /* check version? */ | ||
419 | if (readl(iobase + R104_VERSION) != 0x4000) { | ||
420 | dev_dbg(dev, "no supported mmc controller found\n"); | ||
421 | result = -ENODEV; | ||
422 | goto err; | ||
423 | } | ||
424 | /* allocate privdata */ | ||
425 | mmc = pcmcia_dev->priv = | ||
426 | mmc_alloc_host(sizeof(struct sdricoh_host), &pcmcia_dev->dev); | ||
427 | if (!mmc) { | ||
428 | dev_err(dev, "mmc_alloc_host failed\n"); | ||
429 | result = -ENOMEM; | ||
430 | goto err; | ||
431 | } | ||
432 | host = mmc_priv(mmc); | ||
433 | |||
434 | host->iobase = iobase; | ||
435 | host->dev = dev; | ||
436 | host->pci_dev = pci_dev; | ||
437 | |||
438 | mmc->ops = &sdricoh_ops; | ||
439 | |||
440 | /* FIXME: frequency and voltage handling is done by the controller | ||
441 | */ | ||
442 | mmc->f_min = 450000; | ||
443 | mmc->f_max = 24000000; | ||
444 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | ||
445 | mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
446 | |||
447 | mmc->max_seg_size = 1024 * 512; | ||
448 | mmc->max_blk_size = 512; | ||
449 | |||
450 | /* reset the controler */ | ||
451 | if (sdricoh_reset(host)) { | ||
452 | dev_dbg(dev, "could not reset\n"); | ||
453 | result = -EIO; | ||
454 | goto err; | ||
455 | |||
456 | } | ||
457 | |||
458 | result = mmc_add_host(mmc); | ||
459 | |||
460 | if (!result) { | ||
461 | dev_dbg(dev, "mmc host registered\n"); | ||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | err: | ||
466 | if (iobase) | ||
467 | iounmap(iobase); | ||
468 | if (mmc) | ||
469 | mmc_free_host(mmc); | ||
470 | |||
471 | return result; | ||
472 | } | ||
473 | |||
474 | /* search for supported mmc controllers */ | ||
475 | static int sdricoh_pcmcia_probe(struct pcmcia_device *pcmcia_dev) | ||
476 | { | ||
477 | struct pci_dev *pci_dev = NULL; | ||
478 | |||
479 | dev_info(&pcmcia_dev->dev, "Searching MMC controller for pcmcia device" | ||
480 | " %s %s ...\n", pcmcia_dev->prod_id[0], pcmcia_dev->prod_id[1]); | ||
481 | |||
482 | /* search pci cardbus bridge that contains the mmc controler */ | ||
483 | /* the io region is already claimed by yenta_socket... */ | ||
484 | while ((pci_dev = | ||
485 | pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, | ||
486 | pci_dev))) { | ||
487 | /* try to init the device */ | ||
488 | if (!sdricoh_init_mmc(pci_dev, pcmcia_dev)) { | ||
489 | dev_info(&pcmcia_dev->dev, "MMC controller found\n"); | ||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | } | ||
494 | dev_err(&pcmcia_dev->dev, "No MMC controller was found.\n"); | ||
495 | return -ENODEV; | ||
496 | } | ||
497 | |||
498 | static void sdricoh_pcmcia_detach(struct pcmcia_device *link) | ||
499 | { | ||
500 | struct mmc_host *mmc = link->priv; | ||
501 | |||
502 | dev_dbg(&link->dev, "detach\n"); | ||
503 | |||
504 | /* remove mmc host */ | ||
505 | if (mmc) { | ||
506 | struct sdricoh_host *host = mmc_priv(mmc); | ||
507 | mmc_remove_host(mmc); | ||
508 | pci_iounmap(host->pci_dev, host->iobase); | ||
509 | pci_dev_put(host->pci_dev); | ||
510 | mmc_free_host(mmc); | ||
511 | } | ||
512 | pcmcia_disable_device(link); | ||
513 | |||
514 | } | ||
515 | |||
516 | #ifdef CONFIG_PM | ||
517 | static int sdricoh_pcmcia_suspend(struct pcmcia_device *link) | ||
518 | { | ||
519 | struct mmc_host *mmc = link->priv; | ||
520 | dev_dbg(&link->dev, "suspend\n"); | ||
521 | mmc_suspend_host(mmc, PMSG_SUSPEND); | ||
522 | return 0; | ||
523 | } | ||
524 | |||
525 | static int sdricoh_pcmcia_resume(struct pcmcia_device *link) | ||
526 | { | ||
527 | struct mmc_host *mmc = link->priv; | ||
528 | dev_dbg(&link->dev, "resume\n"); | ||
529 | sdricoh_reset(mmc_priv(mmc)); | ||
530 | mmc_resume_host(mmc); | ||
531 | return 0; | ||
532 | } | ||
533 | #else | ||
534 | #define sdricoh_pcmcia_suspend NULL | ||
535 | #define sdricoh_pcmcia_resume NULL | ||
536 | #endif | ||
537 | |||
538 | static struct pcmcia_driver sdricoh_driver = { | ||
539 | .drv = { | ||
540 | .name = DRIVER_NAME, | ||
541 | }, | ||
542 | .probe = sdricoh_pcmcia_probe, | ||
543 | .remove = sdricoh_pcmcia_detach, | ||
544 | .id_table = pcmcia_ids, | ||
545 | .suspend = sdricoh_pcmcia_suspend, | ||
546 | .resume = sdricoh_pcmcia_resume, | ||
547 | }; | ||
548 | |||
549 | /*****************************************************************************\ | ||
550 | * * | ||
551 | * Driver init/exit * | ||
552 | * * | ||
553 | \*****************************************************************************/ | ||
554 | |||
555 | static int __init sdricoh_drv_init(void) | ||
556 | { | ||
557 | return pcmcia_register_driver(&sdricoh_driver); | ||
558 | } | ||
559 | |||
560 | static void __exit sdricoh_drv_exit(void) | ||
561 | { | ||
562 | pcmcia_unregister_driver(&sdricoh_driver); | ||
563 | } | ||
564 | |||
565 | module_init(sdricoh_drv_init); | ||
566 | module_exit(sdricoh_drv_exit); | ||
567 | |||
568 | module_param(switchlocked, uint, 0444); | ||
569 | |||
570 | MODULE_AUTHOR("Sascha Sommer <saschasommer@freenet.de>"); | ||
571 | MODULE_DESCRIPTION("Ricoh PCMCIA Secure Digital Interface driver"); | ||
572 | MODULE_LICENSE("GPL"); | ||
573 | |||
574 | MODULE_PARM_DESC(switchlocked, "Switch the cards locked status." | ||
575 | "Use this when unlocked cards are shown readonly (default 0)"); | ||
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c index 1c14a186f000..13844843e8de 100644 --- a/drivers/mmc/host/tifm_sd.c +++ b/drivers/mmc/host/tifm_sd.c | |||
@@ -973,7 +973,7 @@ static int tifm_sd_probe(struct tifm_dev *sock) | |||
973 | 973 | ||
974 | mmc->ops = &tifm_sd_ops; | 974 | mmc->ops = &tifm_sd_ops; |
975 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | 975 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
976 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; | 976 | mmc->caps = MMC_CAP_4_BIT_DATA; |
977 | mmc->f_min = 20000000 / 60; | 977 | mmc->f_min = 20000000 / 60; |
978 | mmc->f_max = 24000000; | 978 | mmc->f_max = 24000000; |
979 | 979 | ||
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c index c303e7f57ab4..adda37952032 100644 --- a/drivers/mmc/host/wbsd.c +++ b/drivers/mmc/host/wbsd.c | |||
@@ -68,16 +68,16 @@ static const int unlock_codes[] = { 0x83, 0x87 }; | |||
68 | 68 | ||
69 | static const int valid_ids[] = { | 69 | static const int valid_ids[] = { |
70 | 0x7112, | 70 | 0x7112, |
71 | }; | 71 | }; |
72 | 72 | ||
73 | #ifdef CONFIG_PNP | 73 | #ifdef CONFIG_PNP |
74 | static unsigned int nopnp = 0; | 74 | static unsigned int param_nopnp = 0; |
75 | #else | 75 | #else |
76 | static const unsigned int nopnp = 1; | 76 | static const unsigned int param_nopnp = 1; |
77 | #endif | 77 | #endif |
78 | static unsigned int io = 0x248; | 78 | static unsigned int param_io = 0x248; |
79 | static unsigned int irq = 6; | 79 | static unsigned int param_irq = 6; |
80 | static int dma = 2; | 80 | static int param_dma = 2; |
81 | 81 | ||
82 | /* | 82 | /* |
83 | * Basic functions | 83 | * Basic functions |
@@ -939,7 +939,7 @@ static int wbsd_get_ro(struct mmc_host *mmc) | |||
939 | 939 | ||
940 | spin_unlock_bh(&host->lock); | 940 | spin_unlock_bh(&host->lock); |
941 | 941 | ||
942 | return csr & WBSD_WRPT; | 942 | return !!(csr & WBSD_WRPT); |
943 | } | 943 | } |
944 | 944 | ||
945 | static const struct mmc_host_ops wbsd_ops = { | 945 | static const struct mmc_host_ops wbsd_ops = { |
@@ -1219,7 +1219,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev) | |||
1219 | mmc->f_min = 375000; | 1219 | mmc->f_min = 375000; |
1220 | mmc->f_max = 24000000; | 1220 | mmc->f_max = 24000000; |
1221 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; | 1221 | mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; |
1222 | mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; | 1222 | mmc->caps = MMC_CAP_4_BIT_DATA; |
1223 | 1223 | ||
1224 | spin_lock_init(&host->lock); | 1224 | spin_lock_init(&host->lock); |
1225 | 1225 | ||
@@ -1420,7 +1420,7 @@ kfree: | |||
1420 | 1420 | ||
1421 | dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, | 1421 | dma_unmap_single(mmc_dev(host->mmc), host->dma_addr, |
1422 | WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); | 1422 | WBSD_DMA_SIZE, DMA_BIDIRECTIONAL); |
1423 | host->dma_addr = (dma_addr_t)NULL; | 1423 | host->dma_addr = 0; |
1424 | 1424 | ||
1425 | kfree(host->dma_buffer); | 1425 | kfree(host->dma_buffer); |
1426 | host->dma_buffer = NULL; | 1426 | host->dma_buffer = NULL; |
@@ -1445,7 +1445,7 @@ static void wbsd_release_dma(struct wbsd_host *host) | |||
1445 | 1445 | ||
1446 | host->dma = -1; | 1446 | host->dma = -1; |
1447 | host->dma_buffer = NULL; | 1447 | host->dma_buffer = NULL; |
1448 | host->dma_addr = (dma_addr_t)NULL; | 1448 | host->dma_addr = 0; |
1449 | } | 1449 | } |
1450 | 1450 | ||
1451 | /* | 1451 | /* |
@@ -1765,7 +1765,7 @@ static void __devexit wbsd_shutdown(struct device *dev, int pnp) | |||
1765 | static int __devinit wbsd_probe(struct platform_device *dev) | 1765 | static int __devinit wbsd_probe(struct platform_device *dev) |
1766 | { | 1766 | { |
1767 | /* Use the module parameters for resources */ | 1767 | /* Use the module parameters for resources */ |
1768 | return wbsd_init(&dev->dev, io, irq, dma, 0); | 1768 | return wbsd_init(&dev->dev, param_io, param_irq, param_dma, 0); |
1769 | } | 1769 | } |
1770 | 1770 | ||
1771 | static int __devexit wbsd_remove(struct platform_device *dev) | 1771 | static int __devexit wbsd_remove(struct platform_device *dev) |
@@ -1979,14 +1979,14 @@ static int __init wbsd_drv_init(void) | |||
1979 | 1979 | ||
1980 | #ifdef CONFIG_PNP | 1980 | #ifdef CONFIG_PNP |
1981 | 1981 | ||
1982 | if (!nopnp) { | 1982 | if (!param_nopnp) { |
1983 | result = pnp_register_driver(&wbsd_pnp_driver); | 1983 | result = pnp_register_driver(&wbsd_pnp_driver); |
1984 | if (result < 0) | 1984 | if (result < 0) |
1985 | return result; | 1985 | return result; |
1986 | } | 1986 | } |
1987 | #endif /* CONFIG_PNP */ | 1987 | #endif /* CONFIG_PNP */ |
1988 | 1988 | ||
1989 | if (nopnp) { | 1989 | if (param_nopnp) { |
1990 | result = platform_driver_register(&wbsd_driver); | 1990 | result = platform_driver_register(&wbsd_driver); |
1991 | if (result < 0) | 1991 | if (result < 0) |
1992 | return result; | 1992 | return result; |
@@ -2012,12 +2012,12 @@ static void __exit wbsd_drv_exit(void) | |||
2012 | { | 2012 | { |
2013 | #ifdef CONFIG_PNP | 2013 | #ifdef CONFIG_PNP |
2014 | 2014 | ||
2015 | if (!nopnp) | 2015 | if (!param_nopnp) |
2016 | pnp_unregister_driver(&wbsd_pnp_driver); | 2016 | pnp_unregister_driver(&wbsd_pnp_driver); |
2017 | 2017 | ||
2018 | #endif /* CONFIG_PNP */ | 2018 | #endif /* CONFIG_PNP */ |
2019 | 2019 | ||
2020 | if (nopnp) { | 2020 | if (param_nopnp) { |
2021 | platform_device_unregister(wbsd_device); | 2021 | platform_device_unregister(wbsd_device); |
2022 | 2022 | ||
2023 | platform_driver_unregister(&wbsd_driver); | 2023 | platform_driver_unregister(&wbsd_driver); |
@@ -2029,11 +2029,11 @@ static void __exit wbsd_drv_exit(void) | |||
2029 | module_init(wbsd_drv_init); | 2029 | module_init(wbsd_drv_init); |
2030 | module_exit(wbsd_drv_exit); | 2030 | module_exit(wbsd_drv_exit); |
2031 | #ifdef CONFIG_PNP | 2031 | #ifdef CONFIG_PNP |
2032 | module_param(nopnp, uint, 0444); | 2032 | module_param_named(nopnp, param_nopnp, uint, 0444); |
2033 | #endif | 2033 | #endif |
2034 | module_param(io, uint, 0444); | 2034 | module_param_named(io, param_io, uint, 0444); |
2035 | module_param(irq, uint, 0444); | 2035 | module_param_named(irq, param_irq, uint, 0444); |
2036 | module_param(dma, int, 0444); | 2036 | module_param_named(dma, param_dma, int, 0444); |
2037 | 2037 | ||
2038 | MODULE_LICENSE("GPL"); | 2038 | MODULE_LICENSE("GPL"); |
2039 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); | 2039 | MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); |
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 665341e43055..387a13395015 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c | |||
@@ -585,8 +585,9 @@ static struct config_item_type netconsole_target_type = { | |||
585 | * Group operations and type for netconsole_subsys. | 585 | * Group operations and type for netconsole_subsys. |
586 | */ | 586 | */ |
587 | 587 | ||
588 | static struct config_item *make_netconsole_target(struct config_group *group, | 588 | static int make_netconsole_target(struct config_group *group, |
589 | const char *name) | 589 | const char *name, |
590 | struct config_item **new_item) | ||
590 | { | 591 | { |
591 | unsigned long flags; | 592 | unsigned long flags; |
592 | struct netconsole_target *nt; | 593 | struct netconsole_target *nt; |
@@ -598,7 +599,7 @@ static struct config_item *make_netconsole_target(struct config_group *group, | |||
598 | nt = kzalloc(sizeof(*nt), GFP_KERNEL); | 599 | nt = kzalloc(sizeof(*nt), GFP_KERNEL); |
599 | if (!nt) { | 600 | if (!nt) { |
600 | printk(KERN_ERR "netconsole: failed to allocate memory\n"); | 601 | printk(KERN_ERR "netconsole: failed to allocate memory\n"); |
601 | return NULL; | 602 | return -ENOMEM; |
602 | } | 603 | } |
603 | 604 | ||
604 | nt->np.name = "netconsole"; | 605 | nt->np.name = "netconsole"; |
@@ -615,7 +616,8 @@ static struct config_item *make_netconsole_target(struct config_group *group, | |||
615 | list_add(&nt->list, &target_list); | 616 | list_add(&nt->list, &target_list); |
616 | spin_unlock_irqrestore(&target_list_lock, flags); | 617 | spin_unlock_irqrestore(&target_list_lock, flags); |
617 | 618 | ||
618 | return &nt->item; | 619 | *new_item = &nt->item; |
620 | return 0; | ||
619 | } | 621 | } |
620 | 622 | ||
621 | static void drop_netconsole_target(struct config_group *group, | 623 | static void drop_netconsole_target(struct config_group *group, |
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c index 3dd537be87d8..b54e2ea8346b 100644 --- a/drivers/net/wireless/libertas/if_sdio.c +++ b/drivers/net/wireless/libertas/if_sdio.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/net/wireless/libertas/if_sdio.c | 2 | * linux/drivers/net/wireless/libertas/if_sdio.c |
3 | * | 3 | * |
4 | * Copyright 2007 Pierre Ossman | 4 | * Copyright 2007-2008 Pierre Ossman |
5 | * | 5 | * |
6 | * Inspired by if_cs.c, Copyright 2007 Holger Schurig | 6 | * Inspired by if_cs.c, Copyright 2007 Holger Schurig |
7 | * | 7 | * |
@@ -266,13 +266,10 @@ static int if_sdio_card_to_host(struct if_sdio_card *card) | |||
266 | 266 | ||
267 | /* | 267 | /* |
268 | * The transfer must be in one transaction or the firmware | 268 | * The transfer must be in one transaction or the firmware |
269 | * goes suicidal. | 269 | * goes suicidal. There's no way to guarantee that for all |
270 | * controllers, but we can at least try. | ||
270 | */ | 271 | */ |
271 | chunk = size; | 272 | chunk = sdio_align_size(card->func, size); |
272 | if ((chunk > card->func->cur_blksize) || (chunk > 512)) { | ||
273 | chunk = (chunk + card->func->cur_blksize - 1) / | ||
274 | card->func->cur_blksize * card->func->cur_blksize; | ||
275 | } | ||
276 | 273 | ||
277 | ret = sdio_readsb(card->func, card->buffer, card->ioport, chunk); | 274 | ret = sdio_readsb(card->func, card->buffer, card->ioport, chunk); |
278 | if (ret) | 275 | if (ret) |
@@ -696,13 +693,10 @@ static int if_sdio_host_to_card(struct lbs_private *priv, | |||
696 | 693 | ||
697 | /* | 694 | /* |
698 | * The transfer must be in one transaction or the firmware | 695 | * The transfer must be in one transaction or the firmware |
699 | * goes suicidal. | 696 | * goes suicidal. There's no way to guarantee that for all |
697 | * controllers, but we can at least try. | ||
700 | */ | 698 | */ |
701 | size = nb + 4; | 699 | size = sdio_align_size(card->func, nb + 4); |
702 | if ((size > card->func->cur_blksize) || (size > 512)) { | ||
703 | size = (size + card->func->cur_blksize - 1) / | ||
704 | card->func->cur_blksize * card->func->cur_blksize; | ||
705 | } | ||
706 | 700 | ||
707 | packet = kzalloc(sizeof(struct if_sdio_packet) + size, | 701 | packet = kzalloc(sizeof(struct if_sdio_packet) + size, |
708 | GFP_ATOMIC); | 702 | GFP_ATOMIC); |
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile index 4d1ce2e7361e..7d63f8ced24b 100644 --- a/drivers/pci/Makefile +++ b/drivers/pci/Makefile | |||
@@ -2,7 +2,7 @@ | |||
2 | # Makefile for the PCI bus specific drivers. | 2 | # Makefile for the PCI bus specific drivers. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-y += access.o bus.o probe.o remove.o pci.o quirks.o \ | 5 | obj-y += access.o bus.o probe.o remove.o pci.o quirks.o slot.o \ |
6 | pci-driver.o search.o pci-sysfs.o rom.o setup-res.o | 6 | pci-driver.o search.o pci-sysfs.o rom.o setup-res.o |
7 | obj-$(CONFIG_PROC_FS) += proc.o | 7 | obj-$(CONFIG_PROC_FS) += proc.o |
8 | 8 | ||
diff --git a/drivers/pci/hotplug/acpi_pcihp.c b/drivers/pci/hotplug/acpi_pcihp.c index f8c187a763bd..93e37f0666ab 100644 --- a/drivers/pci/hotplug/acpi_pcihp.c +++ b/drivers/pci/hotplug/acpi_pcihp.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/types.h> | 30 | #include <linux/types.h> |
31 | #include <linux/pci.h> | 31 | #include <linux/pci.h> |
32 | #include <linux/pci_hotplug.h> | 32 | #include <linux/pci_hotplug.h> |
33 | #include <linux/pci-acpi.h> | ||
33 | #include <acpi/acpi.h> | 34 | #include <acpi/acpi.h> |
34 | #include <acpi/acpi_bus.h> | 35 | #include <acpi/acpi_bus.h> |
35 | #include <acpi/actypes.h> | 36 | #include <acpi/actypes.h> |
@@ -299,7 +300,7 @@ free_and_return: | |||
299 | * | 300 | * |
300 | * @handle - the handle of the hotplug controller. | 301 | * @handle - the handle of the hotplug controller. |
301 | */ | 302 | */ |
302 | acpi_status acpi_run_oshp(acpi_handle handle) | 303 | static acpi_status acpi_run_oshp(acpi_handle handle) |
303 | { | 304 | { |
304 | acpi_status status; | 305 | acpi_status status; |
305 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; | 306 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; |
@@ -322,9 +323,6 @@ acpi_status acpi_run_oshp(acpi_handle handle) | |||
322 | kfree(string.pointer); | 323 | kfree(string.pointer); |
323 | return status; | 324 | return status; |
324 | } | 325 | } |
325 | EXPORT_SYMBOL_GPL(acpi_run_oshp); | ||
326 | |||
327 | |||
328 | 326 | ||
329 | /* acpi_get_hp_params_from_firmware | 327 | /* acpi_get_hp_params_from_firmware |
330 | * | 328 | * |
@@ -374,6 +372,85 @@ acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus, | |||
374 | } | 372 | } |
375 | EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware); | 373 | EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware); |
376 | 374 | ||
375 | /** | ||
376 | * acpi_get_hp_hw_control_from_firmware | ||
377 | * @dev: the pci_dev of the bridge that has a hotplug controller | ||
378 | * @flags: requested control bits for _OSC | ||
379 | * | ||
380 | * Attempt to take hotplug control from firmware. | ||
381 | */ | ||
382 | int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags) | ||
383 | { | ||
384 | acpi_status status; | ||
385 | acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); | ||
386 | struct pci_dev *pdev = dev; | ||
387 | struct pci_bus *parent; | ||
388 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
389 | |||
390 | flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | | ||
391 | OSC_SHPC_NATIVE_HP_CONTROL | | ||
392 | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); | ||
393 | if (!flags) { | ||
394 | err("Invalid flags %u specified!\n", flags); | ||
395 | return -EINVAL; | ||
396 | } | ||
397 | |||
398 | /* | ||
399 | * Per PCI firmware specification, we should run the ACPI _OSC | ||
400 | * method to get control of hotplug hardware before using it. If | ||
401 | * an _OSC is missing, we look for an OSHP to do the same thing. | ||
402 | * To handle different BIOS behavior, we look for _OSC and OSHP | ||
403 | * within the scope of the hotplug controller and its parents, | ||
404 | * upto the host bridge under which this controller exists. | ||
405 | */ | ||
406 | while (!handle) { | ||
407 | /* | ||
408 | * This hotplug controller was not listed in the ACPI name | ||
409 | * space at all. Try to get acpi handle of parent pci bus. | ||
410 | */ | ||
411 | if (!pdev || !pdev->bus->parent) | ||
412 | break; | ||
413 | parent = pdev->bus->parent; | ||
414 | dbg("Could not find %s in acpi namespace, trying parent\n", | ||
415 | pci_name(pdev)); | ||
416 | if (!parent->self) | ||
417 | /* Parent must be a host bridge */ | ||
418 | handle = acpi_get_pci_rootbridge_handle( | ||
419 | pci_domain_nr(parent), | ||
420 | parent->number); | ||
421 | else | ||
422 | handle = DEVICE_ACPI_HANDLE(&(parent->self->dev)); | ||
423 | pdev = parent->self; | ||
424 | } | ||
425 | |||
426 | while (handle) { | ||
427 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); | ||
428 | dbg("Trying to get hotplug control for %s \n", | ||
429 | (char *)string.pointer); | ||
430 | status = pci_osc_control_set(handle, flags); | ||
431 | if (status == AE_NOT_FOUND) | ||
432 | status = acpi_run_oshp(handle); | ||
433 | if (ACPI_SUCCESS(status)) { | ||
434 | dbg("Gained control for hotplug HW for pci %s (%s)\n", | ||
435 | pci_name(dev), (char *)string.pointer); | ||
436 | kfree(string.pointer); | ||
437 | return 0; | ||
438 | } | ||
439 | if (acpi_root_bridge(handle)) | ||
440 | break; | ||
441 | chandle = handle; | ||
442 | status = acpi_get_parent(chandle, &handle); | ||
443 | if (ACPI_FAILURE(status)) | ||
444 | break; | ||
445 | } | ||
446 | |||
447 | dbg("Cannot get control of hotplug hardware for pci %s\n", | ||
448 | pci_name(dev)); | ||
449 | |||
450 | kfree(string.pointer); | ||
451 | return -ENODEV; | ||
452 | } | ||
453 | EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware); | ||
377 | 454 | ||
378 | /* acpi_root_bridge - check to see if this acpi object is a root bridge | 455 | /* acpi_root_bridge - check to see if this acpi object is a root bridge |
379 | * | 456 | * |
diff --git a/drivers/pci/hotplug/acpiphp.h b/drivers/pci/hotplug/acpiphp.h index 7a29164d4b32..eecf7cbf4139 100644 --- a/drivers/pci/hotplug/acpiphp.h +++ b/drivers/pci/hotplug/acpiphp.h | |||
@@ -215,7 +215,6 @@ extern u8 acpiphp_get_power_status (struct acpiphp_slot *slot); | |||
215 | extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot); | 215 | extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot); |
216 | extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); | 216 | extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot); |
217 | extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); | 217 | extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot); |
218 | extern u32 acpiphp_get_address (struct acpiphp_slot *slot); | ||
219 | 218 | ||
220 | /* variables */ | 219 | /* variables */ |
221 | extern int acpiphp_debug; | 220 | extern int acpiphp_debug; |
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c index 7af68ba27903..0e496e866a84 100644 --- a/drivers/pci/hotplug/acpiphp_core.c +++ b/drivers/pci/hotplug/acpiphp_core.c | |||
@@ -70,7 +70,6 @@ static int disable_slot (struct hotplug_slot *slot); | |||
70 | static int set_attention_status (struct hotplug_slot *slot, u8 value); | 70 | static int set_attention_status (struct hotplug_slot *slot, u8 value); |
71 | static int get_power_status (struct hotplug_slot *slot, u8 *value); | 71 | static int get_power_status (struct hotplug_slot *slot, u8 *value); |
72 | static int get_attention_status (struct hotplug_slot *slot, u8 *value); | 72 | static int get_attention_status (struct hotplug_slot *slot, u8 *value); |
73 | static int get_address (struct hotplug_slot *slot, u32 *value); | ||
74 | static int get_latch_status (struct hotplug_slot *slot, u8 *value); | 73 | static int get_latch_status (struct hotplug_slot *slot, u8 *value); |
75 | static int get_adapter_status (struct hotplug_slot *slot, u8 *value); | 74 | static int get_adapter_status (struct hotplug_slot *slot, u8 *value); |
76 | 75 | ||
@@ -83,7 +82,6 @@ static struct hotplug_slot_ops acpi_hotplug_slot_ops = { | |||
83 | .get_attention_status = get_attention_status, | 82 | .get_attention_status = get_attention_status, |
84 | .get_latch_status = get_latch_status, | 83 | .get_latch_status = get_latch_status, |
85 | .get_adapter_status = get_adapter_status, | 84 | .get_adapter_status = get_adapter_status, |
86 | .get_address = get_address, | ||
87 | }; | 85 | }; |
88 | 86 | ||
89 | 87 | ||
@@ -274,23 +272,6 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) | |||
274 | return 0; | 272 | return 0; |
275 | } | 273 | } |
276 | 274 | ||
277 | |||
278 | /** | ||
279 | * get_address - get pci address of a slot | ||
280 | * @hotplug_slot: slot to get status | ||
281 | * @value: pointer to struct pci_busdev (seg, bus, dev) | ||
282 | */ | ||
283 | static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) | ||
284 | { | ||
285 | struct slot *slot = hotplug_slot->private; | ||
286 | |||
287 | dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); | ||
288 | |||
289 | *value = acpiphp_get_address(slot->acpi_slot); | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | static int __init init_acpi(void) | 275 | static int __init init_acpi(void) |
295 | { | 276 | { |
296 | int retval; | 277 | int retval; |
@@ -357,7 +338,11 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot) | |||
357 | acpiphp_slot->slot = slot; | 338 | acpiphp_slot->slot = slot; |
358 | snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun); | 339 | snprintf(slot->name, sizeof(slot->name), "%u", slot->acpi_slot->sun); |
359 | 340 | ||
360 | retval = pci_hp_register(slot->hotplug_slot); | 341 | retval = pci_hp_register(slot->hotplug_slot, |
342 | acpiphp_slot->bridge->pci_bus, | ||
343 | acpiphp_slot->device); | ||
344 | if (retval == -EBUSY) | ||
345 | goto error_hpslot; | ||
361 | if (retval) { | 346 | if (retval) { |
362 | err("pci_hp_register failed with error %d\n", retval); | 347 | err("pci_hp_register failed with error %d\n", retval); |
363 | goto error_hpslot; | 348 | goto error_hpslot; |
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 91156f85a926..a3e4705dd8f0 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c | |||
@@ -258,7 +258,12 @@ register_slot(acpi_handle handle, u32 lvl, void *context, void **rv) | |||
258 | bridge->pci_bus->number, slot->device); | 258 | bridge->pci_bus->number, slot->device); |
259 | retval = acpiphp_register_hotplug_slot(slot); | 259 | retval = acpiphp_register_hotplug_slot(slot); |
260 | if (retval) { | 260 | if (retval) { |
261 | warn("acpiphp_register_hotplug_slot failed(err code = 0x%x)\n", retval); | 261 | if (retval == -EBUSY) |
262 | warn("Slot %d already registered by another " | ||
263 | "hotplug driver\n", slot->sun); | ||
264 | else | ||
265 | warn("acpiphp_register_hotplug_slot failed " | ||
266 | "(err code = 0x%x)\n", retval); | ||
262 | goto err_exit; | 267 | goto err_exit; |
263 | } | 268 | } |
264 | } | 269 | } |
@@ -1878,19 +1883,3 @@ u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot) | |||
1878 | 1883 | ||
1879 | return (sta == 0) ? 0 : 1; | 1884 | return (sta == 0) ? 0 : 1; |
1880 | } | 1885 | } |
1881 | |||
1882 | |||
1883 | /* | ||
1884 | * pci address (seg/bus/dev) | ||
1885 | */ | ||
1886 | u32 acpiphp_get_address(struct acpiphp_slot *slot) | ||
1887 | { | ||
1888 | u32 address; | ||
1889 | struct pci_bus *pci_bus = slot->bridge->pci_bus; | ||
1890 | |||
1891 | address = (pci_domain_nr(pci_bus) << 16) | | ||
1892 | (pci_bus->number << 8) | | ||
1893 | slot->device; | ||
1894 | |||
1895 | return address; | ||
1896 | } | ||
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c index ede9051fdb5d..2b7c45e39370 100644 --- a/drivers/pci/hotplug/acpiphp_ibm.c +++ b/drivers/pci/hotplug/acpiphp_ibm.c | |||
@@ -33,8 +33,10 @@ | |||
33 | #include <linux/kobject.h> | 33 | #include <linux/kobject.h> |
34 | #include <asm/uaccess.h> | 34 | #include <asm/uaccess.h> |
35 | #include <linux/moduleparam.h> | 35 | #include <linux/moduleparam.h> |
36 | #include <linux/pci.h> | ||
36 | 37 | ||
37 | #include "acpiphp.h" | 38 | #include "acpiphp.h" |
39 | #include "../pci.h" | ||
38 | 40 | ||
39 | #define DRIVER_VERSION "1.0.1" | 41 | #define DRIVER_VERSION "1.0.1" |
40 | #define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>" | 42 | #define DRIVER_AUTHOR "Irene Zubarev <zubarev@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>" |
@@ -430,7 +432,7 @@ static int __init ibm_acpiphp_init(void) | |||
430 | int retval = 0; | 432 | int retval = 0; |
431 | acpi_status status; | 433 | acpi_status status; |
432 | struct acpi_device *device; | 434 | struct acpi_device *device; |
433 | struct kobject *sysdir = &pci_hotplug_slots_kset->kobj; | 435 | struct kobject *sysdir = &pci_slots_kset->kobj; |
434 | 436 | ||
435 | dbg("%s\n", __func__); | 437 | dbg("%s\n", __func__); |
436 | 438 | ||
@@ -477,7 +479,7 @@ init_return: | |||
477 | static void __exit ibm_acpiphp_exit(void) | 479 | static void __exit ibm_acpiphp_exit(void) |
478 | { | 480 | { |
479 | acpi_status status; | 481 | acpi_status status; |
480 | struct kobject *sysdir = &pci_hotplug_slots_kset->kobj; | 482 | struct kobject *sysdir = &pci_slots_kset->kobj; |
481 | 483 | ||
482 | dbg("%s\n", __func__); | 484 | dbg("%s\n", __func__); |
483 | 485 | ||
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c index d8a6b80ab42a..935947991dc9 100644 --- a/drivers/pci/hotplug/cpci_hotplug_core.c +++ b/drivers/pci/hotplug/cpci_hotplug_core.c | |||
@@ -285,7 +285,7 @@ cpci_hp_register_bus(struct pci_bus *bus, u8 first, u8 last) | |||
285 | info->attention_status = cpci_get_attention_status(slot); | 285 | info->attention_status = cpci_get_attention_status(slot); |
286 | 286 | ||
287 | dbg("registering slot %s", slot->hotplug_slot->name); | 287 | dbg("registering slot %s", slot->hotplug_slot->name); |
288 | status = pci_hp_register(slot->hotplug_slot); | 288 | status = pci_hp_register(slot->hotplug_slot, bus, i); |
289 | if (status) { | 289 | if (status) { |
290 | err("pci_hp_register failed with error %d", status); | 290 | err("pci_hp_register failed with error %d", status); |
291 | goto error_name; | 291 | goto error_name; |
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c index 36b115b27b0b..54defec51d08 100644 --- a/drivers/pci/hotplug/cpqphp_core.c +++ b/drivers/pci/hotplug/cpqphp_core.c | |||
@@ -434,7 +434,9 @@ static int ctrl_slot_setup(struct controller *ctrl, | |||
434 | slot->bus, slot->device, | 434 | slot->bus, slot->device, |
435 | slot->number, ctrl->slot_device_offset, | 435 | slot->number, ctrl->slot_device_offset, |
436 | slot_number); | 436 | slot_number); |
437 | result = pci_hp_register(hotplug_slot); | 437 | result = pci_hp_register(hotplug_slot, |
438 | ctrl->pci_dev->subordinate, | ||
439 | slot->device); | ||
438 | if (result) { | 440 | if (result) { |
439 | err("pci_hp_register failed with error %d\n", result); | 441 | err("pci_hp_register failed with error %d\n", result); |
440 | goto error_name; | 442 | goto error_name; |
diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c index 7e9a827c2687..40337a06c18a 100644 --- a/drivers/pci/hotplug/fakephp.c +++ b/drivers/pci/hotplug/fakephp.c | |||
@@ -66,6 +66,7 @@ struct dummy_slot { | |||
66 | struct pci_dev *dev; | 66 | struct pci_dev *dev; |
67 | struct work_struct remove_work; | 67 | struct work_struct remove_work; |
68 | unsigned long removed; | 68 | unsigned long removed; |
69 | char name[8]; | ||
69 | }; | 70 | }; |
70 | 71 | ||
71 | static int debug; | 72 | static int debug; |
@@ -100,6 +101,7 @@ static int add_slot(struct pci_dev *dev) | |||
100 | struct dummy_slot *dslot; | 101 | struct dummy_slot *dslot; |
101 | struct hotplug_slot *slot; | 102 | struct hotplug_slot *slot; |
102 | int retval = -ENOMEM; | 103 | int retval = -ENOMEM; |
104 | static int count = 1; | ||
103 | 105 | ||
104 | slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); | 106 | slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL); |
105 | if (!slot) | 107 | if (!slot) |
@@ -113,18 +115,18 @@ static int add_slot(struct pci_dev *dev) | |||
113 | slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; | 115 | slot->info->max_bus_speed = PCI_SPEED_UNKNOWN; |
114 | slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; | 116 | slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN; |
115 | 117 | ||
116 | slot->name = &dev->dev.bus_id[0]; | ||
117 | dbg("slot->name = %s\n", slot->name); | ||
118 | |||
119 | dslot = kzalloc(sizeof(struct dummy_slot), GFP_KERNEL); | 118 | dslot = kzalloc(sizeof(struct dummy_slot), GFP_KERNEL); |
120 | if (!dslot) | 119 | if (!dslot) |
121 | goto error_info; | 120 | goto error_info; |
122 | 121 | ||
122 | slot->name = dslot->name; | ||
123 | snprintf(slot->name, sizeof(dslot->name), "fake%d", count++); | ||
124 | dbg("slot->name = %s\n", slot->name); | ||
123 | slot->ops = &dummy_hotplug_slot_ops; | 125 | slot->ops = &dummy_hotplug_slot_ops; |
124 | slot->release = &dummy_release; | 126 | slot->release = &dummy_release; |
125 | slot->private = dslot; | 127 | slot->private = dslot; |
126 | 128 | ||
127 | retval = pci_hp_register(slot); | 129 | retval = pci_hp_register(slot, dev->bus, PCI_SLOT(dev->devfn)); |
128 | if (retval) { | 130 | if (retval) { |
129 | err("pci_hp_register failed with error %d\n", retval); | 131 | err("pci_hp_register failed with error %d\n", retval); |
130 | goto error_dslot; | 132 | goto error_dslot; |
@@ -148,17 +150,17 @@ error: | |||
148 | static int __init pci_scan_buses(void) | 150 | static int __init pci_scan_buses(void) |
149 | { | 151 | { |
150 | struct pci_dev *dev = NULL; | 152 | struct pci_dev *dev = NULL; |
151 | int retval = 0; | 153 | int lastslot = 0; |
152 | 154 | ||
153 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { | 155 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { |
154 | retval = add_slot(dev); | 156 | if (PCI_FUNC(dev->devfn) > 0 && |
155 | if (retval) { | 157 | lastslot == PCI_SLOT(dev->devfn)) |
156 | pci_dev_put(dev); | 158 | continue; |
157 | break; | 159 | lastslot = PCI_SLOT(dev->devfn); |
158 | } | 160 | add_slot(dev); |
159 | } | 161 | } |
160 | 162 | ||
161 | return retval; | 163 | return 0; |
162 | } | 164 | } |
163 | 165 | ||
164 | static void remove_slot(struct dummy_slot *dslot) | 166 | static void remove_slot(struct dummy_slot *dslot) |
@@ -296,23 +298,9 @@ static int enable_slot(struct hotplug_slot *hotplug_slot) | |||
296 | return 0; | 298 | return 0; |
297 | } | 299 | } |
298 | 300 | ||
299 | /* find the hotplug_slot for the pci_dev */ | ||
300 | static struct hotplug_slot *get_slot_from_dev(struct pci_dev *dev) | ||
301 | { | ||
302 | struct dummy_slot *dslot; | ||
303 | |||
304 | list_for_each_entry(dslot, &slot_list, node) { | ||
305 | if (dslot->dev == dev) | ||
306 | return dslot->slot; | ||
307 | } | ||
308 | return NULL; | ||
309 | } | ||
310 | |||
311 | |||
312 | static int disable_slot(struct hotplug_slot *slot) | 301 | static int disable_slot(struct hotplug_slot *slot) |
313 | { | 302 | { |
314 | struct dummy_slot *dslot; | 303 | struct dummy_slot *dslot; |
315 | struct hotplug_slot *hslot; | ||
316 | struct pci_dev *dev; | 304 | struct pci_dev *dev; |
317 | int func; | 305 | int func; |
318 | 306 | ||
@@ -322,41 +310,27 @@ static int disable_slot(struct hotplug_slot *slot) | |||
322 | 310 | ||
323 | dbg("%s - physical_slot = %s\n", __func__, slot->name); | 311 | dbg("%s - physical_slot = %s\n", __func__, slot->name); |
324 | 312 | ||
325 | /* don't disable bridged devices just yet, we can't handle them easily... */ | 313 | for (func = 7; func >= 0; func--) { |
326 | if (dslot->dev->subordinate) { | 314 | dev = pci_get_slot(dslot->dev->bus, dslot->dev->devfn + func); |
327 | err("Can't remove PCI devices with other PCI devices behind it yet.\n"); | 315 | if (!dev) |
328 | return -ENODEV; | 316 | continue; |
329 | } | 317 | |
330 | if (test_and_set_bit(0, &dslot->removed)) { | 318 | if (test_and_set_bit(0, &dslot->removed)) { |
331 | dbg("Slot already scheduled for removal\n"); | 319 | dbg("Slot already scheduled for removal\n"); |
332 | return -ENODEV; | 320 | return -ENODEV; |
333 | } | ||
334 | /* search for subfunctions and disable them first */ | ||
335 | if (!(dslot->dev->devfn & 7)) { | ||
336 | for (func = 1; func < 8; func++) { | ||
337 | dev = pci_get_slot(dslot->dev->bus, | ||
338 | dslot->dev->devfn + func); | ||
339 | if (dev) { | ||
340 | hslot = get_slot_from_dev(dev); | ||
341 | if (hslot) | ||
342 | disable_slot(hslot); | ||
343 | else { | ||
344 | err("Hotplug slot not found for subfunction of PCI device\n"); | ||
345 | return -ENODEV; | ||
346 | } | ||
347 | pci_dev_put(dev); | ||
348 | } else | ||
349 | dbg("No device in slot found\n"); | ||
350 | } | 321 | } |
351 | } | ||
352 | 322 | ||
353 | /* remove the device from the pci core */ | 323 | /* queue work item to blow away this sysfs entry and other |
354 | pci_remove_bus_device(dslot->dev); | 324 | * parts. |
325 | */ | ||
326 | INIT_WORK(&dslot->remove_work, remove_slot_worker); | ||
327 | queue_work(dummyphp_wq, &dslot->remove_work); | ||
355 | 328 | ||
356 | /* queue work item to blow away this sysfs entry and other parts. */ | 329 | /* blow away this sysfs entry and other parts. */ |
357 | INIT_WORK(&dslot->remove_work, remove_slot_worker); | 330 | remove_slot(dslot); |
358 | queue_work(dummyphp_wq, &dslot->remove_work); | ||
359 | 331 | ||
332 | pci_dev_put(dev); | ||
333 | } | ||
360 | return 0; | 334 | return 0; |
361 | } | 335 | } |
362 | 336 | ||
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c index dca7efc14be2..8467d0287325 100644 --- a/drivers/pci/hotplug/ibmphp_ebda.c +++ b/drivers/pci/hotplug/ibmphp_ebda.c | |||
@@ -1001,7 +1001,8 @@ static int __init ebda_rsrc_controller (void) | |||
1001 | tmp_slot = list_entry (list, struct slot, ibm_slot_list); | 1001 | tmp_slot = list_entry (list, struct slot, ibm_slot_list); |
1002 | 1002 | ||
1003 | snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot)); | 1003 | snprintf (tmp_slot->hotplug_slot->name, 30, "%s", create_file_name (tmp_slot)); |
1004 | pci_hp_register (tmp_slot->hotplug_slot); | 1004 | pci_hp_register(tmp_slot->hotplug_slot, |
1005 | pci_find_bus(0, tmp_slot->bus), tmp_slot->device); | ||
1005 | } | 1006 | } |
1006 | 1007 | ||
1007 | print_ebda_hpc (); | 1008 | print_ebda_hpc (); |
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c index a11021e8ce37..5f85b1b120e3 100644 --- a/drivers/pci/hotplug/pci_hotplug_core.c +++ b/drivers/pci/hotplug/pci_hotplug_core.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/pci.h> | 40 | #include <linux/pci.h> |
41 | #include <linux/pci_hotplug.h> | 41 | #include <linux/pci_hotplug.h> |
42 | #include <asm/uaccess.h> | 42 | #include <asm/uaccess.h> |
43 | #include "../pci.h" | ||
43 | 44 | ||
44 | #define MY_NAME "pci_hotplug" | 45 | #define MY_NAME "pci_hotplug" |
45 | 46 | ||
@@ -60,41 +61,7 @@ static int debug; | |||
60 | ////////////////////////////////////////////////////////////////// | 61 | ////////////////////////////////////////////////////////////////// |
61 | 62 | ||
62 | static LIST_HEAD(pci_hotplug_slot_list); | 63 | static LIST_HEAD(pci_hotplug_slot_list); |
63 | 64 | static DEFINE_SPINLOCK(pci_hotplug_slot_list_lock); | |
64 | struct kset *pci_hotplug_slots_kset; | ||
65 | |||
66 | static ssize_t hotplug_slot_attr_show(struct kobject *kobj, | ||
67 | struct attribute *attr, char *buf) | ||
68 | { | ||
69 | struct hotplug_slot *slot = to_hotplug_slot(kobj); | ||
70 | struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr); | ||
71 | return attribute->show ? attribute->show(slot, buf) : -EIO; | ||
72 | } | ||
73 | |||
74 | static ssize_t hotplug_slot_attr_store(struct kobject *kobj, | ||
75 | struct attribute *attr, const char *buf, size_t len) | ||
76 | { | ||
77 | struct hotplug_slot *slot = to_hotplug_slot(kobj); | ||
78 | struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr); | ||
79 | return attribute->store ? attribute->store(slot, buf, len) : -EIO; | ||
80 | } | ||
81 | |||
82 | static struct sysfs_ops hotplug_slot_sysfs_ops = { | ||
83 | .show = hotplug_slot_attr_show, | ||
84 | .store = hotplug_slot_attr_store, | ||
85 | }; | ||
86 | |||
87 | static void hotplug_slot_release(struct kobject *kobj) | ||
88 | { | ||
89 | struct hotplug_slot *slot = to_hotplug_slot(kobj); | ||
90 | if (slot->release) | ||
91 | slot->release(slot); | ||
92 | } | ||
93 | |||
94 | static struct kobj_type hotplug_slot_ktype = { | ||
95 | .sysfs_ops = &hotplug_slot_sysfs_ops, | ||
96 | .release = &hotplug_slot_release, | ||
97 | }; | ||
98 | 65 | ||
99 | /* these strings match up with the values in pci_bus_speed */ | 66 | /* these strings match up with the values in pci_bus_speed */ |
100 | static char *pci_bus_speed_strings[] = { | 67 | static char *pci_bus_speed_strings[] = { |
@@ -149,16 +116,15 @@ GET_STATUS(power_status, u8) | |||
149 | GET_STATUS(attention_status, u8) | 116 | GET_STATUS(attention_status, u8) |
150 | GET_STATUS(latch_status, u8) | 117 | GET_STATUS(latch_status, u8) |
151 | GET_STATUS(adapter_status, u8) | 118 | GET_STATUS(adapter_status, u8) |
152 | GET_STATUS(address, u32) | ||
153 | GET_STATUS(max_bus_speed, enum pci_bus_speed) | 119 | GET_STATUS(max_bus_speed, enum pci_bus_speed) |
154 | GET_STATUS(cur_bus_speed, enum pci_bus_speed) | 120 | GET_STATUS(cur_bus_speed, enum pci_bus_speed) |
155 | 121 | ||
156 | static ssize_t power_read_file (struct hotplug_slot *slot, char *buf) | 122 | static ssize_t power_read_file(struct pci_slot *slot, char *buf) |
157 | { | 123 | { |
158 | int retval; | 124 | int retval; |
159 | u8 value; | 125 | u8 value; |
160 | 126 | ||
161 | retval = get_power_status (slot, &value); | 127 | retval = get_power_status(slot->hotplug, &value); |
162 | if (retval) | 128 | if (retval) |
163 | goto exit; | 129 | goto exit; |
164 | retval = sprintf (buf, "%d\n", value); | 130 | retval = sprintf (buf, "%d\n", value); |
@@ -166,9 +132,10 @@ exit: | |||
166 | return retval; | 132 | return retval; |
167 | } | 133 | } |
168 | 134 | ||
169 | static ssize_t power_write_file (struct hotplug_slot *slot, const char *buf, | 135 | static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf, |
170 | size_t count) | 136 | size_t count) |
171 | { | 137 | { |
138 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
172 | unsigned long lpower; | 139 | unsigned long lpower; |
173 | u8 power; | 140 | u8 power; |
174 | int retval = 0; | 141 | int retval = 0; |
@@ -204,29 +171,30 @@ exit: | |||
204 | return count; | 171 | return count; |
205 | } | 172 | } |
206 | 173 | ||
207 | static struct hotplug_slot_attribute hotplug_slot_attr_power = { | 174 | static struct pci_slot_attribute hotplug_slot_attr_power = { |
208 | .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR}, | 175 | .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR}, |
209 | .show = power_read_file, | 176 | .show = power_read_file, |
210 | .store = power_write_file | 177 | .store = power_write_file |
211 | }; | 178 | }; |
212 | 179 | ||
213 | static ssize_t attention_read_file (struct hotplug_slot *slot, char *buf) | 180 | static ssize_t attention_read_file(struct pci_slot *slot, char *buf) |
214 | { | 181 | { |
215 | int retval; | 182 | int retval; |
216 | u8 value; | 183 | u8 value; |
217 | 184 | ||
218 | retval = get_attention_status (slot, &value); | 185 | retval = get_attention_status(slot->hotplug, &value); |
219 | if (retval) | 186 | if (retval) |
220 | goto exit; | 187 | goto exit; |
221 | retval = sprintf (buf, "%d\n", value); | 188 | retval = sprintf(buf, "%d\n", value); |
222 | 189 | ||
223 | exit: | 190 | exit: |
224 | return retval; | 191 | return retval; |
225 | } | 192 | } |
226 | 193 | ||
227 | static ssize_t attention_write_file (struct hotplug_slot *slot, const char *buf, | 194 | static ssize_t attention_write_file(struct pci_slot *slot, const char *buf, |
228 | size_t count) | 195 | size_t count) |
229 | { | 196 | { |
197 | struct hotplug_slot_ops *ops = slot->hotplug->ops; | ||
230 | unsigned long lattention; | 198 | unsigned long lattention; |
231 | u8 attention; | 199 | u8 attention; |
232 | int retval = 0; | 200 | int retval = 0; |
@@ -235,13 +203,13 @@ static ssize_t attention_write_file (struct hotplug_slot *slot, const char *buf, | |||
235 | attention = (u8)(lattention & 0xff); | 203 | attention = (u8)(lattention & 0xff); |
236 | dbg (" - attention = %d\n", attention); | 204 | dbg (" - attention = %d\n", attention); |
237 | 205 | ||
238 | if (!try_module_get(slot->ops->owner)) { | 206 | if (!try_module_get(ops->owner)) { |
239 | retval = -ENODEV; | 207 | retval = -ENODEV; |
240 | goto exit; | 208 | goto exit; |
241 | } | 209 | } |
242 | if (slot->ops->set_attention_status) | 210 | if (ops->set_attention_status) |
243 | retval = slot->ops->set_attention_status(slot, attention); | 211 | retval = ops->set_attention_status(slot->hotplug, attention); |
244 | module_put(slot->ops->owner); | 212 | module_put(ops->owner); |
245 | 213 | ||
246 | exit: | 214 | exit: |
247 | if (retval) | 215 | if (retval) |
@@ -249,18 +217,18 @@ exit: | |||
249 | return count; | 217 | return count; |
250 | } | 218 | } |
251 | 219 | ||
252 | static struct hotplug_slot_attribute hotplug_slot_attr_attention = { | 220 | static struct pci_slot_attribute hotplug_slot_attr_attention = { |
253 | .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR}, | 221 | .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR}, |
254 | .show = attention_read_file, | 222 | .show = attention_read_file, |
255 | .store = attention_write_file | 223 | .store = attention_write_file |
256 | }; | 224 | }; |
257 | 225 | ||
258 | static ssize_t latch_read_file (struct hotplug_slot *slot, char *buf) | 226 | static ssize_t latch_read_file(struct pci_slot *slot, char *buf) |
259 | { | 227 | { |
260 | int retval; | 228 | int retval; |
261 | u8 value; | 229 | u8 value; |
262 | 230 | ||
263 | retval = get_latch_status (slot, &value); | 231 | retval = get_latch_status(slot->hotplug, &value); |
264 | if (retval) | 232 | if (retval) |
265 | goto exit; | 233 | goto exit; |
266 | retval = sprintf (buf, "%d\n", value); | 234 | retval = sprintf (buf, "%d\n", value); |
@@ -269,17 +237,17 @@ exit: | |||
269 | return retval; | 237 | return retval; |
270 | } | 238 | } |
271 | 239 | ||
272 | static struct hotplug_slot_attribute hotplug_slot_attr_latch = { | 240 | static struct pci_slot_attribute hotplug_slot_attr_latch = { |
273 | .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO}, | 241 | .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO}, |
274 | .show = latch_read_file, | 242 | .show = latch_read_file, |
275 | }; | 243 | }; |
276 | 244 | ||
277 | static ssize_t presence_read_file (struct hotplug_slot *slot, char *buf) | 245 | static ssize_t presence_read_file(struct pci_slot *slot, char *buf) |
278 | { | 246 | { |
279 | int retval; | 247 | int retval; |
280 | u8 value; | 248 | u8 value; |
281 | 249 | ||
282 | retval = get_adapter_status (slot, &value); | 250 | retval = get_adapter_status(slot->hotplug, &value); |
283 | if (retval) | 251 | if (retval) |
284 | goto exit; | 252 | goto exit; |
285 | retval = sprintf (buf, "%d\n", value); | 253 | retval = sprintf (buf, "%d\n", value); |
@@ -288,42 +256,20 @@ exit: | |||
288 | return retval; | 256 | return retval; |
289 | } | 257 | } |
290 | 258 | ||
291 | static struct hotplug_slot_attribute hotplug_slot_attr_presence = { | 259 | static struct pci_slot_attribute hotplug_slot_attr_presence = { |
292 | .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO}, | 260 | .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO}, |
293 | .show = presence_read_file, | 261 | .show = presence_read_file, |
294 | }; | 262 | }; |
295 | 263 | ||
296 | static ssize_t address_read_file (struct hotplug_slot *slot, char *buf) | ||
297 | { | ||
298 | int retval; | ||
299 | u32 address; | ||
300 | |||
301 | retval = get_address (slot, &address); | ||
302 | if (retval) | ||
303 | goto exit; | ||
304 | retval = sprintf (buf, "%04x:%02x:%02x\n", | ||
305 | (address >> 16) & 0xffff, | ||
306 | (address >> 8) & 0xff, | ||
307 | address & 0xff); | ||
308 | |||
309 | exit: | ||
310 | return retval; | ||
311 | } | ||
312 | |||
313 | static struct hotplug_slot_attribute hotplug_slot_attr_address = { | ||
314 | .attr = {.name = "address", .mode = S_IFREG | S_IRUGO}, | ||
315 | .show = address_read_file, | ||
316 | }; | ||
317 | |||
318 | static char *unknown_speed = "Unknown bus speed"; | 264 | static char *unknown_speed = "Unknown bus speed"; |
319 | 265 | ||
320 | static ssize_t max_bus_speed_read_file (struct hotplug_slot *slot, char *buf) | 266 | static ssize_t max_bus_speed_read_file(struct pci_slot *slot, char *buf) |
321 | { | 267 | { |
322 | char *speed_string; | 268 | char *speed_string; |
323 | int retval; | 269 | int retval; |
324 | enum pci_bus_speed value; | 270 | enum pci_bus_speed value; |
325 | 271 | ||
326 | retval = get_max_bus_speed (slot, &value); | 272 | retval = get_max_bus_speed(slot->hotplug, &value); |
327 | if (retval) | 273 | if (retval) |
328 | goto exit; | 274 | goto exit; |
329 | 275 | ||
@@ -338,18 +284,18 @@ exit: | |||
338 | return retval; | 284 | return retval; |
339 | } | 285 | } |
340 | 286 | ||
341 | static struct hotplug_slot_attribute hotplug_slot_attr_max_bus_speed = { | 287 | static struct pci_slot_attribute hotplug_slot_attr_max_bus_speed = { |
342 | .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO}, | 288 | .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO}, |
343 | .show = max_bus_speed_read_file, | 289 | .show = max_bus_speed_read_file, |
344 | }; | 290 | }; |
345 | 291 | ||
346 | static ssize_t cur_bus_speed_read_file (struct hotplug_slot *slot, char *buf) | 292 | static ssize_t cur_bus_speed_read_file(struct pci_slot *slot, char *buf) |
347 | { | 293 | { |
348 | char *speed_string; | 294 | char *speed_string; |
349 | int retval; | 295 | int retval; |
350 | enum pci_bus_speed value; | 296 | enum pci_bus_speed value; |
351 | 297 | ||
352 | retval = get_cur_bus_speed (slot, &value); | 298 | retval = get_cur_bus_speed(slot->hotplug, &value); |
353 | if (retval) | 299 | if (retval) |
354 | goto exit; | 300 | goto exit; |
355 | 301 | ||
@@ -364,14 +310,15 @@ exit: | |||
364 | return retval; | 310 | return retval; |
365 | } | 311 | } |
366 | 312 | ||
367 | static struct hotplug_slot_attribute hotplug_slot_attr_cur_bus_speed = { | 313 | static struct pci_slot_attribute hotplug_slot_attr_cur_bus_speed = { |
368 | .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO}, | 314 | .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO}, |
369 | .show = cur_bus_speed_read_file, | 315 | .show = cur_bus_speed_read_file, |
370 | }; | 316 | }; |
371 | 317 | ||
372 | static ssize_t test_write_file (struct hotplug_slot *slot, const char *buf, | 318 | static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf, |
373 | size_t count) | 319 | size_t count) |
374 | { | 320 | { |
321 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
375 | unsigned long ltest; | 322 | unsigned long ltest; |
376 | u32 test; | 323 | u32 test; |
377 | int retval = 0; | 324 | int retval = 0; |
@@ -394,13 +341,14 @@ exit: | |||
394 | return count; | 341 | return count; |
395 | } | 342 | } |
396 | 343 | ||
397 | static struct hotplug_slot_attribute hotplug_slot_attr_test = { | 344 | static struct pci_slot_attribute hotplug_slot_attr_test = { |
398 | .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR}, | 345 | .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR}, |
399 | .store = test_write_file | 346 | .store = test_write_file |
400 | }; | 347 | }; |
401 | 348 | ||
402 | static int has_power_file (struct hotplug_slot *slot) | 349 | static int has_power_file(struct pci_slot *pci_slot) |
403 | { | 350 | { |
351 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
404 | if ((!slot) || (!slot->ops)) | 352 | if ((!slot) || (!slot->ops)) |
405 | return -ENODEV; | 353 | return -ENODEV; |
406 | if ((slot->ops->enable_slot) || | 354 | if ((slot->ops->enable_slot) || |
@@ -410,8 +358,9 @@ static int has_power_file (struct hotplug_slot *slot) | |||
410 | return -ENOENT; | 358 | return -ENOENT; |
411 | } | 359 | } |
412 | 360 | ||
413 | static int has_attention_file (struct hotplug_slot *slot) | 361 | static int has_attention_file(struct pci_slot *pci_slot) |
414 | { | 362 | { |
363 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
415 | if ((!slot) || (!slot->ops)) | 364 | if ((!slot) || (!slot->ops)) |
416 | return -ENODEV; | 365 | return -ENODEV; |
417 | if ((slot->ops->set_attention_status) || | 366 | if ((slot->ops->set_attention_status) || |
@@ -420,8 +369,9 @@ static int has_attention_file (struct hotplug_slot *slot) | |||
420 | return -ENOENT; | 369 | return -ENOENT; |
421 | } | 370 | } |
422 | 371 | ||
423 | static int has_latch_file (struct hotplug_slot *slot) | 372 | static int has_latch_file(struct pci_slot *pci_slot) |
424 | { | 373 | { |
374 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
425 | if ((!slot) || (!slot->ops)) | 375 | if ((!slot) || (!slot->ops)) |
426 | return -ENODEV; | 376 | return -ENODEV; |
427 | if (slot->ops->get_latch_status) | 377 | if (slot->ops->get_latch_status) |
@@ -429,8 +379,9 @@ static int has_latch_file (struct hotplug_slot *slot) | |||
429 | return -ENOENT; | 379 | return -ENOENT; |
430 | } | 380 | } |
431 | 381 | ||
432 | static int has_adapter_file (struct hotplug_slot *slot) | 382 | static int has_adapter_file(struct pci_slot *pci_slot) |
433 | { | 383 | { |
384 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
434 | if ((!slot) || (!slot->ops)) | 385 | if ((!slot) || (!slot->ops)) |
435 | return -ENODEV; | 386 | return -ENODEV; |
436 | if (slot->ops->get_adapter_status) | 387 | if (slot->ops->get_adapter_status) |
@@ -438,17 +389,9 @@ static int has_adapter_file (struct hotplug_slot *slot) | |||
438 | return -ENOENT; | 389 | return -ENOENT; |
439 | } | 390 | } |
440 | 391 | ||
441 | static int has_address_file (struct hotplug_slot *slot) | 392 | static int has_max_bus_speed_file(struct pci_slot *pci_slot) |
442 | { | ||
443 | if ((!slot) || (!slot->ops)) | ||
444 | return -ENODEV; | ||
445 | if (slot->ops->get_address) | ||
446 | return 0; | ||
447 | return -ENOENT; | ||
448 | } | ||
449 | |||
450 | static int has_max_bus_speed_file (struct hotplug_slot *slot) | ||
451 | { | 393 | { |
394 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
452 | if ((!slot) || (!slot->ops)) | 395 | if ((!slot) || (!slot->ops)) |
453 | return -ENODEV; | 396 | return -ENODEV; |
454 | if (slot->ops->get_max_bus_speed) | 397 | if (slot->ops->get_max_bus_speed) |
@@ -456,8 +399,9 @@ static int has_max_bus_speed_file (struct hotplug_slot *slot) | |||
456 | return -ENOENT; | 399 | return -ENOENT; |
457 | } | 400 | } |
458 | 401 | ||
459 | static int has_cur_bus_speed_file (struct hotplug_slot *slot) | 402 | static int has_cur_bus_speed_file(struct pci_slot *pci_slot) |
460 | { | 403 | { |
404 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
461 | if ((!slot) || (!slot->ops)) | 405 | if ((!slot) || (!slot->ops)) |
462 | return -ENODEV; | 406 | return -ENODEV; |
463 | if (slot->ops->get_cur_bus_speed) | 407 | if (slot->ops->get_cur_bus_speed) |
@@ -465,8 +409,9 @@ static int has_cur_bus_speed_file (struct hotplug_slot *slot) | |||
465 | return -ENOENT; | 409 | return -ENOENT; |
466 | } | 410 | } |
467 | 411 | ||
468 | static int has_test_file (struct hotplug_slot *slot) | 412 | static int has_test_file(struct pci_slot *pci_slot) |
469 | { | 413 | { |
414 | struct hotplug_slot *slot = pci_slot->hotplug; | ||
470 | if ((!slot) || (!slot->ops)) | 415 | if ((!slot) || (!slot->ops)) |
471 | return -ENODEV; | 416 | return -ENODEV; |
472 | if (slot->ops->hardware_test) | 417 | if (slot->ops->hardware_test) |
@@ -474,7 +419,7 @@ static int has_test_file (struct hotplug_slot *slot) | |||
474 | return -ENOENT; | 419 | return -ENOENT; |
475 | } | 420 | } |
476 | 421 | ||
477 | static int fs_add_slot (struct hotplug_slot *slot) | 422 | static int fs_add_slot(struct pci_slot *slot) |
478 | { | 423 | { |
479 | int retval = 0; | 424 | int retval = 0; |
480 | 425 | ||
@@ -505,13 +450,6 @@ static int fs_add_slot (struct hotplug_slot *slot) | |||
505 | goto exit_adapter; | 450 | goto exit_adapter; |
506 | } | 451 | } |
507 | 452 | ||
508 | if (has_address_file(slot) == 0) { | ||
509 | retval = sysfs_create_file(&slot->kobj, | ||
510 | &hotplug_slot_attr_address.attr); | ||
511 | if (retval) | ||
512 | goto exit_address; | ||
513 | } | ||
514 | |||
515 | if (has_max_bus_speed_file(slot) == 0) { | 453 | if (has_max_bus_speed_file(slot) == 0) { |
516 | retval = sysfs_create_file(&slot->kobj, | 454 | retval = sysfs_create_file(&slot->kobj, |
517 | &hotplug_slot_attr_max_bus_speed.attr); | 455 | &hotplug_slot_attr_max_bus_speed.attr); |
@@ -544,10 +482,6 @@ exit_cur_speed: | |||
544 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); | 482 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); |
545 | 483 | ||
546 | exit_max_speed: | 484 | exit_max_speed: |
547 | if (has_address_file(slot) == 0) | ||
548 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr); | ||
549 | |||
550 | exit_address: | ||
551 | if (has_adapter_file(slot) == 0) | 485 | if (has_adapter_file(slot) == 0) |
552 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); | 486 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); |
553 | 487 | ||
@@ -567,7 +501,7 @@ exit: | |||
567 | return retval; | 501 | return retval; |
568 | } | 502 | } |
569 | 503 | ||
570 | static void fs_remove_slot (struct hotplug_slot *slot) | 504 | static void fs_remove_slot(struct pci_slot *slot) |
571 | { | 505 | { |
572 | if (has_power_file(slot) == 0) | 506 | if (has_power_file(slot) == 0) |
573 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr); | 507 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr); |
@@ -581,9 +515,6 @@ static void fs_remove_slot (struct hotplug_slot *slot) | |||
581 | if (has_adapter_file(slot) == 0) | 515 | if (has_adapter_file(slot) == 0) |
582 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); | 516 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr); |
583 | 517 | ||
584 | if (has_address_file(slot) == 0) | ||
585 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr); | ||
586 | |||
587 | if (has_max_bus_speed_file(slot) == 0) | 518 | if (has_max_bus_speed_file(slot) == 0) |
588 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); | 519 | sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr); |
589 | 520 | ||
@@ -599,27 +530,33 @@ static struct hotplug_slot *get_slot_from_name (const char *name) | |||
599 | struct hotplug_slot *slot; | 530 | struct hotplug_slot *slot; |
600 | struct list_head *tmp; | 531 | struct list_head *tmp; |
601 | 532 | ||
533 | spin_lock(&pci_hotplug_slot_list_lock); | ||
602 | list_for_each (tmp, &pci_hotplug_slot_list) { | 534 | list_for_each (tmp, &pci_hotplug_slot_list) { |
603 | slot = list_entry (tmp, struct hotplug_slot, slot_list); | 535 | slot = list_entry (tmp, struct hotplug_slot, slot_list); |
604 | if (strcmp(slot->name, name) == 0) | 536 | if (strcmp(slot->name, name) == 0) |
605 | return slot; | 537 | goto out; |
606 | } | 538 | } |
607 | return NULL; | 539 | slot = NULL; |
540 | out: | ||
541 | spin_unlock(&pci_hotplug_slot_list_lock); | ||
542 | return slot; | ||
608 | } | 543 | } |
609 | 544 | ||
610 | /** | 545 | /** |
611 | * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem | 546 | * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem |
547 | * @bus: bus this slot is on | ||
612 | * @slot: pointer to the &struct hotplug_slot to register | 548 | * @slot: pointer to the &struct hotplug_slot to register |
549 | * @slot_nr: slot number | ||
613 | * | 550 | * |
614 | * Registers a hotplug slot with the pci hotplug subsystem, which will allow | 551 | * Registers a hotplug slot with the pci hotplug subsystem, which will allow |
615 | * userspace interaction to the slot. | 552 | * userspace interaction to the slot. |
616 | * | 553 | * |
617 | * Returns 0 if successful, anything else for an error. | 554 | * Returns 0 if successful, anything else for an error. |
618 | */ | 555 | */ |
619 | int pci_hp_register (struct hotplug_slot *slot) | 556 | int pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus, int slot_nr) |
620 | { | 557 | { |
621 | int result; | 558 | int result; |
622 | struct hotplug_slot *tmp; | 559 | struct pci_slot *pci_slot; |
623 | 560 | ||
624 | if (slot == NULL) | 561 | if (slot == NULL) |
625 | return -ENODEV; | 562 | return -ENODEV; |
@@ -632,57 +569,89 @@ int pci_hp_register (struct hotplug_slot *slot) | |||
632 | } | 569 | } |
633 | 570 | ||
634 | /* Check if we have already registered a slot with the same name. */ | 571 | /* Check if we have already registered a slot with the same name. */ |
635 | tmp = get_slot_from_name(slot->name); | 572 | if (get_slot_from_name(slot->name)) |
636 | if (tmp) | ||
637 | return -EEXIST; | 573 | return -EEXIST; |
638 | 574 | ||
639 | slot->kobj.kset = pci_hotplug_slots_kset; | 575 | /* |
640 | result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL, | 576 | * No problems if we call this interface from both ACPI_PCI_SLOT |
641 | "%s", slot->name); | 577 | * driver and call it here again. If we've already created the |
642 | if (result) { | 578 | * pci_slot, the interface will simply bump the refcount. |
643 | err("Unable to register kobject '%s'", slot->name); | 579 | */ |
644 | return -EINVAL; | 580 | pci_slot = pci_create_slot(bus, slot_nr, slot->name); |
581 | if (IS_ERR(pci_slot)) | ||
582 | return PTR_ERR(pci_slot); | ||
583 | |||
584 | if (pci_slot->hotplug) { | ||
585 | dbg("%s: already claimed\n", __func__); | ||
586 | pci_destroy_slot(pci_slot); | ||
587 | return -EBUSY; | ||
645 | } | 588 | } |
646 | 589 | ||
647 | list_add (&slot->slot_list, &pci_hotplug_slot_list); | 590 | slot->pci_slot = pci_slot; |
591 | pci_slot->hotplug = slot; | ||
592 | |||
593 | /* | ||
594 | * Allow pcihp drivers to override the ACPI_PCI_SLOT name. | ||
595 | */ | ||
596 | if (strcmp(kobject_name(&pci_slot->kobj), slot->name)) { | ||
597 | result = kobject_rename(&pci_slot->kobj, slot->name); | ||
598 | if (result) { | ||
599 | pci_destroy_slot(pci_slot); | ||
600 | return result; | ||
601 | } | ||
602 | } | ||
603 | |||
604 | spin_lock(&pci_hotplug_slot_list_lock); | ||
605 | list_add(&slot->slot_list, &pci_hotplug_slot_list); | ||
606 | spin_unlock(&pci_hotplug_slot_list_lock); | ||
607 | |||
608 | result = fs_add_slot(pci_slot); | ||
609 | kobject_uevent(&pci_slot->kobj, KOBJ_ADD); | ||
610 | dbg("Added slot %s to the list\n", slot->name); | ||
611 | |||
648 | 612 | ||
649 | result = fs_add_slot (slot); | ||
650 | kobject_uevent(&slot->kobj, KOBJ_ADD); | ||
651 | dbg ("Added slot %s to the list\n", slot->name); | ||
652 | return result; | 613 | return result; |
653 | } | 614 | } |
654 | 615 | ||
655 | /** | 616 | /** |
656 | * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem | 617 | * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem |
657 | * @slot: pointer to the &struct hotplug_slot to deregister | 618 | * @hotplug: pointer to the &struct hotplug_slot to deregister |
658 | * | 619 | * |
659 | * The @slot must have been registered with the pci hotplug subsystem | 620 | * The @slot must have been registered with the pci hotplug subsystem |
660 | * previously with a call to pci_hp_register(). | 621 | * previously with a call to pci_hp_register(). |
661 | * | 622 | * |
662 | * Returns 0 if successful, anything else for an error. | 623 | * Returns 0 if successful, anything else for an error. |
663 | */ | 624 | */ |
664 | int pci_hp_deregister (struct hotplug_slot *slot) | 625 | int pci_hp_deregister(struct hotplug_slot *hotplug) |
665 | { | 626 | { |
666 | struct hotplug_slot *temp; | 627 | struct hotplug_slot *temp; |
628 | struct pci_slot *slot; | ||
667 | 629 | ||
668 | if (slot == NULL) | 630 | if (!hotplug) |
669 | return -ENODEV; | 631 | return -ENODEV; |
670 | 632 | ||
671 | temp = get_slot_from_name (slot->name); | 633 | temp = get_slot_from_name(hotplug->name); |
672 | if (temp != slot) { | 634 | if (temp != hotplug) |
673 | return -ENODEV; | 635 | return -ENODEV; |
674 | } | ||
675 | list_del (&slot->slot_list); | ||
676 | 636 | ||
677 | fs_remove_slot (slot); | 637 | spin_lock(&pci_hotplug_slot_list_lock); |
678 | dbg ("Removed slot %s from the list\n", slot->name); | 638 | list_del(&hotplug->slot_list); |
679 | kobject_put(&slot->kobj); | 639 | spin_unlock(&pci_hotplug_slot_list_lock); |
640 | |||
641 | slot = hotplug->pci_slot; | ||
642 | fs_remove_slot(slot); | ||
643 | dbg("Removed slot %s from the list\n", hotplug->name); | ||
644 | |||
645 | hotplug->release(hotplug); | ||
646 | slot->hotplug = NULL; | ||
647 | pci_destroy_slot(slot); | ||
648 | |||
680 | return 0; | 649 | return 0; |
681 | } | 650 | } |
682 | 651 | ||
683 | /** | 652 | /** |
684 | * pci_hp_change_slot_info - changes the slot's information structure in the core | 653 | * pci_hp_change_slot_info - changes the slot's information structure in the core |
685 | * @slot: pointer to the slot whose info has changed | 654 | * @hotplug: pointer to the slot whose info has changed |
686 | * @info: pointer to the info copy into the slot's info structure | 655 | * @info: pointer to the info copy into the slot's info structure |
687 | * | 656 | * |
688 | * @slot must have been registered with the pci | 657 | * @slot must have been registered with the pci |
@@ -690,13 +659,15 @@ int pci_hp_deregister (struct hotplug_slot *slot) | |||
690 | * | 659 | * |
691 | * Returns 0 if successful, anything else for an error. | 660 | * Returns 0 if successful, anything else for an error. |
692 | */ | 661 | */ |
693 | int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot, | 662 | int __must_check pci_hp_change_slot_info(struct hotplug_slot *hotplug, |
694 | struct hotplug_slot_info *info) | 663 | struct hotplug_slot_info *info) |
695 | { | 664 | { |
696 | if ((slot == NULL) || (info == NULL)) | 665 | struct pci_slot *slot; |
666 | if (!hotplug || !info) | ||
697 | return -ENODEV; | 667 | return -ENODEV; |
668 | slot = hotplug->pci_slot; | ||
698 | 669 | ||
699 | memcpy (slot->info, info, sizeof (struct hotplug_slot_info)); | 670 | memcpy(hotplug->info, info, sizeof(struct hotplug_slot_info)); |
700 | 671 | ||
701 | return 0; | 672 | return 0; |
702 | } | 673 | } |
@@ -704,36 +675,22 @@ int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot, | |||
704 | static int __init pci_hotplug_init (void) | 675 | static int __init pci_hotplug_init (void) |
705 | { | 676 | { |
706 | int result; | 677 | int result; |
707 | struct kset *pci_bus_kset; | ||
708 | 678 | ||
709 | pci_bus_kset = bus_get_kset(&pci_bus_type); | ||
710 | |||
711 | pci_hotplug_slots_kset = kset_create_and_add("slots", NULL, | ||
712 | &pci_bus_kset->kobj); | ||
713 | if (!pci_hotplug_slots_kset) { | ||
714 | result = -ENOMEM; | ||
715 | err("Register subsys error\n"); | ||
716 | goto exit; | ||
717 | } | ||
718 | result = cpci_hotplug_init(debug); | 679 | result = cpci_hotplug_init(debug); |
719 | if (result) { | 680 | if (result) { |
720 | err ("cpci_hotplug_init with error %d\n", result); | 681 | err ("cpci_hotplug_init with error %d\n", result); |
721 | goto err_subsys; | 682 | goto err_cpci; |
722 | } | 683 | } |
723 | 684 | ||
724 | info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); | 685 | info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); |
725 | goto exit; | ||
726 | 686 | ||
727 | err_subsys: | 687 | err_cpci: |
728 | kset_unregister(pci_hotplug_slots_kset); | ||
729 | exit: | ||
730 | return result; | 688 | return result; |
731 | } | 689 | } |
732 | 690 | ||
733 | static void __exit pci_hotplug_exit (void) | 691 | static void __exit pci_hotplug_exit (void) |
734 | { | 692 | { |
735 | cpci_hotplug_exit(); | 693 | cpci_hotplug_exit(); |
736 | kset_unregister(pci_hotplug_slots_kset); | ||
737 | } | 694 | } |
738 | 695 | ||
739 | module_init(pci_hotplug_init); | 696 | module_init(pci_hotplug_init); |
@@ -745,7 +702,6 @@ MODULE_LICENSE("GPL"); | |||
745 | module_param(debug, bool, 0644); | 702 | module_param(debug, bool, 0644); |
746 | MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); | 703 | MODULE_PARM_DESC(debug, "Debugging mode enabled or not"); |
747 | 704 | ||
748 | EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset); | ||
749 | EXPORT_SYMBOL_GPL(pci_hp_register); | 705 | EXPORT_SYMBOL_GPL(pci_hp_register); |
750 | EXPORT_SYMBOL_GPL(pci_hp_deregister); | 706 | EXPORT_SYMBOL_GPL(pci_hp_deregister); |
751 | EXPORT_SYMBOL_GPL(pci_hp_change_slot_info); | 707 | EXPORT_SYMBOL_GPL(pci_hp_change_slot_info); |
diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index 79c9ddaad3fb..e3a1e7e7dba2 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h | |||
@@ -43,6 +43,7 @@ extern int pciehp_poll_mode; | |||
43 | extern int pciehp_poll_time; | 43 | extern int pciehp_poll_time; |
44 | extern int pciehp_debug; | 44 | extern int pciehp_debug; |
45 | extern int pciehp_force; | 45 | extern int pciehp_force; |
46 | extern int pciehp_slot_with_bus; | ||
46 | extern struct workqueue_struct *pciehp_wq; | 47 | extern struct workqueue_struct *pciehp_wq; |
47 | 48 | ||
48 | #define dbg(format, arg...) \ | 49 | #define dbg(format, arg...) \ |
@@ -96,7 +97,7 @@ struct controller { | |||
96 | u32 slot_cap; | 97 | u32 slot_cap; |
97 | u8 cap_base; | 98 | u8 cap_base; |
98 | struct timer_list poll_timer; | 99 | struct timer_list poll_timer; |
99 | volatile int cmd_busy; | 100 | int cmd_busy; |
100 | unsigned int no_cmd_complete:1; | 101 | unsigned int no_cmd_complete:1; |
101 | }; | 102 | }; |
102 | 103 | ||
@@ -156,10 +157,10 @@ extern u8 pciehp_handle_power_fault(struct slot *p_slot); | |||
156 | extern int pciehp_configure_device(struct slot *p_slot); | 157 | extern int pciehp_configure_device(struct slot *p_slot); |
157 | extern int pciehp_unconfigure_device(struct slot *p_slot); | 158 | extern int pciehp_unconfigure_device(struct slot *p_slot); |
158 | extern void pciehp_queue_pushbutton_work(struct work_struct *work); | 159 | extern void pciehp_queue_pushbutton_work(struct work_struct *work); |
159 | int pcie_init(struct controller *ctrl, struct pcie_device *dev); | 160 | struct controller *pcie_init(struct pcie_device *dev); |
160 | int pciehp_enable_slot(struct slot *p_slot); | 161 | int pciehp_enable_slot(struct slot *p_slot); |
161 | int pciehp_disable_slot(struct slot *p_slot); | 162 | int pciehp_disable_slot(struct slot *p_slot); |
162 | int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev); | 163 | int pcie_enable_notification(struct controller *ctrl); |
163 | 164 | ||
164 | static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) | 165 | static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device) |
165 | { | 166 | { |
@@ -202,8 +203,13 @@ struct hpc_ops { | |||
202 | #include <acpi/actypes.h> | 203 | #include <acpi/actypes.h> |
203 | #include <linux/pci-acpi.h> | 204 | #include <linux/pci-acpi.h> |
204 | 205 | ||
205 | #define pciehp_get_hp_hw_control_from_firmware(dev) \ | 206 | static inline int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev) |
206 | pciehp_acpi_get_hp_hw_control_from_firmware(dev) | 207 | { |
208 | u32 flags = (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | | ||
209 | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); | ||
210 | return acpi_get_hp_hw_control_from_firmware(dev, flags); | ||
211 | } | ||
212 | |||
207 | static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, | 213 | static inline int pciehp_get_hp_params_from_firmware(struct pci_dev *dev, |
208 | struct hotplug_params *hpp) | 214 | struct hotplug_params *hpp) |
209 | { | 215 | { |
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c index 48a2ed378914..3677495c4f91 100644 --- a/drivers/pci/hotplug/pciehp_core.c +++ b/drivers/pci/hotplug/pciehp_core.c | |||
@@ -72,7 +72,6 @@ static int get_power_status (struct hotplug_slot *slot, u8 *value); | |||
72 | static int get_attention_status (struct hotplug_slot *slot, u8 *value); | 72 | static int get_attention_status (struct hotplug_slot *slot, u8 *value); |
73 | static int get_latch_status (struct hotplug_slot *slot, u8 *value); | 73 | static int get_latch_status (struct hotplug_slot *slot, u8 *value); |
74 | static int get_adapter_status (struct hotplug_slot *slot, u8 *value); | 74 | static int get_adapter_status (struct hotplug_slot *slot, u8 *value); |
75 | static int get_address (struct hotplug_slot *slot, u32 *value); | ||
76 | static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); | 75 | static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); |
77 | static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); | 76 | static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); |
78 | 77 | ||
@@ -85,7 +84,6 @@ static struct hotplug_slot_ops pciehp_hotplug_slot_ops = { | |||
85 | .get_attention_status = get_attention_status, | 84 | .get_attention_status = get_attention_status, |
86 | .get_latch_status = get_latch_status, | 85 | .get_latch_status = get_latch_status, |
87 | .get_adapter_status = get_adapter_status, | 86 | .get_adapter_status = get_adapter_status, |
88 | .get_address = get_address, | ||
89 | .get_max_bus_speed = get_max_bus_speed, | 87 | .get_max_bus_speed = get_max_bus_speed, |
90 | .get_cur_bus_speed = get_cur_bus_speed, | 88 | .get_cur_bus_speed = get_cur_bus_speed, |
91 | }; | 89 | }; |
@@ -185,23 +183,10 @@ static struct hotplug_slot_attribute hotplug_slot_attr_lock = { | |||
185 | */ | 183 | */ |
186 | static void release_slot(struct hotplug_slot *hotplug_slot) | 184 | static void release_slot(struct hotplug_slot *hotplug_slot) |
187 | { | 185 | { |
188 | struct slot *slot = hotplug_slot->private; | ||
189 | |||
190 | dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); | 186 | dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); |
191 | 187 | ||
192 | kfree(slot->hotplug_slot->info); | 188 | kfree(hotplug_slot->info); |
193 | kfree(slot->hotplug_slot); | 189 | kfree(hotplug_slot); |
194 | kfree(slot); | ||
195 | } | ||
196 | |||
197 | static void make_slot_name(struct slot *slot) | ||
198 | { | ||
199 | if (pciehp_slot_with_bus) | ||
200 | snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", | ||
201 | slot->bus, slot->number); | ||
202 | else | ||
203 | snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%d", | ||
204 | slot->number); | ||
205 | } | 190 | } |
206 | 191 | ||
207 | static int init_slots(struct controller *ctrl) | 192 | static int init_slots(struct controller *ctrl) |
@@ -210,49 +195,34 @@ static int init_slots(struct controller *ctrl) | |||
210 | struct hotplug_slot *hotplug_slot; | 195 | struct hotplug_slot *hotplug_slot; |
211 | struct hotplug_slot_info *info; | 196 | struct hotplug_slot_info *info; |
212 | int retval = -ENOMEM; | 197 | int retval = -ENOMEM; |
213 | int i; | ||
214 | |||
215 | for (i = 0; i < ctrl->num_slots; i++) { | ||
216 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); | ||
217 | if (!slot) | ||
218 | goto error; | ||
219 | 198 | ||
199 | list_for_each_entry(slot, &ctrl->slot_list, slot_list) { | ||
220 | hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); | 200 | hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); |
221 | if (!hotplug_slot) | 201 | if (!hotplug_slot) |
222 | goto error_slot; | 202 | goto error; |
223 | slot->hotplug_slot = hotplug_slot; | ||
224 | 203 | ||
225 | info = kzalloc(sizeof(*info), GFP_KERNEL); | 204 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
226 | if (!info) | 205 | if (!info) |
227 | goto error_hpslot; | 206 | goto error_hpslot; |
228 | hotplug_slot->info = info; | ||
229 | |||
230 | hotplug_slot->name = slot->name; | ||
231 | |||
232 | slot->hp_slot = i; | ||
233 | slot->ctrl = ctrl; | ||
234 | slot->bus = ctrl->pci_dev->subordinate->number; | ||
235 | slot->device = ctrl->slot_device_offset + i; | ||
236 | slot->hpc_ops = ctrl->hpc_ops; | ||
237 | slot->number = ctrl->first_slot; | ||
238 | mutex_init(&slot->lock); | ||
239 | INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); | ||
240 | 207 | ||
241 | /* register this slot with the hotplug pci core */ | 208 | /* register this slot with the hotplug pci core */ |
209 | hotplug_slot->info = info; | ||
210 | hotplug_slot->name = slot->name; | ||
242 | hotplug_slot->private = slot; | 211 | hotplug_slot->private = slot; |
243 | hotplug_slot->release = &release_slot; | 212 | hotplug_slot->release = &release_slot; |
244 | make_slot_name(slot); | ||
245 | hotplug_slot->ops = &pciehp_hotplug_slot_ops; | 213 | hotplug_slot->ops = &pciehp_hotplug_slot_ops; |
246 | |||
247 | get_power_status(hotplug_slot, &info->power_status); | 214 | get_power_status(hotplug_slot, &info->power_status); |
248 | get_attention_status(hotplug_slot, &info->attention_status); | 215 | get_attention_status(hotplug_slot, &info->attention_status); |
249 | get_latch_status(hotplug_slot, &info->latch_status); | 216 | get_latch_status(hotplug_slot, &info->latch_status); |
250 | get_adapter_status(hotplug_slot, &info->adapter_status); | 217 | get_adapter_status(hotplug_slot, &info->adapter_status); |
218 | slot->hotplug_slot = hotplug_slot; | ||
251 | 219 | ||
252 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " | 220 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " |
253 | "slot_device_offset=%x\n", slot->bus, slot->device, | 221 | "slot_device_offset=%x\n", slot->bus, slot->device, |
254 | slot->hp_slot, slot->number, ctrl->slot_device_offset); | 222 | slot->hp_slot, slot->number, ctrl->slot_device_offset); |
255 | retval = pci_hp_register(hotplug_slot); | 223 | retval = pci_hp_register(hotplug_slot, |
224 | ctrl->pci_dev->subordinate, | ||
225 | slot->device); | ||
256 | if (retval) { | 226 | if (retval) { |
257 | err("pci_hp_register failed with error %d\n", retval); | 227 | err("pci_hp_register failed with error %d\n", retval); |
258 | if (retval == -EEXIST) | 228 | if (retval == -EEXIST) |
@@ -263,7 +233,7 @@ static int init_slots(struct controller *ctrl) | |||
263 | } | 233 | } |
264 | /* create additional sysfs entries */ | 234 | /* create additional sysfs entries */ |
265 | if (EMI(ctrl)) { | 235 | if (EMI(ctrl)) { |
266 | retval = sysfs_create_file(&hotplug_slot->kobj, | 236 | retval = sysfs_create_file(&hotplug_slot->pci_slot->kobj, |
267 | &hotplug_slot_attr_lock.attr); | 237 | &hotplug_slot_attr_lock.attr); |
268 | if (retval) { | 238 | if (retval) { |
269 | pci_hp_deregister(hotplug_slot); | 239 | pci_hp_deregister(hotplug_slot); |
@@ -271,8 +241,6 @@ static int init_slots(struct controller *ctrl) | |||
271 | goto error_info; | 241 | goto error_info; |
272 | } | 242 | } |
273 | } | 243 | } |
274 | |||
275 | list_add(&slot->slot_list, &ctrl->slot_list); | ||
276 | } | 244 | } |
277 | 245 | ||
278 | return 0; | 246 | return 0; |
@@ -280,27 +248,18 @@ error_info: | |||
280 | kfree(info); | 248 | kfree(info); |
281 | error_hpslot: | 249 | error_hpslot: |
282 | kfree(hotplug_slot); | 250 | kfree(hotplug_slot); |
283 | error_slot: | ||
284 | kfree(slot); | ||
285 | error: | 251 | error: |
286 | return retval; | 252 | return retval; |
287 | } | 253 | } |
288 | 254 | ||
289 | static void cleanup_slots(struct controller *ctrl) | 255 | static void cleanup_slots(struct controller *ctrl) |
290 | { | 256 | { |
291 | struct list_head *tmp; | ||
292 | struct list_head *next; | ||
293 | struct slot *slot; | 257 | struct slot *slot; |
294 | 258 | ||
295 | list_for_each_safe(tmp, next, &ctrl->slot_list) { | 259 | list_for_each_entry(slot, &ctrl->slot_list, slot_list) { |
296 | slot = list_entry(tmp, struct slot, slot_list); | ||
297 | list_del(&slot->slot_list); | ||
298 | if (EMI(ctrl)) | 260 | if (EMI(ctrl)) |
299 | sysfs_remove_file(&slot->hotplug_slot->kobj, | 261 | sysfs_remove_file(&slot->hotplug_slot->pci_slot->kobj, |
300 | &hotplug_slot_attr_lock.attr); | 262 | &hotplug_slot_attr_lock.attr); |
301 | cancel_delayed_work(&slot->work); | ||
302 | flush_scheduled_work(); | ||
303 | flush_workqueue(pciehp_wq); | ||
304 | pci_hp_deregister(slot->hotplug_slot); | 263 | pci_hp_deregister(slot->hotplug_slot); |
305 | } | 264 | } |
306 | } | 265 | } |
@@ -398,19 +357,8 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value) | |||
398 | return 0; | 357 | return 0; |
399 | } | 358 | } |
400 | 359 | ||
401 | static int get_address(struct hotplug_slot *hotplug_slot, u32 *value) | 360 | static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, |
402 | { | 361 | enum pci_bus_speed *value) |
403 | struct slot *slot = hotplug_slot->private; | ||
404 | struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; | ||
405 | |||
406 | dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); | ||
407 | |||
408 | *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device; | ||
409 | |||
410 | return 0; | ||
411 | } | ||
412 | |||
413 | static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) | ||
414 | { | 362 | { |
415 | struct slot *slot = hotplug_slot->private; | 363 | struct slot *slot = hotplug_slot->private; |
416 | int retval; | 364 | int retval; |
@@ -444,34 +392,30 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_ | |||
444 | struct controller *ctrl; | 392 | struct controller *ctrl; |
445 | struct slot *t_slot; | 393 | struct slot *t_slot; |
446 | u8 value; | 394 | u8 value; |
447 | struct pci_dev *pdev; | 395 | struct pci_dev *pdev = dev->port; |
448 | 396 | ||
449 | ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); | 397 | if (pciehp_force) |
450 | if (!ctrl) { | 398 | dbg("Bypassing BIOS check for pciehp use on %s\n", |
451 | err("%s : out of memory\n", __func__); | 399 | pci_name(pdev)); |
400 | else if (pciehp_get_hp_hw_control_from_firmware(pdev)) | ||
452 | goto err_out_none; | 401 | goto err_out_none; |
453 | } | ||
454 | INIT_LIST_HEAD(&ctrl->slot_list); | ||
455 | |||
456 | pdev = dev->port; | ||
457 | ctrl->pci_dev = pdev; | ||
458 | 402 | ||
459 | rc = pcie_init(ctrl, dev); | 403 | ctrl = pcie_init(dev); |
460 | if (rc) { | 404 | if (!ctrl) { |
461 | dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME); | 405 | dbg("%s: controller initialization failed\n", PCIE_MODULE_NAME); |
462 | goto err_out_free_ctrl; | 406 | goto err_out_none; |
463 | } | 407 | } |
464 | 408 | set_service_data(dev, ctrl); | |
465 | pci_set_drvdata(pdev, ctrl); | ||
466 | |||
467 | dbg("%s: ctrl bus=0x%x, device=%x, function=%x, irq=%x\n", | ||
468 | __func__, pdev->bus->number, PCI_SLOT(pdev->devfn), | ||
469 | PCI_FUNC(pdev->devfn), pdev->irq); | ||
470 | 409 | ||
471 | /* Setup the slot information structures */ | 410 | /* Setup the slot information structures */ |
472 | rc = init_slots(ctrl); | 411 | rc = init_slots(ctrl); |
473 | if (rc) { | 412 | if (rc) { |
474 | err("%s: slot initialization failed\n", PCIE_MODULE_NAME); | 413 | if (rc == -EBUSY) |
414 | warn("%s: slot already registered by another " | ||
415 | "hotplug driver\n", PCIE_MODULE_NAME); | ||
416 | else | ||
417 | err("%s: slot initialization failed\n", | ||
418 | PCIE_MODULE_NAME); | ||
475 | goto err_out_release_ctlr; | 419 | goto err_out_release_ctlr; |
476 | } | 420 | } |
477 | 421 | ||
@@ -495,20 +439,16 @@ err_out_free_ctrl_slot: | |||
495 | cleanup_slots(ctrl); | 439 | cleanup_slots(ctrl); |
496 | err_out_release_ctlr: | 440 | err_out_release_ctlr: |
497 | ctrl->hpc_ops->release_ctlr(ctrl); | 441 | ctrl->hpc_ops->release_ctlr(ctrl); |
498 | err_out_free_ctrl: | ||
499 | kfree(ctrl); | ||
500 | err_out_none: | 442 | err_out_none: |
501 | return -ENODEV; | 443 | return -ENODEV; |
502 | } | 444 | } |
503 | 445 | ||
504 | static void pciehp_remove (struct pcie_device *dev) | 446 | static void pciehp_remove (struct pcie_device *dev) |
505 | { | 447 | { |
506 | struct pci_dev *pdev = dev->port; | 448 | struct controller *ctrl = get_service_data(dev); |
507 | struct controller *ctrl = pci_get_drvdata(pdev); | ||
508 | 449 | ||
509 | cleanup_slots(ctrl); | 450 | cleanup_slots(ctrl); |
510 | ctrl->hpc_ops->release_ctlr(ctrl); | 451 | ctrl->hpc_ops->release_ctlr(ctrl); |
511 | kfree(ctrl); | ||
512 | } | 452 | } |
513 | 453 | ||
514 | #ifdef CONFIG_PM | 454 | #ifdef CONFIG_PM |
@@ -522,13 +462,12 @@ static int pciehp_resume (struct pcie_device *dev) | |||
522 | { | 462 | { |
523 | printk("%s ENTRY\n", __func__); | 463 | printk("%s ENTRY\n", __func__); |
524 | if (pciehp_force) { | 464 | if (pciehp_force) { |
525 | struct pci_dev *pdev = dev->port; | 465 | struct controller *ctrl = get_service_data(dev); |
526 | struct controller *ctrl = pci_get_drvdata(pdev); | ||
527 | struct slot *t_slot; | 466 | struct slot *t_slot; |
528 | u8 status; | 467 | u8 status; |
529 | 468 | ||
530 | /* reinitialize the chipset's event detection logic */ | 469 | /* reinitialize the chipset's event detection logic */ |
531 | pcie_init_hardware_part2(ctrl, dev); | 470 | pcie_enable_notification(ctrl); |
532 | 471 | ||
533 | t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); | 472 | t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); |
534 | 473 | ||
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 79f104963166..1323a43285d7 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c | |||
@@ -247,30 +247,32 @@ static inline void pciehp_free_irq(struct controller *ctrl) | |||
247 | free_irq(ctrl->pci_dev->irq, ctrl); | 247 | free_irq(ctrl->pci_dev->irq, ctrl); |
248 | } | 248 | } |
249 | 249 | ||
250 | static inline int pcie_poll_cmd(struct controller *ctrl) | 250 | static int pcie_poll_cmd(struct controller *ctrl) |
251 | { | 251 | { |
252 | u16 slot_status; | 252 | u16 slot_status; |
253 | int timeout = 1000; | 253 | int timeout = 1000; |
254 | 254 | ||
255 | if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) | 255 | if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) { |
256 | if (slot_status & CMD_COMPLETED) | 256 | if (slot_status & CMD_COMPLETED) { |
257 | goto completed; | 257 | pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED); |
258 | for (timeout = 1000; timeout > 0; timeout -= 100) { | 258 | return 1; |
259 | msleep(100); | 259 | } |
260 | if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) | 260 | } |
261 | if (slot_status & CMD_COMPLETED) | 261 | while (timeout > 1000) { |
262 | goto completed; | 262 | msleep(10); |
263 | timeout -= 10; | ||
264 | if (!pciehp_readw(ctrl, SLOTSTATUS, &slot_status)) { | ||
265 | if (slot_status & CMD_COMPLETED) { | ||
266 | pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED); | ||
267 | return 1; | ||
268 | } | ||
269 | } | ||
263 | } | 270 | } |
264 | return 0; /* timeout */ | 271 | return 0; /* timeout */ |
265 | |||
266 | completed: | ||
267 | pciehp_writew(ctrl, SLOTSTATUS, CMD_COMPLETED); | ||
268 | return timeout; | ||
269 | } | 272 | } |
270 | 273 | ||
271 | static inline int pcie_wait_cmd(struct controller *ctrl, int poll) | 274 | static void pcie_wait_cmd(struct controller *ctrl, int poll) |
272 | { | 275 | { |
273 | int retval = 0; | ||
274 | unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; | 276 | unsigned int msecs = pciehp_poll_mode ? 2500 : 1000; |
275 | unsigned long timeout = msecs_to_jiffies(msecs); | 277 | unsigned long timeout = msecs_to_jiffies(msecs); |
276 | int rc; | 278 | int rc; |
@@ -278,16 +280,9 @@ static inline int pcie_wait_cmd(struct controller *ctrl, int poll) | |||
278 | if (poll) | 280 | if (poll) |
279 | rc = pcie_poll_cmd(ctrl); | 281 | rc = pcie_poll_cmd(ctrl); |
280 | else | 282 | else |
281 | rc = wait_event_interruptible_timeout(ctrl->queue, | 283 | rc = wait_event_timeout(ctrl->queue, !ctrl->cmd_busy, timeout); |
282 | !ctrl->cmd_busy, timeout); | ||
283 | if (!rc) | 284 | if (!rc) |
284 | dbg("Command not completed in 1000 msec\n"); | 285 | dbg("Command not completed in 1000 msec\n"); |
285 | else if (rc < 0) { | ||
286 | retval = -EINTR; | ||
287 | info("Command was interrupted by a signal\n"); | ||
288 | } | ||
289 | |||
290 | return retval; | ||
291 | } | 286 | } |
292 | 287 | ||
293 | /** | 288 | /** |
@@ -342,10 +337,6 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask) | |||
342 | 337 | ||
343 | slot_ctrl &= ~mask; | 338 | slot_ctrl &= ~mask; |
344 | slot_ctrl |= (cmd & mask); | 339 | slot_ctrl |= (cmd & mask); |
345 | /* Don't enable command completed if caller is changing it. */ | ||
346 | if (!(mask & CMD_CMPL_INTR_ENABLE)) | ||
347 | slot_ctrl |= CMD_CMPL_INTR_ENABLE; | ||
348 | |||
349 | ctrl->cmd_busy = 1; | 340 | ctrl->cmd_busy = 1; |
350 | smp_mb(); | 341 | smp_mb(); |
351 | retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl); | 342 | retval = pciehp_writew(ctrl, SLOTCTRL, slot_ctrl); |
@@ -365,7 +356,7 @@ static int pcie_write_cmd(struct controller *ctrl, u16 cmd, u16 mask) | |||
365 | if (!(slot_ctrl & HP_INTR_ENABLE) || | 356 | if (!(slot_ctrl & HP_INTR_ENABLE) || |
366 | !(slot_ctrl & CMD_CMPL_INTR_ENABLE)) | 357 | !(slot_ctrl & CMD_CMPL_INTR_ENABLE)) |
367 | poll = 1; | 358 | poll = 1; |
368 | retval = pcie_wait_cmd(ctrl, poll); | 359 | pcie_wait_cmd(ctrl, poll); |
369 | } | 360 | } |
370 | out: | 361 | out: |
371 | mutex_unlock(&ctrl->ctrl_lock); | 362 | mutex_unlock(&ctrl->ctrl_lock); |
@@ -614,23 +605,6 @@ static void hpc_set_green_led_blink(struct slot *slot) | |||
614 | __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); | 605 | __func__, ctrl->cap_base + SLOTCTRL, slot_cmd); |
615 | } | 606 | } |
616 | 607 | ||
617 | static void hpc_release_ctlr(struct controller *ctrl) | ||
618 | { | ||
619 | /* Mask Hot-plug Interrupt Enable */ | ||
620 | if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) | ||
621 | err("%s: Cannot mask hotplut interrupt enable\n", __func__); | ||
622 | |||
623 | /* Free interrupt handler or interrupt polling timer */ | ||
624 | pciehp_free_irq(ctrl); | ||
625 | |||
626 | /* | ||
627 | * If this is the last controller to be released, destroy the | ||
628 | * pciehp work queue | ||
629 | */ | ||
630 | if (atomic_dec_and_test(&pciehp_num_controllers)) | ||
631 | destroy_workqueue(pciehp_wq); | ||
632 | } | ||
633 | |||
634 | static int hpc_power_on_slot(struct slot * slot) | 608 | static int hpc_power_on_slot(struct slot * slot) |
635 | { | 609 | { |
636 | struct controller *ctrl = slot->ctrl; | 610 | struct controller *ctrl = slot->ctrl; |
@@ -785,7 +759,7 @@ static irqreturn_t pcie_isr(int irq, void *dev_id) | |||
785 | intr_loc |= detected; | 759 | intr_loc |= detected; |
786 | if (!intr_loc) | 760 | if (!intr_loc) |
787 | return IRQ_NONE; | 761 | return IRQ_NONE; |
788 | if (pciehp_writew(ctrl, SLOTSTATUS, detected)) { | 762 | if (detected && pciehp_writew(ctrl, SLOTSTATUS, detected)) { |
789 | err("%s: Cannot write to SLOTSTATUS\n", __func__); | 763 | err("%s: Cannot write to SLOTSTATUS\n", __func__); |
790 | return IRQ_NONE; | 764 | return IRQ_NONE; |
791 | } | 765 | } |
@@ -797,25 +771,13 @@ static irqreturn_t pcie_isr(int irq, void *dev_id) | |||
797 | if (intr_loc & CMD_COMPLETED) { | 771 | if (intr_loc & CMD_COMPLETED) { |
798 | ctrl->cmd_busy = 0; | 772 | ctrl->cmd_busy = 0; |
799 | smp_mb(); | 773 | smp_mb(); |
800 | wake_up_interruptible(&ctrl->queue); | 774 | wake_up(&ctrl->queue); |
801 | } | 775 | } |
802 | 776 | ||
803 | if (!(intr_loc & ~CMD_COMPLETED)) | 777 | if (!(intr_loc & ~CMD_COMPLETED)) |
804 | return IRQ_HANDLED; | 778 | return IRQ_HANDLED; |
805 | 779 | ||
806 | /* | ||
807 | * Return without handling events if this handler routine is | ||
808 | * called before controller initialization is done. This may | ||
809 | * happen if hotplug event or another interrupt that shares | ||
810 | * the IRQ with pciehp arrives before slot initialization is | ||
811 | * done after interrupt handler is registered. | ||
812 | * | ||
813 | * FIXME - Need more structural fixes. We need to be ready to | ||
814 | * handle the event before installing interrupt handler. | ||
815 | */ | ||
816 | p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); | 780 | p_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); |
817 | if (!p_slot || !p_slot->hpc_ops) | ||
818 | return IRQ_HANDLED; | ||
819 | 781 | ||
820 | /* Check MRL Sensor Changed */ | 782 | /* Check MRL Sensor Changed */ |
821 | if (intr_loc & MRL_SENS_CHANGED) | 783 | if (intr_loc & MRL_SENS_CHANGED) |
@@ -992,6 +954,7 @@ static int hpc_get_cur_lnk_width(struct slot *slot, | |||
992 | return retval; | 954 | return retval; |
993 | } | 955 | } |
994 | 956 | ||
957 | static void pcie_release_ctrl(struct controller *ctrl); | ||
995 | static struct hpc_ops pciehp_hpc_ops = { | 958 | static struct hpc_ops pciehp_hpc_ops = { |
996 | .power_on_slot = hpc_power_on_slot, | 959 | .power_on_slot = hpc_power_on_slot, |
997 | .power_off_slot = hpc_power_off_slot, | 960 | .power_off_slot = hpc_power_off_slot, |
@@ -1013,97 +976,11 @@ static struct hpc_ops pciehp_hpc_ops = { | |||
1013 | .green_led_off = hpc_set_green_led_off, | 976 | .green_led_off = hpc_set_green_led_off, |
1014 | .green_led_blink = hpc_set_green_led_blink, | 977 | .green_led_blink = hpc_set_green_led_blink, |
1015 | 978 | ||
1016 | .release_ctlr = hpc_release_ctlr, | 979 | .release_ctlr = pcie_release_ctrl, |
1017 | .check_lnk_status = hpc_check_lnk_status, | 980 | .check_lnk_status = hpc_check_lnk_status, |
1018 | }; | 981 | }; |
1019 | 982 | ||
1020 | #ifdef CONFIG_ACPI | 983 | int pcie_enable_notification(struct controller *ctrl) |
1021 | static int pciehp_acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev) | ||
1022 | { | ||
1023 | acpi_status status; | ||
1024 | acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev)); | ||
1025 | struct pci_dev *pdev = dev; | ||
1026 | struct pci_bus *parent; | ||
1027 | struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
1028 | |||
1029 | /* | ||
1030 | * Per PCI firmware specification, we should run the ACPI _OSC | ||
1031 | * method to get control of hotplug hardware before using it. | ||
1032 | * If an _OSC is missing, we look for an OSHP to do the same thing. | ||
1033 | * To handle different BIOS behavior, we look for _OSC and OSHP | ||
1034 | * within the scope of the hotplug controller and its parents, upto | ||
1035 | * the host bridge under which this controller exists. | ||
1036 | */ | ||
1037 | while (!handle) { | ||
1038 | /* | ||
1039 | * This hotplug controller was not listed in the ACPI name | ||
1040 | * space at all. Try to get acpi handle of parent pci bus. | ||
1041 | */ | ||
1042 | if (!pdev || !pdev->bus->parent) | ||
1043 | break; | ||
1044 | parent = pdev->bus->parent; | ||
1045 | dbg("Could not find %s in acpi namespace, trying parent\n", | ||
1046 | pci_name(pdev)); | ||
1047 | if (!parent->self) | ||
1048 | /* Parent must be a host bridge */ | ||
1049 | handle = acpi_get_pci_rootbridge_handle( | ||
1050 | pci_domain_nr(parent), | ||
1051 | parent->number); | ||
1052 | else | ||
1053 | handle = DEVICE_ACPI_HANDLE( | ||
1054 | &(parent->self->dev)); | ||
1055 | pdev = parent->self; | ||
1056 | } | ||
1057 | |||
1058 | while (handle) { | ||
1059 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &string); | ||
1060 | dbg("Trying to get hotplug control for %s \n", | ||
1061 | (char *)string.pointer); | ||
1062 | status = pci_osc_control_set(handle, | ||
1063 | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL | | ||
1064 | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL); | ||
1065 | if (status == AE_NOT_FOUND) | ||
1066 | status = acpi_run_oshp(handle); | ||
1067 | if (ACPI_SUCCESS(status)) { | ||
1068 | dbg("Gained control for hotplug HW for pci %s (%s)\n", | ||
1069 | pci_name(dev), (char *)string.pointer); | ||
1070 | kfree(string.pointer); | ||
1071 | return 0; | ||
1072 | } | ||
1073 | if (acpi_root_bridge(handle)) | ||
1074 | break; | ||
1075 | chandle = handle; | ||
1076 | status = acpi_get_parent(chandle, &handle); | ||
1077 | if (ACPI_FAILURE(status)) | ||
1078 | break; | ||
1079 | } | ||
1080 | |||
1081 | dbg("Cannot get control of hotplug hardware for pci %s\n", | ||
1082 | pci_name(dev)); | ||
1083 | |||
1084 | kfree(string.pointer); | ||
1085 | return -1; | ||
1086 | } | ||
1087 | #endif | ||
1088 | |||
1089 | static int pcie_init_hardware_part1(struct controller *ctrl, | ||
1090 | struct pcie_device *dev) | ||
1091 | { | ||
1092 | /* Clear all remaining event bits in Slot Status register */ | ||
1093 | if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) { | ||
1094 | err("%s: Cannot write to SLOTSTATUS register\n", __func__); | ||
1095 | return -1; | ||
1096 | } | ||
1097 | |||
1098 | /* Mask Hot-plug Interrupt Enable */ | ||
1099 | if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE)) { | ||
1100 | err("%s: Cannot mask hotplug interrupt enable\n", __func__); | ||
1101 | return -1; | ||
1102 | } | ||
1103 | return 0; | ||
1104 | } | ||
1105 | |||
1106 | int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev) | ||
1107 | { | 984 | { |
1108 | u16 cmd, mask; | 985 | u16 cmd, mask; |
1109 | 986 | ||
@@ -1115,30 +992,83 @@ int pcie_init_hardware_part2(struct controller *ctrl, struct pcie_device *dev) | |||
1115 | if (MRL_SENS(ctrl)) | 992 | if (MRL_SENS(ctrl)) |
1116 | cmd |= MRL_DETECT_ENABLE; | 993 | cmd |= MRL_DETECT_ENABLE; |
1117 | if (!pciehp_poll_mode) | 994 | if (!pciehp_poll_mode) |
1118 | cmd |= HP_INTR_ENABLE; | 995 | cmd |= HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE; |
1119 | 996 | ||
1120 | mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | | 997 | mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE | |
1121 | PWR_FAULT_DETECT_ENABLE | MRL_DETECT_ENABLE | HP_INTR_ENABLE; | 998 | PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE; |
1122 | 999 | ||
1123 | if (pcie_write_cmd(ctrl, cmd, mask)) { | 1000 | if (pcie_write_cmd(ctrl, cmd, mask)) { |
1124 | err("%s: Cannot enable software notification\n", __func__); | 1001 | err("%s: Cannot enable software notification\n", __func__); |
1125 | goto abort; | 1002 | return -1; |
1126 | } | 1003 | } |
1004 | return 0; | ||
1005 | } | ||
1127 | 1006 | ||
1128 | if (pciehp_force) | 1007 | static void pcie_disable_notification(struct controller *ctrl) |
1129 | dbg("Bypassing BIOS check for pciehp use on %s\n", | 1008 | { |
1130 | pci_name(ctrl->pci_dev)); | 1009 | u16 mask; |
1131 | else if (pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev)) | 1010 | mask = PRSN_DETECT_ENABLE | ATTN_BUTTN_ENABLE | MRL_DETECT_ENABLE | |
1132 | goto abort_disable_intr; | 1011 | PWR_FAULT_DETECT_ENABLE | HP_INTR_ENABLE | CMD_CMPL_INTR_ENABLE; |
1012 | if (pcie_write_cmd(ctrl, 0, mask)) | ||
1013 | warn("%s: Cannot disable software notification\n", __func__); | ||
1014 | } | ||
1133 | 1015 | ||
1016 | static int pcie_init_notification(struct controller *ctrl) | ||
1017 | { | ||
1018 | if (pciehp_request_irq(ctrl)) | ||
1019 | return -1; | ||
1020 | if (pcie_enable_notification(ctrl)) { | ||
1021 | pciehp_free_irq(ctrl); | ||
1022 | return -1; | ||
1023 | } | ||
1134 | return 0; | 1024 | return 0; |
1025 | } | ||
1135 | 1026 | ||
1136 | /* We end up here for the many possible ways to fail this API. */ | 1027 | static void pcie_shutdown_notification(struct controller *ctrl) |
1137 | abort_disable_intr: | 1028 | { |
1138 | if (pcie_write_cmd(ctrl, 0, HP_INTR_ENABLE)) | 1029 | pcie_disable_notification(ctrl); |
1139 | err("%s : disabling interrupts failed\n", __func__); | 1030 | pciehp_free_irq(ctrl); |
1140 | abort: | 1031 | } |
1141 | return -1; | 1032 | |
1033 | static void make_slot_name(struct slot *slot) | ||
1034 | { | ||
1035 | if (pciehp_slot_with_bus) | ||
1036 | snprintf(slot->name, SLOT_NAME_SIZE, "%04d_%04d", | ||
1037 | slot->bus, slot->number); | ||
1038 | else | ||
1039 | snprintf(slot->name, SLOT_NAME_SIZE, "%d", slot->number); | ||
1040 | } | ||
1041 | |||
1042 | static int pcie_init_slot(struct controller *ctrl) | ||
1043 | { | ||
1044 | struct slot *slot; | ||
1045 | |||
1046 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); | ||
1047 | if (!slot) | ||
1048 | return -ENOMEM; | ||
1049 | |||
1050 | slot->hp_slot = 0; | ||
1051 | slot->ctrl = ctrl; | ||
1052 | slot->bus = ctrl->pci_dev->subordinate->number; | ||
1053 | slot->device = ctrl->slot_device_offset + slot->hp_slot; | ||
1054 | slot->hpc_ops = ctrl->hpc_ops; | ||
1055 | slot->number = ctrl->first_slot; | ||
1056 | make_slot_name(slot); | ||
1057 | mutex_init(&slot->lock); | ||
1058 | INIT_DELAYED_WORK(&slot->work, pciehp_queue_pushbutton_work); | ||
1059 | list_add(&slot->slot_list, &ctrl->slot_list); | ||
1060 | return 0; | ||
1061 | } | ||
1062 | |||
1063 | static void pcie_cleanup_slot(struct controller *ctrl) | ||
1064 | { | ||
1065 | struct slot *slot; | ||
1066 | slot = list_first_entry(&ctrl->slot_list, struct slot, slot_list); | ||
1067 | list_del(&slot->slot_list); | ||
1068 | cancel_delayed_work(&slot->work); | ||
1069 | flush_scheduled_work(); | ||
1070 | flush_workqueue(pciehp_wq); | ||
1071 | kfree(slot); | ||
1142 | } | 1072 | } |
1143 | 1073 | ||
1144 | static inline void dbg_ctrl(struct controller *ctrl) | 1074 | static inline void dbg_ctrl(struct controller *ctrl) |
@@ -1176,15 +1106,23 @@ static inline void dbg_ctrl(struct controller *ctrl) | |||
1176 | dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes"); | 1106 | dbg(" Comamnd Completed : %3s\n", NO_CMD_CMPL(ctrl)? "no" : "yes"); |
1177 | pciehp_readw(ctrl, SLOTSTATUS, ®16); | 1107 | pciehp_readw(ctrl, SLOTSTATUS, ®16); |
1178 | dbg("Slot Status : 0x%04x\n", reg16); | 1108 | dbg("Slot Status : 0x%04x\n", reg16); |
1179 | pciehp_readw(ctrl, SLOTSTATUS, ®16); | 1109 | pciehp_readw(ctrl, SLOTCTRL, ®16); |
1180 | dbg("Slot Control : 0x%04x\n", reg16); | 1110 | dbg("Slot Control : 0x%04x\n", reg16); |
1181 | } | 1111 | } |
1182 | 1112 | ||
1183 | int pcie_init(struct controller *ctrl, struct pcie_device *dev) | 1113 | struct controller *pcie_init(struct pcie_device *dev) |
1184 | { | 1114 | { |
1115 | struct controller *ctrl; | ||
1185 | u32 slot_cap; | 1116 | u32 slot_cap; |
1186 | struct pci_dev *pdev = dev->port; | 1117 | struct pci_dev *pdev = dev->port; |
1187 | 1118 | ||
1119 | ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); | ||
1120 | if (!ctrl) { | ||
1121 | err("%s : out of memory\n", __func__); | ||
1122 | goto abort; | ||
1123 | } | ||
1124 | INIT_LIST_HEAD(&ctrl->slot_list); | ||
1125 | |||
1188 | ctrl->pci_dev = pdev; | 1126 | ctrl->pci_dev = pdev; |
1189 | ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); | 1127 | ctrl->cap_base = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
1190 | if (!ctrl->cap_base) { | 1128 | if (!ctrl->cap_base) { |
@@ -1215,15 +1153,12 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev) | |||
1215 | !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl))) | 1153 | !(POWER_CTRL(ctrl) | ATTN_LED(ctrl) | PWR_LED(ctrl) | EMI(ctrl))) |
1216 | ctrl->no_cmd_complete = 1; | 1154 | ctrl->no_cmd_complete = 1; |
1217 | 1155 | ||
1218 | info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", | 1156 | /* Clear all remaining event bits in Slot Status register */ |
1219 | pdev->vendor, pdev->device, | 1157 | if (pciehp_writew(ctrl, SLOTSTATUS, 0x1f)) |
1220 | pdev->subsystem_vendor, pdev->subsystem_device); | 1158 | goto abort_ctrl; |
1221 | 1159 | ||
1222 | if (pcie_init_hardware_part1(ctrl, dev)) | 1160 | /* Disable sotfware notification */ |
1223 | goto abort; | 1161 | pcie_disable_notification(ctrl); |
1224 | |||
1225 | if (pciehp_request_irq(ctrl)) | ||
1226 | goto abort; | ||
1227 | 1162 | ||
1228 | /* | 1163 | /* |
1229 | * If this is the first controller to be initialized, | 1164 | * If this is the first controller to be initialized, |
@@ -1231,18 +1166,39 @@ int pcie_init(struct controller *ctrl, struct pcie_device *dev) | |||
1231 | */ | 1166 | */ |
1232 | if (atomic_add_return(1, &pciehp_num_controllers) == 1) { | 1167 | if (atomic_add_return(1, &pciehp_num_controllers) == 1) { |
1233 | pciehp_wq = create_singlethread_workqueue("pciehpd"); | 1168 | pciehp_wq = create_singlethread_workqueue("pciehpd"); |
1234 | if (!pciehp_wq) { | 1169 | if (!pciehp_wq) |
1235 | goto abort_free_irq; | 1170 | goto abort_ctrl; |
1236 | } | ||
1237 | } | 1171 | } |
1238 | 1172 | ||
1239 | if (pcie_init_hardware_part2(ctrl, dev)) | 1173 | info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", |
1240 | goto abort_free_irq; | 1174 | pdev->vendor, pdev->device, |
1175 | pdev->subsystem_vendor, pdev->subsystem_device); | ||
1176 | |||
1177 | if (pcie_init_slot(ctrl)) | ||
1178 | goto abort_ctrl; | ||
1241 | 1179 | ||
1242 | return 0; | 1180 | if (pcie_init_notification(ctrl)) |
1181 | goto abort_slot; | ||
1243 | 1182 | ||
1244 | abort_free_irq: | 1183 | return ctrl; |
1245 | pciehp_free_irq(ctrl); | 1184 | |
1185 | abort_slot: | ||
1186 | pcie_cleanup_slot(ctrl); | ||
1187 | abort_ctrl: | ||
1188 | kfree(ctrl); | ||
1246 | abort: | 1189 | abort: |
1247 | return -1; | 1190 | return NULL; |
1191 | } | ||
1192 | |||
1193 | void pcie_release_ctrl(struct controller *ctrl) | ||
1194 | { | ||
1195 | pcie_shutdown_notification(ctrl); | ||
1196 | pcie_cleanup_slot(ctrl); | ||
1197 | /* | ||
1198 | * If this is the last controller to be released, destroy the | ||
1199 | * pciehp work queue | ||
1200 | */ | ||
1201 | if (atomic_dec_and_test(&pciehp_num_controllers)) | ||
1202 | destroy_workqueue(pciehp_wq); | ||
1203 | kfree(ctrl); | ||
1248 | } | 1204 | } |
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c index 779c5db71be4..a796301ea03f 100644 --- a/drivers/pci/hotplug/rpadlpar_sysfs.c +++ b/drivers/pci/hotplug/rpadlpar_sysfs.c | |||
@@ -14,8 +14,10 @@ | |||
14 | */ | 14 | */ |
15 | #include <linux/kobject.h> | 15 | #include <linux/kobject.h> |
16 | #include <linux/string.h> | 16 | #include <linux/string.h> |
17 | #include <linux/pci.h> | ||
17 | #include <linux/pci_hotplug.h> | 18 | #include <linux/pci_hotplug.h> |
18 | #include "rpadlpar.h" | 19 | #include "rpadlpar.h" |
20 | #include "../pci.h" | ||
19 | 21 | ||
20 | #define DLPAR_KOBJ_NAME "control" | 22 | #define DLPAR_KOBJ_NAME "control" |
21 | 23 | ||
@@ -27,7 +29,6 @@ | |||
27 | 29 | ||
28 | #define MAX_DRC_NAME_LEN 64 | 30 | #define MAX_DRC_NAME_LEN 64 |
29 | 31 | ||
30 | |||
31 | static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, | 32 | static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr, |
32 | const char *buf, size_t nbytes) | 33 | const char *buf, size_t nbytes) |
33 | { | 34 | { |
@@ -112,7 +113,7 @@ int dlpar_sysfs_init(void) | |||
112 | int error; | 113 | int error; |
113 | 114 | ||
114 | dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME, | 115 | dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME, |
115 | &pci_hotplug_slots_kset->kobj); | 116 | &pci_slots_kset->kobj); |
116 | if (!dlpar_kobj) | 117 | if (!dlpar_kobj) |
117 | return -EINVAL; | 118 | return -EINVAL; |
118 | 119 | ||
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c index 56197b600d36..9b714ea93d20 100644 --- a/drivers/pci/hotplug/rpaphp_slot.c +++ b/drivers/pci/hotplug/rpaphp_slot.c | |||
@@ -33,33 +33,6 @@ | |||
33 | #include <asm/rtas.h> | 33 | #include <asm/rtas.h> |
34 | #include "rpaphp.h" | 34 | #include "rpaphp.h" |
35 | 35 | ||
36 | static ssize_t address_read_file (struct hotplug_slot *php_slot, char *buf) | ||
37 | { | ||
38 | int retval; | ||
39 | struct slot *slot = (struct slot *)php_slot->private; | ||
40 | struct pci_bus *bus; | ||
41 | |||
42 | if (!slot) | ||
43 | return -ENOENT; | ||
44 | |||
45 | bus = slot->bus; | ||
46 | if (!bus) | ||
47 | return -ENOENT; | ||
48 | |||
49 | if (bus->self) | ||
50 | retval = sprintf(buf, pci_name(bus->self)); | ||
51 | else | ||
52 | retval = sprintf(buf, "%04x:%02x:00.0", | ||
53 | pci_domain_nr(bus), bus->number); | ||
54 | |||
55 | return retval; | ||
56 | } | ||
57 | |||
58 | static struct hotplug_slot_attribute php_attr_address = { | ||
59 | .attr = {.name = "address", .mode = S_IFREG | S_IRUGO}, | ||
60 | .show = address_read_file, | ||
61 | }; | ||
62 | |||
63 | /* free up the memory used by a slot */ | 36 | /* free up the memory used by a slot */ |
64 | static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) | 37 | static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) |
65 | { | 38 | { |
@@ -135,9 +108,6 @@ int rpaphp_deregister_slot(struct slot *slot) | |||
135 | 108 | ||
136 | list_del(&slot->rpaphp_slot_list); | 109 | list_del(&slot->rpaphp_slot_list); |
137 | 110 | ||
138 | /* remove "address" file */ | ||
139 | sysfs_remove_file(&php_slot->kobj, &php_attr_address.attr); | ||
140 | |||
141 | retval = pci_hp_deregister(php_slot); | 111 | retval = pci_hp_deregister(php_slot); |
142 | if (retval) | 112 | if (retval) |
143 | err("Problem unregistering a slot %s\n", slot->name); | 113 | err("Problem unregistering a slot %s\n", slot->name); |
@@ -151,6 +121,7 @@ int rpaphp_register_slot(struct slot *slot) | |||
151 | { | 121 | { |
152 | struct hotplug_slot *php_slot = slot->hotplug_slot; | 122 | struct hotplug_slot *php_slot = slot->hotplug_slot; |
153 | int retval; | 123 | int retval; |
124 | int slotno; | ||
154 | 125 | ||
155 | dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", | 126 | dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", |
156 | __func__, slot->dn->full_name, slot->index, slot->name, | 127 | __func__, slot->dn->full_name, slot->index, slot->name, |
@@ -162,19 +133,16 @@ int rpaphp_register_slot(struct slot *slot) | |||
162 | return -EAGAIN; | 133 | return -EAGAIN; |
163 | } | 134 | } |
164 | 135 | ||
165 | retval = pci_hp_register(php_slot); | 136 | if (slot->dn->child) |
137 | slotno = PCI_SLOT(PCI_DN(slot->dn->child)->devfn); | ||
138 | else | ||
139 | slotno = -1; | ||
140 | retval = pci_hp_register(php_slot, slot->bus, slotno); | ||
166 | if (retval) { | 141 | if (retval) { |
167 | err("pci_hp_register failed with error %d\n", retval); | 142 | err("pci_hp_register failed with error %d\n", retval); |
168 | return retval; | 143 | return retval; |
169 | } | 144 | } |
170 | 145 | ||
171 | /* create "address" file */ | ||
172 | retval = sysfs_create_file(&php_slot->kobj, &php_attr_address.attr); | ||
173 | if (retval) { | ||
174 | err("sysfs_create_file failed with error %d\n", retval); | ||
175 | goto sysfs_fail; | ||
176 | } | ||
177 | |||
178 | /* add slot to our internal list */ | 146 | /* add slot to our internal list */ |
179 | list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); | 147 | list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); |
180 | info("Slot [%s] registered\n", slot->name); | 148 | info("Slot [%s] registered\n", slot->name); |
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c index 2fe37cd85b69..410fe0394a8e 100644 --- a/drivers/pci/hotplug/sgi_hotplug.c +++ b/drivers/pci/hotplug/sgi_hotplug.c | |||
@@ -197,13 +197,15 @@ static int sn_hp_slot_private_alloc(struct hotplug_slot *bss_hotplug_slot, | |||
197 | static struct hotplug_slot * sn_hp_destroy(void) | 197 | static struct hotplug_slot * sn_hp_destroy(void) |
198 | { | 198 | { |
199 | struct slot *slot; | 199 | struct slot *slot; |
200 | struct pci_slot *pci_slot; | ||
200 | struct hotplug_slot *bss_hotplug_slot = NULL; | 201 | struct hotplug_slot *bss_hotplug_slot = NULL; |
201 | 202 | ||
202 | list_for_each_entry(slot, &sn_hp_list, hp_list) { | 203 | list_for_each_entry(slot, &sn_hp_list, hp_list) { |
203 | bss_hotplug_slot = slot->hotplug_slot; | 204 | bss_hotplug_slot = slot->hotplug_slot; |
205 | pci_slot = bss_hotplug_slot->pci_slot; | ||
204 | list_del(&((struct slot *)bss_hotplug_slot->private)-> | 206 | list_del(&((struct slot *)bss_hotplug_slot->private)-> |
205 | hp_list); | 207 | hp_list); |
206 | sysfs_remove_file(&bss_hotplug_slot->kobj, | 208 | sysfs_remove_file(&pci_slot->kobj, |
207 | &sn_slot_path_attr.attr); | 209 | &sn_slot_path_attr.attr); |
208 | break; | 210 | break; |
209 | } | 211 | } |
@@ -614,6 +616,7 @@ static void sn_release_slot(struct hotplug_slot *bss_hotplug_slot) | |||
614 | static int sn_hotplug_slot_register(struct pci_bus *pci_bus) | 616 | static int sn_hotplug_slot_register(struct pci_bus *pci_bus) |
615 | { | 617 | { |
616 | int device; | 618 | int device; |
619 | struct pci_slot *pci_slot; | ||
617 | struct hotplug_slot *bss_hotplug_slot; | 620 | struct hotplug_slot *bss_hotplug_slot; |
618 | int rc = 0; | 621 | int rc = 0; |
619 | 622 | ||
@@ -650,11 +653,12 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus) | |||
650 | bss_hotplug_slot->ops = &sn_hotplug_slot_ops; | 653 | bss_hotplug_slot->ops = &sn_hotplug_slot_ops; |
651 | bss_hotplug_slot->release = &sn_release_slot; | 654 | bss_hotplug_slot->release = &sn_release_slot; |
652 | 655 | ||
653 | rc = pci_hp_register(bss_hotplug_slot); | 656 | rc = pci_hp_register(bss_hotplug_slot, pci_bus, device); |
654 | if (rc) | 657 | if (rc) |
655 | goto register_err; | 658 | goto register_err; |
656 | 659 | ||
657 | rc = sysfs_create_file(&bss_hotplug_slot->kobj, | 660 | pci_slot = bss_hotplug_slot->pci_slot; |
661 | rc = sysfs_create_file(&pci_slot->kobj, | ||
658 | &sn_slot_path_attr.attr); | 662 | &sn_slot_path_attr.attr); |
659 | if (rc) | 663 | if (rc) |
660 | goto register_err; | 664 | goto register_err; |
@@ -664,7 +668,7 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus) | |||
664 | 668 | ||
665 | register_err: | 669 | register_err: |
666 | dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n", | 670 | dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n", |
667 | rc); | 671 | rc); |
668 | 672 | ||
669 | alloc_err: | 673 | alloc_err: |
670 | if (rc == -ENOMEM) | 674 | if (rc == -ENOMEM) |
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h index f66e8d6315ab..8a026f750deb 100644 --- a/drivers/pci/hotplug/shpchp.h +++ b/drivers/pci/hotplug/shpchp.h | |||
@@ -170,6 +170,7 @@ extern void shpchp_queue_pushbutton_work(struct work_struct *work); | |||
170 | extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev); | 170 | extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev); |
171 | 171 | ||
172 | #ifdef CONFIG_ACPI | 172 | #ifdef CONFIG_ACPI |
173 | #include <linux/pci-acpi.h> | ||
173 | static inline int get_hp_params_from_firmware(struct pci_dev *dev, | 174 | static inline int get_hp_params_from_firmware(struct pci_dev *dev, |
174 | struct hotplug_params *hpp) | 175 | struct hotplug_params *hpp) |
175 | { | 176 | { |
@@ -177,14 +178,15 @@ static inline int get_hp_params_from_firmware(struct pci_dev *dev, | |||
177 | return -ENODEV; | 178 | return -ENODEV; |
178 | return 0; | 179 | return 0; |
179 | } | 180 | } |
180 | #define get_hp_hw_control_from_firmware(pdev) \ | 181 | |
181 | do { \ | 182 | static inline int get_hp_hw_control_from_firmware(struct pci_dev *dev) |
182 | if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \ | 183 | { |
183 | acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev)));\ | 184 | u32 flags = OSC_SHPC_NATIVE_HP_CONTROL; |
184 | } while (0) | 185 | return acpi_get_hp_hw_control_from_firmware(dev, flags); |
186 | } | ||
185 | #else | 187 | #else |
186 | #define get_hp_params_from_firmware(dev, hpp) (-ENODEV) | 188 | #define get_hp_params_from_firmware(dev, hpp) (-ENODEV) |
187 | #define get_hp_hw_control_from_firmware(dev) do { } while (0) | 189 | #define get_hp_hw_control_from_firmware(dev) (0) |
188 | #endif | 190 | #endif |
189 | 191 | ||
190 | struct ctrl_reg { | 192 | struct ctrl_reg { |
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c index 97848654652a..a8cbd039b85b 100644 --- a/drivers/pci/hotplug/shpchp_core.c +++ b/drivers/pci/hotplug/shpchp_core.c | |||
@@ -39,7 +39,7 @@ | |||
39 | int shpchp_debug; | 39 | int shpchp_debug; |
40 | int shpchp_poll_mode; | 40 | int shpchp_poll_mode; |
41 | int shpchp_poll_time; | 41 | int shpchp_poll_time; |
42 | int shpchp_slot_with_bus; | 42 | static int shpchp_slot_with_bus; |
43 | struct workqueue_struct *shpchp_wq; | 43 | struct workqueue_struct *shpchp_wq; |
44 | 44 | ||
45 | #define DRIVER_VERSION "0.4" | 45 | #define DRIVER_VERSION "0.4" |
@@ -68,7 +68,6 @@ static int get_power_status (struct hotplug_slot *slot, u8 *value); | |||
68 | static int get_attention_status (struct hotplug_slot *slot, u8 *value); | 68 | static int get_attention_status (struct hotplug_slot *slot, u8 *value); |
69 | static int get_latch_status (struct hotplug_slot *slot, u8 *value); | 69 | static int get_latch_status (struct hotplug_slot *slot, u8 *value); |
70 | static int get_adapter_status (struct hotplug_slot *slot, u8 *value); | 70 | static int get_adapter_status (struct hotplug_slot *slot, u8 *value); |
71 | static int get_address (struct hotplug_slot *slot, u32 *value); | ||
72 | static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); | 71 | static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); |
73 | static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); | 72 | static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value); |
74 | 73 | ||
@@ -81,7 +80,6 @@ static struct hotplug_slot_ops shpchp_hotplug_slot_ops = { | |||
81 | .get_attention_status = get_attention_status, | 80 | .get_attention_status = get_attention_status, |
82 | .get_latch_status = get_latch_status, | 81 | .get_latch_status = get_latch_status, |
83 | .get_adapter_status = get_adapter_status, | 82 | .get_adapter_status = get_adapter_status, |
84 | .get_address = get_address, | ||
85 | .get_max_bus_speed = get_max_bus_speed, | 83 | .get_max_bus_speed = get_max_bus_speed, |
86 | .get_cur_bus_speed = get_cur_bus_speed, | 84 | .get_cur_bus_speed = get_cur_bus_speed, |
87 | }; | 85 | }; |
@@ -159,7 +157,8 @@ static int init_slots(struct controller *ctrl) | |||
159 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " | 157 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " |
160 | "slot_device_offset=%x\n", slot->bus, slot->device, | 158 | "slot_device_offset=%x\n", slot->bus, slot->device, |
161 | slot->hp_slot, slot->number, ctrl->slot_device_offset); | 159 | slot->hp_slot, slot->number, ctrl->slot_device_offset); |
162 | retval = pci_hp_register(slot->hotplug_slot); | 160 | retval = pci_hp_register(slot->hotplug_slot, |
161 | ctrl->pci_dev->subordinate, slot->device); | ||
163 | if (retval) { | 162 | if (retval) { |
164 | err("pci_hp_register failed with error %d\n", retval); | 163 | err("pci_hp_register failed with error %d\n", retval); |
165 | if (retval == -EEXIST) | 164 | if (retval == -EEXIST) |
@@ -288,19 +287,8 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) | |||
288 | return 0; | 287 | return 0; |
289 | } | 288 | } |
290 | 289 | ||
291 | static int get_address (struct hotplug_slot *hotplug_slot, u32 *value) | 290 | static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, |
292 | { | 291 | enum pci_bus_speed *value) |
293 | struct slot *slot = get_slot(hotplug_slot); | ||
294 | struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; | ||
295 | |||
296 | dbg("%s - physical_slot = %s\n", __func__, hotplug_slot->name); | ||
297 | |||
298 | *value = (pci_domain_nr(bus) << 16) | (slot->bus << 8) | slot->device; | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) | ||
304 | { | 292 | { |
305 | struct slot *slot = get_slot(hotplug_slot); | 293 | struct slot *slot = get_slot(hotplug_slot); |
306 | int retval; | 294 | int retval; |
@@ -330,13 +318,14 @@ static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp | |||
330 | 318 | ||
331 | static int is_shpc_capable(struct pci_dev *dev) | 319 | static int is_shpc_capable(struct pci_dev *dev) |
332 | { | 320 | { |
333 | if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == | 321 | if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == |
334 | PCI_DEVICE_ID_AMD_GOLAM_7450)) | 322 | PCI_DEVICE_ID_AMD_GOLAM_7450)) |
335 | return 1; | 323 | return 1; |
336 | if (pci_find_capability(dev, PCI_CAP_ID_SHPC)) | 324 | if (!pci_find_capability(dev, PCI_CAP_ID_SHPC)) |
337 | return 1; | 325 | return 0; |
338 | 326 | if (get_hp_hw_control_from_firmware(dev)) | |
339 | return 0; | 327 | return 0; |
328 | return 1; | ||
340 | } | 329 | } |
341 | 330 | ||
342 | static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | 331 | static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c index 7d770b2cd889..7a0bff364cd4 100644 --- a/drivers/pci/hotplug/shpchp_hpc.c +++ b/drivers/pci/hotplug/shpchp_hpc.c | |||
@@ -1084,7 +1084,6 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev) | |||
1084 | dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __func__, | 1084 | dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __func__, |
1085 | pdev->bus->number, PCI_SLOT(pdev->devfn), | 1085 | pdev->bus->number, PCI_SLOT(pdev->devfn), |
1086 | PCI_FUNC(pdev->devfn), pdev->irq); | 1086 | PCI_FUNC(pdev->devfn), pdev->irq); |
1087 | get_hp_hw_control_from_firmware(pdev); | ||
1088 | 1087 | ||
1089 | /* | 1088 | /* |
1090 | * If this is the first controller to be initialized, | 1089 | * If this is the first controller to be initialized, |
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c index bb0642318a95..3f7b81c065d2 100644 --- a/drivers/pci/intel-iommu.c +++ b/drivers/pci/intel-iommu.c | |||
@@ -1748,7 +1748,6 @@ int __init init_dmars(void) | |||
1748 | deferred_flush = kzalloc(g_num_of_iommus * | 1748 | deferred_flush = kzalloc(g_num_of_iommus * |
1749 | sizeof(struct deferred_flush_tables), GFP_KERNEL); | 1749 | sizeof(struct deferred_flush_tables), GFP_KERNEL); |
1750 | if (!deferred_flush) { | 1750 | if (!deferred_flush) { |
1751 | kfree(g_iommus); | ||
1752 | ret = -ENOMEM; | 1751 | ret = -ENOMEM; |
1753 | goto error; | 1752 | goto error; |
1754 | } | 1753 | } |
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c index 8c61304cbb37..15af618d36e2 100644 --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c | |||
@@ -70,12 +70,10 @@ arch_teardown_msi_irqs(struct pci_dev *dev) | |||
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | static void msi_set_enable(struct pci_dev *dev, int enable) | 73 | static void __msi_set_enable(struct pci_dev *dev, int pos, int enable) |
74 | { | 74 | { |
75 | int pos; | ||
76 | u16 control; | 75 | u16 control; |
77 | 76 | ||
78 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); | ||
79 | if (pos) { | 77 | if (pos) { |
80 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); | 78 | pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); |
81 | control &= ~PCI_MSI_FLAGS_ENABLE; | 79 | control &= ~PCI_MSI_FLAGS_ENABLE; |
@@ -85,6 +83,11 @@ static void msi_set_enable(struct pci_dev *dev, int enable) | |||
85 | } | 83 | } |
86 | } | 84 | } |
87 | 85 | ||
86 | static void msi_set_enable(struct pci_dev *dev, int enable) | ||
87 | { | ||
88 | __msi_set_enable(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), enable); | ||
89 | } | ||
90 | |||
88 | static void msix_set_enable(struct pci_dev *dev, int enable) | 91 | static void msix_set_enable(struct pci_dev *dev, int enable) |
89 | { | 92 | { |
90 | int pos; | 93 | int pos; |
@@ -141,7 +144,8 @@ static void msi_set_mask_bits(unsigned int irq, u32 mask, u32 flag) | |||
141 | mask_bits |= flag & mask; | 144 | mask_bits |= flag & mask; |
142 | pci_write_config_dword(entry->dev, pos, mask_bits); | 145 | pci_write_config_dword(entry->dev, pos, mask_bits); |
143 | } else { | 146 | } else { |
144 | msi_set_enable(entry->dev, !flag); | 147 | __msi_set_enable(entry->dev, entry->msi_attrib.pos, |
148 | !flag); | ||
145 | } | 149 | } |
146 | break; | 150 | break; |
147 | case PCI_CAP_ID_MSIX: | 151 | case PCI_CAP_ID_MSIX: |
@@ -561,9 +565,8 @@ int pci_enable_msi(struct pci_dev* dev) | |||
561 | 565 | ||
562 | /* Check whether driver already requested for MSI-X irqs */ | 566 | /* Check whether driver already requested for MSI-X irqs */ |
563 | if (dev->msix_enabled) { | 567 | if (dev->msix_enabled) { |
564 | printk(KERN_INFO "PCI: %s: Can't enable MSI. " | 568 | dev_info(&dev->dev, "can't enable MSI " |
565 | "Device already has MSI-X enabled\n", | 569 | "(MSI-X already enabled)\n"); |
566 | pci_name(dev)); | ||
567 | return -EINVAL; | 570 | return -EINVAL; |
568 | } | 571 | } |
569 | status = msi_capability_init(dev); | 572 | status = msi_capability_init(dev); |
@@ -686,9 +689,8 @@ int pci_enable_msix(struct pci_dev* dev, struct msix_entry *entries, int nvec) | |||
686 | 689 | ||
687 | /* Check whether driver already requested for MSI irq */ | 690 | /* Check whether driver already requested for MSI irq */ |
688 | if (dev->msi_enabled) { | 691 | if (dev->msi_enabled) { |
689 | printk(KERN_INFO "PCI: %s: Can't enable MSI-X. " | 692 | dev_info(&dev->dev, "can't enable MSI-X " |
690 | "Device already has an MSI irq assigned\n", | 693 | "(MSI IRQ already assigned)\n"); |
691 | pci_name(dev)); | ||
692 | return -EINVAL; | 694 | return -EINVAL; |
693 | } | 695 | } |
694 | status = msix_capability_init(dev, entries, nvec); | 696 | status = msix_capability_init(dev, entries, nvec); |
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 9d6fc8e6285d..7764768b6a0e 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c | |||
@@ -21,12 +21,19 @@ | |||
21 | 21 | ||
22 | struct acpi_osc_data { | 22 | struct acpi_osc_data { |
23 | acpi_handle handle; | 23 | acpi_handle handle; |
24 | u32 ctrlset_buf[3]; | 24 | u32 support_set; |
25 | u32 global_ctrlsets; | 25 | u32 control_set; |
26 | int is_queried; | ||
27 | u32 query_result; | ||
26 | struct list_head sibiling; | 28 | struct list_head sibiling; |
27 | }; | 29 | }; |
28 | static LIST_HEAD(acpi_osc_data_list); | 30 | static LIST_HEAD(acpi_osc_data_list); |
29 | 31 | ||
32 | struct acpi_osc_args { | ||
33 | u32 capbuf[3]; | ||
34 | u32 query_result; | ||
35 | }; | ||
36 | |||
30 | static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle) | 37 | static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle) |
31 | { | 38 | { |
32 | struct acpi_osc_data *data; | 39 | struct acpi_osc_data *data; |
@@ -44,42 +51,18 @@ static struct acpi_osc_data *acpi_get_osc_data(acpi_handle handle) | |||
44 | return data; | 51 | return data; |
45 | } | 52 | } |
46 | 53 | ||
47 | static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; | 54 | static u8 OSC_UUID[16] = {0x5B, 0x4D, 0xDB, 0x33, 0xF7, 0x1F, 0x1C, 0x40, |
55 | 0x96, 0x57, 0x74, 0x41, 0xC0, 0x3D, 0xD7, 0x66}; | ||
48 | 56 | ||
49 | static acpi_status | 57 | static acpi_status acpi_run_osc(acpi_handle handle, |
50 | acpi_query_osc ( | 58 | struct acpi_osc_args *osc_args) |
51 | acpi_handle handle, | ||
52 | u32 level, | ||
53 | void *context, | ||
54 | void **retval ) | ||
55 | { | 59 | { |
56 | acpi_status status; | 60 | acpi_status status; |
57 | struct acpi_object_list input; | 61 | struct acpi_object_list input; |
58 | union acpi_object in_params[4]; | 62 | union acpi_object in_params[4]; |
59 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | 63 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
60 | union acpi_object *out_obj; | 64 | union acpi_object *out_obj; |
61 | u32 osc_dw0; | 65 | u32 osc_dw0, flags = osc_args->capbuf[OSC_QUERY_TYPE]; |
62 | acpi_status *ret_status = (acpi_status *)retval; | ||
63 | struct acpi_osc_data *osc_data; | ||
64 | u32 flags = (unsigned long)context, temp; | ||
65 | acpi_handle tmp; | ||
66 | |||
67 | status = acpi_get_handle(handle, "_OSC", &tmp); | ||
68 | if (ACPI_FAILURE(status)) | ||
69 | return status; | ||
70 | |||
71 | osc_data = acpi_get_osc_data(handle); | ||
72 | if (!osc_data) { | ||
73 | printk(KERN_ERR "acpi osc data array is full\n"); | ||
74 | return AE_ERROR; | ||
75 | } | ||
76 | |||
77 | osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] |= (flags & OSC_SUPPORT_MASKS); | ||
78 | |||
79 | /* do _OSC query for all possible controls */ | ||
80 | temp = osc_data->ctrlset_buf[OSC_CONTROL_TYPE]; | ||
81 | osc_data->ctrlset_buf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; | ||
82 | osc_data->ctrlset_buf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; | ||
83 | 66 | ||
84 | /* Setting up input parameters */ | 67 | /* Setting up input parameters */ |
85 | input.count = 4; | 68 | input.count = 4; |
@@ -93,20 +76,19 @@ acpi_query_osc ( | |||
93 | in_params[2].integer.value = 3; | 76 | in_params[2].integer.value = 3; |
94 | in_params[3].type = ACPI_TYPE_BUFFER; | 77 | in_params[3].type = ACPI_TYPE_BUFFER; |
95 | in_params[3].buffer.length = 12; | 78 | in_params[3].buffer.length = 12; |
96 | in_params[3].buffer.pointer = (u8 *)osc_data->ctrlset_buf; | 79 | in_params[3].buffer.pointer = (u8 *)osc_args->capbuf; |
97 | 80 | ||
98 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); | 81 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); |
99 | if (ACPI_FAILURE(status)) | 82 | if (ACPI_FAILURE(status)) |
100 | goto out_nofree; | 83 | return status; |
101 | out_obj = output.pointer; | ||
102 | 84 | ||
85 | out_obj = output.pointer; | ||
103 | if (out_obj->type != ACPI_TYPE_BUFFER) { | 86 | if (out_obj->type != ACPI_TYPE_BUFFER) { |
104 | printk(KERN_DEBUG | 87 | printk(KERN_DEBUG "Evaluate _OSC returns wrong type\n"); |
105 | "Evaluate _OSC returns wrong type\n"); | ||
106 | status = AE_TYPE; | 88 | status = AE_TYPE; |
107 | goto query_osc_out; | 89 | goto out_kfree; |
108 | } | 90 | } |
109 | osc_dw0 = *((u32 *) out_obj->buffer.pointer); | 91 | osc_dw0 = *((u32 *)out_obj->buffer.pointer); |
110 | if (osc_dw0) { | 92 | if (osc_dw0) { |
111 | if (osc_dw0 & OSC_REQUEST_ERROR) | 93 | if (osc_dw0 & OSC_REQUEST_ERROR) |
112 | printk(KERN_DEBUG "_OSC request fails\n"); | 94 | printk(KERN_DEBUG "_OSC request fails\n"); |
@@ -115,93 +97,58 @@ acpi_query_osc ( | |||
115 | if (osc_dw0 & OSC_INVALID_REVISION_ERROR) | 97 | if (osc_dw0 & OSC_INVALID_REVISION_ERROR) |
116 | printk(KERN_DEBUG "_OSC invalid revision\n"); | 98 | printk(KERN_DEBUG "_OSC invalid revision\n"); |
117 | if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { | 99 | if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { |
118 | /* Update Global Control Set */ | 100 | if (flags & OSC_QUERY_ENABLE) |
119 | osc_data->global_ctrlsets = | 101 | goto out_success; |
120 | *((u32 *)(out_obj->buffer.pointer + 8)); | 102 | printk(KERN_DEBUG "_OSC FW not grant req. control\n"); |
121 | status = AE_OK; | 103 | status = AE_SUPPORT; |
122 | goto query_osc_out; | 104 | goto out_kfree; |
123 | } | 105 | } |
124 | status = AE_ERROR; | 106 | status = AE_ERROR; |
125 | goto query_osc_out; | 107 | goto out_kfree; |
126 | } | 108 | } |
127 | 109 | out_success: | |
128 | /* Update Global Control Set */ | 110 | if (flags & OSC_QUERY_ENABLE) |
129 | osc_data->global_ctrlsets = *((u32 *)(out_obj->buffer.pointer + 8)); | 111 | osc_args->query_result = |
112 | *((u32 *)(out_obj->buffer.pointer + 8)); | ||
130 | status = AE_OK; | 113 | status = AE_OK; |
131 | 114 | ||
132 | query_osc_out: | 115 | out_kfree: |
133 | kfree(output.pointer); | 116 | kfree(output.pointer); |
134 | out_nofree: | ||
135 | *ret_status = status; | ||
136 | |||
137 | osc_data->ctrlset_buf[OSC_QUERY_TYPE] = !OSC_QUERY_ENABLE; | ||
138 | osc_data->ctrlset_buf[OSC_CONTROL_TYPE] = temp; | ||
139 | if (ACPI_FAILURE(status)) { | ||
140 | /* no osc support at all */ | ||
141 | osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] = 0; | ||
142 | } | ||
143 | |||
144 | return status; | 117 | return status; |
145 | } | 118 | } |
146 | 119 | ||
147 | 120 | static acpi_status acpi_query_osc(acpi_handle handle, | |
148 | static acpi_status | 121 | u32 level, void *context, void **retval) |
149 | acpi_run_osc ( | ||
150 | acpi_handle handle, | ||
151 | void *context) | ||
152 | { | 122 | { |
153 | acpi_status status; | 123 | acpi_status status; |
154 | struct acpi_object_list input; | 124 | struct acpi_osc_data *osc_data; |
155 | union acpi_object in_params[4]; | 125 | u32 flags = (unsigned long)context, support_set; |
156 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | 126 | acpi_handle tmp; |
157 | union acpi_object *out_obj; | 127 | struct acpi_osc_args osc_args; |
158 | u32 osc_dw0; | ||
159 | |||
160 | /* Setting up input parameters */ | ||
161 | input.count = 4; | ||
162 | input.pointer = in_params; | ||
163 | in_params[0].type = ACPI_TYPE_BUFFER; | ||
164 | in_params[0].buffer.length = 16; | ||
165 | in_params[0].buffer.pointer = OSC_UUID; | ||
166 | in_params[1].type = ACPI_TYPE_INTEGER; | ||
167 | in_params[1].integer.value = 1; | ||
168 | in_params[2].type = ACPI_TYPE_INTEGER; | ||
169 | in_params[2].integer.value = 3; | ||
170 | in_params[3].type = ACPI_TYPE_BUFFER; | ||
171 | in_params[3].buffer.length = 12; | ||
172 | in_params[3].buffer.pointer = (u8 *)context; | ||
173 | 128 | ||
174 | status = acpi_evaluate_object(handle, "_OSC", &input, &output); | 129 | status = acpi_get_handle(handle, "_OSC", &tmp); |
175 | if (ACPI_FAILURE (status)) | 130 | if (ACPI_FAILURE(status)) |
176 | return status; | 131 | return status; |
177 | 132 | ||
178 | out_obj = output.pointer; | 133 | osc_data = acpi_get_osc_data(handle); |
179 | if (out_obj->type != ACPI_TYPE_BUFFER) { | 134 | if (!osc_data) { |
180 | printk(KERN_DEBUG | 135 | printk(KERN_ERR "acpi osc data array is full\n"); |
181 | "Evaluate _OSC returns wrong type\n"); | 136 | return AE_ERROR; |
182 | status = AE_TYPE; | ||
183 | goto run_osc_out; | ||
184 | } | 137 | } |
185 | osc_dw0 = *((u32 *) out_obj->buffer.pointer); | 138 | |
186 | if (osc_dw0) { | 139 | /* do _OSC query for all possible controls */ |
187 | if (osc_dw0 & OSC_REQUEST_ERROR) | 140 | support_set = osc_data->support_set | (flags & OSC_SUPPORT_MASKS); |
188 | printk(KERN_DEBUG "_OSC request fails\n"); | 141 | osc_args.capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; |
189 | if (osc_dw0 & OSC_INVALID_UUID_ERROR) | 142 | osc_args.capbuf[OSC_SUPPORT_TYPE] = support_set; |
190 | printk(KERN_DEBUG "_OSC invalid UUID\n"); | 143 | osc_args.capbuf[OSC_CONTROL_TYPE] = OSC_CONTROL_MASKS; |
191 | if (osc_dw0 & OSC_INVALID_REVISION_ERROR) | 144 | |
192 | printk(KERN_DEBUG "_OSC invalid revision\n"); | 145 | status = acpi_run_osc(handle, &osc_args); |
193 | if (osc_dw0 & OSC_CAPABILITIES_MASK_ERROR) { | 146 | if (ACPI_SUCCESS(status)) { |
194 | printk(KERN_DEBUG "_OSC FW not grant req. control\n"); | 147 | osc_data->support_set = support_set; |
195 | status = AE_SUPPORT; | 148 | osc_data->query_result = osc_args.query_result; |
196 | goto run_osc_out; | 149 | osc_data->is_queried = 1; |
197 | } | ||
198 | status = AE_ERROR; | ||
199 | goto run_osc_out; | ||
200 | } | 150 | } |
201 | status = AE_OK; | ||
202 | 151 | ||
203 | run_osc_out: | ||
204 | kfree(output.pointer); | ||
205 | return status; | 152 | return status; |
206 | } | 153 | } |
207 | 154 | ||
@@ -215,15 +162,11 @@ run_osc_out: | |||
215 | **/ | 162 | **/ |
216 | acpi_status __pci_osc_support_set(u32 flags, const char *hid) | 163 | acpi_status __pci_osc_support_set(u32 flags, const char *hid) |
217 | { | 164 | { |
218 | acpi_status retval = AE_NOT_FOUND; | 165 | if (!(flags & OSC_SUPPORT_MASKS)) |
219 | |||
220 | if (!(flags & OSC_SUPPORT_MASKS)) { | ||
221 | return AE_TYPE; | 166 | return AE_TYPE; |
222 | } | 167 | |
223 | acpi_get_devices(hid, | 168 | acpi_get_devices(hid, acpi_query_osc, |
224 | acpi_query_osc, | 169 | (void *)(unsigned long)flags, NULL); |
225 | (void *)(unsigned long)flags, | ||
226 | (void **) &retval ); | ||
227 | return AE_OK; | 170 | return AE_OK; |
228 | } | 171 | } |
229 | 172 | ||
@@ -236,10 +179,11 @@ acpi_status __pci_osc_support_set(u32 flags, const char *hid) | |||
236 | **/ | 179 | **/ |
237 | acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) | 180 | acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) |
238 | { | 181 | { |
239 | acpi_status status; | 182 | acpi_status status; |
240 | u32 ctrlset; | 183 | u32 ctrlset, control_set; |
241 | acpi_handle tmp; | 184 | acpi_handle tmp; |
242 | struct acpi_osc_data *osc_data; | 185 | struct acpi_osc_data *osc_data; |
186 | struct acpi_osc_args osc_args; | ||
243 | 187 | ||
244 | status = acpi_get_handle(handle, "_OSC", &tmp); | 188 | status = acpi_get_handle(handle, "_OSC", &tmp); |
245 | if (ACPI_FAILURE(status)) | 189 | if (ACPI_FAILURE(status)) |
@@ -252,24 +196,25 @@ acpi_status pci_osc_control_set(acpi_handle handle, u32 flags) | |||
252 | } | 196 | } |
253 | 197 | ||
254 | ctrlset = (flags & OSC_CONTROL_MASKS); | 198 | ctrlset = (flags & OSC_CONTROL_MASKS); |
255 | if (!ctrlset) { | 199 | if (!ctrlset) |
256 | return AE_TYPE; | 200 | return AE_TYPE; |
257 | } | 201 | |
258 | if (osc_data->ctrlset_buf[OSC_SUPPORT_TYPE] && | 202 | if (osc_data->is_queried && |
259 | ((osc_data->global_ctrlsets & ctrlset) != ctrlset)) { | 203 | ((osc_data->query_result & ctrlset) != ctrlset)) |
260 | return AE_SUPPORT; | 204 | return AE_SUPPORT; |
261 | } | 205 | |
262 | osc_data->ctrlset_buf[OSC_CONTROL_TYPE] |= ctrlset; | 206 | control_set = osc_data->control_set | ctrlset; |
263 | status = acpi_run_osc(handle, osc_data->ctrlset_buf); | 207 | osc_args.capbuf[OSC_QUERY_TYPE] = 0; |
264 | if (ACPI_FAILURE (status)) { | 208 | osc_args.capbuf[OSC_SUPPORT_TYPE] = osc_data->support_set; |
265 | osc_data->ctrlset_buf[OSC_CONTROL_TYPE] &= ~ctrlset; | 209 | osc_args.capbuf[OSC_CONTROL_TYPE] = control_set; |
266 | } | 210 | status = acpi_run_osc(handle, &osc_args); |
267 | 211 | if (ACPI_SUCCESS(status)) | |
212 | osc_data->control_set = control_set; | ||
213 | |||
268 | return status; | 214 | return status; |
269 | } | 215 | } |
270 | EXPORT_SYMBOL(pci_osc_control_set); | 216 | EXPORT_SYMBOL(pci_osc_control_set); |
271 | 217 | ||
272 | #ifdef CONFIG_ACPI_SLEEP | ||
273 | /* | 218 | /* |
274 | * _SxD returns the D-state with the highest power | 219 | * _SxD returns the D-state with the highest power |
275 | * (lowest D-state number) supported in the S-state "x". | 220 | * (lowest D-state number) supported in the S-state "x". |
@@ -293,13 +238,11 @@ EXPORT_SYMBOL(pci_osc_control_set); | |||
293 | * choose highest power _SxD or any lower power | 238 | * choose highest power _SxD or any lower power |
294 | */ | 239 | */ |
295 | 240 | ||
296 | static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev, | 241 | static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) |
297 | pm_message_t state) | ||
298 | { | 242 | { |
299 | int acpi_state; | 243 | int acpi_state; |
300 | 244 | ||
301 | acpi_state = acpi_pm_device_sleep_state(&pdev->dev, | 245 | acpi_state = acpi_pm_device_sleep_state(&pdev->dev, NULL); |
302 | device_may_wakeup(&pdev->dev), NULL); | ||
303 | if (acpi_state < 0) | 246 | if (acpi_state < 0) |
304 | return PCI_POWER_ERROR; | 247 | return PCI_POWER_ERROR; |
305 | 248 | ||
@@ -315,7 +258,13 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev, | |||
315 | } | 258 | } |
316 | return PCI_POWER_ERROR; | 259 | return PCI_POWER_ERROR; |
317 | } | 260 | } |
318 | #endif | 261 | |
262 | static bool acpi_pci_power_manageable(struct pci_dev *dev) | ||
263 | { | ||
264 | acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); | ||
265 | |||
266 | return handle ? acpi_bus_power_manageable(handle) : false; | ||
267 | } | ||
319 | 268 | ||
320 | static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) | 269 | static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) |
321 | { | 270 | { |
@@ -328,12 +277,11 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
328 | [PCI_D3hot] = ACPI_STATE_D3, | 277 | [PCI_D3hot] = ACPI_STATE_D3, |
329 | [PCI_D3cold] = ACPI_STATE_D3 | 278 | [PCI_D3cold] = ACPI_STATE_D3 |
330 | }; | 279 | }; |
280 | int error = -EINVAL; | ||
331 | 281 | ||
332 | if (!handle) | ||
333 | return -ENODEV; | ||
334 | /* If the ACPI device has _EJ0, ignore the device */ | 282 | /* If the ACPI device has _EJ0, ignore the device */ |
335 | if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp))) | 283 | if (!handle || ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp))) |
336 | return 0; | 284 | return -ENODEV; |
337 | 285 | ||
338 | switch (state) { | 286 | switch (state) { |
339 | case PCI_D0: | 287 | case PCI_D0: |
@@ -341,11 +289,41 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
341 | case PCI_D2: | 289 | case PCI_D2: |
342 | case PCI_D3hot: | 290 | case PCI_D3hot: |
343 | case PCI_D3cold: | 291 | case PCI_D3cold: |
344 | return acpi_bus_set_power(handle, state_conv[state]); | 292 | error = acpi_bus_set_power(handle, state_conv[state]); |
345 | } | 293 | } |
346 | return -EINVAL; | 294 | |
295 | if (!error) | ||
296 | dev_printk(KERN_INFO, &dev->dev, | ||
297 | "power state changed by ACPI to D%d\n", state); | ||
298 | |||
299 | return error; | ||
300 | } | ||
301 | |||
302 | static bool acpi_pci_can_wakeup(struct pci_dev *dev) | ||
303 | { | ||
304 | acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); | ||
305 | |||
306 | return handle ? acpi_bus_can_wakeup(handle) : false; | ||
307 | } | ||
308 | |||
309 | static int acpi_pci_sleep_wake(struct pci_dev *dev, bool enable) | ||
310 | { | ||
311 | int error = acpi_pm_device_sleep_wake(&dev->dev, enable); | ||
312 | |||
313 | if (!error) | ||
314 | dev_printk(KERN_INFO, &dev->dev, | ||
315 | "wake-up capability %s by ACPI\n", | ||
316 | enable ? "enabled" : "disabled"); | ||
317 | return error; | ||
347 | } | 318 | } |
348 | 319 | ||
320 | static struct pci_platform_pm_ops acpi_pci_platform_pm = { | ||
321 | .is_manageable = acpi_pci_power_manageable, | ||
322 | .set_state = acpi_pci_set_power_state, | ||
323 | .choose_state = acpi_pci_choose_state, | ||
324 | .can_wakeup = acpi_pci_can_wakeup, | ||
325 | .sleep_wake = acpi_pci_sleep_wake, | ||
326 | }; | ||
349 | 327 | ||
350 | /* ACPI bus type */ | 328 | /* ACPI bus type */ |
351 | static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) | 329 | static int acpi_pci_find_device(struct device *dev, acpi_handle *handle) |
@@ -397,10 +375,7 @@ static int __init acpi_pci_init(void) | |||
397 | ret = register_acpi_bus_type(&acpi_pci_bus); | 375 | ret = register_acpi_bus_type(&acpi_pci_bus); |
398 | if (ret) | 376 | if (ret) |
399 | return 0; | 377 | return 0; |
400 | #ifdef CONFIG_ACPI_SLEEP | 378 | pci_set_platform_pm(&acpi_pci_platform_pm); |
401 | platform_pci_choose_state = acpi_pci_choose_state; | ||
402 | #endif | ||
403 | platform_pci_set_power_state = acpi_pci_set_power_state; | ||
404 | return 0; | 379 | return 0; |
405 | } | 380 | } |
406 | arch_initcall(acpi_pci_init); | 381 | arch_initcall(acpi_pci_init); |
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index e1637bd82b8e..a13f53486114 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
@@ -274,7 +274,57 @@ static int pci_device_remove(struct device * dev) | |||
274 | return 0; | 274 | return 0; |
275 | } | 275 | } |
276 | 276 | ||
277 | static int pci_device_suspend(struct device * dev, pm_message_t state) | 277 | static void pci_device_shutdown(struct device *dev) |
278 | { | ||
279 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
280 | struct pci_driver *drv = pci_dev->driver; | ||
281 | |||
282 | if (drv && drv->shutdown) | ||
283 | drv->shutdown(pci_dev); | ||
284 | pci_msi_shutdown(pci_dev); | ||
285 | pci_msix_shutdown(pci_dev); | ||
286 | } | ||
287 | |||
288 | #ifdef CONFIG_PM_SLEEP | ||
289 | |||
290 | /* | ||
291 | * Default "suspend" method for devices that have no driver provided suspend, | ||
292 | * or not even a driver at all. | ||
293 | */ | ||
294 | static void pci_default_pm_suspend(struct pci_dev *pci_dev) | ||
295 | { | ||
296 | pci_save_state(pci_dev); | ||
297 | /* | ||
298 | * mark its power state as "unknown", since we don't know if | ||
299 | * e.g. the BIOS will change its device state when we suspend. | ||
300 | */ | ||
301 | if (pci_dev->current_state == PCI_D0) | ||
302 | pci_dev->current_state = PCI_UNKNOWN; | ||
303 | } | ||
304 | |||
305 | /* | ||
306 | * Default "resume" method for devices that have no driver provided resume, | ||
307 | * or not even a driver at all. | ||
308 | */ | ||
309 | static int pci_default_pm_resume(struct pci_dev *pci_dev) | ||
310 | { | ||
311 | int retval = 0; | ||
312 | |||
313 | /* restore the PCI config space */ | ||
314 | pci_restore_state(pci_dev); | ||
315 | /* if the device was enabled before suspend, reenable */ | ||
316 | retval = pci_reenable_device(pci_dev); | ||
317 | /* | ||
318 | * if the device was busmaster before the suspend, make it busmaster | ||
319 | * again | ||
320 | */ | ||
321 | if (pci_dev->is_busmaster) | ||
322 | pci_set_master(pci_dev); | ||
323 | |||
324 | return retval; | ||
325 | } | ||
326 | |||
327 | static int pci_legacy_suspend(struct device *dev, pm_message_t state) | ||
278 | { | 328 | { |
279 | struct pci_dev * pci_dev = to_pci_dev(dev); | 329 | struct pci_dev * pci_dev = to_pci_dev(dev); |
280 | struct pci_driver * drv = pci_dev->driver; | 330 | struct pci_driver * drv = pci_dev->driver; |
@@ -284,18 +334,12 @@ static int pci_device_suspend(struct device * dev, pm_message_t state) | |||
284 | i = drv->suspend(pci_dev, state); | 334 | i = drv->suspend(pci_dev, state); |
285 | suspend_report_result(drv->suspend, i); | 335 | suspend_report_result(drv->suspend, i); |
286 | } else { | 336 | } else { |
287 | pci_save_state(pci_dev); | 337 | pci_default_pm_suspend(pci_dev); |
288 | /* | ||
289 | * mark its power state as "unknown", since we don't know if | ||
290 | * e.g. the BIOS will change its device state when we suspend. | ||
291 | */ | ||
292 | if (pci_dev->current_state == PCI_D0) | ||
293 | pci_dev->current_state = PCI_UNKNOWN; | ||
294 | } | 338 | } |
295 | return i; | 339 | return i; |
296 | } | 340 | } |
297 | 341 | ||
298 | static int pci_device_suspend_late(struct device * dev, pm_message_t state) | 342 | static int pci_legacy_suspend_late(struct device *dev, pm_message_t state) |
299 | { | 343 | { |
300 | struct pci_dev * pci_dev = to_pci_dev(dev); | 344 | struct pci_dev * pci_dev = to_pci_dev(dev); |
301 | struct pci_driver * drv = pci_dev->driver; | 345 | struct pci_driver * drv = pci_dev->driver; |
@@ -308,26 +352,7 @@ static int pci_device_suspend_late(struct device * dev, pm_message_t state) | |||
308 | return i; | 352 | return i; |
309 | } | 353 | } |
310 | 354 | ||
311 | /* | 355 | static int pci_legacy_resume(struct device *dev) |
312 | * Default resume method for devices that have no driver provided resume, | ||
313 | * or not even a driver at all. | ||
314 | */ | ||
315 | static int pci_default_resume(struct pci_dev *pci_dev) | ||
316 | { | ||
317 | int retval = 0; | ||
318 | |||
319 | /* restore the PCI config space */ | ||
320 | pci_restore_state(pci_dev); | ||
321 | /* if the device was enabled before suspend, reenable */ | ||
322 | retval = pci_reenable_device(pci_dev); | ||
323 | /* if the device was busmaster before the suspend, make it busmaster again */ | ||
324 | if (pci_dev->is_busmaster) | ||
325 | pci_set_master(pci_dev); | ||
326 | |||
327 | return retval; | ||
328 | } | ||
329 | |||
330 | static int pci_device_resume(struct device * dev) | ||
331 | { | 356 | { |
332 | int error; | 357 | int error; |
333 | struct pci_dev * pci_dev = to_pci_dev(dev); | 358 | struct pci_dev * pci_dev = to_pci_dev(dev); |
@@ -336,34 +361,313 @@ static int pci_device_resume(struct device * dev) | |||
336 | if (drv && drv->resume) | 361 | if (drv && drv->resume) |
337 | error = drv->resume(pci_dev); | 362 | error = drv->resume(pci_dev); |
338 | else | 363 | else |
339 | error = pci_default_resume(pci_dev); | 364 | error = pci_default_pm_resume(pci_dev); |
340 | return error; | 365 | return error; |
341 | } | 366 | } |
342 | 367 | ||
343 | static int pci_device_resume_early(struct device * dev) | 368 | static int pci_legacy_resume_early(struct device *dev) |
344 | { | 369 | { |
345 | int error = 0; | 370 | int error = 0; |
346 | struct pci_dev * pci_dev = to_pci_dev(dev); | 371 | struct pci_dev * pci_dev = to_pci_dev(dev); |
347 | struct pci_driver * drv = pci_dev->driver; | 372 | struct pci_driver * drv = pci_dev->driver; |
348 | 373 | ||
349 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
350 | |||
351 | if (drv && drv->resume_early) | 374 | if (drv && drv->resume_early) |
352 | error = drv->resume_early(pci_dev); | 375 | error = drv->resume_early(pci_dev); |
353 | return error; | 376 | return error; |
354 | } | 377 | } |
355 | 378 | ||
356 | static void pci_device_shutdown(struct device *dev) | 379 | static int pci_pm_prepare(struct device *dev) |
380 | { | ||
381 | struct device_driver *drv = dev->driver; | ||
382 | int error = 0; | ||
383 | |||
384 | if (drv && drv->pm && drv->pm->prepare) | ||
385 | error = drv->pm->prepare(dev); | ||
386 | |||
387 | return error; | ||
388 | } | ||
389 | |||
390 | static void pci_pm_complete(struct device *dev) | ||
391 | { | ||
392 | struct device_driver *drv = dev->driver; | ||
393 | |||
394 | if (drv && drv->pm && drv->pm->complete) | ||
395 | drv->pm->complete(dev); | ||
396 | } | ||
397 | |||
398 | #ifdef CONFIG_SUSPEND | ||
399 | |||
400 | static int pci_pm_suspend(struct device *dev) | ||
401 | { | ||
402 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
403 | struct device_driver *drv = dev->driver; | ||
404 | int error = 0; | ||
405 | |||
406 | if (drv && drv->pm) { | ||
407 | if (drv->pm->suspend) { | ||
408 | error = drv->pm->suspend(dev); | ||
409 | suspend_report_result(drv->pm->suspend, error); | ||
410 | } else { | ||
411 | pci_default_pm_suspend(pci_dev); | ||
412 | } | ||
413 | } else { | ||
414 | error = pci_legacy_suspend(dev, PMSG_SUSPEND); | ||
415 | } | ||
416 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
417 | |||
418 | return error; | ||
419 | } | ||
420 | |||
421 | static int pci_pm_suspend_noirq(struct device *dev) | ||
357 | { | 422 | { |
358 | struct pci_dev *pci_dev = to_pci_dev(dev); | 423 | struct pci_dev *pci_dev = to_pci_dev(dev); |
359 | struct pci_driver *drv = pci_dev->driver; | 424 | struct pci_driver *drv = pci_dev->driver; |
425 | int error = 0; | ||
360 | 426 | ||
361 | if (drv && drv->shutdown) | 427 | if (drv && drv->pm) { |
362 | drv->shutdown(pci_dev); | 428 | if (drv->pm->suspend_noirq) { |
363 | pci_msi_shutdown(pci_dev); | 429 | error = drv->pm->suspend_noirq(dev); |
364 | pci_msix_shutdown(pci_dev); | 430 | suspend_report_result(drv->pm->suspend_noirq, error); |
431 | } | ||
432 | } else { | ||
433 | error = pci_legacy_suspend_late(dev, PMSG_SUSPEND); | ||
434 | } | ||
435 | |||
436 | return error; | ||
365 | } | 437 | } |
366 | 438 | ||
439 | static int pci_pm_resume(struct device *dev) | ||
440 | { | ||
441 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
442 | struct device_driver *drv = dev->driver; | ||
443 | int error; | ||
444 | |||
445 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
446 | |||
447 | if (drv && drv->pm) { | ||
448 | error = drv->pm->resume ? drv->pm->resume(dev) : | ||
449 | pci_default_pm_resume(pci_dev); | ||
450 | } else { | ||
451 | error = pci_legacy_resume(dev); | ||
452 | } | ||
453 | |||
454 | return error; | ||
455 | } | ||
456 | |||
457 | static int pci_pm_resume_noirq(struct device *dev) | ||
458 | { | ||
459 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
460 | struct pci_driver *drv = pci_dev->driver; | ||
461 | int error = 0; | ||
462 | |||
463 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
464 | |||
465 | if (drv && drv->pm) { | ||
466 | if (drv->pm->resume_noirq) | ||
467 | error = drv->pm->resume_noirq(dev); | ||
468 | } else { | ||
469 | error = pci_legacy_resume_early(dev); | ||
470 | } | ||
471 | |||
472 | return error; | ||
473 | } | ||
474 | |||
475 | #else /* !CONFIG_SUSPEND */ | ||
476 | |||
477 | #define pci_pm_suspend NULL | ||
478 | #define pci_pm_suspend_noirq NULL | ||
479 | #define pci_pm_resume NULL | ||
480 | #define pci_pm_resume_noirq NULL | ||
481 | |||
482 | #endif /* !CONFIG_SUSPEND */ | ||
483 | |||
484 | #ifdef CONFIG_HIBERNATION | ||
485 | |||
486 | static int pci_pm_freeze(struct device *dev) | ||
487 | { | ||
488 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
489 | struct device_driver *drv = dev->driver; | ||
490 | int error = 0; | ||
491 | |||
492 | if (drv && drv->pm) { | ||
493 | if (drv->pm->freeze) { | ||
494 | error = drv->pm->freeze(dev); | ||
495 | suspend_report_result(drv->pm->freeze, error); | ||
496 | } else { | ||
497 | pci_default_pm_suspend(pci_dev); | ||
498 | } | ||
499 | } else { | ||
500 | error = pci_legacy_suspend(dev, PMSG_FREEZE); | ||
501 | pci_fixup_device(pci_fixup_suspend, pci_dev); | ||
502 | } | ||
503 | |||
504 | return error; | ||
505 | } | ||
506 | |||
507 | static int pci_pm_freeze_noirq(struct device *dev) | ||
508 | { | ||
509 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
510 | struct pci_driver *drv = pci_dev->driver; | ||
511 | int error = 0; | ||
512 | |||
513 | if (drv && drv->pm) { | ||
514 | if (drv->pm->freeze_noirq) { | ||
515 | error = drv->pm->freeze_noirq(dev); | ||
516 | suspend_report_result(drv->pm->freeze_noirq, error); | ||
517 | } | ||
518 | } else { | ||
519 | error = pci_legacy_suspend_late(dev, PMSG_FREEZE); | ||
520 | } | ||
521 | |||
522 | return error; | ||
523 | } | ||
524 | |||
525 | static int pci_pm_thaw(struct device *dev) | ||
526 | { | ||
527 | struct device_driver *drv = dev->driver; | ||
528 | int error = 0; | ||
529 | |||
530 | if (drv && drv->pm) { | ||
531 | if (drv->pm->thaw) | ||
532 | error = drv->pm->thaw(dev); | ||
533 | } else { | ||
534 | pci_fixup_device(pci_fixup_resume, to_pci_dev(dev)); | ||
535 | error = pci_legacy_resume(dev); | ||
536 | } | ||
537 | |||
538 | return error; | ||
539 | } | ||
540 | |||
541 | static int pci_pm_thaw_noirq(struct device *dev) | ||
542 | { | ||
543 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
544 | struct pci_driver *drv = pci_dev->driver; | ||
545 | int error = 0; | ||
546 | |||
547 | if (drv && drv->pm) { | ||
548 | if (drv->pm->thaw_noirq) | ||
549 | error = drv->pm->thaw_noirq(dev); | ||
550 | } else { | ||
551 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
552 | error = pci_legacy_resume_early(dev); | ||
553 | } | ||
554 | |||
555 | return error; | ||
556 | } | ||
557 | |||
558 | static int pci_pm_poweroff(struct device *dev) | ||
559 | { | ||
560 | struct device_driver *drv = dev->driver; | ||
561 | int error = 0; | ||
562 | |||
563 | pci_fixup_device(pci_fixup_suspend, to_pci_dev(dev)); | ||
564 | |||
565 | if (drv && drv->pm) { | ||
566 | if (drv->pm->poweroff) { | ||
567 | error = drv->pm->poweroff(dev); | ||
568 | suspend_report_result(drv->pm->poweroff, error); | ||
569 | } | ||
570 | } else { | ||
571 | error = pci_legacy_suspend(dev, PMSG_HIBERNATE); | ||
572 | } | ||
573 | |||
574 | return error; | ||
575 | } | ||
576 | |||
577 | static int pci_pm_poweroff_noirq(struct device *dev) | ||
578 | { | ||
579 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
580 | struct pci_driver *drv = pci_dev->driver; | ||
581 | int error = 0; | ||
582 | |||
583 | if (drv && drv->pm) { | ||
584 | if (drv->pm->poweroff_noirq) { | ||
585 | error = drv->pm->poweroff_noirq(dev); | ||
586 | suspend_report_result(drv->pm->poweroff_noirq, error); | ||
587 | } | ||
588 | } else { | ||
589 | error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE); | ||
590 | } | ||
591 | |||
592 | return error; | ||
593 | } | ||
594 | |||
595 | static int pci_pm_restore(struct device *dev) | ||
596 | { | ||
597 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
598 | struct device_driver *drv = dev->driver; | ||
599 | int error; | ||
600 | |||
601 | if (drv && drv->pm) { | ||
602 | error = drv->pm->restore ? drv->pm->restore(dev) : | ||
603 | pci_default_pm_resume(pci_dev); | ||
604 | } else { | ||
605 | error = pci_legacy_resume(dev); | ||
606 | } | ||
607 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
608 | |||
609 | return error; | ||
610 | } | ||
611 | |||
612 | static int pci_pm_restore_noirq(struct device *dev) | ||
613 | { | ||
614 | struct pci_dev *pci_dev = to_pci_dev(dev); | ||
615 | struct pci_driver *drv = pci_dev->driver; | ||
616 | int error = 0; | ||
617 | |||
618 | pci_fixup_device(pci_fixup_resume, pci_dev); | ||
619 | |||
620 | if (drv && drv->pm) { | ||
621 | if (drv->pm->restore_noirq) | ||
622 | error = drv->pm->restore_noirq(dev); | ||
623 | } else { | ||
624 | error = pci_legacy_resume_early(dev); | ||
625 | } | ||
626 | pci_fixup_device(pci_fixup_resume_early, pci_dev); | ||
627 | |||
628 | return error; | ||
629 | } | ||
630 | |||
631 | #else /* !CONFIG_HIBERNATION */ | ||
632 | |||
633 | #define pci_pm_freeze NULL | ||
634 | #define pci_pm_freeze_noirq NULL | ||
635 | #define pci_pm_thaw NULL | ||
636 | #define pci_pm_thaw_noirq NULL | ||
637 | #define pci_pm_poweroff NULL | ||
638 | #define pci_pm_poweroff_noirq NULL | ||
639 | #define pci_pm_restore NULL | ||
640 | #define pci_pm_restore_noirq NULL | ||
641 | |||
642 | #endif /* !CONFIG_HIBERNATION */ | ||
643 | |||
644 | struct pm_ext_ops pci_pm_ops = { | ||
645 | .base = { | ||
646 | .prepare = pci_pm_prepare, | ||
647 | .complete = pci_pm_complete, | ||
648 | .suspend = pci_pm_suspend, | ||
649 | .resume = pci_pm_resume, | ||
650 | .freeze = pci_pm_freeze, | ||
651 | .thaw = pci_pm_thaw, | ||
652 | .poweroff = pci_pm_poweroff, | ||
653 | .restore = pci_pm_restore, | ||
654 | }, | ||
655 | .suspend_noirq = pci_pm_suspend_noirq, | ||
656 | .resume_noirq = pci_pm_resume_noirq, | ||
657 | .freeze_noirq = pci_pm_freeze_noirq, | ||
658 | .thaw_noirq = pci_pm_thaw_noirq, | ||
659 | .poweroff_noirq = pci_pm_poweroff_noirq, | ||
660 | .restore_noirq = pci_pm_restore_noirq, | ||
661 | }; | ||
662 | |||
663 | #define PCI_PM_OPS_PTR &pci_pm_ops | ||
664 | |||
665 | #else /* !CONFIG_PM_SLEEP */ | ||
666 | |||
667 | #define PCI_PM_OPS_PTR NULL | ||
668 | |||
669 | #endif /* !CONFIG_PM_SLEEP */ | ||
670 | |||
367 | /** | 671 | /** |
368 | * __pci_register_driver - register a new pci driver | 672 | * __pci_register_driver - register a new pci driver |
369 | * @drv: the driver structure to register | 673 | * @drv: the driver structure to register |
@@ -386,6 +690,9 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner, | |||
386 | drv->driver.owner = owner; | 690 | drv->driver.owner = owner; |
387 | drv->driver.mod_name = mod_name; | 691 | drv->driver.mod_name = mod_name; |
388 | 692 | ||
693 | if (drv->pm) | ||
694 | drv->driver.pm = &drv->pm->base; | ||
695 | |||
389 | spin_lock_init(&drv->dynids.lock); | 696 | spin_lock_init(&drv->dynids.lock); |
390 | INIT_LIST_HEAD(&drv->dynids.list); | 697 | INIT_LIST_HEAD(&drv->dynids.list); |
391 | 698 | ||
@@ -511,12 +818,9 @@ struct bus_type pci_bus_type = { | |||
511 | .uevent = pci_uevent, | 818 | .uevent = pci_uevent, |
512 | .probe = pci_device_probe, | 819 | .probe = pci_device_probe, |
513 | .remove = pci_device_remove, | 820 | .remove = pci_device_remove, |
514 | .suspend = pci_device_suspend, | ||
515 | .suspend_late = pci_device_suspend_late, | ||
516 | .resume_early = pci_device_resume_early, | ||
517 | .resume = pci_device_resume, | ||
518 | .shutdown = pci_device_shutdown, | 821 | .shutdown = pci_device_shutdown, |
519 | .dev_attrs = pci_dev_attrs, | 822 | .dev_attrs = pci_dev_attrs, |
823 | .pm = PCI_PM_OPS_PTR, | ||
520 | }; | 824 | }; |
521 | 825 | ||
522 | static int __init pci_driver_init(void) | 826 | static int __init pci_driver_init(void) |
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index e4548ab2a93c..44a46c92b721 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: pci.c,v 1.91 1999/01/21 13:34:01 davem Exp $ | ||
3 | * | ||
4 | * PCI Bus Services, see include/linux/pci.h for further explanation. | 2 | * PCI Bus Services, see include/linux/pci.h for further explanation. |
5 | * | 3 | * |
6 | * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, | 4 | * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, |
@@ -19,6 +17,7 @@ | |||
19 | #include <linux/string.h> | 17 | #include <linux/string.h> |
20 | #include <linux/log2.h> | 18 | #include <linux/log2.h> |
21 | #include <linux/pci-aspm.h> | 19 | #include <linux/pci-aspm.h> |
20 | #include <linux/pm_wakeup.h> | ||
22 | #include <asm/dma.h> /* isa_dma_bridge_buggy */ | 21 | #include <asm/dma.h> /* isa_dma_bridge_buggy */ |
23 | #include "pci.h" | 22 | #include "pci.h" |
24 | 23 | ||
@@ -378,74 +377,90 @@ pci_restore_bars(struct pci_dev *dev) | |||
378 | pci_update_resource(dev, &dev->resource[i], i); | 377 | pci_update_resource(dev, &dev->resource[i], i); |
379 | } | 378 | } |
380 | 379 | ||
381 | int (*platform_pci_set_power_state)(struct pci_dev *dev, pci_power_t t); | 380 | static struct pci_platform_pm_ops *pci_platform_pm; |
382 | 381 | ||
383 | /** | 382 | int pci_set_platform_pm(struct pci_platform_pm_ops *ops) |
384 | * pci_set_power_state - Set the power state of a PCI device | ||
385 | * @dev: PCI device to be suspended | ||
386 | * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering | ||
387 | * | ||
388 | * Transition a device to a new power state, using the Power Management | ||
389 | * Capabilities in the device's config space. | ||
390 | * | ||
391 | * RETURN VALUE: | ||
392 | * -EINVAL if trying to enter a lower state than we're already in. | ||
393 | * 0 if we're already in the requested state. | ||
394 | * -EIO if device does not support PCI PM. | ||
395 | * 0 if we can successfully change the power state. | ||
396 | */ | ||
397 | int | ||
398 | pci_set_power_state(struct pci_dev *dev, pci_power_t state) | ||
399 | { | 383 | { |
400 | int pm, need_restore = 0; | 384 | if (!ops->is_manageable || !ops->set_state || !ops->choose_state |
401 | u16 pmcsr, pmc; | 385 | || !ops->sleep_wake || !ops->can_wakeup) |
386 | return -EINVAL; | ||
387 | pci_platform_pm = ops; | ||
388 | return 0; | ||
389 | } | ||
402 | 390 | ||
403 | /* bound the state we're entering */ | 391 | static inline bool platform_pci_power_manageable(struct pci_dev *dev) |
404 | if (state > PCI_D3hot) | 392 | { |
405 | state = PCI_D3hot; | 393 | return pci_platform_pm ? pci_platform_pm->is_manageable(dev) : false; |
394 | } | ||
406 | 395 | ||
407 | /* | 396 | static inline int platform_pci_set_power_state(struct pci_dev *dev, |
408 | * If the device or the parent bridge can't support PCI PM, ignore | 397 | pci_power_t t) |
409 | * the request if we're doing anything besides putting it into D0 | 398 | { |
410 | * (which would only happen on boot). | 399 | return pci_platform_pm ? pci_platform_pm->set_state(dev, t) : -ENOSYS; |
411 | */ | 400 | } |
412 | if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) | ||
413 | return 0; | ||
414 | 401 | ||
415 | /* find PCI PM capability in list */ | 402 | static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev) |
416 | pm = pci_find_capability(dev, PCI_CAP_ID_PM); | 403 | { |
404 | return pci_platform_pm ? | ||
405 | pci_platform_pm->choose_state(dev) : PCI_POWER_ERROR; | ||
406 | } | ||
417 | 407 | ||
418 | /* abort if the device doesn't support PM capabilities */ | 408 | static inline bool platform_pci_can_wakeup(struct pci_dev *dev) |
419 | if (!pm) | 409 | { |
410 | return pci_platform_pm ? pci_platform_pm->can_wakeup(dev) : false; | ||
411 | } | ||
412 | |||
413 | static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable) | ||
414 | { | ||
415 | return pci_platform_pm ? | ||
416 | pci_platform_pm->sleep_wake(dev, enable) : -ENODEV; | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * pci_raw_set_power_state - Use PCI PM registers to set the power state of | ||
421 | * given PCI device | ||
422 | * @dev: PCI device to handle. | ||
423 | * @state: PCI power state (D0, D1, D2, D3hot) to put the device into. | ||
424 | * | ||
425 | * RETURN VALUE: | ||
426 | * -EINVAL if the requested state is invalid. | ||
427 | * -EIO if device does not support PCI PM or its PM capabilities register has a | ||
428 | * wrong version, or device doesn't support the requested state. | ||
429 | * 0 if device already is in the requested state. | ||
430 | * 0 if device's power state has been successfully changed. | ||
431 | */ | ||
432 | static int | ||
433 | pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) | ||
434 | { | ||
435 | u16 pmcsr; | ||
436 | bool need_restore = false; | ||
437 | |||
438 | if (!dev->pm_cap) | ||
420 | return -EIO; | 439 | return -EIO; |
421 | 440 | ||
441 | if (state < PCI_D0 || state > PCI_D3hot) | ||
442 | return -EINVAL; | ||
443 | |||
422 | /* Validate current state: | 444 | /* Validate current state: |
423 | * Can enter D0 from any state, but if we can only go deeper | 445 | * Can enter D0 from any state, but if we can only go deeper |
424 | * to sleep if we're already in a low power state | 446 | * to sleep if we're already in a low power state |
425 | */ | 447 | */ |
426 | if (state != PCI_D0 && dev->current_state > state) { | 448 | if (dev->current_state == state) { |
427 | printk(KERN_ERR "%s(): %s: state=%d, current state=%d\n", | 449 | /* we're already there */ |
428 | __func__, pci_name(dev), state, dev->current_state); | 450 | return 0; |
451 | } else if (state != PCI_D0 && dev->current_state <= PCI_D3cold | ||
452 | && dev->current_state > state) { | ||
453 | dev_err(&dev->dev, "invalid power transition " | ||
454 | "(from state %d to %d)\n", dev->current_state, state); | ||
429 | return -EINVAL; | 455 | return -EINVAL; |
430 | } else if (dev->current_state == state) | ||
431 | return 0; /* we're already there */ | ||
432 | |||
433 | |||
434 | pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc); | ||
435 | if ((pmc & PCI_PM_CAP_VER_MASK) > 3) { | ||
436 | printk(KERN_DEBUG | ||
437 | "PCI: %s has unsupported PM cap regs version (%u)\n", | ||
438 | pci_name(dev), pmc & PCI_PM_CAP_VER_MASK); | ||
439 | return -EIO; | ||
440 | } | 456 | } |
441 | 457 | ||
442 | /* check if this device supports the desired state */ | 458 | /* check if this device supports the desired state */ |
443 | if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1)) | 459 | if ((state == PCI_D1 && !dev->d1_support) |
444 | return -EIO; | 460 | || (state == PCI_D2 && !dev->d2_support)) |
445 | else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2)) | ||
446 | return -EIO; | 461 | return -EIO; |
447 | 462 | ||
448 | pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr); | 463 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); |
449 | 464 | ||
450 | /* If we're (effectively) in D3, force entire word to 0. | 465 | /* If we're (effectively) in D3, force entire word to 0. |
451 | * This doesn't affect PME_Status, disables PME_En, and | 466 | * This doesn't affect PME_Status, disables PME_En, and |
@@ -461,7 +476,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
461 | case PCI_UNKNOWN: /* Boot-up */ | 476 | case PCI_UNKNOWN: /* Boot-up */ |
462 | if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot | 477 | if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot |
463 | && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) | 478 | && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) |
464 | need_restore = 1; | 479 | need_restore = true; |
465 | /* Fall-through: force to D0 */ | 480 | /* Fall-through: force to D0 */ |
466 | default: | 481 | default: |
467 | pmcsr = 0; | 482 | pmcsr = 0; |
@@ -469,7 +484,7 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
469 | } | 484 | } |
470 | 485 | ||
471 | /* enter specified state */ | 486 | /* enter specified state */ |
472 | pci_write_config_word(dev, pm + PCI_PM_CTRL, pmcsr); | 487 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); |
473 | 488 | ||
474 | /* Mandatory power management transition delays */ | 489 | /* Mandatory power management transition delays */ |
475 | /* see PCI PM 1.1 5.6.1 table 18 */ | 490 | /* see PCI PM 1.1 5.6.1 table 18 */ |
@@ -478,13 +493,6 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
478 | else if (state == PCI_D2 || dev->current_state == PCI_D2) | 493 | else if (state == PCI_D2 || dev->current_state == PCI_D2) |
479 | udelay(200); | 494 | udelay(200); |
480 | 495 | ||
481 | /* | ||
482 | * Give firmware a chance to be called, such as ACPI _PRx, _PSx | ||
483 | * Firmware method after native method ? | ||
484 | */ | ||
485 | if (platform_pci_set_power_state) | ||
486 | platform_pci_set_power_state(dev, state); | ||
487 | |||
488 | dev->current_state = state; | 496 | dev->current_state = state; |
489 | 497 | ||
490 | /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT | 498 | /* According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT |
@@ -508,8 +516,77 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
508 | return 0; | 516 | return 0; |
509 | } | 517 | } |
510 | 518 | ||
511 | pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, pm_message_t state); | 519 | /** |
512 | 520 | * pci_update_current_state - Read PCI power state of given device from its | |
521 | * PCI PM registers and cache it | ||
522 | * @dev: PCI device to handle. | ||
523 | */ | ||
524 | static void pci_update_current_state(struct pci_dev *dev) | ||
525 | { | ||
526 | if (dev->pm_cap) { | ||
527 | u16 pmcsr; | ||
528 | |||
529 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); | ||
530 | dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /** | ||
535 | * pci_set_power_state - Set the power state of a PCI device | ||
536 | * @dev: PCI device to handle. | ||
537 | * @state: PCI power state (D0, D1, D2, D3hot) to put the device into. | ||
538 | * | ||
539 | * Transition a device to a new power state, using the platform formware and/or | ||
540 | * the device's PCI PM registers. | ||
541 | * | ||
542 | * RETURN VALUE: | ||
543 | * -EINVAL if the requested state is invalid. | ||
544 | * -EIO if device does not support PCI PM or its PM capabilities register has a | ||
545 | * wrong version, or device doesn't support the requested state. | ||
546 | * 0 if device already is in the requested state. | ||
547 | * 0 if device's power state has been successfully changed. | ||
548 | */ | ||
549 | int pci_set_power_state(struct pci_dev *dev, pci_power_t state) | ||
550 | { | ||
551 | int error; | ||
552 | |||
553 | /* bound the state we're entering */ | ||
554 | if (state > PCI_D3hot) | ||
555 | state = PCI_D3hot; | ||
556 | else if (state < PCI_D0) | ||
557 | state = PCI_D0; | ||
558 | else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) | ||
559 | /* | ||
560 | * If the device or the parent bridge do not support PCI PM, | ||
561 | * ignore the request if we're doing anything other than putting | ||
562 | * it into D0 (which would only happen on boot). | ||
563 | */ | ||
564 | return 0; | ||
565 | |||
566 | if (state == PCI_D0 && platform_pci_power_manageable(dev)) { | ||
567 | /* | ||
568 | * Allow the platform to change the state, for example via ACPI | ||
569 | * _PR0, _PS0 and some such, but do not trust it. | ||
570 | */ | ||
571 | int ret = platform_pci_set_power_state(dev, PCI_D0); | ||
572 | if (!ret) | ||
573 | pci_update_current_state(dev); | ||
574 | } | ||
575 | |||
576 | error = pci_raw_set_power_state(dev, state); | ||
577 | |||
578 | if (state > PCI_D0 && platform_pci_power_manageable(dev)) { | ||
579 | /* Allow the platform to finalize the transition */ | ||
580 | int ret = platform_pci_set_power_state(dev, state); | ||
581 | if (!ret) { | ||
582 | pci_update_current_state(dev); | ||
583 | error = 0; | ||
584 | } | ||
585 | } | ||
586 | |||
587 | return error; | ||
588 | } | ||
589 | |||
513 | /** | 590 | /** |
514 | * pci_choose_state - Choose the power state of a PCI device | 591 | * pci_choose_state - Choose the power state of a PCI device |
515 | * @dev: PCI device to be suspended | 592 | * @dev: PCI device to be suspended |
@@ -527,11 +604,9 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) | |||
527 | if (!pci_find_capability(dev, PCI_CAP_ID_PM)) | 604 | if (!pci_find_capability(dev, PCI_CAP_ID_PM)) |
528 | return PCI_D0; | 605 | return PCI_D0; |
529 | 606 | ||
530 | if (platform_pci_choose_state) { | 607 | ret = platform_pci_choose_state(dev); |
531 | ret = platform_pci_choose_state(dev, state); | 608 | if (ret != PCI_POWER_ERROR) |
532 | if (ret != PCI_POWER_ERROR) | 609 | return ret; |
533 | return ret; | ||
534 | } | ||
535 | 610 | ||
536 | switch (state.event) { | 611 | switch (state.event) { |
537 | case PM_EVENT_ON: | 612 | case PM_EVENT_ON: |
@@ -543,7 +618,8 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) | |||
543 | case PM_EVENT_HIBERNATE: | 618 | case PM_EVENT_HIBERNATE: |
544 | return PCI_D3hot; | 619 | return PCI_D3hot; |
545 | default: | 620 | default: |
546 | printk("Unrecognized suspend event %d\n", state.event); | 621 | dev_info(&dev->dev, "unrecognized suspend event %d\n", |
622 | state.event); | ||
547 | BUG(); | 623 | BUG(); |
548 | } | 624 | } |
549 | return PCI_D0; | 625 | return PCI_D0; |
@@ -568,7 +644,7 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
568 | else | 644 | else |
569 | found = 1; | 645 | found = 1; |
570 | if (!save_state) { | 646 | if (!save_state) { |
571 | dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); | 647 | dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n"); |
572 | return -ENOMEM; | 648 | return -ENOMEM; |
573 | } | 649 | } |
574 | cap = (u16 *)&save_state->data[0]; | 650 | cap = (u16 *)&save_state->data[0]; |
@@ -619,7 +695,7 @@ static int pci_save_pcix_state(struct pci_dev *dev) | |||
619 | else | 695 | else |
620 | found = 1; | 696 | found = 1; |
621 | if (!save_state) { | 697 | if (!save_state) { |
622 | dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); | 698 | dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n"); |
623 | return -ENOMEM; | 699 | return -ENOMEM; |
624 | } | 700 | } |
625 | cap = (u16 *)&save_state->data[0]; | 701 | cap = (u16 *)&save_state->data[0]; |
@@ -685,10 +761,9 @@ pci_restore_state(struct pci_dev *dev) | |||
685 | for (i = 15; i >= 0; i--) { | 761 | for (i = 15; i >= 0; i--) { |
686 | pci_read_config_dword(dev, i * 4, &val); | 762 | pci_read_config_dword(dev, i * 4, &val); |
687 | if (val != dev->saved_config_space[i]) { | 763 | if (val != dev->saved_config_space[i]) { |
688 | printk(KERN_DEBUG "PM: Writing back config space on " | 764 | dev_printk(KERN_DEBUG, &dev->dev, "restoring config " |
689 | "device %s at offset %x (was %x, writing %x)\n", | 765 | "space at offset %#x (was %#x, writing %#x)\n", |
690 | pci_name(dev), i, | 766 | i, val, (int)dev->saved_config_space[i]); |
691 | val, (int)dev->saved_config_space[i]); | ||
692 | pci_write_config_dword(dev,i * 4, | 767 | pci_write_config_dword(dev,i * 4, |
693 | dev->saved_config_space[i]); | 768 | dev->saved_config_space[i]); |
694 | } | 769 | } |
@@ -961,6 +1036,46 @@ int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state) | |||
961 | } | 1036 | } |
962 | 1037 | ||
963 | /** | 1038 | /** |
1039 | * pci_pme_capable - check the capability of PCI device to generate PME# | ||
1040 | * @dev: PCI device to handle. | ||
1041 | * @state: PCI state from which device will issue PME#. | ||
1042 | */ | ||
1043 | static bool pci_pme_capable(struct pci_dev *dev, pci_power_t state) | ||
1044 | { | ||
1045 | if (!dev->pm_cap) | ||
1046 | return false; | ||
1047 | |||
1048 | return !!(dev->pme_support & (1 << state)); | ||
1049 | } | ||
1050 | |||
1051 | /** | ||
1052 | * pci_pme_active - enable or disable PCI device's PME# function | ||
1053 | * @dev: PCI device to handle. | ||
1054 | * @enable: 'true' to enable PME# generation; 'false' to disable it. | ||
1055 | * | ||
1056 | * The caller must verify that the device is capable of generating PME# before | ||
1057 | * calling this function with @enable equal to 'true'. | ||
1058 | */ | ||
1059 | static void pci_pme_active(struct pci_dev *dev, bool enable) | ||
1060 | { | ||
1061 | u16 pmcsr; | ||
1062 | |||
1063 | if (!dev->pm_cap) | ||
1064 | return; | ||
1065 | |||
1066 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); | ||
1067 | /* Clear PME_Status by writing 1 to it and enable PME# */ | ||
1068 | pmcsr |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE; | ||
1069 | if (!enable) | ||
1070 | pmcsr &= ~PCI_PM_CTRL_PME_ENABLE; | ||
1071 | |||
1072 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); | ||
1073 | |||
1074 | dev_printk(KERN_INFO, &dev->dev, "PME# %s\n", | ||
1075 | enable ? "enabled" : "disabled"); | ||
1076 | } | ||
1077 | |||
1078 | /** | ||
964 | * pci_enable_wake - enable PCI device as wakeup event source | 1079 | * pci_enable_wake - enable PCI device as wakeup event source |
965 | * @dev: PCI device affected | 1080 | * @dev: PCI device affected |
966 | * @state: PCI state from which device will issue wakeup events | 1081 | * @state: PCI state from which device will issue wakeup events |
@@ -971,66 +1086,173 @@ int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state) | |||
971 | * called automatically by this routine. | 1086 | * called automatically by this routine. |
972 | * | 1087 | * |
973 | * Devices with legacy power management (no standard PCI PM capabilities) | 1088 | * Devices with legacy power management (no standard PCI PM capabilities) |
974 | * always require such platform hooks. Depending on the platform, devices | 1089 | * always require such platform hooks. |
975 | * supporting the standard PCI PME# signal may require such platform hooks; | ||
976 | * they always update bits in config space to allow PME# generation. | ||
977 | * | 1090 | * |
978 | * -EIO is returned if the device can't ever be a wakeup event source. | 1091 | * RETURN VALUE: |
979 | * -EINVAL is returned if the device can't generate wakeup events from | 1092 | * 0 is returned on success |
980 | * the specified PCI state. Returns zero if the operation is successful. | 1093 | * -EINVAL is returned if device is not supposed to wake up the system |
1094 | * Error code depending on the platform is returned if both the platform and | ||
1095 | * the native mechanism fail to enable the generation of wake-up events | ||
981 | */ | 1096 | */ |
982 | int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) | 1097 | int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) |
983 | { | 1098 | { |
984 | int pm; | 1099 | int error = 0; |
985 | int status; | 1100 | bool pme_done = false; |
986 | u16 value; | 1101 | |
987 | 1102 | if (!device_may_wakeup(&dev->dev)) | |
988 | /* Note that drivers should verify device_may_wakeup(&dev->dev) | 1103 | return -EINVAL; |
989 | * before calling this function. Platform code should report | 1104 | |
990 | * errors when drivers try to enable wakeup on devices that | 1105 | /* |
991 | * can't issue wakeups, or on which wakeups were disabled by | 1106 | * According to "PCI System Architecture" 4th ed. by Tom Shanley & Don |
992 | * userspace updating the /sys/devices.../power/wakeup file. | 1107 | * Anderson we should be doing PME# wake enable followed by ACPI wake |
1108 | * enable. To disable wake-up we call the platform first, for symmetry. | ||
993 | */ | 1109 | */ |
994 | 1110 | ||
995 | status = call_platform_enable_wakeup(&dev->dev, enable); | 1111 | if (!enable && platform_pci_can_wakeup(dev)) |
1112 | error = platform_pci_sleep_wake(dev, false); | ||
996 | 1113 | ||
997 | /* find PCI PM capability in list */ | 1114 | if (!enable || pci_pme_capable(dev, state)) { |
998 | pm = pci_find_capability(dev, PCI_CAP_ID_PM); | 1115 | pci_pme_active(dev, enable); |
1116 | pme_done = true; | ||
1117 | } | ||
999 | 1118 | ||
1000 | /* If device doesn't support PM Capabilities, but caller wants to | 1119 | if (enable && platform_pci_can_wakeup(dev)) |
1001 | * disable wake events, it's a NOP. Otherwise fail unless the | 1120 | error = platform_pci_sleep_wake(dev, true); |
1002 | * platform hooks handled this legacy device already. | ||
1003 | */ | ||
1004 | if (!pm) | ||
1005 | return enable ? status : 0; | ||
1006 | 1121 | ||
1007 | /* Check device's ability to generate PME# */ | 1122 | return pme_done ? 0 : error; |
1008 | pci_read_config_word(dev,pm+PCI_PM_PMC,&value); | 1123 | } |
1009 | 1124 | ||
1010 | value &= PCI_PM_CAP_PME_MASK; | 1125 | /** |
1011 | value >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */ | 1126 | * pci_prepare_to_sleep - prepare PCI device for system-wide transition into |
1127 | * a sleep state | ||
1128 | * @dev: Device to handle. | ||
1129 | * | ||
1130 | * Choose the power state appropriate for the device depending on whether | ||
1131 | * it can wake up the system and/or is power manageable by the platform | ||
1132 | * (PCI_D3hot is the default) and put the device into that state. | ||
1133 | */ | ||
1134 | int pci_prepare_to_sleep(struct pci_dev *dev) | ||
1135 | { | ||
1136 | pci_power_t target_state = PCI_D3hot; | ||
1137 | int error; | ||
1012 | 1138 | ||
1013 | /* Check if it can generate PME# from requested state. */ | 1139 | if (platform_pci_power_manageable(dev)) { |
1014 | if (!value || !(value & (1 << state))) { | 1140 | /* |
1015 | /* if it can't, revert what the platform hook changed, | 1141 | * Call the platform to choose the target state of the device |
1016 | * always reporting the base "EINVAL, can't PME#" error | 1142 | * and enable wake-up from this state if supported. |
1017 | */ | 1143 | */ |
1018 | if (enable) | 1144 | pci_power_t state = platform_pci_choose_state(dev); |
1019 | call_platform_enable_wakeup(&dev->dev, 0); | 1145 | |
1020 | return enable ? -EINVAL : 0; | 1146 | switch (state) { |
1147 | case PCI_POWER_ERROR: | ||
1148 | case PCI_UNKNOWN: | ||
1149 | break; | ||
1150 | case PCI_D1: | ||
1151 | case PCI_D2: | ||
1152 | if (pci_no_d1d2(dev)) | ||
1153 | break; | ||
1154 | default: | ||
1155 | target_state = state; | ||
1156 | } | ||
1157 | } else if (device_may_wakeup(&dev->dev)) { | ||
1158 | /* | ||
1159 | * Find the deepest state from which the device can generate | ||
1160 | * wake-up events, make it the target state and enable device | ||
1161 | * to generate PME#. | ||
1162 | */ | ||
1163 | if (!dev->pm_cap) | ||
1164 | return -EIO; | ||
1165 | |||
1166 | if (dev->pme_support) { | ||
1167 | while (target_state | ||
1168 | && !(dev->pme_support & (1 << target_state))) | ||
1169 | target_state--; | ||
1170 | } | ||
1021 | } | 1171 | } |
1022 | 1172 | ||
1023 | pci_read_config_word(dev, pm + PCI_PM_CTRL, &value); | 1173 | pci_enable_wake(dev, target_state, true); |
1024 | 1174 | ||
1025 | /* Clear PME_Status by writing 1 to it and enable PME# */ | 1175 | error = pci_set_power_state(dev, target_state); |
1026 | value |= PCI_PM_CTRL_PME_STATUS | PCI_PM_CTRL_PME_ENABLE; | ||
1027 | 1176 | ||
1028 | if (!enable) | 1177 | if (error) |
1029 | value &= ~PCI_PM_CTRL_PME_ENABLE; | 1178 | pci_enable_wake(dev, target_state, false); |
1030 | 1179 | ||
1031 | pci_write_config_word(dev, pm + PCI_PM_CTRL, value); | 1180 | return error; |
1181 | } | ||
1032 | 1182 | ||
1033 | return 0; | 1183 | /** |
1184 | * pci_back_from_sleep - turn PCI device on during system-wide transition into | ||
1185 | * the working state a sleep state | ||
1186 | * @dev: Device to handle. | ||
1187 | * | ||
1188 | * Disable device's sytem wake-up capability and put it into D0. | ||
1189 | */ | ||
1190 | int pci_back_from_sleep(struct pci_dev *dev) | ||
1191 | { | ||
1192 | pci_enable_wake(dev, PCI_D0, false); | ||
1193 | return pci_set_power_state(dev, PCI_D0); | ||
1194 | } | ||
1195 | |||
1196 | /** | ||
1197 | * pci_pm_init - Initialize PM functions of given PCI device | ||
1198 | * @dev: PCI device to handle. | ||
1199 | */ | ||
1200 | void pci_pm_init(struct pci_dev *dev) | ||
1201 | { | ||
1202 | int pm; | ||
1203 | u16 pmc; | ||
1204 | |||
1205 | dev->pm_cap = 0; | ||
1206 | |||
1207 | /* find PCI PM capability in list */ | ||
1208 | pm = pci_find_capability(dev, PCI_CAP_ID_PM); | ||
1209 | if (!pm) | ||
1210 | return; | ||
1211 | /* Check device's ability to generate PME# */ | ||
1212 | pci_read_config_word(dev, pm + PCI_PM_PMC, &pmc); | ||
1213 | |||
1214 | if ((pmc & PCI_PM_CAP_VER_MASK) > 3) { | ||
1215 | dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n", | ||
1216 | pmc & PCI_PM_CAP_VER_MASK); | ||
1217 | return; | ||
1218 | } | ||
1219 | |||
1220 | dev->pm_cap = pm; | ||
1221 | |||
1222 | dev->d1_support = false; | ||
1223 | dev->d2_support = false; | ||
1224 | if (!pci_no_d1d2(dev)) { | ||
1225 | if (pmc & PCI_PM_CAP_D1) { | ||
1226 | dev_printk(KERN_DEBUG, &dev->dev, "supports D1\n"); | ||
1227 | dev->d1_support = true; | ||
1228 | } | ||
1229 | if (pmc & PCI_PM_CAP_D2) { | ||
1230 | dev_printk(KERN_DEBUG, &dev->dev, "supports D2\n"); | ||
1231 | dev->d2_support = true; | ||
1232 | } | ||
1233 | } | ||
1234 | |||
1235 | pmc &= PCI_PM_CAP_PME_MASK; | ||
1236 | if (pmc) { | ||
1237 | dev_printk(KERN_INFO, &dev->dev, | ||
1238 | "PME# supported from%s%s%s%s%s\n", | ||
1239 | (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "", | ||
1240 | (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "", | ||
1241 | (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "", | ||
1242 | (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "", | ||
1243 | (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : ""); | ||
1244 | dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT; | ||
1245 | /* | ||
1246 | * Make device's PM flags reflect the wake-up capability, but | ||
1247 | * let the user space enable it to wake up the system as needed. | ||
1248 | */ | ||
1249 | device_set_wakeup_capable(&dev->dev, true); | ||
1250 | device_set_wakeup_enable(&dev->dev, false); | ||
1251 | /* Disable the PME# generation functionality */ | ||
1252 | pci_pme_active(dev, false); | ||
1253 | } else { | ||
1254 | dev->pme_support = 0; | ||
1255 | } | ||
1034 | } | 1256 | } |
1035 | 1257 | ||
1036 | int | 1258 | int |
@@ -1116,13 +1338,11 @@ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) | |||
1116 | return 0; | 1338 | return 0; |
1117 | 1339 | ||
1118 | err_out: | 1340 | err_out: |
1119 | printk (KERN_WARNING "PCI: Unable to reserve %s region #%d:%llx@%llx " | 1341 | dev_warn(&pdev->dev, "BAR %d: can't reserve %s region [%#llx-%#llx]\n", |
1120 | "for device %s\n", | 1342 | bar, |
1121 | pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", | 1343 | pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", |
1122 | bar + 1, /* PCI BAR # */ | 1344 | (unsigned long long)pci_resource_start(pdev, bar), |
1123 | (unsigned long long)pci_resource_len(pdev, bar), | 1345 | (unsigned long long)pci_resource_end(pdev, bar)); |
1124 | (unsigned long long)pci_resource_start(pdev, bar), | ||
1125 | pci_name(pdev)); | ||
1126 | return -EBUSY; | 1346 | return -EBUSY; |
1127 | } | 1347 | } |
1128 | 1348 | ||
@@ -1214,7 +1434,7 @@ pci_set_master(struct pci_dev *dev) | |||
1214 | 1434 | ||
1215 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | 1435 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
1216 | if (! (cmd & PCI_COMMAND_MASTER)) { | 1436 | if (! (cmd & PCI_COMMAND_MASTER)) { |
1217 | pr_debug("PCI: Enabling bus mastering for device %s\n", pci_name(dev)); | 1437 | dev_dbg(&dev->dev, "enabling bus mastering\n"); |
1218 | cmd |= PCI_COMMAND_MASTER; | 1438 | cmd |= PCI_COMMAND_MASTER; |
1219 | pci_write_config_word(dev, PCI_COMMAND, cmd); | 1439 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
1220 | } | 1440 | } |
@@ -1279,8 +1499,8 @@ pci_set_cacheline_size(struct pci_dev *dev) | |||
1279 | if (cacheline_size == pci_cache_line_size) | 1499 | if (cacheline_size == pci_cache_line_size) |
1280 | return 0; | 1500 | return 0; |
1281 | 1501 | ||
1282 | printk(KERN_DEBUG "PCI: cache line size of %d is not supported " | 1502 | dev_printk(KERN_DEBUG, &dev->dev, "cache line size of %d is not " |
1283 | "by device %s\n", pci_cache_line_size << 2, pci_name(dev)); | 1503 | "supported\n", pci_cache_line_size << 2); |
1284 | 1504 | ||
1285 | return -EINVAL; | 1505 | return -EINVAL; |
1286 | } | 1506 | } |
@@ -1305,8 +1525,7 @@ pci_set_mwi(struct pci_dev *dev) | |||
1305 | 1525 | ||
1306 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | 1526 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
1307 | if (! (cmd & PCI_COMMAND_INVALIDATE)) { | 1527 | if (! (cmd & PCI_COMMAND_INVALIDATE)) { |
1308 | pr_debug("PCI: Enabling Mem-Wr-Inval for device %s\n", | 1528 | dev_dbg(&dev->dev, "enabling Mem-Wr-Inval\n"); |
1309 | pci_name(dev)); | ||
1310 | cmd |= PCI_COMMAND_INVALIDATE; | 1529 | cmd |= PCI_COMMAND_INVALIDATE; |
1311 | pci_write_config_word(dev, PCI_COMMAND, cmd); | 1530 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
1312 | } | 1531 | } |
@@ -1702,5 +1921,7 @@ EXPORT_SYMBOL(pci_set_power_state); | |||
1702 | EXPORT_SYMBOL(pci_save_state); | 1921 | EXPORT_SYMBOL(pci_save_state); |
1703 | EXPORT_SYMBOL(pci_restore_state); | 1922 | EXPORT_SYMBOL(pci_restore_state); |
1704 | EXPORT_SYMBOL(pci_enable_wake); | 1923 | EXPORT_SYMBOL(pci_enable_wake); |
1924 | EXPORT_SYMBOL(pci_prepare_to_sleep); | ||
1925 | EXPORT_SYMBOL(pci_back_from_sleep); | ||
1705 | EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); | 1926 | EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); |
1706 | 1927 | ||
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 00408c97e5fc..d807cd786f20 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h | |||
@@ -5,11 +5,36 @@ extern int pci_create_sysfs_dev_files(struct pci_dev *pdev); | |||
5 | extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev); | 5 | extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev); |
6 | extern void pci_cleanup_rom(struct pci_dev *dev); | 6 | extern void pci_cleanup_rom(struct pci_dev *dev); |
7 | 7 | ||
8 | /* Firmware callbacks */ | 8 | /** |
9 | extern pci_power_t (*platform_pci_choose_state)(struct pci_dev *dev, | 9 | * Firmware PM callbacks |
10 | pm_message_t state); | 10 | * |
11 | extern int (*platform_pci_set_power_state)(struct pci_dev *dev, | 11 | * @is_manageable - returns 'true' if given device is power manageable by the |
12 | pci_power_t state); | 12 | * platform firmware |
13 | * | ||
14 | * @set_state - invokes the platform firmware to set the device's power state | ||
15 | * | ||
16 | * @choose_state - returns PCI power state of given device preferred by the | ||
17 | * platform; to be used during system-wide transitions from a | ||
18 | * sleeping state to the working state and vice versa | ||
19 | * | ||
20 | * @can_wakeup - returns 'true' if given device is capable of waking up the | ||
21 | * system from a sleeping state | ||
22 | * | ||
23 | * @sleep_wake - enables/disables the system wake up capability of given device | ||
24 | * | ||
25 | * If given platform is generally capable of power managing PCI devices, all of | ||
26 | * these callbacks are mandatory. | ||
27 | */ | ||
28 | struct pci_platform_pm_ops { | ||
29 | bool (*is_manageable)(struct pci_dev *dev); | ||
30 | int (*set_state)(struct pci_dev *dev, pci_power_t state); | ||
31 | pci_power_t (*choose_state)(struct pci_dev *dev); | ||
32 | bool (*can_wakeup)(struct pci_dev *dev); | ||
33 | int (*sleep_wake)(struct pci_dev *dev, bool enable); | ||
34 | }; | ||
35 | |||
36 | extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops); | ||
37 | extern void pci_pm_init(struct pci_dev *dev); | ||
13 | 38 | ||
14 | extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); | 39 | extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); |
15 | extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val); | 40 | extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val); |
@@ -106,3 +131,16 @@ pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) | |||
106 | } | 131 | } |
107 | 132 | ||
108 | struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev); | 133 | struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev); |
134 | |||
135 | /* PCI slot sysfs helper code */ | ||
136 | #define to_pci_slot(s) container_of(s, struct pci_slot, kobj) | ||
137 | |||
138 | extern struct kset *pci_slots_kset; | ||
139 | |||
140 | struct pci_slot_attribute { | ||
141 | struct attribute attr; | ||
142 | ssize_t (*show)(struct pci_slot *, char *); | ||
143 | ssize_t (*store)(struct pci_slot *, const char *, size_t); | ||
144 | }; | ||
145 | #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr) | ||
146 | |||
diff --git a/drivers/pci/pcie/aer/aerdrv.c b/drivers/pci/pcie/aer/aerdrv.c index 07c3bdb6edc2..77036f46acfe 100644 --- a/drivers/pci/pcie/aer/aerdrv.c +++ b/drivers/pci/pcie/aer/aerdrv.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/pcieport_if.h> | 26 | #include <linux/pcieport_if.h> |
27 | 27 | ||
28 | #include "aerdrv.h" | 28 | #include "aerdrv.h" |
29 | #include "../../pci.h" | ||
29 | 30 | ||
30 | /* | 31 | /* |
31 | * Version Information | 32 | * Version Information |
@@ -219,8 +220,7 @@ static int __devinit aer_probe (struct pcie_device *dev, | |||
219 | 220 | ||
220 | /* Alloc rpc data structure */ | 221 | /* Alloc rpc data structure */ |
221 | if (!(rpc = aer_alloc_rpc(dev))) { | 222 | if (!(rpc = aer_alloc_rpc(dev))) { |
222 | printk(KERN_DEBUG "%s: Alloc rpc fails on PCIE device[%s]\n", | 223 | dev_printk(KERN_DEBUG, device, "alloc rpc failed\n"); |
223 | __func__, device->bus_id); | ||
224 | aer_remove(dev); | 224 | aer_remove(dev); |
225 | return -ENOMEM; | 225 | return -ENOMEM; |
226 | } | 226 | } |
@@ -228,8 +228,7 @@ static int __devinit aer_probe (struct pcie_device *dev, | |||
228 | /* Request IRQ ISR */ | 228 | /* Request IRQ ISR */ |
229 | if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", | 229 | if ((status = request_irq(dev->irq, aer_irq, IRQF_SHARED, "aerdrv", |
230 | dev))) { | 230 | dev))) { |
231 | printk(KERN_DEBUG "%s: Request ISR fails on PCIE device[%s]\n", | 231 | dev_printk(KERN_DEBUG, device, "request IRQ failed\n"); |
232 | __func__, device->bus_id); | ||
233 | aer_remove(dev); | 232 | aer_remove(dev); |
234 | return status; | 233 | return status; |
235 | } | 234 | } |
@@ -273,7 +272,7 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) | |||
273 | * to issue Configuration Requests to those devices. | 272 | * to issue Configuration Requests to those devices. |
274 | */ | 273 | */ |
275 | msleep(200); | 274 | msleep(200); |
276 | printk(KERN_DEBUG "Complete link reset at Root[%s]\n", dev->dev.bus_id); | 275 | dev_printk(KERN_DEBUG, &dev->dev, "Root Port link has been reset\n"); |
277 | 276 | ||
278 | /* Enable Root Port's interrupt in response to error messages */ | 277 | /* Enable Root Port's interrupt in response to error messages */ |
279 | pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status); | 278 | pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &status); |
diff --git a/drivers/pci/pcie/aer/aerdrv_acpi.c b/drivers/pci/pcie/aer/aerdrv_acpi.c index d39a78dbd026..30f581b8791f 100644 --- a/drivers/pci/pcie/aer/aerdrv_acpi.c +++ b/drivers/pci/pcie/aer/aerdrv_acpi.c | |||
@@ -50,10 +50,10 @@ int aer_osc_setup(struct pcie_device *pciedev) | |||
50 | } | 50 | } |
51 | 51 | ||
52 | if (ACPI_FAILURE(status)) { | 52 | if (ACPI_FAILURE(status)) { |
53 | printk(KERN_DEBUG "AER service couldn't init device %s - %s\n", | 53 | dev_printk(KERN_DEBUG, &pciedev->device, "AER service couldn't " |
54 | pciedev->device.bus_id, | 54 | "init device: %s\n", |
55 | (status == AE_SUPPORT || status == AE_NOT_FOUND) ? | 55 | (status == AE_SUPPORT || status == AE_NOT_FOUND) ? |
56 | "no _OSC support" : "Run ACPI _OSC fails"); | 56 | "no _OSC support" : "_OSC failed"); |
57 | return -1; | 57 | return -1; |
58 | } | 58 | } |
59 | 59 | ||
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c index aaa82392d1dc..ee5e7b5176d0 100644 --- a/drivers/pci/pcie/aer/aerdrv_core.c +++ b/drivers/pci/pcie/aer/aerdrv_core.c | |||
@@ -221,9 +221,9 @@ static void report_error_detected(struct pci_dev *dev, void *data) | |||
221 | * of a driver for this device is unaware of | 221 | * of a driver for this device is unaware of |
222 | * its hw state. | 222 | * its hw state. |
223 | */ | 223 | */ |
224 | printk(KERN_DEBUG "Device ID[%s] has %s\n", | 224 | dev_printk(KERN_DEBUG, &dev->dev, "device has %s\n", |
225 | dev->dev.bus_id, (dev->driver) ? | 225 | dev->driver ? |
226 | "no AER-aware driver" : "no driver"); | 226 | "no AER-aware driver" : "no driver"); |
227 | } | 227 | } |
228 | return; | 228 | return; |
229 | } | 229 | } |
@@ -304,7 +304,7 @@ static pci_ers_result_t broadcast_error_message(struct pci_dev *dev, | |||
304 | { | 304 | { |
305 | struct aer_broadcast_data result_data; | 305 | struct aer_broadcast_data result_data; |
306 | 306 | ||
307 | printk(KERN_DEBUG "Broadcast %s message\n", error_mesg); | 307 | dev_printk(KERN_DEBUG, &dev->dev, "broadcast %s message\n", error_mesg); |
308 | result_data.state = state; | 308 | result_data.state = state; |
309 | if (cb == report_error_detected) | 309 | if (cb == report_error_detected) |
310 | result_data.result = PCI_ERS_RESULT_CAN_RECOVER; | 310 | result_data.result = PCI_ERS_RESULT_CAN_RECOVER; |
@@ -404,18 +404,16 @@ static pci_ers_result_t reset_link(struct pcie_device *aerdev, | |||
404 | data.aer_driver = | 404 | data.aer_driver = |
405 | to_service_driver(aerdev->device.driver); | 405 | to_service_driver(aerdev->device.driver); |
406 | } else { | 406 | } else { |
407 | printk(KERN_DEBUG "No link-reset support to Device ID" | 407 | dev_printk(KERN_DEBUG, &dev->dev, "no link-reset " |
408 | "[%s]\n", | 408 | "support\n"); |
409 | dev->dev.bus_id); | ||
410 | return PCI_ERS_RESULT_DISCONNECT; | 409 | return PCI_ERS_RESULT_DISCONNECT; |
411 | } | 410 | } |
412 | } | 411 | } |
413 | 412 | ||
414 | status = data.aer_driver->reset_link(udev); | 413 | status = data.aer_driver->reset_link(udev); |
415 | if (status != PCI_ERS_RESULT_RECOVERED) { | 414 | if (status != PCI_ERS_RESULT_RECOVERED) { |
416 | printk(KERN_DEBUG "Link reset at upstream Device ID" | 415 | dev_printk(KERN_DEBUG, &dev->dev, "link reset at upstream " |
417 | "[%s] failed\n", | 416 | "device %s failed\n", pci_name(udev)); |
418 | udev->dev.bus_id); | ||
419 | return PCI_ERS_RESULT_DISCONNECT; | 417 | return PCI_ERS_RESULT_DISCONNECT; |
420 | } | 418 | } |
421 | 419 | ||
@@ -511,10 +509,12 @@ static void handle_error_source(struct pcie_device * aerdev, | |||
511 | } else { | 509 | } else { |
512 | status = do_recovery(aerdev, dev, info.severity); | 510 | status = do_recovery(aerdev, dev, info.severity); |
513 | if (status == PCI_ERS_RESULT_RECOVERED) { | 511 | if (status == PCI_ERS_RESULT_RECOVERED) { |
514 | printk(KERN_DEBUG "AER driver successfully recovered\n"); | 512 | dev_printk(KERN_DEBUG, &dev->dev, "AER driver " |
513 | "successfully recovered\n"); | ||
515 | } else { | 514 | } else { |
516 | /* TODO: Should kernel panic here? */ | 515 | /* TODO: Should kernel panic here? */ |
517 | printk(KERN_DEBUG "AER driver didn't recover\n"); | 516 | dev_printk(KERN_DEBUG, &dev->dev, "AER driver didn't " |
517 | "recover\n"); | ||
518 | } | 518 | } |
519 | } | 519 | } |
520 | } | 520 | } |
diff --git a/drivers/pci/pcie/portdrv_bus.c b/drivers/pci/pcie/portdrv_bus.c index 3f0976868eda..359fe5568df1 100644 --- a/drivers/pci/pcie/portdrv_bus.c +++ b/drivers/pci/pcie/portdrv_bus.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/pm.h> | 13 | #include <linux/pm.h> |
14 | 14 | ||
15 | #include <linux/pcieport_if.h> | 15 | #include <linux/pcieport_if.h> |
16 | #include "portdrv.h" | ||
16 | 17 | ||
17 | static int pcie_port_bus_match(struct device *dev, struct device_driver *drv); | 18 | static int pcie_port_bus_match(struct device *dev, struct device_driver *drv); |
18 | static int pcie_port_bus_suspend(struct device *dev, pm_message_t state); | 19 | static int pcie_port_bus_suspend(struct device *dev, pm_message_t state); |
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c index fb0abfa508dc..890f0d2b370a 100644 --- a/drivers/pci/pcie/portdrv_core.c +++ b/drivers/pci/pcie/portdrv_core.c | |||
@@ -23,20 +23,20 @@ static int pcie_port_probe_service(struct device *dev) | |||
23 | { | 23 | { |
24 | struct pcie_device *pciedev; | 24 | struct pcie_device *pciedev; |
25 | struct pcie_port_service_driver *driver; | 25 | struct pcie_port_service_driver *driver; |
26 | int status = -ENODEV; | 26 | int status; |
27 | 27 | ||
28 | if (!dev || !dev->driver) | 28 | if (!dev || !dev->driver) |
29 | return status; | 29 | return -ENODEV; |
30 | 30 | ||
31 | driver = to_service_driver(dev->driver); | 31 | driver = to_service_driver(dev->driver); |
32 | if (!driver || !driver->probe) | 32 | if (!driver || !driver->probe) |
33 | return status; | 33 | return -ENODEV; |
34 | 34 | ||
35 | pciedev = to_pcie_device(dev); | 35 | pciedev = to_pcie_device(dev); |
36 | status = driver->probe(pciedev, driver->id_table); | 36 | status = driver->probe(pciedev, driver->id_table); |
37 | if (!status) { | 37 | if (!status) { |
38 | printk(KERN_DEBUG "Load service driver %s on pcie device %s\n", | 38 | dev_printk(KERN_DEBUG, dev, "service driver %s loaded\n", |
39 | driver->name, dev->bus_id); | 39 | driver->name); |
40 | get_device(dev); | 40 | get_device(dev); |
41 | } | 41 | } |
42 | return status; | 42 | return status; |
@@ -53,8 +53,8 @@ static int pcie_port_remove_service(struct device *dev) | |||
53 | pciedev = to_pcie_device(dev); | 53 | pciedev = to_pcie_device(dev); |
54 | driver = to_service_driver(dev->driver); | 54 | driver = to_service_driver(dev->driver); |
55 | if (driver && driver->remove) { | 55 | if (driver && driver->remove) { |
56 | printk(KERN_DEBUG "Unload service driver %s on pcie device %s\n", | 56 | dev_printk(KERN_DEBUG, dev, "unloading service driver %s\n", |
57 | driver->name, dev->bus_id); | 57 | driver->name); |
58 | driver->remove(pciedev); | 58 | driver->remove(pciedev); |
59 | put_device(dev); | 59 | put_device(dev); |
60 | } | 60 | } |
@@ -103,7 +103,7 @@ static int pcie_port_resume_service(struct device *dev) | |||
103 | */ | 103 | */ |
104 | static void release_pcie_device(struct device *dev) | 104 | static void release_pcie_device(struct device *dev) |
105 | { | 105 | { |
106 | printk(KERN_DEBUG "Free Port Service[%s]\n", dev->bus_id); | 106 | dev_printk(KERN_DEBUG, dev, "free port service\n"); |
107 | kfree(to_pcie_device(dev)); | 107 | kfree(to_pcie_device(dev)); |
108 | } | 108 | } |
109 | 109 | ||
@@ -150,7 +150,7 @@ static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask) | |||
150 | if (pos) { | 150 | if (pos) { |
151 | struct msix_entry msix_entries[PCIE_PORT_DEVICE_MAXSERVICES] = | 151 | struct msix_entry msix_entries[PCIE_PORT_DEVICE_MAXSERVICES] = |
152 | {{0, 0}, {0, 1}, {0, 2}, {0, 3}}; | 152 | {{0, 0}, {0, 1}, {0, 2}, {0, 3}}; |
153 | printk("%s Found MSIX capability\n", __func__); | 153 | dev_info(&dev->dev, "found MSI-X capability\n"); |
154 | status = pci_enable_msix(dev, msix_entries, nvec); | 154 | status = pci_enable_msix(dev, msix_entries, nvec); |
155 | if (!status) { | 155 | if (!status) { |
156 | int j = 0; | 156 | int j = 0; |
@@ -165,7 +165,7 @@ static int assign_interrupt_mode(struct pci_dev *dev, int *vectors, int mask) | |||
165 | if (status) { | 165 | if (status) { |
166 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); | 166 | pos = pci_find_capability(dev, PCI_CAP_ID_MSI); |
167 | if (pos) { | 167 | if (pos) { |
168 | printk("%s Found MSI capability\n", __func__); | 168 | dev_info(&dev->dev, "found MSI capability\n"); |
169 | status = pci_enable_msi(dev); | 169 | status = pci_enable_msi(dev); |
170 | if (!status) { | 170 | if (!status) { |
171 | interrupt_mode = PCIE_PORT_MSI_MODE; | 171 | interrupt_mode = PCIE_PORT_MSI_MODE; |
@@ -252,7 +252,7 @@ static struct pcie_device* alloc_pcie_device(struct pci_dev *parent, | |||
252 | return NULL; | 252 | return NULL; |
253 | 253 | ||
254 | pcie_device_init(parent, device, port_type, service_type, irq,irq_mode); | 254 | pcie_device_init(parent, device, port_type, service_type, irq,irq_mode); |
255 | printk(KERN_DEBUG "Allocate Port Service[%s]\n", device->device.bus_id); | 255 | dev_printk(KERN_DEBUG, &device->device, "allocate port service\n"); |
256 | return device; | 256 | return device; |
257 | } | 257 | } |
258 | 258 | ||
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index 51d163238d93..367c9c20000d 100644 --- a/drivers/pci/pcie/portdrv_pci.c +++ b/drivers/pci/pcie/portdrv_pci.c | |||
@@ -91,9 +91,8 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev, | |||
91 | 91 | ||
92 | pci_set_master(dev); | 92 | pci_set_master(dev); |
93 | if (!dev->irq && dev->pin) { | 93 | if (!dev->irq && dev->pin) { |
94 | printk(KERN_WARNING | 94 | dev_warn(&dev->dev, "device [%04x/%04x] has invalid IRQ; " |
95 | "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n", | 95 | "check vendor BIOS\n", dev->vendor, dev->device); |
96 | __func__, dev->vendor, dev->device); | ||
97 | } | 96 | } |
98 | if (pcie_port_device_register(dev)) { | 97 | if (pcie_port_device_register(dev)) { |
99 | pci_disable_device(dev); | 98 | pci_disable_device(dev); |
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 3706ce7972dd..b1724cf31b66 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -277,8 +277,8 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom) | |||
277 | res->end = res->start + sz64; | 277 | res->end = res->start + sz64; |
278 | #else | 278 | #else |
279 | if (sz64 > 0x100000000ULL) { | 279 | if (sz64 > 0x100000000ULL) { |
280 | printk(KERN_ERR "PCI: Unable to handle 64-bit " | 280 | dev_err(&dev->dev, "BAR %d: can't handle 64-bit" |
281 | "BAR for device %s\n", pci_name(dev)); | 281 | " BAR\n", pos); |
282 | res->start = 0; | 282 | res->start = 0; |
283 | res->flags = 0; | 283 | res->flags = 0; |
284 | } else if (lhi) { | 284 | } else if (lhi) { |
@@ -329,7 +329,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
329 | return; | 329 | return; |
330 | 330 | ||
331 | if (dev->transparent) { | 331 | if (dev->transparent) { |
332 | printk(KERN_INFO "PCI: Transparent bridge - %s\n", pci_name(dev)); | 332 | dev_info(&dev->dev, "transparent bridge\n"); |
333 | for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++) | 333 | for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++) |
334 | child->resource[i] = child->parent->resource[i - 3]; | 334 | child->resource[i] = child->parent->resource[i - 3]; |
335 | } | 335 | } |
@@ -392,7 +392,8 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child) | |||
392 | limit |= ((long) mem_limit_hi) << 32; | 392 | limit |= ((long) mem_limit_hi) << 32; |
393 | #else | 393 | #else |
394 | if (mem_base_hi || mem_limit_hi) { | 394 | if (mem_base_hi || mem_limit_hi) { |
395 | printk(KERN_ERR "PCI: Unable to handle 64-bit address space for bridge %s\n", pci_name(dev)); | 395 | dev_err(&dev->dev, "can't handle 64-bit " |
396 | "address space for bridge\n"); | ||
396 | return; | 397 | return; |
397 | } | 398 | } |
398 | #endif | 399 | #endif |
@@ -414,6 +415,7 @@ static struct pci_bus * pci_alloc_bus(void) | |||
414 | INIT_LIST_HEAD(&b->node); | 415 | INIT_LIST_HEAD(&b->node); |
415 | INIT_LIST_HEAD(&b->children); | 416 | INIT_LIST_HEAD(&b->children); |
416 | INIT_LIST_HEAD(&b->devices); | 417 | INIT_LIST_HEAD(&b->devices); |
418 | INIT_LIST_HEAD(&b->slots); | ||
417 | } | 419 | } |
418 | return b; | 420 | return b; |
419 | } | 421 | } |
@@ -511,8 +513,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, | |||
511 | 513 | ||
512 | pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); | 514 | pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); |
513 | 515 | ||
514 | pr_debug("PCI: Scanning behind PCI bridge %s, config %06x, pass %d\n", | 516 | dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n", |
515 | pci_name(dev), buses & 0xffffff, pass); | 517 | buses & 0xffffff, pass); |
516 | 518 | ||
517 | /* Disable MasterAbortMode during probing to avoid reporting | 519 | /* Disable MasterAbortMode during probing to avoid reporting |
518 | of bus errors (in some architectures) */ | 520 | of bus errors (in some architectures) */ |
@@ -535,8 +537,8 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, | |||
535 | * ignore it. This can happen with the i450NX chipset. | 537 | * ignore it. This can happen with the i450NX chipset. |
536 | */ | 538 | */ |
537 | if (pci_find_bus(pci_domain_nr(bus), busnr)) { | 539 | if (pci_find_bus(pci_domain_nr(bus), busnr)) { |
538 | printk(KERN_INFO "PCI: Bus %04x:%02x already known\n", | 540 | dev_info(&dev->dev, "bus %04x:%02x already known\n", |
539 | pci_domain_nr(bus), busnr); | 541 | pci_domain_nr(bus), busnr); |
540 | goto out; | 542 | goto out; |
541 | } | 543 | } |
542 | 544 | ||
@@ -711,8 +713,9 @@ static int pci_setup_device(struct pci_dev * dev) | |||
711 | { | 713 | { |
712 | u32 class; | 714 | u32 class; |
713 | 715 | ||
714 | sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), | 716 | dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus), |
715 | dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); | 717 | dev->bus->number, PCI_SLOT(dev->devfn), |
718 | PCI_FUNC(dev->devfn)); | ||
716 | 719 | ||
717 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); | 720 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); |
718 | dev->revision = class & 0xff; | 721 | dev->revision = class & 0xff; |
@@ -720,7 +723,7 @@ static int pci_setup_device(struct pci_dev * dev) | |||
720 | dev->class = class; | 723 | dev->class = class; |
721 | class >>= 8; | 724 | class >>= 8; |
722 | 725 | ||
723 | pr_debug("PCI: Found %s [%04x/%04x] %06x %02x\n", pci_name(dev), | 726 | dev_dbg(&dev->dev, "found [%04x/%04x] class %06x header type %02x\n", |
724 | dev->vendor, dev->device, class, dev->hdr_type); | 727 | dev->vendor, dev->device, class, dev->hdr_type); |
725 | 728 | ||
726 | /* "Unknown power state" */ | 729 | /* "Unknown power state" */ |
@@ -788,13 +791,13 @@ static int pci_setup_device(struct pci_dev * dev) | |||
788 | break; | 791 | break; |
789 | 792 | ||
790 | default: /* unknown header */ | 793 | default: /* unknown header */ |
791 | printk(KERN_ERR "PCI: device %s has unknown header type %02x, ignoring.\n", | 794 | dev_err(&dev->dev, "unknown header type %02x, " |
792 | pci_name(dev), dev->hdr_type); | 795 | "ignoring device\n", dev->hdr_type); |
793 | return -1; | 796 | return -1; |
794 | 797 | ||
795 | bad: | 798 | bad: |
796 | printk(KERN_ERR "PCI: %s: class %x doesn't match header type %02x. Ignoring class.\n", | 799 | dev_err(&dev->dev, "ignoring class %02x (doesn't match header " |
797 | pci_name(dev), class, dev->hdr_type); | 800 | "type %02x)\n", class, dev->hdr_type); |
798 | dev->class = PCI_CLASS_NOT_DEFINED; | 801 | dev->class = PCI_CLASS_NOT_DEFINED; |
799 | } | 802 | } |
800 | 803 | ||
@@ -927,7 +930,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) | |||
927 | return NULL; | 930 | return NULL; |
928 | /* Card hasn't responded in 60 seconds? Must be stuck. */ | 931 | /* Card hasn't responded in 60 seconds? Must be stuck. */ |
929 | if (delay > 60 * 1000) { | 932 | if (delay > 60 * 1000) { |
930 | printk(KERN_WARNING "Device %04x:%02x:%02x.%d not " | 933 | printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not " |
931 | "responding\n", pci_domain_nr(bus), | 934 | "responding\n", pci_domain_nr(bus), |
932 | bus->number, PCI_SLOT(devfn), | 935 | bus->number, PCI_SLOT(devfn), |
933 | PCI_FUNC(devfn)); | 936 | PCI_FUNC(devfn)); |
@@ -984,6 +987,9 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) | |||
984 | /* Fix up broken headers */ | 987 | /* Fix up broken headers */ |
985 | pci_fixup_device(pci_fixup_header, dev); | 988 | pci_fixup_device(pci_fixup_header, dev); |
986 | 989 | ||
990 | /* Initialize power management of the device */ | ||
991 | pci_pm_init(dev); | ||
992 | |||
987 | /* | 993 | /* |
988 | * Add the device to our list of discovered devices | 994 | * Add the device to our list of discovered devices |
989 | * and the bus list for fixup functions, etc. | 995 | * and the bus list for fixup functions, etc. |
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c index 963a97642ae9..4400dffbd93a 100644 --- a/drivers/pci/proc.c +++ b/drivers/pci/proc.c | |||
@@ -1,6 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: proc.c,v 1.13 1998/05/12 07:36:07 mj Exp $ | ||
3 | * | ||
4 | * Procfs interface for the PCI bus. | 2 | * Procfs interface for the PCI bus. |
5 | * | 3 | * |
6 | * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz> | 4 | * Copyright (c) 1997--1999 Martin Mares <mj@ucw.cz> |
@@ -482,5 +480,5 @@ static int __init pci_proc_init(void) | |||
482 | return 0; | 480 | return 0; |
483 | } | 481 | } |
484 | 482 | ||
485 | __initcall(pci_proc_init); | 483 | device_initcall(pci_proc_init); |
486 | 484 | ||
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 338a3f94b4d4..12d489395fad 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c | |||
@@ -556,7 +556,7 @@ static void quirk_via_ioapic(struct pci_dev *dev) | |||
556 | pci_write_config_byte (dev, 0x58, tmp); | 556 | pci_write_config_byte (dev, 0x58, tmp); |
557 | } | 557 | } |
558 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); | 558 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); |
559 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); | 559 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic); |
560 | 560 | ||
561 | /* | 561 | /* |
562 | * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. | 562 | * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. |
@@ -576,7 +576,7 @@ static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev) | |||
576 | } | 576 | } |
577 | } | 577 | } |
578 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); | 578 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); |
579 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); | 579 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); |
580 | 580 | ||
581 | /* | 581 | /* |
582 | * The AMD io apic can hang the box when an apic irq is masked. | 582 | * The AMD io apic can hang the box when an apic irq is masked. |
@@ -622,7 +622,7 @@ static void quirk_amd_8131_ioapic(struct pci_dev *dev) | |||
622 | } | 622 | } |
623 | } | 623 | } |
624 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); | 624 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); |
625 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); | 625 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); |
626 | #endif /* CONFIG_X86_IO_APIC */ | 626 | #endif /* CONFIG_X86_IO_APIC */ |
627 | 627 | ||
628 | /* | 628 | /* |
@@ -774,7 +774,7 @@ static void quirk_cardbus_legacy(struct pci_dev *dev) | |||
774 | pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0); | 774 | pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0); |
775 | } | 775 | } |
776 | DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); | 776 | DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); |
777 | DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); | 777 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); |
778 | 778 | ||
779 | /* | 779 | /* |
780 | * Following the PCI ordering rules is optional on the AMD762. I'm not | 780 | * Following the PCI ordering rules is optional on the AMD762. I'm not |
@@ -797,7 +797,7 @@ static void quirk_amd_ordering(struct pci_dev *dev) | |||
797 | } | 797 | } |
798 | } | 798 | } |
799 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); | 799 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); |
800 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); | 800 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering); |
801 | 801 | ||
802 | /* | 802 | /* |
803 | * DreamWorks provided workaround for Dunord I-3000 problem | 803 | * DreamWorks provided workaround for Dunord I-3000 problem |
@@ -865,7 +865,7 @@ static void quirk_disable_pxb(struct pci_dev *pdev) | |||
865 | } | 865 | } |
866 | } | 866 | } |
867 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); | 867 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); |
868 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); | 868 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb); |
869 | 869 | ||
870 | static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev) | 870 | static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev) |
871 | { | 871 | { |
@@ -885,9 +885,9 @@ static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev) | |||
885 | } | 885 | } |
886 | } | 886 | } |
887 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); | 887 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); |
888 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); | 888 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode); |
889 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); | 889 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); |
890 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); | 890 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode); |
891 | 891 | ||
892 | /* | 892 | /* |
893 | * Serverworks CSB5 IDE does not fully support native mode | 893 | * Serverworks CSB5 IDE does not fully support native mode |
@@ -1054,6 +1054,20 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev) | |||
1054 | * its on-board VGA controller */ | 1054 | * its on-board VGA controller */ |
1055 | asus_hides_smbus = 1; | 1055 | asus_hides_smbus = 1; |
1056 | } | 1056 | } |
1057 | else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_IG) | ||
1058 | switch(dev->subsystem_device) { | ||
1059 | case 0x00b8: /* Compaq Evo D510 CMT */ | ||
1060 | case 0x00b9: /* Compaq Evo D510 SFF */ | ||
1061 | asus_hides_smbus = 1; | ||
1062 | } | ||
1063 | else if (dev->device == PCI_DEVICE_ID_INTEL_82815_CGC) | ||
1064 | switch (dev->subsystem_device) { | ||
1065 | case 0x001A: /* Compaq Deskpro EN SSF P667 815E */ | ||
1066 | /* Motherboard doesn't have host bridge | ||
1067 | * subvendor/subdevice IDs, therefore checking | ||
1068 | * its on-board VGA controller */ | ||
1069 | asus_hides_smbus = 1; | ||
1070 | } | ||
1057 | } | 1071 | } |
1058 | } | 1072 | } |
1059 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge); | 1073 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge); |
@@ -1068,6 +1082,8 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, as | |||
1068 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge); | 1082 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge); |
1069 | 1083 | ||
1070 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge); | 1084 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge); |
1085 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_IG, asus_hides_smbus_hostbridge); | ||
1086 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, asus_hides_smbus_hostbridge); | ||
1071 | 1087 | ||
1072 | static void asus_hides_smbus_lpc(struct pci_dev *dev) | 1088 | static void asus_hides_smbus_lpc(struct pci_dev *dev) |
1073 | { | 1089 | { |
@@ -1093,31 +1109,61 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asu | |||
1093 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); | 1109 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); |
1094 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); | 1110 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); |
1095 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); | 1111 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); |
1096 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc); | 1112 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc); |
1097 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc); | 1113 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc); |
1098 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc); | 1114 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc); |
1099 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc); | 1115 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc); |
1100 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); | 1116 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc); |
1101 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); | 1117 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc); |
1102 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); | 1118 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc); |
1103 | 1119 | ||
1104 | static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev) | 1120 | /* It appears we just have one such device. If not, we have a warning */ |
1121 | static void __iomem *asus_rcba_base; | ||
1122 | static void asus_hides_smbus_lpc_ich6_suspend(struct pci_dev *dev) | ||
1105 | { | 1123 | { |
1106 | u32 val, rcba; | 1124 | u32 rcba; |
1107 | void __iomem *base; | ||
1108 | 1125 | ||
1109 | if (likely(!asus_hides_smbus)) | 1126 | if (likely(!asus_hides_smbus)) |
1110 | return; | 1127 | return; |
1128 | WARN_ON(asus_rcba_base); | ||
1129 | |||
1111 | pci_read_config_dword(dev, 0xF0, &rcba); | 1130 | pci_read_config_dword(dev, 0xF0, &rcba); |
1112 | base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000); /* use bits 31:14, 16 kB aligned */ | 1131 | /* use bits 31:14, 16 kB aligned */ |
1113 | if (base == NULL) return; | 1132 | asus_rcba_base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000); |
1114 | val=readl(base + 0x3418); /* read the Function Disable register, dword mode only */ | 1133 | if (asus_rcba_base == NULL) |
1115 | writel(val & 0xFFFFFFF7, base + 0x3418); /* enable the SMBus device */ | 1134 | return; |
1116 | iounmap(base); | 1135 | } |
1136 | |||
1137 | static void asus_hides_smbus_lpc_ich6_resume_early(struct pci_dev *dev) | ||
1138 | { | ||
1139 | u32 val; | ||
1140 | |||
1141 | if (likely(!asus_hides_smbus || !asus_rcba_base)) | ||
1142 | return; | ||
1143 | /* read the Function Disable register, dword mode only */ | ||
1144 | val = readl(asus_rcba_base + 0x3418); | ||
1145 | writel(val & 0xFFFFFFF7, asus_rcba_base + 0x3418); /* enable the SMBus device */ | ||
1146 | } | ||
1147 | |||
1148 | static void asus_hides_smbus_lpc_ich6_resume(struct pci_dev *dev) | ||
1149 | { | ||
1150 | if (likely(!asus_hides_smbus || !asus_rcba_base)) | ||
1151 | return; | ||
1152 | iounmap(asus_rcba_base); | ||
1153 | asus_rcba_base = NULL; | ||
1117 | dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n"); | 1154 | dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n"); |
1118 | } | 1155 | } |
1156 | |||
1157 | static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev) | ||
1158 | { | ||
1159 | asus_hides_smbus_lpc_ich6_suspend(dev); | ||
1160 | asus_hides_smbus_lpc_ich6_resume_early(dev); | ||
1161 | asus_hides_smbus_lpc_ich6_resume(dev); | ||
1162 | } | ||
1119 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); | 1163 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); |
1120 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6); | 1164 | DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_suspend); |
1165 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume); | ||
1166 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume_early); | ||
1121 | 1167 | ||
1122 | /* | 1168 | /* |
1123 | * SiS 96x south bridge: BIOS typically hides SMBus device... | 1169 | * SiS 96x south bridge: BIOS typically hides SMBus device... |
@@ -1135,10 +1181,10 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_ | |||
1135 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); | 1181 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); |
1136 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); | 1182 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); |
1137 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); | 1183 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); |
1138 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus); | 1184 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus); |
1139 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); | 1185 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus); |
1140 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); | 1186 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus); |
1141 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); | 1187 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus); |
1142 | 1188 | ||
1143 | /* | 1189 | /* |
1144 | * ... This is further complicated by the fact that some SiS96x south | 1190 | * ... This is further complicated by the fact that some SiS96x south |
@@ -1172,7 +1218,7 @@ static void quirk_sis_503(struct pci_dev *dev) | |||
1172 | quirk_sis_96x_smbus(dev); | 1218 | quirk_sis_96x_smbus(dev); |
1173 | } | 1219 | } |
1174 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); | 1220 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); |
1175 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); | 1221 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503); |
1176 | 1222 | ||
1177 | 1223 | ||
1178 | /* | 1224 | /* |
@@ -1205,7 +1251,7 @@ static void asus_hides_ac97_lpc(struct pci_dev *dev) | |||
1205 | } | 1251 | } |
1206 | } | 1252 | } |
1207 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); | 1253 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); |
1208 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); | 1254 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc); |
1209 | 1255 | ||
1210 | #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) | 1256 | #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) |
1211 | 1257 | ||
@@ -1270,12 +1316,12 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, qui | |||
1270 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); | 1316 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); |
1271 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); | 1317 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); |
1272 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); | 1318 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); |
1273 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata); | 1319 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata); |
1274 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata); | 1320 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata); |
1275 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata); | 1321 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata); |
1276 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); | 1322 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata); |
1277 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); | 1323 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata); |
1278 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); | 1324 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata); |
1279 | 1325 | ||
1280 | #endif | 1326 | #endif |
1281 | 1327 | ||
@@ -1521,6 +1567,10 @@ extern struct pci_fixup __start_pci_fixups_enable[]; | |||
1521 | extern struct pci_fixup __end_pci_fixups_enable[]; | 1567 | extern struct pci_fixup __end_pci_fixups_enable[]; |
1522 | extern struct pci_fixup __start_pci_fixups_resume[]; | 1568 | extern struct pci_fixup __start_pci_fixups_resume[]; |
1523 | extern struct pci_fixup __end_pci_fixups_resume[]; | 1569 | extern struct pci_fixup __end_pci_fixups_resume[]; |
1570 | extern struct pci_fixup __start_pci_fixups_resume_early[]; | ||
1571 | extern struct pci_fixup __end_pci_fixups_resume_early[]; | ||
1572 | extern struct pci_fixup __start_pci_fixups_suspend[]; | ||
1573 | extern struct pci_fixup __end_pci_fixups_suspend[]; | ||
1524 | 1574 | ||
1525 | 1575 | ||
1526 | void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) | 1576 | void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) |
@@ -1553,6 +1603,16 @@ void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) | |||
1553 | end = __end_pci_fixups_resume; | 1603 | end = __end_pci_fixups_resume; |
1554 | break; | 1604 | break; |
1555 | 1605 | ||
1606 | case pci_fixup_resume_early: | ||
1607 | start = __start_pci_fixups_resume_early; | ||
1608 | end = __end_pci_fixups_resume_early; | ||
1609 | break; | ||
1610 | |||
1611 | case pci_fixup_suspend: | ||
1612 | start = __start_pci_fixups_suspend; | ||
1613 | end = __end_pci_fixups_suspend; | ||
1614 | break; | ||
1615 | |||
1556 | default: | 1616 | default: |
1557 | /* stupid compiler warning, you would think with an enum... */ | 1617 | /* stupid compiler warning, you would think with an enum... */ |
1558 | return; | 1618 | return; |
@@ -1629,7 +1689,7 @@ static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev) | |||
1629 | } | 1689 | } |
1630 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, | 1690 | DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, |
1631 | quirk_nvidia_ck804_pcie_aer_ext_cap); | 1691 | quirk_nvidia_ck804_pcie_aer_ext_cap); |
1632 | DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, | 1692 | DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, |
1633 | quirk_nvidia_ck804_pcie_aer_ext_cap); | 1693 | quirk_nvidia_ck804_pcie_aer_ext_cap); |
1634 | 1694 | ||
1635 | static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev) | 1695 | static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev) |
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 8ddb918f5f57..827c0a520e2b 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
@@ -27,13 +27,6 @@ | |||
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | 28 | ||
29 | 29 | ||
30 | #define DEBUG_CONFIG 1 | ||
31 | #if DEBUG_CONFIG | ||
32 | #define DBG(x...) printk(x) | ||
33 | #else | ||
34 | #define DBG(x...) | ||
35 | #endif | ||
36 | |||
37 | static void pbus_assign_resources_sorted(struct pci_bus *bus) | 30 | static void pbus_assign_resources_sorted(struct pci_bus *bus) |
38 | { | 31 | { |
39 | struct pci_dev *dev; | 32 | struct pci_dev *dev; |
@@ -81,8 +74,8 @@ void pci_setup_cardbus(struct pci_bus *bus) | |||
81 | struct pci_dev *bridge = bus->self; | 74 | struct pci_dev *bridge = bus->self; |
82 | struct pci_bus_region region; | 75 | struct pci_bus_region region; |
83 | 76 | ||
84 | printk("PCI: Bus %d, cardbus bridge: %s\n", | 77 | dev_info(&bridge->dev, "CardBus bridge, secondary bus %04x:%02x\n", |
85 | bus->number, pci_name(bridge)); | 78 | pci_domain_nr(bus), bus->number); |
86 | 79 | ||
87 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[0]); | 80 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[0]); |
88 | if (bus->resource[0]->flags & IORESOURCE_IO) { | 81 | if (bus->resource[0]->flags & IORESOURCE_IO) { |
@@ -90,7 +83,7 @@ void pci_setup_cardbus(struct pci_bus *bus) | |||
90 | * The IO resource is allocated a range twice as large as it | 83 | * The IO resource is allocated a range twice as large as it |
91 | * would normally need. This allows us to set both IO regs. | 84 | * would normally need. This allows us to set both IO regs. |
92 | */ | 85 | */ |
93 | printk(KERN_INFO " IO window: 0x%08lx-0x%08lx\n", | 86 | dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n", |
94 | (unsigned long)region.start, | 87 | (unsigned long)region.start, |
95 | (unsigned long)region.end); | 88 | (unsigned long)region.end); |
96 | pci_write_config_dword(bridge, PCI_CB_IO_BASE_0, | 89 | pci_write_config_dword(bridge, PCI_CB_IO_BASE_0, |
@@ -101,7 +94,7 @@ void pci_setup_cardbus(struct pci_bus *bus) | |||
101 | 94 | ||
102 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[1]); | 95 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[1]); |
103 | if (bus->resource[1]->flags & IORESOURCE_IO) { | 96 | if (bus->resource[1]->flags & IORESOURCE_IO) { |
104 | printk(KERN_INFO " IO window: 0x%08lx-0x%08lx\n", | 97 | dev_info(&bridge->dev, " IO window: %#08lx-%#08lx\n", |
105 | (unsigned long)region.start, | 98 | (unsigned long)region.start, |
106 | (unsigned long)region.end); | 99 | (unsigned long)region.end); |
107 | pci_write_config_dword(bridge, PCI_CB_IO_BASE_1, | 100 | pci_write_config_dword(bridge, PCI_CB_IO_BASE_1, |
@@ -112,7 +105,7 @@ void pci_setup_cardbus(struct pci_bus *bus) | |||
112 | 105 | ||
113 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[2]); | 106 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[2]); |
114 | if (bus->resource[2]->flags & IORESOURCE_MEM) { | 107 | if (bus->resource[2]->flags & IORESOURCE_MEM) { |
115 | printk(KERN_INFO " PREFETCH window: 0x%08lx-0x%08lx\n", | 108 | dev_info(&bridge->dev, " PREFETCH window: %#08lx-%#08lx\n", |
116 | (unsigned long)region.start, | 109 | (unsigned long)region.start, |
117 | (unsigned long)region.end); | 110 | (unsigned long)region.end); |
118 | pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0, | 111 | pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0, |
@@ -123,7 +116,7 @@ void pci_setup_cardbus(struct pci_bus *bus) | |||
123 | 116 | ||
124 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[3]); | 117 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[3]); |
125 | if (bus->resource[3]->flags & IORESOURCE_MEM) { | 118 | if (bus->resource[3]->flags & IORESOURCE_MEM) { |
126 | printk(KERN_INFO " MEM window: 0x%08lx-0x%08lx\n", | 119 | dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n", |
127 | (unsigned long)region.start, | 120 | (unsigned long)region.start, |
128 | (unsigned long)region.end); | 121 | (unsigned long)region.end); |
129 | pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1, | 122 | pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1, |
@@ -151,7 +144,8 @@ static void pci_setup_bridge(struct pci_bus *bus) | |||
151 | struct pci_bus_region region; | 144 | struct pci_bus_region region; |
152 | u32 l, bu, lu, io_upper16; | 145 | u32 l, bu, lu, io_upper16; |
153 | 146 | ||
154 | DBG(KERN_INFO "PCI: Bridge: %s\n", pci_name(bridge)); | 147 | dev_info(&bridge->dev, "PCI bridge, secondary bus %04x:%02x\n", |
148 | pci_domain_nr(bus), bus->number); | ||
155 | 149 | ||
156 | /* Set up the top and bottom of the PCI I/O segment for this bus. */ | 150 | /* Set up the top and bottom of the PCI I/O segment for this bus. */ |
157 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[0]); | 151 | pcibios_resource_to_bus(bridge, ®ion, bus->resource[0]); |
@@ -162,7 +156,7 @@ static void pci_setup_bridge(struct pci_bus *bus) | |||
162 | l |= region.end & 0xf000; | 156 | l |= region.end & 0xf000; |
163 | /* Set up upper 16 bits of I/O base/limit. */ | 157 | /* Set up upper 16 bits of I/O base/limit. */ |
164 | io_upper16 = (region.end & 0xffff0000) | (region.start >> 16); | 158 | io_upper16 = (region.end & 0xffff0000) | (region.start >> 16); |
165 | DBG(KERN_INFO " IO window: %04lx-%04lx\n", | 159 | dev_info(&bridge->dev, " IO window: %#04lx-%#04lx\n", |
166 | (unsigned long)region.start, | 160 | (unsigned long)region.start, |
167 | (unsigned long)region.end); | 161 | (unsigned long)region.end); |
168 | } | 162 | } |
@@ -170,7 +164,7 @@ static void pci_setup_bridge(struct pci_bus *bus) | |||
170 | /* Clear upper 16 bits of I/O base/limit. */ | 164 | /* Clear upper 16 bits of I/O base/limit. */ |
171 | io_upper16 = 0; | 165 | io_upper16 = 0; |
172 | l = 0x00f0; | 166 | l = 0x00f0; |
173 | DBG(KERN_INFO " IO window: disabled.\n"); | 167 | dev_info(&bridge->dev, " IO window: disabled\n"); |
174 | } | 168 | } |
175 | /* Temporarily disable the I/O range before updating PCI_IO_BASE. */ | 169 | /* Temporarily disable the I/O range before updating PCI_IO_BASE. */ |
176 | pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff); | 170 | pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, 0x0000ffff); |
@@ -185,13 +179,13 @@ static void pci_setup_bridge(struct pci_bus *bus) | |||
185 | if (bus->resource[1]->flags & IORESOURCE_MEM) { | 179 | if (bus->resource[1]->flags & IORESOURCE_MEM) { |
186 | l = (region.start >> 16) & 0xfff0; | 180 | l = (region.start >> 16) & 0xfff0; |
187 | l |= region.end & 0xfff00000; | 181 | l |= region.end & 0xfff00000; |
188 | DBG(KERN_INFO " MEM window: 0x%08lx-0x%08lx\n", | 182 | dev_info(&bridge->dev, " MEM window: %#08lx-%#08lx\n", |
189 | (unsigned long)region.start, | 183 | (unsigned long)region.start, |
190 | (unsigned long)region.end); | 184 | (unsigned long)region.end); |
191 | } | 185 | } |
192 | else { | 186 | else { |
193 | l = 0x0000fff0; | 187 | l = 0x0000fff0; |
194 | DBG(KERN_INFO " MEM window: disabled.\n"); | 188 | dev_info(&bridge->dev, " MEM window: disabled\n"); |
195 | } | 189 | } |
196 | pci_write_config_dword(bridge, PCI_MEMORY_BASE, l); | 190 | pci_write_config_dword(bridge, PCI_MEMORY_BASE, l); |
197 | 191 | ||
@@ -208,13 +202,13 @@ static void pci_setup_bridge(struct pci_bus *bus) | |||
208 | l |= region.end & 0xfff00000; | 202 | l |= region.end & 0xfff00000; |
209 | bu = upper_32_bits(region.start); | 203 | bu = upper_32_bits(region.start); |
210 | lu = upper_32_bits(region.end); | 204 | lu = upper_32_bits(region.end); |
211 | DBG(KERN_INFO " PREFETCH window: 0x%016llx-0x%016llx\n", | 205 | dev_info(&bridge->dev, " PREFETCH window: %#016llx-%#016llx\n", |
212 | (unsigned long long)region.start, | 206 | (unsigned long long)region.start, |
213 | (unsigned long long)region.end); | 207 | (unsigned long long)region.end); |
214 | } | 208 | } |
215 | else { | 209 | else { |
216 | l = 0x0000fff0; | 210 | l = 0x0000fff0; |
217 | DBG(KERN_INFO " PREFETCH window: disabled.\n"); | 211 | dev_info(&bridge->dev, " PREFETCH window: disabled\n"); |
218 | } | 212 | } |
219 | pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l); | 213 | pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l); |
220 | 214 | ||
@@ -361,9 +355,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long | |||
361 | align = (i < PCI_BRIDGE_RESOURCES) ? r_size : r->start; | 355 | align = (i < PCI_BRIDGE_RESOURCES) ? r_size : r->start; |
362 | order = __ffs(align) - 20; | 356 | order = __ffs(align) - 20; |
363 | if (order > 11) { | 357 | if (order > 11) { |
364 | printk(KERN_WARNING "PCI: region %s/%d " | 358 | dev_warn(&dev->dev, "BAR %d too large: " |
365 | "too large: 0x%016llx-0x%016llx\n", | 359 | "%#016llx-%#016llx\n", i, |
366 | pci_name(dev), i, | ||
367 | (unsigned long long)r->start, | 360 | (unsigned long long)r->start, |
368 | (unsigned long long)r->end); | 361 | (unsigned long long)r->end); |
369 | r->flags = 0; | 362 | r->flags = 0; |
@@ -529,8 +522,8 @@ void __ref pci_bus_assign_resources(struct pci_bus *bus) | |||
529 | break; | 522 | break; |
530 | 523 | ||
531 | default: | 524 | default: |
532 | printk(KERN_INFO "PCI: not setting up bridge %s " | 525 | dev_info(&dev->dev, "not setting up bridge for bus " |
533 | "for bus %d\n", pci_name(dev), b->number); | 526 | "%04x:%02x\n", pci_domain_nr(b), b->number); |
534 | break; | 527 | break; |
535 | } | 528 | } |
536 | } | 529 | } |
diff --git a/drivers/pci/setup-irq.c b/drivers/pci/setup-irq.c index 05ca2ed9eb51..aa795fd428de 100644 --- a/drivers/pci/setup-irq.c +++ b/drivers/pci/setup-irq.c | |||
@@ -47,8 +47,7 @@ pdev_fixup_irq(struct pci_dev *dev, | |||
47 | } | 47 | } |
48 | dev->irq = irq; | 48 | dev->irq = irq; |
49 | 49 | ||
50 | pr_debug("PCI: fixup irq: (%s) got %d\n", | 50 | dev_dbg(&dev->dev, "fixup irq: got %d\n", dev->irq); |
51 | kobject_name(&dev->dev.kobj), dev->irq); | ||
52 | 51 | ||
53 | /* Always tell the device, so the driver knows what is | 52 | /* Always tell the device, so the driver knows what is |
54 | the real IRQ to use; the device does not use it. */ | 53 | the real IRQ to use; the device does not use it. */ |
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 7d35cdf4579f..1a5fc83c71b3 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c | |||
@@ -26,8 +26,7 @@ | |||
26 | #include "pci.h" | 26 | #include "pci.h" |
27 | 27 | ||
28 | 28 | ||
29 | void | 29 | void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) |
30 | pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) | ||
31 | { | 30 | { |
32 | struct pci_bus_region region; | 31 | struct pci_bus_region region; |
33 | u32 new, check, mask; | 32 | u32 new, check, mask; |
@@ -43,20 +42,20 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) | |||
43 | /* | 42 | /* |
44 | * Ignore non-moveable resources. This might be legacy resources for | 43 | * Ignore non-moveable resources. This might be legacy resources for |
45 | * which no functional BAR register exists or another important | 44 | * which no functional BAR register exists or another important |
46 | * system resource we should better not move around in system address | 45 | * system resource we shouldn't move around. |
47 | * space. | ||
48 | */ | 46 | */ |
49 | if (res->flags & IORESOURCE_PCI_FIXED) | 47 | if (res->flags & IORESOURCE_PCI_FIXED) |
50 | return; | 48 | return; |
51 | 49 | ||
52 | pcibios_resource_to_bus(dev, ®ion, res); | 50 | pcibios_resource_to_bus(dev, ®ion, res); |
53 | 51 | ||
54 | pr_debug(" got res [%llx:%llx] bus [%llx:%llx] flags %lx for " | 52 | dev_dbg(&dev->dev, "BAR %d: got res [%#llx-%#llx] bus [%#llx-%#llx] " |
55 | "BAR %d of %s\n", (unsigned long long)res->start, | 53 | "flags %#lx\n", resno, |
54 | (unsigned long long)res->start, | ||
56 | (unsigned long long)res->end, | 55 | (unsigned long long)res->end, |
57 | (unsigned long long)region.start, | 56 | (unsigned long long)region.start, |
58 | (unsigned long long)region.end, | 57 | (unsigned long long)region.end, |
59 | (unsigned long)res->flags, resno, pci_name(dev)); | 58 | (unsigned long)res->flags); |
60 | 59 | ||
61 | new = region.start | (res->flags & PCI_REGION_FLAG_MASK); | 60 | new = region.start | (res->flags & PCI_REGION_FLAG_MASK); |
62 | if (res->flags & IORESOURCE_IO) | 61 | if (res->flags & IORESOURCE_IO) |
@@ -81,9 +80,8 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) | |||
81 | pci_read_config_dword(dev, reg, &check); | 80 | pci_read_config_dword(dev, reg, &check); |
82 | 81 | ||
83 | if ((new ^ check) & mask) { | 82 | if ((new ^ check) & mask) { |
84 | printk(KERN_ERR "PCI: Error while updating region " | 83 | dev_err(&dev->dev, "BAR %d: error updating (%#08x != %#08x)\n", |
85 | "%s/%d (%08x != %08x)\n", pci_name(dev), resno, | 84 | resno, new, check); |
86 | new, check); | ||
87 | } | 85 | } |
88 | 86 | ||
89 | if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) == | 87 | if ((new & (PCI_BASE_ADDRESS_SPACE|PCI_BASE_ADDRESS_MEM_TYPE_MASK)) == |
@@ -92,15 +90,14 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno) | |||
92 | pci_write_config_dword(dev, reg + 4, new); | 90 | pci_write_config_dword(dev, reg + 4, new); |
93 | pci_read_config_dword(dev, reg + 4, &check); | 91 | pci_read_config_dword(dev, reg + 4, &check); |
94 | if (check != new) { | 92 | if (check != new) { |
95 | printk(KERN_ERR "PCI: Error updating region " | 93 | dev_err(&dev->dev, "BAR %d: error updating " |
96 | "%s/%d (high %08x != %08x)\n", | 94 | "(high %#08x != %#08x)\n", resno, new, check); |
97 | pci_name(dev), resno, new, check); | ||
98 | } | 95 | } |
99 | } | 96 | } |
100 | res->flags &= ~IORESOURCE_UNSET; | 97 | res->flags &= ~IORESOURCE_UNSET; |
101 | pr_debug("PCI: moved device %s resource %d (%lx) to %x\n", | 98 | dev_dbg(&dev->dev, "BAR %d: moved to bus [%#llx-%#llx] flags %#lx\n", |
102 | pci_name(dev), resno, res->flags, | 99 | resno, (unsigned long long)region.start, |
103 | new & ~PCI_REGION_FLAG_MASK); | 100 | (unsigned long long)region.end, res->flags); |
104 | } | 101 | } |
105 | 102 | ||
106 | int pci_claim_resource(struct pci_dev *dev, int resource) | 103 | int pci_claim_resource(struct pci_dev *dev, int resource) |
@@ -117,10 +114,11 @@ int pci_claim_resource(struct pci_dev *dev, int resource) | |||
117 | err = insert_resource(root, res); | 114 | err = insert_resource(root, res); |
118 | 115 | ||
119 | if (err) { | 116 | if (err) { |
120 | printk(KERN_ERR "PCI: %s region %d of %s %s [%llx:%llx]\n", | 117 | dev_err(&dev->dev, "BAR %d: %s of %s [%#llx-%#llx]\n", |
121 | root ? "Address space collision on" : | 118 | resource, |
122 | "No parent found for", | 119 | root ? "address space collision on" : |
123 | resource, dtype, pci_name(dev), | 120 | "no parent found for", |
121 | dtype, | ||
124 | (unsigned long long)res->start, | 122 | (unsigned long long)res->start, |
125 | (unsigned long long)res->end); | 123 | (unsigned long long)res->end); |
126 | } | 124 | } |
@@ -140,11 +138,10 @@ int pci_assign_resource(struct pci_dev *dev, int resno) | |||
140 | 138 | ||
141 | align = resource_alignment(res); | 139 | align = resource_alignment(res); |
142 | if (!align) { | 140 | if (!align) { |
143 | printk(KERN_ERR "PCI: Cannot allocate resource (bogus " | 141 | dev_err(&dev->dev, "BAR %d: can't allocate resource (bogus " |
144 | "alignment) %d [%llx:%llx] (flags %lx) of %s\n", | 142 | "alignment) [%#llx-%#llx] flags %#lx\n", |
145 | resno, (unsigned long long)res->start, | 143 | resno, (unsigned long long)res->start, |
146 | (unsigned long long)res->end, res->flags, | 144 | (unsigned long long)res->end, res->flags); |
147 | pci_name(dev)); | ||
148 | return -EINVAL; | 145 | return -EINVAL; |
149 | } | 146 | } |
150 | 147 | ||
@@ -165,11 +162,11 @@ int pci_assign_resource(struct pci_dev *dev, int resno) | |||
165 | } | 162 | } |
166 | 163 | ||
167 | if (ret) { | 164 | if (ret) { |
168 | printk(KERN_ERR "PCI: Failed to allocate %s resource " | 165 | dev_err(&dev->dev, "BAR %d: can't allocate %s resource " |
169 | "#%d:%llx@%llx for %s\n", | 166 | "[%#llx-%#llx]\n", resno, |
170 | res->flags & IORESOURCE_IO ? "I/O" : "mem", | 167 | res->flags & IORESOURCE_IO ? "I/O" : "mem", |
171 | resno, (unsigned long long)size, | 168 | (unsigned long long)res->start, |
172 | (unsigned long long)res->start, pci_name(dev)); | 169 | (unsigned long long)res->end); |
173 | } else { | 170 | } else { |
174 | res->flags &= ~IORESOURCE_STARTALIGN; | 171 | res->flags &= ~IORESOURCE_STARTALIGN; |
175 | if (resno < PCI_BRIDGE_RESOURCES) | 172 | if (resno < PCI_BRIDGE_RESOURCES) |
@@ -205,11 +202,11 @@ int pci_assign_resource_fixed(struct pci_dev *dev, int resno) | |||
205 | } | 202 | } |
206 | 203 | ||
207 | if (ret) { | 204 | if (ret) { |
208 | printk(KERN_ERR "PCI: Failed to allocate %s resource " | 205 | dev_err(&dev->dev, "BAR %d: can't allocate %s resource " |
209 | "#%d:%llx@%llx for %s\n", | 206 | "[%#llx-%#llx\n]", resno, |
210 | res->flags & IORESOURCE_IO ? "I/O" : "mem", | 207 | res->flags & IORESOURCE_IO ? "I/O" : "mem", |
211 | resno, (unsigned long long)(res->end - res->start + 1), | 208 | (unsigned long long)res->start, |
212 | (unsigned long long)res->start, pci_name(dev)); | 209 | (unsigned long long)res->end); |
213 | } else if (resno < PCI_BRIDGE_RESOURCES) { | 210 | } else if (resno < PCI_BRIDGE_RESOURCES) { |
214 | pci_update_resource(dev, res, resno); | 211 | pci_update_resource(dev, res, resno); |
215 | } | 212 | } |
@@ -239,11 +236,10 @@ void pdev_sort_resources(struct pci_dev *dev, struct resource_list *head) | |||
239 | 236 | ||
240 | r_align = resource_alignment(r); | 237 | r_align = resource_alignment(r); |
241 | if (!r_align) { | 238 | if (!r_align) { |
242 | printk(KERN_WARNING "PCI: bogus alignment of resource " | 239 | dev_warn(&dev->dev, "BAR %d: bogus alignment " |
243 | "%d [%llx:%llx] (flags %lx) of %s\n", | 240 | "[%#llx-%#llx] flags %#lx\n", |
244 | i, (unsigned long long)r->start, | 241 | i, (unsigned long long)r->start, |
245 | (unsigned long long)r->end, r->flags, | 242 | (unsigned long long)r->end, r->flags); |
246 | pci_name(dev)); | ||
247 | continue; | 243 | continue; |
248 | } | 244 | } |
249 | for (list = head; ; list = list->next) { | 245 | for (list = head; ; list = list->next) { |
@@ -291,7 +287,7 @@ int pci_enable_resources(struct pci_dev *dev, int mask) | |||
291 | 287 | ||
292 | if (!r->parent) { | 288 | if (!r->parent) { |
293 | dev_err(&dev->dev, "device not available because of " | 289 | dev_err(&dev->dev, "device not available because of " |
294 | "BAR %d [%llx:%llx] collisions\n", i, | 290 | "BAR %d [%#llx-%#llx] collisions\n", i, |
295 | (unsigned long long) r->start, | 291 | (unsigned long long) r->start, |
296 | (unsigned long long) r->end); | 292 | (unsigned long long) r->end); |
297 | return -EINVAL; | 293 | return -EINVAL; |
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c new file mode 100644 index 000000000000..7e5b85cbd948 --- /dev/null +++ b/drivers/pci/slot.c | |||
@@ -0,0 +1,233 @@ | |||
1 | /* | ||
2 | * drivers/pci/slot.c | ||
3 | * Copyright (C) 2006 Matthew Wilcox <matthew@wil.cx> | ||
4 | * Copyright (C) 2006-2008 Hewlett-Packard Development Company, L.P. | ||
5 | * Alex Chiang <achiang@hp.com> | ||
6 | */ | ||
7 | |||
8 | #include <linux/kobject.h> | ||
9 | #include <linux/pci.h> | ||
10 | #include <linux/err.h> | ||
11 | #include "pci.h" | ||
12 | |||
13 | struct kset *pci_slots_kset; | ||
14 | EXPORT_SYMBOL_GPL(pci_slots_kset); | ||
15 | |||
16 | static ssize_t pci_slot_attr_show(struct kobject *kobj, | ||
17 | struct attribute *attr, char *buf) | ||
18 | { | ||
19 | struct pci_slot *slot = to_pci_slot(kobj); | ||
20 | struct pci_slot_attribute *attribute = to_pci_slot_attr(attr); | ||
21 | return attribute->show ? attribute->show(slot, buf) : -EIO; | ||
22 | } | ||
23 | |||
24 | static ssize_t pci_slot_attr_store(struct kobject *kobj, | ||
25 | struct attribute *attr, const char *buf, size_t len) | ||
26 | { | ||
27 | struct pci_slot *slot = to_pci_slot(kobj); | ||
28 | struct pci_slot_attribute *attribute = to_pci_slot_attr(attr); | ||
29 | return attribute->store ? attribute->store(slot, buf, len) : -EIO; | ||
30 | } | ||
31 | |||
32 | static struct sysfs_ops pci_slot_sysfs_ops = { | ||
33 | .show = pci_slot_attr_show, | ||
34 | .store = pci_slot_attr_store, | ||
35 | }; | ||
36 | |||
37 | static ssize_t address_read_file(struct pci_slot *slot, char *buf) | ||
38 | { | ||
39 | if (slot->number == 0xff) | ||
40 | return sprintf(buf, "%04x:%02x\n", | ||
41 | pci_domain_nr(slot->bus), | ||
42 | slot->bus->number); | ||
43 | else | ||
44 | return sprintf(buf, "%04x:%02x:%02x\n", | ||
45 | pci_domain_nr(slot->bus), | ||
46 | slot->bus->number, | ||
47 | slot->number); | ||
48 | } | ||
49 | |||
50 | static void pci_slot_release(struct kobject *kobj) | ||
51 | { | ||
52 | struct pci_slot *slot = to_pci_slot(kobj); | ||
53 | |||
54 | pr_debug("%s: releasing pci_slot on %x:%d\n", __func__, | ||
55 | slot->bus->number, slot->number); | ||
56 | |||
57 | list_del(&slot->list); | ||
58 | |||
59 | kfree(slot); | ||
60 | } | ||
61 | |||
62 | static struct pci_slot_attribute pci_slot_attr_address = | ||
63 | __ATTR(address, (S_IFREG | S_IRUGO), address_read_file, NULL); | ||
64 | |||
65 | static struct attribute *pci_slot_default_attrs[] = { | ||
66 | &pci_slot_attr_address.attr, | ||
67 | NULL, | ||
68 | }; | ||
69 | |||
70 | static struct kobj_type pci_slot_ktype = { | ||
71 | .sysfs_ops = &pci_slot_sysfs_ops, | ||
72 | .release = &pci_slot_release, | ||
73 | .default_attrs = pci_slot_default_attrs, | ||
74 | }; | ||
75 | |||
76 | /** | ||
77 | * pci_create_slot - create or increment refcount for physical PCI slot | ||
78 | * @parent: struct pci_bus of parent bridge | ||
79 | * @slot_nr: PCI_SLOT(pci_dev->devfn) or -1 for placeholder | ||
80 | * @name: user visible string presented in /sys/bus/pci/slots/<name> | ||
81 | * | ||
82 | * PCI slots have first class attributes such as address, speed, width, | ||
83 | * and a &struct pci_slot is used to manage them. This interface will | ||
84 | * either return a new &struct pci_slot to the caller, or if the pci_slot | ||
85 | * already exists, its refcount will be incremented. | ||
86 | * | ||
87 | * Slots are uniquely identified by a @pci_bus, @slot_nr, @name tuple. | ||
88 | * | ||
89 | * Placeholder slots: | ||
90 | * In most cases, @pci_bus, @slot_nr will be sufficient to uniquely identify | ||
91 | * a slot. There is one notable exception - pSeries (rpaphp), where the | ||
92 | * @slot_nr cannot be determined until a device is actually inserted into | ||
93 | * the slot. In this scenario, the caller may pass -1 for @slot_nr. | ||
94 | * | ||
95 | * The following semantics are imposed when the caller passes @slot_nr == | ||
96 | * -1. First, the check for existing %struct pci_slot is skipped, as the | ||
97 | * caller may know about several unpopulated slots on a given %struct | ||
98 | * pci_bus, and each slot would have a @slot_nr of -1. Uniqueness for | ||
99 | * these slots is then determined by the @name parameter. We expect | ||
100 | * kobject_init_and_add() to warn us if the caller attempts to create | ||
101 | * multiple slots with the same name. The other change in semantics is | ||
102 | * user-visible, which is the 'address' parameter presented in sysfs will | ||
103 | * consist solely of a dddd:bb tuple, where dddd is the PCI domain of the | ||
104 | * %struct pci_bus and bb is the bus number. In other words, the devfn of | ||
105 | * the 'placeholder' slot will not be displayed. | ||
106 | */ | ||
107 | |||
108 | struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr, | ||
109 | const char *name) | ||
110 | { | ||
111 | struct pci_slot *slot; | ||
112 | int err; | ||
113 | |||
114 | down_write(&pci_bus_sem); | ||
115 | |||
116 | if (slot_nr == -1) | ||
117 | goto placeholder; | ||
118 | |||
119 | /* If we've already created this slot, bump refcount and return. */ | ||
120 | list_for_each_entry(slot, &parent->slots, list) { | ||
121 | if (slot->number == slot_nr) { | ||
122 | kobject_get(&slot->kobj); | ||
123 | pr_debug("%s: inc refcount to %d on %04x:%02x:%02x\n", | ||
124 | __func__, | ||
125 | atomic_read(&slot->kobj.kref.refcount), | ||
126 | pci_domain_nr(parent), parent->number, | ||
127 | slot_nr); | ||
128 | goto out; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | placeholder: | ||
133 | slot = kzalloc(sizeof(*slot), GFP_KERNEL); | ||
134 | if (!slot) { | ||
135 | slot = ERR_PTR(-ENOMEM); | ||
136 | goto out; | ||
137 | } | ||
138 | |||
139 | slot->bus = parent; | ||
140 | slot->number = slot_nr; | ||
141 | |||
142 | slot->kobj.kset = pci_slots_kset; | ||
143 | err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL, | ||
144 | "%s", name); | ||
145 | if (err) { | ||
146 | printk(KERN_ERR "Unable to register kobject %s\n", name); | ||
147 | goto err; | ||
148 | } | ||
149 | |||
150 | INIT_LIST_HEAD(&slot->list); | ||
151 | list_add(&slot->list, &parent->slots); | ||
152 | |||
153 | /* Don't care if debug printk has a -1 for slot_nr */ | ||
154 | pr_debug("%s: created pci_slot on %04x:%02x:%02x\n", | ||
155 | __func__, pci_domain_nr(parent), parent->number, slot_nr); | ||
156 | |||
157 | out: | ||
158 | up_write(&pci_bus_sem); | ||
159 | return slot; | ||
160 | err: | ||
161 | kfree(slot); | ||
162 | slot = ERR_PTR(err); | ||
163 | goto out; | ||
164 | } | ||
165 | EXPORT_SYMBOL_GPL(pci_create_slot); | ||
166 | |||
167 | /** | ||
168 | * pci_update_slot_number - update %struct pci_slot -> number | ||
169 | * @slot - %struct pci_slot to update | ||
170 | * @slot_nr - new number for slot | ||
171 | * | ||
172 | * The primary purpose of this interface is to allow callers who earlier | ||
173 | * created a placeholder slot in pci_create_slot() by passing a -1 as | ||
174 | * slot_nr, to update their %struct pci_slot with the correct @slot_nr. | ||
175 | */ | ||
176 | |||
177 | void pci_update_slot_number(struct pci_slot *slot, int slot_nr) | ||
178 | { | ||
179 | int name_count = 0; | ||
180 | struct pci_slot *tmp; | ||
181 | |||
182 | down_write(&pci_bus_sem); | ||
183 | |||
184 | list_for_each_entry(tmp, &slot->bus->slots, list) { | ||
185 | WARN_ON(tmp->number == slot_nr); | ||
186 | if (!strcmp(kobject_name(&tmp->kobj), kobject_name(&slot->kobj))) | ||
187 | name_count++; | ||
188 | } | ||
189 | |||
190 | if (name_count > 1) | ||
191 | printk(KERN_WARNING "pci_update_slot_number found %d slots with the same name: %s\n", name_count, kobject_name(&slot->kobj)); | ||
192 | |||
193 | slot->number = slot_nr; | ||
194 | up_write(&pci_bus_sem); | ||
195 | } | ||
196 | EXPORT_SYMBOL_GPL(pci_update_slot_number); | ||
197 | |||
198 | /** | ||
199 | * pci_destroy_slot - decrement refcount for physical PCI slot | ||
200 | * @slot: struct pci_slot to decrement | ||
201 | * | ||
202 | * %struct pci_slot is refcounted, so destroying them is really easy; we | ||
203 | * just call kobject_put on its kobj and let our release methods do the | ||
204 | * rest. | ||
205 | */ | ||
206 | |||
207 | void pci_destroy_slot(struct pci_slot *slot) | ||
208 | { | ||
209 | pr_debug("%s: dec refcount to %d on %04x:%02x:%02x\n", __func__, | ||
210 | atomic_read(&slot->kobj.kref.refcount) - 1, | ||
211 | pci_domain_nr(slot->bus), slot->bus->number, slot->number); | ||
212 | |||
213 | down_write(&pci_bus_sem); | ||
214 | kobject_put(&slot->kobj); | ||
215 | up_write(&pci_bus_sem); | ||
216 | } | ||
217 | EXPORT_SYMBOL_GPL(pci_destroy_slot); | ||
218 | |||
219 | static int pci_slot_init(void) | ||
220 | { | ||
221 | struct kset *pci_bus_kset; | ||
222 | |||
223 | pci_bus_kset = bus_get_kset(&pci_bus_type); | ||
224 | pci_slots_kset = kset_create_and_add("slots", NULL, | ||
225 | &pci_bus_kset->kobj); | ||
226 | if (!pci_slots_kset) { | ||
227 | printk(KERN_ERR "PCI: Slot initialization failure\n"); | ||
228 | return -ENOMEM; | ||
229 | } | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | subsys_initcall(pci_slot_init); | ||
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c index 9fcff0c33619..65129b54eb09 100644 --- a/drivers/pcmcia/cistpl.c +++ b/drivers/pcmcia/cistpl.c | |||
@@ -1490,7 +1490,7 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned | |||
1490 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) | 1490 | ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) |
1491 | reserved++; | 1491 | reserved++; |
1492 | } | 1492 | } |
1493 | if ((count) || (reserved > 5) || | 1493 | if ((count == MAX_TUPLES) || (reserved > 5) || |
1494 | ((!dev_ok || !ident_ok) && (count > 10))) | 1494 | ((!dev_ok || !ident_ok) && (count > 10))) |
1495 | count = 0; | 1495 | count = 0; |
1496 | 1496 | ||
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index 886dac823ed6..e3fa9a2d9a3d 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h | |||
@@ -1,3 +1,8 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
3 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
4 | */ | ||
5 | |||
1 | extern spinlock_t pnp_lock; | 6 | extern spinlock_t pnp_lock; |
2 | void *pnp_alloc(long size); | 7 | void *pnp_alloc(long size); |
3 | 8 | ||
@@ -19,22 +24,118 @@ void pnp_remove_card(struct pnp_card *card); | |||
19 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); | 24 | int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev); |
20 | void pnp_remove_card_device(struct pnp_dev *dev); | 25 | void pnp_remove_card_device(struct pnp_dev *dev); |
21 | 26 | ||
22 | struct pnp_option *pnp_build_option(int priority); | 27 | struct pnp_port { |
23 | struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev); | 28 | resource_size_t min; /* min base number */ |
24 | struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, | 29 | resource_size_t max; /* max base number */ |
25 | int priority); | 30 | resource_size_t align; /* align boundary */ |
26 | int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, | 31 | resource_size_t size; /* size of range */ |
27 | struct pnp_irq *data); | 32 | unsigned char flags; /* port flags */ |
28 | int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, | 33 | }; |
29 | struct pnp_dma *data); | 34 | |
30 | int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, | 35 | #define PNP_IRQ_NR 256 |
31 | struct pnp_port *data); | 36 | typedef struct { DECLARE_BITMAP(bits, PNP_IRQ_NR); } pnp_irq_mask_t; |
32 | int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, | 37 | |
33 | struct pnp_mem *data); | 38 | struct pnp_irq { |
39 | pnp_irq_mask_t map; /* bitmap for IRQ lines */ | ||
40 | unsigned char flags; /* IRQ flags */ | ||
41 | }; | ||
42 | |||
43 | struct pnp_dma { | ||
44 | unsigned char map; /* bitmask for DMA channels */ | ||
45 | unsigned char flags; /* DMA flags */ | ||
46 | }; | ||
47 | |||
48 | struct pnp_mem { | ||
49 | resource_size_t min; /* min base number */ | ||
50 | resource_size_t max; /* max base number */ | ||
51 | resource_size_t align; /* align boundary */ | ||
52 | resource_size_t size; /* size of range */ | ||
53 | unsigned char flags; /* memory flags */ | ||
54 | }; | ||
55 | |||
56 | #define PNP_OPTION_DEPENDENT 0x80000000 | ||
57 | #define PNP_OPTION_SET_MASK 0xffff | ||
58 | #define PNP_OPTION_SET_SHIFT 12 | ||
59 | #define PNP_OPTION_PRIORITY_MASK 0xfff | ||
60 | #define PNP_OPTION_PRIORITY_SHIFT 0 | ||
61 | |||
62 | #define PNP_RES_PRIORITY_PREFERRED 0 | ||
63 | #define PNP_RES_PRIORITY_ACCEPTABLE 1 | ||
64 | #define PNP_RES_PRIORITY_FUNCTIONAL 2 | ||
65 | #define PNP_RES_PRIORITY_INVALID PNP_OPTION_PRIORITY_MASK | ||
66 | |||
67 | struct pnp_option { | ||
68 | struct list_head list; | ||
69 | unsigned int flags; /* independent/dependent, set, priority */ | ||
70 | |||
71 | unsigned long type; /* IORESOURCE_{IO,MEM,IRQ,DMA} */ | ||
72 | union { | ||
73 | struct pnp_port port; | ||
74 | struct pnp_irq irq; | ||
75 | struct pnp_dma dma; | ||
76 | struct pnp_mem mem; | ||
77 | } u; | ||
78 | }; | ||
79 | |||
80 | int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
81 | pnp_irq_mask_t *map, unsigned char flags); | ||
82 | int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
83 | unsigned char map, unsigned char flags); | ||
84 | int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
85 | resource_size_t min, resource_size_t max, | ||
86 | resource_size_t align, resource_size_t size, | ||
87 | unsigned char flags); | ||
88 | int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags, | ||
89 | resource_size_t min, resource_size_t max, | ||
90 | resource_size_t align, resource_size_t size, | ||
91 | unsigned char flags); | ||
92 | |||
93 | static inline int pnp_option_is_dependent(struct pnp_option *option) | ||
94 | { | ||
95 | return option->flags & PNP_OPTION_DEPENDENT ? 1 : 0; | ||
96 | } | ||
97 | |||
98 | static inline unsigned int pnp_option_set(struct pnp_option *option) | ||
99 | { | ||
100 | return (option->flags >> PNP_OPTION_SET_SHIFT) & PNP_OPTION_SET_MASK; | ||
101 | } | ||
102 | |||
103 | static inline unsigned int pnp_option_priority(struct pnp_option *option) | ||
104 | { | ||
105 | return (option->flags >> PNP_OPTION_PRIORITY_SHIFT) & | ||
106 | PNP_OPTION_PRIORITY_MASK; | ||
107 | } | ||
108 | |||
109 | static inline unsigned int pnp_new_dependent_set(struct pnp_dev *dev, | ||
110 | int priority) | ||
111 | { | ||
112 | unsigned int flags; | ||
113 | |||
114 | if (priority > PNP_RES_PRIORITY_FUNCTIONAL) { | ||
115 | dev_warn(&dev->dev, "invalid dependent option priority %d " | ||
116 | "clipped to %d", priority, | ||
117 | PNP_RES_PRIORITY_INVALID); | ||
118 | priority = PNP_RES_PRIORITY_INVALID; | ||
119 | } | ||
120 | |||
121 | flags = PNP_OPTION_DEPENDENT | | ||
122 | ((dev->num_dependent_sets & PNP_OPTION_SET_MASK) << | ||
123 | PNP_OPTION_SET_SHIFT) | | ||
124 | ((priority & PNP_OPTION_PRIORITY_MASK) << | ||
125 | PNP_OPTION_PRIORITY_SHIFT); | ||
126 | |||
127 | dev->num_dependent_sets++; | ||
128 | |||
129 | return flags; | ||
130 | } | ||
131 | |||
132 | char *pnp_option_priority_name(struct pnp_option *option); | ||
133 | void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option); | ||
134 | |||
34 | void pnp_init_resources(struct pnp_dev *dev); | 135 | void pnp_init_resources(struct pnp_dev *dev); |
35 | 136 | ||
36 | void pnp_fixup_device(struct pnp_dev *dev); | 137 | void pnp_fixup_device(struct pnp_dev *dev); |
37 | void pnp_free_option(struct pnp_option *option); | 138 | void pnp_free_options(struct pnp_dev *dev); |
38 | int __pnp_add_device(struct pnp_dev *dev); | 139 | int __pnp_add_device(struct pnp_dev *dev); |
39 | void __pnp_remove_device(struct pnp_dev *dev); | 140 | void __pnp_remove_device(struct pnp_dev *dev); |
40 | 141 | ||
@@ -43,29 +144,18 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res); | |||
43 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res); | 144 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res); |
44 | int pnp_check_dma(struct pnp_dev *dev, struct resource *res); | 145 | int pnp_check_dma(struct pnp_dev *dev, struct resource *res); |
45 | 146 | ||
147 | char *pnp_resource_type_name(struct resource *res); | ||
46 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); | 148 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); |
47 | 149 | ||
48 | void pnp_init_resource(struct resource *res); | 150 | void pnp_free_resources(struct pnp_dev *dev); |
49 | 151 | int pnp_resource_type(struct resource *res); | |
50 | struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev, | ||
51 | unsigned int type, unsigned int num); | ||
52 | |||
53 | #define PNP_MAX_PORT 40 | ||
54 | #define PNP_MAX_MEM 24 | ||
55 | #define PNP_MAX_IRQ 2 | ||
56 | #define PNP_MAX_DMA 2 | ||
57 | 152 | ||
58 | struct pnp_resource { | 153 | struct pnp_resource { |
154 | struct list_head list; | ||
59 | struct resource res; | 155 | struct resource res; |
60 | unsigned int index; /* ISAPNP config register index */ | ||
61 | }; | 156 | }; |
62 | 157 | ||
63 | struct pnp_resource_table { | 158 | void pnp_free_resource(struct pnp_resource *pnp_res); |
64 | struct pnp_resource port[PNP_MAX_PORT]; | ||
65 | struct pnp_resource mem[PNP_MAX_MEM]; | ||
66 | struct pnp_resource dma[PNP_MAX_DMA]; | ||
67 | struct pnp_resource irq[PNP_MAX_IRQ]; | ||
68 | }; | ||
69 | 159 | ||
70 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, | 160 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, |
71 | int flags); | 161 | int flags); |
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c index 20771b7d4482..a411582bcd72 100644 --- a/drivers/pnp/core.c +++ b/drivers/pnp/core.c | |||
@@ -99,14 +99,28 @@ static void pnp_free_ids(struct pnp_dev *dev) | |||
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | void pnp_free_resource(struct pnp_resource *pnp_res) | ||
103 | { | ||
104 | list_del(&pnp_res->list); | ||
105 | kfree(pnp_res); | ||
106 | } | ||
107 | |||
108 | void pnp_free_resources(struct pnp_dev *dev) | ||
109 | { | ||
110 | struct pnp_resource *pnp_res, *tmp; | ||
111 | |||
112 | list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) { | ||
113 | pnp_free_resource(pnp_res); | ||
114 | } | ||
115 | } | ||
116 | |||
102 | static void pnp_release_device(struct device *dmdev) | 117 | static void pnp_release_device(struct device *dmdev) |
103 | { | 118 | { |
104 | struct pnp_dev *dev = to_pnp_dev(dmdev); | 119 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
105 | 120 | ||
106 | pnp_free_option(dev->independent); | ||
107 | pnp_free_option(dev->dependent); | ||
108 | pnp_free_ids(dev); | 121 | pnp_free_ids(dev); |
109 | kfree(dev->res); | 122 | pnp_free_resources(dev); |
123 | pnp_free_options(dev); | ||
110 | kfree(dev); | 124 | kfree(dev); |
111 | } | 125 | } |
112 | 126 | ||
@@ -119,12 +133,8 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid | |||
119 | if (!dev) | 133 | if (!dev) |
120 | return NULL; | 134 | return NULL; |
121 | 135 | ||
122 | dev->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); | 136 | INIT_LIST_HEAD(&dev->resources); |
123 | if (!dev->res) { | 137 | INIT_LIST_HEAD(&dev->options); |
124 | kfree(dev); | ||
125 | return NULL; | ||
126 | } | ||
127 | |||
128 | dev->protocol = protocol; | 138 | dev->protocol = protocol; |
129 | dev->number = id; | 139 | dev->number = id; |
130 | dev->dma_mask = DMA_24BIT_MASK; | 140 | dev->dma_mask = DMA_24BIT_MASK; |
@@ -140,7 +150,6 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid | |||
140 | 150 | ||
141 | dev_id = pnp_add_id(dev, pnpid); | 151 | dev_id = pnp_add_id(dev, pnpid); |
142 | if (!dev_id) { | 152 | if (!dev_id) { |
143 | kfree(dev->res); | ||
144 | kfree(dev); | 153 | kfree(dev); |
145 | return NULL; | 154 | return NULL; |
146 | } | 155 | } |
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c index 5695a79f3a52..a876ecf7028c 100644 --- a/drivers/pnp/interface.c +++ b/drivers/pnp/interface.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * | 3 | * |
4 | * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz> | 4 | * Some code, especially possible resource dumping is based on isapnp_proc.c (c) Jaroslav Kysela <perex@perex.cz> |
5 | * Copyright 2002 Adam Belay <ambx1@neo.rr.com> | 5 | * Copyright 2002 Adam Belay <ambx1@neo.rr.com> |
6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
6 | */ | 8 | */ |
7 | 9 | ||
8 | #include <linux/pnp.h> | 10 | #include <linux/pnp.h> |
@@ -53,11 +55,13 @@ static int pnp_printf(pnp_info_buffer_t * buffer, char *fmt, ...) | |||
53 | static void pnp_print_port(pnp_info_buffer_t * buffer, char *space, | 55 | static void pnp_print_port(pnp_info_buffer_t * buffer, char *space, |
54 | struct pnp_port *port) | 56 | struct pnp_port *port) |
55 | { | 57 | { |
56 | pnp_printf(buffer, | 58 | pnp_printf(buffer, "%sport %#llx-%#llx, align %#llx, size %#llx, " |
57 | "%sport 0x%x-0x%x, align 0x%x, size 0x%x, %i-bit address decoding\n", | 59 | "%i-bit address decoding\n", space, |
58 | space, port->min, port->max, | 60 | (unsigned long long) port->min, |
59 | port->align ? (port->align - 1) : 0, port->size, | 61 | (unsigned long long) port->max, |
60 | port->flags & PNP_PORT_FLAG_16BITADDR ? 16 : 10); | 62 | port->align ? ((unsigned long long) port->align - 1) : 0, |
63 | (unsigned long long) port->size, | ||
64 | port->flags & IORESOURCE_IO_16BIT_ADDR ? 16 : 10); | ||
61 | } | 65 | } |
62 | 66 | ||
63 | static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, | 67 | static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, |
@@ -67,7 +71,7 @@ static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, | |||
67 | 71 | ||
68 | pnp_printf(buffer, "%sirq ", space); | 72 | pnp_printf(buffer, "%sirq ", space); |
69 | for (i = 0; i < PNP_IRQ_NR; i++) | 73 | for (i = 0; i < PNP_IRQ_NR; i++) |
70 | if (test_bit(i, irq->map)) { | 74 | if (test_bit(i, irq->map.bits)) { |
71 | if (!first) { | 75 | if (!first) { |
72 | pnp_printf(buffer, ","); | 76 | pnp_printf(buffer, ","); |
73 | } else { | 77 | } else { |
@@ -78,7 +82,7 @@ static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, | |||
78 | else | 82 | else |
79 | pnp_printf(buffer, "%i", i); | 83 | pnp_printf(buffer, "%i", i); |
80 | } | 84 | } |
81 | if (bitmap_empty(irq->map, PNP_IRQ_NR)) | 85 | if (bitmap_empty(irq->map.bits, PNP_IRQ_NR)) |
82 | pnp_printf(buffer, "<none>"); | 86 | pnp_printf(buffer, "<none>"); |
83 | if (irq->flags & IORESOURCE_IRQ_HIGHEDGE) | 87 | if (irq->flags & IORESOURCE_IRQ_HIGHEDGE) |
84 | pnp_printf(buffer, " High-Edge"); | 88 | pnp_printf(buffer, " High-Edge"); |
@@ -88,6 +92,8 @@ static void pnp_print_irq(pnp_info_buffer_t * buffer, char *space, | |||
88 | pnp_printf(buffer, " High-Level"); | 92 | pnp_printf(buffer, " High-Level"); |
89 | if (irq->flags & IORESOURCE_IRQ_LOWLEVEL) | 93 | if (irq->flags & IORESOURCE_IRQ_LOWLEVEL) |
90 | pnp_printf(buffer, " Low-Level"); | 94 | pnp_printf(buffer, " Low-Level"); |
95 | if (irq->flags & IORESOURCE_IRQ_OPTIONAL) | ||
96 | pnp_printf(buffer, " (optional)"); | ||
91 | pnp_printf(buffer, "\n"); | 97 | pnp_printf(buffer, "\n"); |
92 | } | 98 | } |
93 | 99 | ||
@@ -148,8 +154,11 @@ static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space, | |||
148 | { | 154 | { |
149 | char *s; | 155 | char *s; |
150 | 156 | ||
151 | pnp_printf(buffer, "%sMemory 0x%x-0x%x, align 0x%x, size 0x%x", | 157 | pnp_printf(buffer, "%sMemory %#llx-%#llx, align %#llx, size %#llx", |
152 | space, mem->min, mem->max, mem->align, mem->size); | 158 | space, (unsigned long long) mem->min, |
159 | (unsigned long long) mem->max, | ||
160 | (unsigned long long) mem->align, | ||
161 | (unsigned long long) mem->size); | ||
153 | if (mem->flags & IORESOURCE_MEM_WRITEABLE) | 162 | if (mem->flags & IORESOURCE_MEM_WRITEABLE) |
154 | pnp_printf(buffer, ", writeable"); | 163 | pnp_printf(buffer, ", writeable"); |
155 | if (mem->flags & IORESOURCE_MEM_CACHEABLE) | 164 | if (mem->flags & IORESOURCE_MEM_CACHEABLE) |
@@ -177,65 +186,58 @@ static void pnp_print_mem(pnp_info_buffer_t * buffer, char *space, | |||
177 | } | 186 | } |
178 | 187 | ||
179 | static void pnp_print_option(pnp_info_buffer_t * buffer, char *space, | 188 | static void pnp_print_option(pnp_info_buffer_t * buffer, char *space, |
180 | struct pnp_option *option, int dep) | 189 | struct pnp_option *option) |
181 | { | 190 | { |
182 | char *s; | 191 | switch (option->type) { |
183 | struct pnp_port *port; | 192 | case IORESOURCE_IO: |
184 | struct pnp_irq *irq; | 193 | pnp_print_port(buffer, space, &option->u.port); |
185 | struct pnp_dma *dma; | 194 | break; |
186 | struct pnp_mem *mem; | 195 | case IORESOURCE_MEM: |
187 | 196 | pnp_print_mem(buffer, space, &option->u.mem); | |
188 | if (dep) { | 197 | break; |
189 | switch (option->priority) { | 198 | case IORESOURCE_IRQ: |
190 | case PNP_RES_PRIORITY_PREFERRED: | 199 | pnp_print_irq(buffer, space, &option->u.irq); |
191 | s = "preferred"; | 200 | break; |
192 | break; | 201 | case IORESOURCE_DMA: |
193 | case PNP_RES_PRIORITY_ACCEPTABLE: | 202 | pnp_print_dma(buffer, space, &option->u.dma); |
194 | s = "acceptable"; | 203 | break; |
195 | break; | ||
196 | case PNP_RES_PRIORITY_FUNCTIONAL: | ||
197 | s = "functional"; | ||
198 | break; | ||
199 | default: | ||
200 | s = "invalid"; | ||
201 | } | ||
202 | pnp_printf(buffer, "Dependent: %02i - Priority %s\n", dep, s); | ||
203 | } | 204 | } |
204 | |||
205 | for (port = option->port; port; port = port->next) | ||
206 | pnp_print_port(buffer, space, port); | ||
207 | for (irq = option->irq; irq; irq = irq->next) | ||
208 | pnp_print_irq(buffer, space, irq); | ||
209 | for (dma = option->dma; dma; dma = dma->next) | ||
210 | pnp_print_dma(buffer, space, dma); | ||
211 | for (mem = option->mem; mem; mem = mem->next) | ||
212 | pnp_print_mem(buffer, space, mem); | ||
213 | } | 205 | } |
214 | 206 | ||
215 | static ssize_t pnp_show_options(struct device *dmdev, | 207 | static ssize_t pnp_show_options(struct device *dmdev, |
216 | struct device_attribute *attr, char *buf) | 208 | struct device_attribute *attr, char *buf) |
217 | { | 209 | { |
218 | struct pnp_dev *dev = to_pnp_dev(dmdev); | 210 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
219 | struct pnp_option *independent = dev->independent; | 211 | pnp_info_buffer_t *buffer; |
220 | struct pnp_option *dependent = dev->dependent; | 212 | struct pnp_option *option; |
221 | int ret, dep = 1; | 213 | int ret, dep = 0, set = 0; |
214 | char *indent; | ||
222 | 215 | ||
223 | pnp_info_buffer_t *buffer = (pnp_info_buffer_t *) | 216 | buffer = pnp_alloc(sizeof(pnp_info_buffer_t)); |
224 | pnp_alloc(sizeof(pnp_info_buffer_t)); | ||
225 | if (!buffer) | 217 | if (!buffer) |
226 | return -ENOMEM; | 218 | return -ENOMEM; |
227 | 219 | ||
228 | buffer->len = PAGE_SIZE; | 220 | buffer->len = PAGE_SIZE; |
229 | buffer->buffer = buf; | 221 | buffer->buffer = buf; |
230 | buffer->curr = buffer->buffer; | 222 | buffer->curr = buffer->buffer; |
231 | if (independent) | ||
232 | pnp_print_option(buffer, "", independent, 0); | ||
233 | 223 | ||
234 | while (dependent) { | 224 | list_for_each_entry(option, &dev->options, list) { |
235 | pnp_print_option(buffer, " ", dependent, dep); | 225 | if (pnp_option_is_dependent(option)) { |
236 | dependent = dependent->next; | 226 | indent = " "; |
237 | dep++; | 227 | if (!dep || pnp_option_set(option) != set) { |
228 | set = pnp_option_set(option); | ||
229 | dep = 1; | ||
230 | pnp_printf(buffer, "Dependent: %02i - " | ||
231 | "Priority %s\n", set, | ||
232 | pnp_option_priority_name(option)); | ||
233 | } | ||
234 | } else { | ||
235 | dep = 0; | ||
236 | indent = ""; | ||
237 | } | ||
238 | pnp_print_option(buffer, indent, option); | ||
238 | } | 239 | } |
240 | |||
239 | ret = (buffer->curr - buf); | 241 | ret = (buffer->curr - buf); |
240 | kfree(buffer); | 242 | kfree(buffer); |
241 | return ret; | 243 | return ret; |
@@ -248,79 +250,59 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, | |||
248 | char *buf) | 250 | char *buf) |
249 | { | 251 | { |
250 | struct pnp_dev *dev = to_pnp_dev(dmdev); | 252 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
251 | struct resource *res; | ||
252 | int i, ret; | ||
253 | pnp_info_buffer_t *buffer; | 253 | pnp_info_buffer_t *buffer; |
254 | struct pnp_resource *pnp_res; | ||
255 | struct resource *res; | ||
256 | int ret; | ||
254 | 257 | ||
255 | if (!dev) | 258 | if (!dev) |
256 | return -EINVAL; | 259 | return -EINVAL; |
257 | 260 | ||
258 | buffer = (pnp_info_buffer_t *) pnp_alloc(sizeof(pnp_info_buffer_t)); | 261 | buffer = pnp_alloc(sizeof(pnp_info_buffer_t)); |
259 | if (!buffer) | 262 | if (!buffer) |
260 | return -ENOMEM; | 263 | return -ENOMEM; |
264 | |||
261 | buffer->len = PAGE_SIZE; | 265 | buffer->len = PAGE_SIZE; |
262 | buffer->buffer = buf; | 266 | buffer->buffer = buf; |
263 | buffer->curr = buffer->buffer; | 267 | buffer->curr = buffer->buffer; |
264 | 268 | ||
265 | pnp_printf(buffer, "state = "); | 269 | pnp_printf(buffer, "state = %s\n", dev->active ? "active" : "disabled"); |
266 | if (dev->active) | 270 | |
267 | pnp_printf(buffer, "active\n"); | 271 | list_for_each_entry(pnp_res, &dev->resources, list) { |
268 | else | 272 | res = &pnp_res->res; |
269 | pnp_printf(buffer, "disabled\n"); | 273 | |
270 | 274 | pnp_printf(buffer, pnp_resource_type_name(res)); | |
271 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { | 275 | |
272 | if (pnp_resource_valid(res)) { | 276 | if (res->flags & IORESOURCE_DISABLED) { |
273 | pnp_printf(buffer, "io"); | 277 | pnp_printf(buffer, " disabled\n"); |
274 | if (res->flags & IORESOURCE_DISABLED) | 278 | continue; |
275 | pnp_printf(buffer, " disabled\n"); | ||
276 | else | ||
277 | pnp_printf(buffer, " 0x%llx-0x%llx\n", | ||
278 | (unsigned long long) res->start, | ||
279 | (unsigned long long) res->end); | ||
280 | } | ||
281 | } | ||
282 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { | ||
283 | if (pnp_resource_valid(res)) { | ||
284 | pnp_printf(buffer, "mem"); | ||
285 | if (res->flags & IORESOURCE_DISABLED) | ||
286 | pnp_printf(buffer, " disabled\n"); | ||
287 | else | ||
288 | pnp_printf(buffer, " 0x%llx-0x%llx\n", | ||
289 | (unsigned long long) res->start, | ||
290 | (unsigned long long) res->end); | ||
291 | } | ||
292 | } | ||
293 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) { | ||
294 | if (pnp_resource_valid(res)) { | ||
295 | pnp_printf(buffer, "irq"); | ||
296 | if (res->flags & IORESOURCE_DISABLED) | ||
297 | pnp_printf(buffer, " disabled\n"); | ||
298 | else | ||
299 | pnp_printf(buffer, " %lld\n", | ||
300 | (unsigned long long) res->start); | ||
301 | } | 279 | } |
302 | } | 280 | |
303 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) { | 281 | switch (pnp_resource_type(res)) { |
304 | if (pnp_resource_valid(res)) { | 282 | case IORESOURCE_IO: |
305 | pnp_printf(buffer, "dma"); | 283 | case IORESOURCE_MEM: |
306 | if (res->flags & IORESOURCE_DISABLED) | 284 | pnp_printf(buffer, " %#llx-%#llx\n", |
307 | pnp_printf(buffer, " disabled\n"); | 285 | (unsigned long long) res->start, |
308 | else | 286 | (unsigned long long) res->end); |
309 | pnp_printf(buffer, " %lld\n", | 287 | break; |
310 | (unsigned long long) res->start); | 288 | case IORESOURCE_IRQ: |
289 | case IORESOURCE_DMA: | ||
290 | pnp_printf(buffer, " %lld\n", | ||
291 | (unsigned long long) res->start); | ||
292 | break; | ||
311 | } | 293 | } |
312 | } | 294 | } |
295 | |||
313 | ret = (buffer->curr - buf); | 296 | ret = (buffer->curr - buf); |
314 | kfree(buffer); | 297 | kfree(buffer); |
315 | return ret; | 298 | return ret; |
316 | } | 299 | } |
317 | 300 | ||
318 | static ssize_t | 301 | static ssize_t pnp_set_current_resources(struct device *dmdev, |
319 | pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | 302 | struct device_attribute *attr, |
320 | const char *ubuf, size_t count) | 303 | const char *ubuf, size_t count) |
321 | { | 304 | { |
322 | struct pnp_dev *dev = to_pnp_dev(dmdev); | 305 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
323 | struct pnp_resource *pnp_res; | ||
324 | char *buf = (void *)ubuf; | 306 | char *buf = (void *)ubuf; |
325 | int retval = 0; | 307 | int retval = 0; |
326 | resource_size_t start, end; | 308 | resource_size_t start, end; |
@@ -368,7 +350,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
368 | goto done; | 350 | goto done; |
369 | } | 351 | } |
370 | if (!strnicmp(buf, "set", 3)) { | 352 | if (!strnicmp(buf, "set", 3)) { |
371 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; | ||
372 | if (dev->active) | 353 | if (dev->active) |
373 | goto done; | 354 | goto done; |
374 | buf += 3; | 355 | buf += 3; |
@@ -391,10 +372,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
391 | end = simple_strtoul(buf, &buf, 0); | 372 | end = simple_strtoul(buf, &buf, 0); |
392 | } else | 373 | } else |
393 | end = start; | 374 | end = start; |
394 | pnp_res = pnp_add_io_resource(dev, start, end, | 375 | pnp_add_io_resource(dev, start, end, 0); |
395 | 0); | ||
396 | if (pnp_res) | ||
397 | pnp_res->index = nport++; | ||
398 | continue; | 376 | continue; |
399 | } | 377 | } |
400 | if (!strnicmp(buf, "mem", 3)) { | 378 | if (!strnicmp(buf, "mem", 3)) { |
@@ -411,10 +389,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
411 | end = simple_strtoul(buf, &buf, 0); | 389 | end = simple_strtoul(buf, &buf, 0); |
412 | } else | 390 | } else |
413 | end = start; | 391 | end = start; |
414 | pnp_res = pnp_add_mem_resource(dev, start, end, | 392 | pnp_add_mem_resource(dev, start, end, 0); |
415 | 0); | ||
416 | if (pnp_res) | ||
417 | pnp_res->index = nmem++; | ||
418 | continue; | 393 | continue; |
419 | } | 394 | } |
420 | if (!strnicmp(buf, "irq", 3)) { | 395 | if (!strnicmp(buf, "irq", 3)) { |
@@ -422,9 +397,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
422 | while (isspace(*buf)) | 397 | while (isspace(*buf)) |
423 | ++buf; | 398 | ++buf; |
424 | start = simple_strtoul(buf, &buf, 0); | 399 | start = simple_strtoul(buf, &buf, 0); |
425 | pnp_res = pnp_add_irq_resource(dev, start, 0); | 400 | pnp_add_irq_resource(dev, start, 0); |
426 | if (pnp_res) | ||
427 | pnp_res->index = nirq++; | ||
428 | continue; | 401 | continue; |
429 | } | 402 | } |
430 | if (!strnicmp(buf, "dma", 3)) { | 403 | if (!strnicmp(buf, "dma", 3)) { |
@@ -432,9 +405,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
432 | while (isspace(*buf)) | 405 | while (isspace(*buf)) |
433 | ++buf; | 406 | ++buf; |
434 | start = simple_strtoul(buf, &buf, 0); | 407 | start = simple_strtoul(buf, &buf, 0); |
435 | pnp_res = pnp_add_dma_resource(dev, start, 0); | 408 | pnp_add_dma_resource(dev, start, 0); |
436 | if (pnp_res) | ||
437 | pnp_res->index = ndma++; | ||
438 | continue; | 409 | continue; |
439 | } | 410 | } |
440 | break; | 411 | break; |
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c index f1bccdbdeb08..101a835e8759 100644 --- a/drivers/pnp/isapnp/core.c +++ b/drivers/pnp/isapnp/core.c | |||
@@ -429,154 +429,135 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card, | |||
429 | * Add IRQ resource to resources list. | 429 | * Add IRQ resource to resources list. |
430 | */ | 430 | */ |
431 | static void __init isapnp_parse_irq_resource(struct pnp_dev *dev, | 431 | static void __init isapnp_parse_irq_resource(struct pnp_dev *dev, |
432 | struct pnp_option *option, | 432 | unsigned int option_flags, |
433 | int size) | 433 | int size) |
434 | { | 434 | { |
435 | unsigned char tmp[3]; | 435 | unsigned char tmp[3]; |
436 | struct pnp_irq *irq; | ||
437 | unsigned long bits; | 436 | unsigned long bits; |
437 | pnp_irq_mask_t map; | ||
438 | unsigned char flags = IORESOURCE_IRQ_HIGHEDGE; | ||
438 | 439 | ||
439 | isapnp_peek(tmp, size); | 440 | isapnp_peek(tmp, size); |
440 | irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); | ||
441 | if (!irq) | ||
442 | return; | ||
443 | bits = (tmp[1] << 8) | tmp[0]; | 441 | bits = (tmp[1] << 8) | tmp[0]; |
444 | bitmap_copy(irq->map, &bits, 16); | 442 | |
443 | bitmap_zero(map.bits, PNP_IRQ_NR); | ||
444 | bitmap_copy(map.bits, &bits, 16); | ||
445 | |||
445 | if (size > 2) | 446 | if (size > 2) |
446 | irq->flags = tmp[2]; | 447 | flags = tmp[2]; |
447 | else | 448 | |
448 | irq->flags = IORESOURCE_IRQ_HIGHEDGE; | 449 | pnp_register_irq_resource(dev, option_flags, &map, flags); |
449 | pnp_register_irq_resource(dev, option, irq); | ||
450 | } | 450 | } |
451 | 451 | ||
452 | /* | 452 | /* |
453 | * Add DMA resource to resources list. | 453 | * Add DMA resource to resources list. |
454 | */ | 454 | */ |
455 | static void __init isapnp_parse_dma_resource(struct pnp_dev *dev, | 455 | static void __init isapnp_parse_dma_resource(struct pnp_dev *dev, |
456 | struct pnp_option *option, | 456 | unsigned int option_flags, |
457 | int size) | 457 | int size) |
458 | { | 458 | { |
459 | unsigned char tmp[2]; | 459 | unsigned char tmp[2]; |
460 | struct pnp_dma *dma; | ||
461 | 460 | ||
462 | isapnp_peek(tmp, size); | 461 | isapnp_peek(tmp, size); |
463 | dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); | 462 | pnp_register_dma_resource(dev, option_flags, tmp[0], tmp[1]); |
464 | if (!dma) | ||
465 | return; | ||
466 | dma->map = tmp[0]; | ||
467 | dma->flags = tmp[1]; | ||
468 | pnp_register_dma_resource(dev, option, dma); | ||
469 | } | 463 | } |
470 | 464 | ||
471 | /* | 465 | /* |
472 | * Add port resource to resources list. | 466 | * Add port resource to resources list. |
473 | */ | 467 | */ |
474 | static void __init isapnp_parse_port_resource(struct pnp_dev *dev, | 468 | static void __init isapnp_parse_port_resource(struct pnp_dev *dev, |
475 | struct pnp_option *option, | 469 | unsigned int option_flags, |
476 | int size) | 470 | int size) |
477 | { | 471 | { |
478 | unsigned char tmp[7]; | 472 | unsigned char tmp[7]; |
479 | struct pnp_port *port; | 473 | resource_size_t min, max, align, len; |
474 | unsigned char flags; | ||
480 | 475 | ||
481 | isapnp_peek(tmp, size); | 476 | isapnp_peek(tmp, size); |
482 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | 477 | min = (tmp[2] << 8) | tmp[1]; |
483 | if (!port) | 478 | max = (tmp[4] << 8) | tmp[3]; |
484 | return; | 479 | align = tmp[5]; |
485 | port->min = (tmp[2] << 8) | tmp[1]; | 480 | len = tmp[6]; |
486 | port->max = (tmp[4] << 8) | tmp[3]; | 481 | flags = tmp[0] ? IORESOURCE_IO_16BIT_ADDR : 0; |
487 | port->align = tmp[5]; | 482 | pnp_register_port_resource(dev, option_flags, |
488 | port->size = tmp[6]; | 483 | min, max, align, len, flags); |
489 | port->flags = tmp[0] ? PNP_PORT_FLAG_16BITADDR : 0; | ||
490 | pnp_register_port_resource(dev, option, port); | ||
491 | } | 484 | } |
492 | 485 | ||
493 | /* | 486 | /* |
494 | * Add fixed port resource to resources list. | 487 | * Add fixed port resource to resources list. |
495 | */ | 488 | */ |
496 | static void __init isapnp_parse_fixed_port_resource(struct pnp_dev *dev, | 489 | static void __init isapnp_parse_fixed_port_resource(struct pnp_dev *dev, |
497 | struct pnp_option *option, | 490 | unsigned int option_flags, |
498 | int size) | 491 | int size) |
499 | { | 492 | { |
500 | unsigned char tmp[3]; | 493 | unsigned char tmp[3]; |
501 | struct pnp_port *port; | 494 | resource_size_t base, len; |
502 | 495 | ||
503 | isapnp_peek(tmp, size); | 496 | isapnp_peek(tmp, size); |
504 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | 497 | base = (tmp[1] << 8) | tmp[0]; |
505 | if (!port) | 498 | len = tmp[2]; |
506 | return; | 499 | pnp_register_port_resource(dev, option_flags, base, base, 0, len, |
507 | port->min = port->max = (tmp[1] << 8) | tmp[0]; | 500 | IORESOURCE_IO_FIXED); |
508 | port->size = tmp[2]; | ||
509 | port->align = 0; | ||
510 | port->flags = PNP_PORT_FLAG_FIXED; | ||
511 | pnp_register_port_resource(dev, option, port); | ||
512 | } | 501 | } |
513 | 502 | ||
514 | /* | 503 | /* |
515 | * Add memory resource to resources list. | 504 | * Add memory resource to resources list. |
516 | */ | 505 | */ |
517 | static void __init isapnp_parse_mem_resource(struct pnp_dev *dev, | 506 | static void __init isapnp_parse_mem_resource(struct pnp_dev *dev, |
518 | struct pnp_option *option, | 507 | unsigned int option_flags, |
519 | int size) | 508 | int size) |
520 | { | 509 | { |
521 | unsigned char tmp[9]; | 510 | unsigned char tmp[9]; |
522 | struct pnp_mem *mem; | 511 | resource_size_t min, max, align, len; |
512 | unsigned char flags; | ||
523 | 513 | ||
524 | isapnp_peek(tmp, size); | 514 | isapnp_peek(tmp, size); |
525 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 515 | min = ((tmp[2] << 8) | tmp[1]) << 8; |
526 | if (!mem) | 516 | max = ((tmp[4] << 8) | tmp[3]) << 8; |
527 | return; | 517 | align = (tmp[6] << 8) | tmp[5]; |
528 | mem->min = ((tmp[2] << 8) | tmp[1]) << 8; | 518 | len = ((tmp[8] << 8) | tmp[7]) << 8; |
529 | mem->max = ((tmp[4] << 8) | tmp[3]) << 8; | 519 | flags = tmp[0]; |
530 | mem->align = (tmp[6] << 8) | tmp[5]; | 520 | pnp_register_mem_resource(dev, option_flags, |
531 | mem->size = ((tmp[8] << 8) | tmp[7]) << 8; | 521 | min, max, align, len, flags); |
532 | mem->flags = tmp[0]; | ||
533 | pnp_register_mem_resource(dev, option, mem); | ||
534 | } | 522 | } |
535 | 523 | ||
536 | /* | 524 | /* |
537 | * Add 32-bit memory resource to resources list. | 525 | * Add 32-bit memory resource to resources list. |
538 | */ | 526 | */ |
539 | static void __init isapnp_parse_mem32_resource(struct pnp_dev *dev, | 527 | static void __init isapnp_parse_mem32_resource(struct pnp_dev *dev, |
540 | struct pnp_option *option, | 528 | unsigned int option_flags, |
541 | int size) | 529 | int size) |
542 | { | 530 | { |
543 | unsigned char tmp[17]; | 531 | unsigned char tmp[17]; |
544 | struct pnp_mem *mem; | 532 | resource_size_t min, max, align, len; |
533 | unsigned char flags; | ||
545 | 534 | ||
546 | isapnp_peek(tmp, size); | 535 | isapnp_peek(tmp, size); |
547 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 536 | min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; |
548 | if (!mem) | 537 | max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; |
549 | return; | 538 | align = (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9]; |
550 | mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; | 539 | len = (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13]; |
551 | mem->max = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; | 540 | flags = tmp[0]; |
552 | mem->align = | 541 | pnp_register_mem_resource(dev, option_flags, |
553 | (tmp[12] << 24) | (tmp[11] << 16) | (tmp[10] << 8) | tmp[9]; | 542 | min, max, align, len, flags); |
554 | mem->size = | ||
555 | (tmp[16] << 24) | (tmp[15] << 16) | (tmp[14] << 8) | tmp[13]; | ||
556 | mem->flags = tmp[0]; | ||
557 | pnp_register_mem_resource(dev, option, mem); | ||
558 | } | 543 | } |
559 | 544 | ||
560 | /* | 545 | /* |
561 | * Add 32-bit fixed memory resource to resources list. | 546 | * Add 32-bit fixed memory resource to resources list. |
562 | */ | 547 | */ |
563 | static void __init isapnp_parse_fixed_mem32_resource(struct pnp_dev *dev, | 548 | static void __init isapnp_parse_fixed_mem32_resource(struct pnp_dev *dev, |
564 | struct pnp_option *option, | 549 | unsigned int option_flags, |
565 | int size) | 550 | int size) |
566 | { | 551 | { |
567 | unsigned char tmp[9]; | 552 | unsigned char tmp[9]; |
568 | struct pnp_mem *mem; | 553 | resource_size_t base, len; |
554 | unsigned char flags; | ||
569 | 555 | ||
570 | isapnp_peek(tmp, size); | 556 | isapnp_peek(tmp, size); |
571 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 557 | base = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; |
572 | if (!mem) | 558 | len = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; |
573 | return; | 559 | flags = tmp[0]; |
574 | mem->min = mem->max = | 560 | pnp_register_mem_resource(dev, option_flags, base, base, 0, len, flags); |
575 | (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1]; | ||
576 | mem->size = (tmp[8] << 24) | (tmp[7] << 16) | (tmp[6] << 8) | tmp[5]; | ||
577 | mem->align = 0; | ||
578 | mem->flags = tmp[0]; | ||
579 | pnp_register_mem_resource(dev, option, mem); | ||
580 | } | 561 | } |
581 | 562 | ||
582 | /* | 563 | /* |
@@ -604,20 +585,16 @@ isapnp_parse_name(char *name, unsigned int name_max, unsigned short *size) | |||
604 | static int __init isapnp_create_device(struct pnp_card *card, | 585 | static int __init isapnp_create_device(struct pnp_card *card, |
605 | unsigned short size) | 586 | unsigned short size) |
606 | { | 587 | { |
607 | int number = 0, skip = 0, priority = 0, compat = 0; | 588 | int number = 0, skip = 0, priority, compat = 0; |
608 | unsigned char type, tmp[17]; | 589 | unsigned char type, tmp[17]; |
609 | struct pnp_option *option; | 590 | unsigned int option_flags; |
610 | struct pnp_dev *dev; | 591 | struct pnp_dev *dev; |
611 | u32 eisa_id; | 592 | u32 eisa_id; |
612 | char id[8]; | 593 | char id[8]; |
613 | 594 | ||
614 | if ((dev = isapnp_parse_device(card, size, number++)) == NULL) | 595 | if ((dev = isapnp_parse_device(card, size, number++)) == NULL) |
615 | return 1; | 596 | return 1; |
616 | option = pnp_register_independent_option(dev); | 597 | option_flags = 0; |
617 | if (!option) { | ||
618 | kfree(dev); | ||
619 | return 1; | ||
620 | } | ||
621 | pnp_add_card_device(card, dev); | 598 | pnp_add_card_device(card, dev); |
622 | 599 | ||
623 | while (1) { | 600 | while (1) { |
@@ -634,16 +611,11 @@ static int __init isapnp_create_device(struct pnp_card *card, | |||
634 | return 1; | 611 | return 1; |
635 | size = 0; | 612 | size = 0; |
636 | skip = 0; | 613 | skip = 0; |
637 | option = pnp_register_independent_option(dev); | 614 | option_flags = 0; |
638 | if (!option) { | ||
639 | kfree(dev); | ||
640 | return 1; | ||
641 | } | ||
642 | pnp_add_card_device(card, dev); | 615 | pnp_add_card_device(card, dev); |
643 | } else { | 616 | } else { |
644 | skip = 1; | 617 | skip = 1; |
645 | } | 618 | } |
646 | priority = 0; | ||
647 | compat = 0; | 619 | compat = 0; |
648 | break; | 620 | break; |
649 | case _STAG_COMPATDEVID: | 621 | case _STAG_COMPATDEVID: |
@@ -660,44 +632,42 @@ static int __init isapnp_create_device(struct pnp_card *card, | |||
660 | case _STAG_IRQ: | 632 | case _STAG_IRQ: |
661 | if (size < 2 || size > 3) | 633 | if (size < 2 || size > 3) |
662 | goto __skip; | 634 | goto __skip; |
663 | isapnp_parse_irq_resource(dev, option, size); | 635 | isapnp_parse_irq_resource(dev, option_flags, size); |
664 | size = 0; | 636 | size = 0; |
665 | break; | 637 | break; |
666 | case _STAG_DMA: | 638 | case _STAG_DMA: |
667 | if (size != 2) | 639 | if (size != 2) |
668 | goto __skip; | 640 | goto __skip; |
669 | isapnp_parse_dma_resource(dev, option, size); | 641 | isapnp_parse_dma_resource(dev, option_flags, size); |
670 | size = 0; | 642 | size = 0; |
671 | break; | 643 | break; |
672 | case _STAG_STARTDEP: | 644 | case _STAG_STARTDEP: |
673 | if (size > 1) | 645 | if (size > 1) |
674 | goto __skip; | 646 | goto __skip; |
675 | priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE; | 647 | priority = PNP_RES_PRIORITY_ACCEPTABLE; |
676 | if (size > 0) { | 648 | if (size > 0) { |
677 | isapnp_peek(tmp, size); | 649 | isapnp_peek(tmp, size); |
678 | priority = 0x100 | tmp[0]; | 650 | priority = tmp[0]; |
679 | size = 0; | 651 | size = 0; |
680 | } | 652 | } |
681 | option = pnp_register_dependent_option(dev, priority); | 653 | option_flags = pnp_new_dependent_set(dev, priority); |
682 | if (!option) | ||
683 | return 1; | ||
684 | break; | 654 | break; |
685 | case _STAG_ENDDEP: | 655 | case _STAG_ENDDEP: |
686 | if (size != 0) | 656 | if (size != 0) |
687 | goto __skip; | 657 | goto __skip; |
688 | priority = 0; | 658 | option_flags = 0; |
689 | dev_dbg(&dev->dev, "end dependent options\n"); | ||
690 | break; | 659 | break; |
691 | case _STAG_IOPORT: | 660 | case _STAG_IOPORT: |
692 | if (size != 7) | 661 | if (size != 7) |
693 | goto __skip; | 662 | goto __skip; |
694 | isapnp_parse_port_resource(dev, option, size); | 663 | isapnp_parse_port_resource(dev, option_flags, size); |
695 | size = 0; | 664 | size = 0; |
696 | break; | 665 | break; |
697 | case _STAG_FIXEDIO: | 666 | case _STAG_FIXEDIO: |
698 | if (size != 3) | 667 | if (size != 3) |
699 | goto __skip; | 668 | goto __skip; |
700 | isapnp_parse_fixed_port_resource(dev, option, size); | 669 | isapnp_parse_fixed_port_resource(dev, option_flags, |
670 | size); | ||
701 | size = 0; | 671 | size = 0; |
702 | break; | 672 | break; |
703 | case _STAG_VENDOR: | 673 | case _STAG_VENDOR: |
@@ -705,7 +675,7 @@ static int __init isapnp_create_device(struct pnp_card *card, | |||
705 | case _LTAG_MEMRANGE: | 675 | case _LTAG_MEMRANGE: |
706 | if (size != 9) | 676 | if (size != 9) |
707 | goto __skip; | 677 | goto __skip; |
708 | isapnp_parse_mem_resource(dev, option, size); | 678 | isapnp_parse_mem_resource(dev, option_flags, size); |
709 | size = 0; | 679 | size = 0; |
710 | break; | 680 | break; |
711 | case _LTAG_ANSISTR: | 681 | case _LTAG_ANSISTR: |
@@ -720,13 +690,14 @@ static int __init isapnp_create_device(struct pnp_card *card, | |||
720 | case _LTAG_MEM32RANGE: | 690 | case _LTAG_MEM32RANGE: |
721 | if (size != 17) | 691 | if (size != 17) |
722 | goto __skip; | 692 | goto __skip; |
723 | isapnp_parse_mem32_resource(dev, option, size); | 693 | isapnp_parse_mem32_resource(dev, option_flags, size); |
724 | size = 0; | 694 | size = 0; |
725 | break; | 695 | break; |
726 | case _LTAG_FIXEDMEM32RANGE: | 696 | case _LTAG_FIXEDMEM32RANGE: |
727 | if (size != 9) | 697 | if (size != 9) |
728 | goto __skip; | 698 | goto __skip; |
729 | isapnp_parse_fixed_mem32_resource(dev, option, size); | 699 | isapnp_parse_fixed_mem32_resource(dev, option_flags, |
700 | size); | ||
730 | size = 0; | 701 | size = 0; |
731 | break; | 702 | break; |
732 | case _STAG_END: | 703 | case _STAG_END: |
@@ -928,7 +899,6 @@ EXPORT_SYMBOL(isapnp_write_byte); | |||
928 | 899 | ||
929 | static int isapnp_get_resources(struct pnp_dev *dev) | 900 | static int isapnp_get_resources(struct pnp_dev *dev) |
930 | { | 901 | { |
931 | struct pnp_resource *pnp_res; | ||
932 | int i, ret; | 902 | int i, ret; |
933 | 903 | ||
934 | dev_dbg(&dev->dev, "get resources\n"); | 904 | dev_dbg(&dev->dev, "get resources\n"); |
@@ -940,35 +910,23 @@ static int isapnp_get_resources(struct pnp_dev *dev) | |||
940 | 910 | ||
941 | for (i = 0; i < ISAPNP_MAX_PORT; i++) { | 911 | for (i = 0; i < ISAPNP_MAX_PORT; i++) { |
942 | ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1)); | 912 | ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1)); |
943 | if (ret) { | 913 | pnp_add_io_resource(dev, ret, ret, |
944 | pnp_res = pnp_add_io_resource(dev, ret, ret, 0); | 914 | ret == 0 ? IORESOURCE_DISABLED : 0); |
945 | if (pnp_res) | ||
946 | pnp_res->index = i; | ||
947 | } | ||
948 | } | 915 | } |
949 | for (i = 0; i < ISAPNP_MAX_MEM; i++) { | 916 | for (i = 0; i < ISAPNP_MAX_MEM; i++) { |
950 | ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8; | 917 | ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8; |
951 | if (ret) { | 918 | pnp_add_mem_resource(dev, ret, ret, |
952 | pnp_res = pnp_add_mem_resource(dev, ret, ret, 0); | 919 | ret == 0 ? IORESOURCE_DISABLED : 0); |
953 | if (pnp_res) | ||
954 | pnp_res->index = i; | ||
955 | } | ||
956 | } | 920 | } |
957 | for (i = 0; i < ISAPNP_MAX_IRQ; i++) { | 921 | for (i = 0; i < ISAPNP_MAX_IRQ; i++) { |
958 | ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8; | 922 | ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8; |
959 | if (ret) { | 923 | pnp_add_irq_resource(dev, ret, |
960 | pnp_res = pnp_add_irq_resource(dev, ret, 0); | 924 | ret == 0 ? IORESOURCE_DISABLED : 0); |
961 | if (pnp_res) | ||
962 | pnp_res->index = i; | ||
963 | } | ||
964 | } | 925 | } |
965 | for (i = 0; i < ISAPNP_MAX_DMA; i++) { | 926 | for (i = 0; i < ISAPNP_MAX_DMA; i++) { |
966 | ret = isapnp_read_byte(ISAPNP_CFG_DMA + i); | 927 | ret = isapnp_read_byte(ISAPNP_CFG_DMA + i); |
967 | if (ret != 4) { | 928 | pnp_add_dma_resource(dev, ret, |
968 | pnp_res = pnp_add_dma_resource(dev, ret, 0); | 929 | ret == 4 ? IORESOURCE_DISABLED : 0); |
969 | if (pnp_res) | ||
970 | pnp_res->index = i; | ||
971 | } | ||
972 | } | 930 | } |
973 | 931 | ||
974 | __end: | 932 | __end: |
@@ -978,62 +936,45 @@ __end: | |||
978 | 936 | ||
979 | static int isapnp_set_resources(struct pnp_dev *dev) | 937 | static int isapnp_set_resources(struct pnp_dev *dev) |
980 | { | 938 | { |
981 | struct pnp_resource *pnp_res; | ||
982 | struct resource *res; | 939 | struct resource *res; |
983 | int tmp, index; | 940 | int tmp; |
984 | 941 | ||
985 | dev_dbg(&dev->dev, "set resources\n"); | 942 | dev_dbg(&dev->dev, "set resources\n"); |
986 | isapnp_cfg_begin(dev->card->number, dev->number); | 943 | isapnp_cfg_begin(dev->card->number, dev->number); |
987 | dev->active = 1; | 944 | dev->active = 1; |
988 | for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { | 945 | for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { |
989 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, tmp); | 946 | res = pnp_get_resource(dev, IORESOURCE_IO, tmp); |
990 | if (!pnp_res) | 947 | if (pnp_resource_enabled(res)) { |
991 | continue; | ||
992 | res = &pnp_res->res; | ||
993 | if (pnp_resource_valid(res)) { | ||
994 | index = pnp_res->index; | ||
995 | dev_dbg(&dev->dev, " set io %d to %#llx\n", | 948 | dev_dbg(&dev->dev, " set io %d to %#llx\n", |
996 | index, (unsigned long long) res->start); | 949 | tmp, (unsigned long long) res->start); |
997 | isapnp_write_word(ISAPNP_CFG_PORT + (index << 1), | 950 | isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1), |
998 | res->start); | 951 | res->start); |
999 | } | 952 | } |
1000 | } | 953 | } |
1001 | for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { | 954 | for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { |
1002 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, tmp); | 955 | res = pnp_get_resource(dev, IORESOURCE_IRQ, tmp); |
1003 | if (!pnp_res) | 956 | if (pnp_resource_enabled(res)) { |
1004 | continue; | ||
1005 | res = &pnp_res->res; | ||
1006 | if (pnp_resource_valid(res)) { | ||
1007 | int irq = res->start; | 957 | int irq = res->start; |
1008 | if (irq == 2) | 958 | if (irq == 2) |
1009 | irq = 9; | 959 | irq = 9; |
1010 | index = pnp_res->index; | 960 | dev_dbg(&dev->dev, " set irq %d to %d\n", tmp, irq); |
1011 | dev_dbg(&dev->dev, " set irq %d to %d\n", index, irq); | 961 | isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq); |
1012 | isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq); | ||
1013 | } | 962 | } |
1014 | } | 963 | } |
1015 | for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { | 964 | for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { |
1016 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, tmp); | 965 | res = pnp_get_resource(dev, IORESOURCE_DMA, tmp); |
1017 | if (!pnp_res) | 966 | if (pnp_resource_enabled(res)) { |
1018 | continue; | ||
1019 | res = &pnp_res->res; | ||
1020 | if (pnp_resource_valid(res)) { | ||
1021 | index = pnp_res->index; | ||
1022 | dev_dbg(&dev->dev, " set dma %d to %lld\n", | 967 | dev_dbg(&dev->dev, " set dma %d to %lld\n", |
1023 | index, (unsigned long long) res->start); | 968 | tmp, (unsigned long long) res->start); |
1024 | isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start); | 969 | isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start); |
1025 | } | 970 | } |
1026 | } | 971 | } |
1027 | for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { | 972 | for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { |
1028 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, tmp); | 973 | res = pnp_get_resource(dev, IORESOURCE_MEM, tmp); |
1029 | if (!pnp_res) | 974 | if (pnp_resource_enabled(res)) { |
1030 | continue; | ||
1031 | res = &pnp_res->res; | ||
1032 | if (pnp_resource_valid(res)) { | ||
1033 | index = pnp_res->index; | ||
1034 | dev_dbg(&dev->dev, " set mem %d to %#llx\n", | 975 | dev_dbg(&dev->dev, " set mem %d to %#llx\n", |
1035 | index, (unsigned long long) res->start); | 976 | tmp, (unsigned long long) res->start); |
1036 | isapnp_write_word(ISAPNP_CFG_MEM + (index << 3), | 977 | isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3), |
1037 | (res->start >> 8) & 0xffff); | 978 | (res->start >> 8) & 0xffff); |
1038 | } | 979 | } |
1039 | } | 980 | } |
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c index bea0914ff947..b526eaad3f6c 100644 --- a/drivers/pnp/manager.c +++ b/drivers/pnp/manager.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * | 3 | * |
4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> | 4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> |
5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> | 5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
6 | */ | 8 | */ |
7 | 9 | ||
8 | #include <linux/errno.h> | 10 | #include <linux/errno.h> |
@@ -19,82 +21,64 @@ DEFINE_MUTEX(pnp_res_mutex); | |||
19 | 21 | ||
20 | static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) | 22 | static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) |
21 | { | 23 | { |
22 | struct pnp_resource *pnp_res; | 24 | struct resource *res, local_res; |
23 | struct resource *res; | ||
24 | |||
25 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, idx); | ||
26 | if (!pnp_res) { | ||
27 | dev_err(&dev->dev, "too many I/O port resources\n"); | ||
28 | /* pretend we were successful so at least the manager won't try again */ | ||
29 | return 1; | ||
30 | } | ||
31 | |||
32 | res = &pnp_res->res; | ||
33 | 25 | ||
34 | /* check if this resource has been manually set, if so skip */ | 26 | res = pnp_get_resource(dev, IORESOURCE_IO, idx); |
35 | if (!(res->flags & IORESOURCE_AUTO)) { | 27 | if (res) { |
36 | dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " | 28 | dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " |
37 | "flags %#lx\n", idx, (unsigned long long) res->start, | 29 | "flags %#lx\n", idx, (unsigned long long) res->start, |
38 | (unsigned long long) res->end, res->flags); | 30 | (unsigned long long) res->end, res->flags); |
39 | return 1; | 31 | return 0; |
40 | } | 32 | } |
41 | 33 | ||
42 | /* set the initial values */ | 34 | res = &local_res; |
43 | pnp_res->index = idx; | 35 | res->flags = rule->flags | IORESOURCE_AUTO; |
44 | res->flags |= rule->flags | IORESOURCE_IO; | 36 | res->start = 0; |
45 | res->flags &= ~IORESOURCE_UNSET; | 37 | res->end = 0; |
46 | 38 | ||
47 | if (!rule->size) { | 39 | if (!rule->size) { |
48 | res->flags |= IORESOURCE_DISABLED; | 40 | res->flags |= IORESOURCE_DISABLED; |
49 | dev_dbg(&dev->dev, " io %d disabled\n", idx); | 41 | dev_dbg(&dev->dev, " io %d disabled\n", idx); |
50 | return 1; /* skip disabled resource requests */ | 42 | goto __add; |
51 | } | 43 | } |
52 | 44 | ||
53 | res->start = rule->min; | 45 | res->start = rule->min; |
54 | res->end = res->start + rule->size - 1; | 46 | res->end = res->start + rule->size - 1; |
55 | 47 | ||
56 | /* run through until pnp_check_port is happy */ | ||
57 | while (!pnp_check_port(dev, res)) { | 48 | while (!pnp_check_port(dev, res)) { |
58 | res->start += rule->align; | 49 | res->start += rule->align; |
59 | res->end = res->start + rule->size - 1; | 50 | res->end = res->start + rule->size - 1; |
60 | if (res->start > rule->max || !rule->align) { | 51 | if (res->start > rule->max || !rule->align) { |
61 | dev_dbg(&dev->dev, " couldn't assign io %d\n", idx); | 52 | dev_dbg(&dev->dev, " couldn't assign io %d " |
62 | return 0; | 53 | "(min %#llx max %#llx)\n", idx, |
54 | (unsigned long long) rule->min, | ||
55 | (unsigned long long) rule->max); | ||
56 | return -EBUSY; | ||
63 | } | 57 | } |
64 | } | 58 | } |
65 | dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx, | 59 | |
66 | (unsigned long long) res->start, (unsigned long long) res->end); | 60 | __add: |
67 | return 1; | 61 | pnp_add_io_resource(dev, res->start, res->end, res->flags); |
62 | return 0; | ||
68 | } | 63 | } |
69 | 64 | ||
70 | static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) | 65 | static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) |
71 | { | 66 | { |
72 | struct pnp_resource *pnp_res; | 67 | struct resource *res, local_res; |
73 | struct resource *res; | ||
74 | |||
75 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, idx); | ||
76 | if (!pnp_res) { | ||
77 | dev_err(&dev->dev, "too many memory resources\n"); | ||
78 | /* pretend we were successful so at least the manager won't try again */ | ||
79 | return 1; | ||
80 | } | ||
81 | 68 | ||
82 | res = &pnp_res->res; | 69 | res = pnp_get_resource(dev, IORESOURCE_MEM, idx); |
83 | 70 | if (res) { | |
84 | /* check if this resource has been manually set, if so skip */ | ||
85 | if (!(res->flags & IORESOURCE_AUTO)) { | ||
86 | dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " | 71 | dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " |
87 | "flags %#lx\n", idx, (unsigned long long) res->start, | 72 | "flags %#lx\n", idx, (unsigned long long) res->start, |
88 | (unsigned long long) res->end, res->flags); | 73 | (unsigned long long) res->end, res->flags); |
89 | return 1; | 74 | return 0; |
90 | } | 75 | } |
91 | 76 | ||
92 | /* set the initial values */ | 77 | res = &local_res; |
93 | pnp_res->index = idx; | 78 | res->flags = rule->flags | IORESOURCE_AUTO; |
94 | res->flags |= rule->flags | IORESOURCE_MEM; | 79 | res->start = 0; |
95 | res->flags &= ~IORESOURCE_UNSET; | 80 | res->end = 0; |
96 | 81 | ||
97 | /* convert pnp flags to standard Linux flags */ | ||
98 | if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) | 82 | if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) |
99 | res->flags |= IORESOURCE_READONLY; | 83 | res->flags |= IORESOURCE_READONLY; |
100 | if (rule->flags & IORESOURCE_MEM_CACHEABLE) | 84 | if (rule->flags & IORESOURCE_MEM_CACHEABLE) |
@@ -107,30 +91,32 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) | |||
107 | if (!rule->size) { | 91 | if (!rule->size) { |
108 | res->flags |= IORESOURCE_DISABLED; | 92 | res->flags |= IORESOURCE_DISABLED; |
109 | dev_dbg(&dev->dev, " mem %d disabled\n", idx); | 93 | dev_dbg(&dev->dev, " mem %d disabled\n", idx); |
110 | return 1; /* skip disabled resource requests */ | 94 | goto __add; |
111 | } | 95 | } |
112 | 96 | ||
113 | res->start = rule->min; | 97 | res->start = rule->min; |
114 | res->end = res->start + rule->size - 1; | 98 | res->end = res->start + rule->size - 1; |
115 | 99 | ||
116 | /* run through until pnp_check_mem is happy */ | ||
117 | while (!pnp_check_mem(dev, res)) { | 100 | while (!pnp_check_mem(dev, res)) { |
118 | res->start += rule->align; | 101 | res->start += rule->align; |
119 | res->end = res->start + rule->size - 1; | 102 | res->end = res->start + rule->size - 1; |
120 | if (res->start > rule->max || !rule->align) { | 103 | if (res->start > rule->max || !rule->align) { |
121 | dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx); | 104 | dev_dbg(&dev->dev, " couldn't assign mem %d " |
122 | return 0; | 105 | "(min %#llx max %#llx)\n", idx, |
106 | (unsigned long long) rule->min, | ||
107 | (unsigned long long) rule->max); | ||
108 | return -EBUSY; | ||
123 | } | 109 | } |
124 | } | 110 | } |
125 | dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx, | 111 | |
126 | (unsigned long long) res->start, (unsigned long long) res->end); | 112 | __add: |
127 | return 1; | 113 | pnp_add_mem_resource(dev, res->start, res->end, res->flags); |
114 | return 0; | ||
128 | } | 115 | } |
129 | 116 | ||
130 | static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) | 117 | static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) |
131 | { | 118 | { |
132 | struct pnp_resource *pnp_res; | 119 | struct resource *res, local_res; |
133 | struct resource *res; | ||
134 | int i; | 120 | int i; |
135 | 121 | ||
136 | /* IRQ priority: this table is good for i386 */ | 122 | /* IRQ priority: this table is good for i386 */ |
@@ -138,59 +124,57 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) | |||
138 | 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 | 124 | 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 |
139 | }; | 125 | }; |
140 | 126 | ||
141 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, idx); | 127 | res = pnp_get_resource(dev, IORESOURCE_IRQ, idx); |
142 | if (!pnp_res) { | 128 | if (res) { |
143 | dev_err(&dev->dev, "too many IRQ resources\n"); | ||
144 | /* pretend we were successful so at least the manager won't try again */ | ||
145 | return 1; | ||
146 | } | ||
147 | |||
148 | res = &pnp_res->res; | ||
149 | |||
150 | /* check if this resource has been manually set, if so skip */ | ||
151 | if (!(res->flags & IORESOURCE_AUTO)) { | ||
152 | dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", | 129 | dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", |
153 | idx, (int) res->start, res->flags); | 130 | idx, (int) res->start, res->flags); |
154 | return 1; | 131 | return 0; |
155 | } | 132 | } |
156 | 133 | ||
157 | /* set the initial values */ | 134 | res = &local_res; |
158 | pnp_res->index = idx; | 135 | res->flags = rule->flags | IORESOURCE_AUTO; |
159 | res->flags |= rule->flags | IORESOURCE_IRQ; | 136 | res->start = -1; |
160 | res->flags &= ~IORESOURCE_UNSET; | 137 | res->end = -1; |
161 | 138 | ||
162 | if (bitmap_empty(rule->map, PNP_IRQ_NR)) { | 139 | if (bitmap_empty(rule->map.bits, PNP_IRQ_NR)) { |
163 | res->flags |= IORESOURCE_DISABLED; | 140 | res->flags |= IORESOURCE_DISABLED; |
164 | dev_dbg(&dev->dev, " irq %d disabled\n", idx); | 141 | dev_dbg(&dev->dev, " irq %d disabled\n", idx); |
165 | return 1; /* skip disabled resource requests */ | 142 | goto __add; |
166 | } | 143 | } |
167 | 144 | ||
168 | /* TBD: need check for >16 IRQ */ | 145 | /* TBD: need check for >16 IRQ */ |
169 | res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16); | 146 | res->start = find_next_bit(rule->map.bits, PNP_IRQ_NR, 16); |
170 | if (res->start < PNP_IRQ_NR) { | 147 | if (res->start < PNP_IRQ_NR) { |
171 | res->end = res->start; | 148 | res->end = res->start; |
172 | dev_dbg(&dev->dev, " assign irq %d %d\n", idx, | 149 | goto __add; |
173 | (int) res->start); | ||
174 | return 1; | ||
175 | } | 150 | } |
176 | for (i = 0; i < 16; i++) { | 151 | for (i = 0; i < 16; i++) { |
177 | if (test_bit(xtab[i], rule->map)) { | 152 | if (test_bit(xtab[i], rule->map.bits)) { |
178 | res->start = res->end = xtab[i]; | 153 | res->start = res->end = xtab[i]; |
179 | if (pnp_check_irq(dev, res)) { | 154 | if (pnp_check_irq(dev, res)) |
180 | dev_dbg(&dev->dev, " assign irq %d %d\n", idx, | 155 | goto __add; |
181 | (int) res->start); | ||
182 | return 1; | ||
183 | } | ||
184 | } | 156 | } |
185 | } | 157 | } |
158 | |||
159 | if (rule->flags & IORESOURCE_IRQ_OPTIONAL) { | ||
160 | res->start = -1; | ||
161 | res->end = -1; | ||
162 | res->flags |= IORESOURCE_DISABLED; | ||
163 | dev_dbg(&dev->dev, " irq %d disabled (optional)\n", idx); | ||
164 | goto __add; | ||
165 | } | ||
166 | |||
186 | dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); | 167 | dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); |
168 | return -EBUSY; | ||
169 | |||
170 | __add: | ||
171 | pnp_add_irq_resource(dev, res->start, res->flags); | ||
187 | return 0; | 172 | return 0; |
188 | } | 173 | } |
189 | 174 | ||
190 | static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) | 175 | static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) |
191 | { | 176 | { |
192 | struct pnp_resource *pnp_res; | 177 | struct resource *res, local_res; |
193 | struct resource *res; | ||
194 | int i; | 178 | int i; |
195 | 179 | ||
196 | /* DMA priority: this table is good for i386 */ | 180 | /* DMA priority: this table is good for i386 */ |
@@ -198,231 +182,99 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) | |||
198 | 1, 3, 5, 6, 7, 0, 2, 4 | 182 | 1, 3, 5, 6, 7, 0, 2, 4 |
199 | }; | 183 | }; |
200 | 184 | ||
201 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, idx); | 185 | res = pnp_get_resource(dev, IORESOURCE_DMA, idx); |
202 | if (!pnp_res) { | 186 | if (res) { |
203 | dev_err(&dev->dev, "too many DMA resources\n"); | ||
204 | return; | ||
205 | } | ||
206 | |||
207 | res = &pnp_res->res; | ||
208 | |||
209 | /* check if this resource has been manually set, if so skip */ | ||
210 | if (!(res->flags & IORESOURCE_AUTO)) { | ||
211 | dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", | 187 | dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", |
212 | idx, (int) res->start, res->flags); | 188 | idx, (int) res->start, res->flags); |
213 | return; | 189 | return 0; |
214 | } | 190 | } |
215 | 191 | ||
216 | /* set the initial values */ | 192 | res = &local_res; |
217 | pnp_res->index = idx; | 193 | res->flags = rule->flags | IORESOURCE_AUTO; |
218 | res->flags |= rule->flags | IORESOURCE_DMA; | 194 | res->start = -1; |
219 | res->flags &= ~IORESOURCE_UNSET; | 195 | res->end = -1; |
220 | 196 | ||
221 | for (i = 0; i < 8; i++) { | 197 | for (i = 0; i < 8; i++) { |
222 | if (rule->map & (1 << xtab[i])) { | 198 | if (rule->map & (1 << xtab[i])) { |
223 | res->start = res->end = xtab[i]; | 199 | res->start = res->end = xtab[i]; |
224 | if (pnp_check_dma(dev, res)) { | 200 | if (pnp_check_dma(dev, res)) |
225 | dev_dbg(&dev->dev, " assign dma %d %d\n", idx, | 201 | goto __add; |
226 | (int) res->start); | ||
227 | return; | ||
228 | } | ||
229 | } | 202 | } |
230 | } | 203 | } |
231 | #ifdef MAX_DMA_CHANNELS | 204 | #ifdef MAX_DMA_CHANNELS |
232 | res->start = res->end = MAX_DMA_CHANNELS; | 205 | res->start = res->end = MAX_DMA_CHANNELS; |
233 | #endif | 206 | #endif |
234 | res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; | 207 | res->flags |= IORESOURCE_DISABLED; |
235 | dev_dbg(&dev->dev, " disable dma %d\n", idx); | 208 | dev_dbg(&dev->dev, " disable dma %d\n", idx); |
236 | } | ||
237 | |||
238 | void pnp_init_resource(struct resource *res) | ||
239 | { | ||
240 | unsigned long type; | ||
241 | |||
242 | type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM | | ||
243 | IORESOURCE_IRQ | IORESOURCE_DMA); | ||
244 | 209 | ||
245 | res->name = NULL; | 210 | __add: |
246 | res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET; | 211 | pnp_add_dma_resource(dev, res->start, res->flags); |
247 | if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) { | 212 | return 0; |
248 | res->start = -1; | ||
249 | res->end = -1; | ||
250 | } else { | ||
251 | res->start = 0; | ||
252 | res->end = 0; | ||
253 | } | ||
254 | } | 213 | } |
255 | 214 | ||
256 | /** | ||
257 | * pnp_init_resources - Resets a resource table to default values. | ||
258 | * @table: pointer to the desired resource table | ||
259 | */ | ||
260 | void pnp_init_resources(struct pnp_dev *dev) | 215 | void pnp_init_resources(struct pnp_dev *dev) |
261 | { | 216 | { |
262 | struct resource *res; | 217 | pnp_free_resources(dev); |
263 | int idx; | ||
264 | |||
265 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { | ||
266 | res = &dev->res->irq[idx].res; | ||
267 | res->flags = IORESOURCE_IRQ; | ||
268 | pnp_init_resource(res); | ||
269 | } | ||
270 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { | ||
271 | res = &dev->res->dma[idx].res; | ||
272 | res->flags = IORESOURCE_DMA; | ||
273 | pnp_init_resource(res); | ||
274 | } | ||
275 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { | ||
276 | res = &dev->res->port[idx].res; | ||
277 | res->flags = IORESOURCE_IO; | ||
278 | pnp_init_resource(res); | ||
279 | } | ||
280 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { | ||
281 | res = &dev->res->mem[idx].res; | ||
282 | res->flags = IORESOURCE_MEM; | ||
283 | pnp_init_resource(res); | ||
284 | } | ||
285 | } | 218 | } |
286 | 219 | ||
287 | /** | ||
288 | * pnp_clean_resources - clears resources that were not manually set | ||
289 | * @res: the resources to clean | ||
290 | */ | ||
291 | static void pnp_clean_resource_table(struct pnp_dev *dev) | 220 | static void pnp_clean_resource_table(struct pnp_dev *dev) |
292 | { | 221 | { |
293 | struct resource *res; | 222 | struct pnp_resource *pnp_res, *tmp; |
294 | int idx; | 223 | |
295 | 224 | list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) { | |
296 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { | 225 | if (pnp_res->res.flags & IORESOURCE_AUTO) |
297 | res = &dev->res->irq[idx].res; | 226 | pnp_free_resource(pnp_res); |
298 | if (res->flags & IORESOURCE_AUTO) { | ||
299 | res->flags = IORESOURCE_IRQ; | ||
300 | pnp_init_resource(res); | ||
301 | } | ||
302 | } | ||
303 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { | ||
304 | res = &dev->res->dma[idx].res; | ||
305 | if (res->flags & IORESOURCE_AUTO) { | ||
306 | res->flags = IORESOURCE_DMA; | ||
307 | pnp_init_resource(res); | ||
308 | } | ||
309 | } | ||
310 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { | ||
311 | res = &dev->res->port[idx].res; | ||
312 | if (res->flags & IORESOURCE_AUTO) { | ||
313 | res->flags = IORESOURCE_IO; | ||
314 | pnp_init_resource(res); | ||
315 | } | ||
316 | } | ||
317 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { | ||
318 | res = &dev->res->mem[idx].res; | ||
319 | if (res->flags & IORESOURCE_AUTO) { | ||
320 | res->flags = IORESOURCE_MEM; | ||
321 | pnp_init_resource(res); | ||
322 | } | ||
323 | } | 227 | } |
324 | } | 228 | } |
325 | 229 | ||
326 | /** | 230 | /** |
327 | * pnp_assign_resources - assigns resources to the device based on the specified dependent number | 231 | * pnp_assign_resources - assigns resources to the device based on the specified dependent number |
328 | * @dev: pointer to the desired device | 232 | * @dev: pointer to the desired device |
329 | * @depnum: the dependent function number | 233 | * @set: the dependent function number |
330 | * | ||
331 | * Only set depnum to 0 if the device does not have dependent options. | ||
332 | */ | 234 | */ |
333 | static int pnp_assign_resources(struct pnp_dev *dev, int depnum) | 235 | static int pnp_assign_resources(struct pnp_dev *dev, int set) |
334 | { | 236 | { |
335 | struct pnp_port *port; | 237 | struct pnp_option *option; |
336 | struct pnp_mem *mem; | ||
337 | struct pnp_irq *irq; | ||
338 | struct pnp_dma *dma; | ||
339 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; | 238 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; |
239 | int ret = 0; | ||
340 | 240 | ||
341 | if (!pnp_can_configure(dev)) | 241 | dev_dbg(&dev->dev, "pnp_assign_resources, try dependent set %d\n", set); |
342 | return -ENODEV; | ||
343 | |||
344 | dbg_pnp_show_resources(dev, "before pnp_assign_resources"); | ||
345 | mutex_lock(&pnp_res_mutex); | 242 | mutex_lock(&pnp_res_mutex); |
346 | pnp_clean_resource_table(dev); | 243 | pnp_clean_resource_table(dev); |
347 | if (dev->independent) { | ||
348 | dev_dbg(&dev->dev, "assigning independent options\n"); | ||
349 | port = dev->independent->port; | ||
350 | mem = dev->independent->mem; | ||
351 | irq = dev->independent->irq; | ||
352 | dma = dev->independent->dma; | ||
353 | while (port) { | ||
354 | if (!pnp_assign_port(dev, port, nport)) | ||
355 | goto fail; | ||
356 | nport++; | ||
357 | port = port->next; | ||
358 | } | ||
359 | while (mem) { | ||
360 | if (!pnp_assign_mem(dev, mem, nmem)) | ||
361 | goto fail; | ||
362 | nmem++; | ||
363 | mem = mem->next; | ||
364 | } | ||
365 | while (irq) { | ||
366 | if (!pnp_assign_irq(dev, irq, nirq)) | ||
367 | goto fail; | ||
368 | nirq++; | ||
369 | irq = irq->next; | ||
370 | } | ||
371 | while (dma) { | ||
372 | pnp_assign_dma(dev, dma, ndma); | ||
373 | ndma++; | ||
374 | dma = dma->next; | ||
375 | } | ||
376 | } | ||
377 | 244 | ||
378 | if (depnum) { | 245 | list_for_each_entry(option, &dev->options, list) { |
379 | struct pnp_option *dep; | 246 | if (pnp_option_is_dependent(option) && |
380 | int i; | 247 | pnp_option_set(option) != set) |
381 | 248 | continue; | |
382 | dev_dbg(&dev->dev, "assigning dependent option %d\n", depnum); | 249 | |
383 | for (i = 1, dep = dev->dependent; i < depnum; | 250 | switch (option->type) { |
384 | i++, dep = dep->next) | 251 | case IORESOURCE_IO: |
385 | if (!dep) | 252 | ret = pnp_assign_port(dev, &option->u.port, nport++); |
386 | goto fail; | 253 | break; |
387 | port = dep->port; | 254 | case IORESOURCE_MEM: |
388 | mem = dep->mem; | 255 | ret = pnp_assign_mem(dev, &option->u.mem, nmem++); |
389 | irq = dep->irq; | 256 | break; |
390 | dma = dep->dma; | 257 | case IORESOURCE_IRQ: |
391 | while (port) { | 258 | ret = pnp_assign_irq(dev, &option->u.irq, nirq++); |
392 | if (!pnp_assign_port(dev, port, nport)) | 259 | break; |
393 | goto fail; | 260 | case IORESOURCE_DMA: |
394 | nport++; | 261 | ret = pnp_assign_dma(dev, &option->u.dma, ndma++); |
395 | port = port->next; | 262 | break; |
396 | } | 263 | default: |
397 | while (mem) { | 264 | ret = -EINVAL; |
398 | if (!pnp_assign_mem(dev, mem, nmem)) | 265 | break; |
399 | goto fail; | ||
400 | nmem++; | ||
401 | mem = mem->next; | ||
402 | } | ||
403 | while (irq) { | ||
404 | if (!pnp_assign_irq(dev, irq, nirq)) | ||
405 | goto fail; | ||
406 | nirq++; | ||
407 | irq = irq->next; | ||
408 | } | 266 | } |
409 | while (dma) { | 267 | if (ret < 0) |
410 | pnp_assign_dma(dev, dma, ndma); | 268 | break; |
411 | ndma++; | 269 | } |
412 | dma = dma->next; | ||
413 | } | ||
414 | } else if (dev->dependent) | ||
415 | goto fail; | ||
416 | |||
417 | mutex_unlock(&pnp_res_mutex); | ||
418 | dbg_pnp_show_resources(dev, "after pnp_assign_resources"); | ||
419 | return 1; | ||
420 | 270 | ||
421 | fail: | ||
422 | pnp_clean_resource_table(dev); | ||
423 | mutex_unlock(&pnp_res_mutex); | 271 | mutex_unlock(&pnp_res_mutex); |
424 | dbg_pnp_show_resources(dev, "after pnp_assign_resources (failed)"); | 272 | if (ret < 0) { |
425 | return 0; | 273 | dev_dbg(&dev->dev, "pnp_assign_resources failed (%d)\n", ret); |
274 | pnp_clean_resource_table(dev); | ||
275 | } else | ||
276 | dbg_pnp_show_resources(dev, "pnp_assign_resources succeeded"); | ||
277 | return ret; | ||
426 | } | 278 | } |
427 | 279 | ||
428 | /** | 280 | /** |
@@ -431,29 +283,25 @@ fail: | |||
431 | */ | 283 | */ |
432 | int pnp_auto_config_dev(struct pnp_dev *dev) | 284 | int pnp_auto_config_dev(struct pnp_dev *dev) |
433 | { | 285 | { |
434 | struct pnp_option *dep; | 286 | int i, ret; |
435 | int i = 1; | ||
436 | 287 | ||
437 | if (!pnp_can_configure(dev)) { | 288 | if (!pnp_can_configure(dev)) { |
438 | dev_dbg(&dev->dev, "configuration not supported\n"); | 289 | dev_dbg(&dev->dev, "configuration not supported\n"); |
439 | return -ENODEV; | 290 | return -ENODEV; |
440 | } | 291 | } |
441 | 292 | ||
442 | if (!dev->dependent) { | 293 | ret = pnp_assign_resources(dev, 0); |
443 | if (pnp_assign_resources(dev, 0)) | 294 | if (ret == 0) |
295 | return 0; | ||
296 | |||
297 | for (i = 1; i < dev->num_dependent_sets; i++) { | ||
298 | ret = pnp_assign_resources(dev, i); | ||
299 | if (ret == 0) | ||
444 | return 0; | 300 | return 0; |
445 | } else { | ||
446 | dep = dev->dependent; | ||
447 | do { | ||
448 | if (pnp_assign_resources(dev, i)) | ||
449 | return 0; | ||
450 | dep = dep->next; | ||
451 | i++; | ||
452 | } while (dep); | ||
453 | } | 301 | } |
454 | 302 | ||
455 | dev_err(&dev->dev, "unable to assign resources\n"); | 303 | dev_err(&dev->dev, "unable to assign resources\n"); |
456 | return -EBUSY; | 304 | return ret; |
457 | } | 305 | } |
458 | 306 | ||
459 | /** | 307 | /** |
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 50902773beaf..c1b9ea34977b 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c | |||
@@ -117,9 +117,7 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) | |||
117 | { | 117 | { |
118 | int power_state; | 118 | int power_state; |
119 | 119 | ||
120 | power_state = acpi_pm_device_sleep_state(&dev->dev, | 120 | power_state = acpi_pm_device_sleep_state(&dev->dev, NULL); |
121 | device_may_wakeup(&dev->dev), | ||
122 | NULL); | ||
123 | if (power_state < 0) | 121 | if (power_state < 0) |
124 | power_state = (state.event == PM_EVENT_ON) ? | 122 | power_state = (state.event == PM_EVENT_ON) ? |
125 | ACPI_STATE_D0 : ACPI_STATE_D3; | 123 | ACPI_STATE_D0 : ACPI_STATE_D3; |
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index 46c791adb894..d7e9f2152df0 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * | 3 | * |
4 | * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr> | 4 | * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr> |
5 | * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com> | 5 | * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com> |
6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
6 | * | 8 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 9 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU General Public License as published by the | 10 | * under the terms of the GNU General Public License as published by the |
@@ -98,8 +100,10 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev, | |||
98 | int irq, flags; | 100 | int irq, flags; |
99 | int p, t; | 101 | int p, t; |
100 | 102 | ||
101 | if (!valid_IRQ(gsi)) | 103 | if (!valid_IRQ(gsi)) { |
104 | pnp_add_irq_resource(dev, gsi, IORESOURCE_DISABLED); | ||
102 | return; | 105 | return; |
106 | } | ||
103 | 107 | ||
104 | /* | 108 | /* |
105 | * in IO-APIC mode, use overrided attribute. Two reasons: | 109 | * in IO-APIC mode, use overrided attribute. Two reasons: |
@@ -178,13 +182,68 @@ static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start, | |||
178 | u64 end = start + len - 1; | 182 | u64 end = start + len - 1; |
179 | 183 | ||
180 | if (io_decode == ACPI_DECODE_16) | 184 | if (io_decode == ACPI_DECODE_16) |
181 | flags |= PNP_PORT_FLAG_16BITADDR; | 185 | flags |= IORESOURCE_IO_16BIT_ADDR; |
182 | if (len == 0 || end >= 0x10003) | 186 | if (len == 0 || end >= 0x10003) |
183 | flags |= IORESOURCE_DISABLED; | 187 | flags |= IORESOURCE_DISABLED; |
184 | 188 | ||
185 | pnp_add_io_resource(dev, start, end, flags); | 189 | pnp_add_io_resource(dev, start, end, flags); |
186 | } | 190 | } |
187 | 191 | ||
192 | /* | ||
193 | * Device CSRs that do not appear in PCI config space should be described | ||
194 | * via ACPI. This would normally be done with Address Space Descriptors | ||
195 | * marked as "consumer-only," but old versions of Windows and Linux ignore | ||
196 | * the producer/consumer flag, so HP invented a vendor-defined resource to | ||
197 | * describe the location and size of CSR space. | ||
198 | */ | ||
199 | static struct acpi_vendor_uuid hp_ccsr_uuid = { | ||
200 | .subtype = 2, | ||
201 | .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a, | ||
202 | 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad }, | ||
203 | }; | ||
204 | |||
205 | static int vendor_resource_matches(struct pnp_dev *dev, | ||
206 | struct acpi_resource_vendor_typed *vendor, | ||
207 | struct acpi_vendor_uuid *match, | ||
208 | int expected_len) | ||
209 | { | ||
210 | int uuid_len = sizeof(vendor->uuid); | ||
211 | u8 uuid_subtype = vendor->uuid_subtype; | ||
212 | u8 *uuid = vendor->uuid; | ||
213 | int actual_len; | ||
214 | |||
215 | /* byte_length includes uuid_subtype and uuid */ | ||
216 | actual_len = vendor->byte_length - uuid_len - 1; | ||
217 | |||
218 | if (uuid_subtype == match->subtype && | ||
219 | uuid_len == sizeof(match->data) && | ||
220 | memcmp(uuid, match->data, uuid_len) == 0) { | ||
221 | if (expected_len && expected_len != actual_len) { | ||
222 | dev_err(&dev->dev, "wrong vendor descriptor size; " | ||
223 | "expected %d, found %d bytes\n", | ||
224 | expected_len, actual_len); | ||
225 | return 0; | ||
226 | } | ||
227 | |||
228 | return 1; | ||
229 | } | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static void pnpacpi_parse_allocated_vendor(struct pnp_dev *dev, | ||
235 | struct acpi_resource_vendor_typed *vendor) | ||
236 | { | ||
237 | if (vendor_resource_matches(dev, vendor, &hp_ccsr_uuid, 16)) { | ||
238 | u64 start, length; | ||
239 | |||
240 | memcpy(&start, vendor->byte_data, sizeof(start)); | ||
241 | memcpy(&length, vendor->byte_data + 8, sizeof(length)); | ||
242 | |||
243 | pnp_add_mem_resource(dev, start, start + length - 1, 0); | ||
244 | } | ||
245 | } | ||
246 | |||
188 | static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, | 247 | static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, |
189 | u64 start, u64 len, | 248 | u64 start, u64 len, |
190 | int write_protect) | 249 | int write_protect) |
@@ -235,6 +294,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, | |||
235 | struct acpi_resource_dma *dma; | 294 | struct acpi_resource_dma *dma; |
236 | struct acpi_resource_io *io; | 295 | struct acpi_resource_io *io; |
237 | struct acpi_resource_fixed_io *fixed_io; | 296 | struct acpi_resource_fixed_io *fixed_io; |
297 | struct acpi_resource_vendor_typed *vendor_typed; | ||
238 | struct acpi_resource_memory24 *memory24; | 298 | struct acpi_resource_memory24 *memory24; |
239 | struct acpi_resource_memory32 *memory32; | 299 | struct acpi_resource_memory32 *memory32; |
240 | struct acpi_resource_fixed_memory32 *fixed_memory32; | 300 | struct acpi_resource_fixed_memory32 *fixed_memory32; |
@@ -248,24 +308,39 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, | |||
248 | * _CRS, but some firmware violates this, so parse them all. | 308 | * _CRS, but some firmware violates this, so parse them all. |
249 | */ | 309 | */ |
250 | irq = &res->data.irq; | 310 | irq = &res->data.irq; |
251 | for (i = 0; i < irq->interrupt_count; i++) { | 311 | if (irq->interrupt_count == 0) |
252 | pnpacpi_parse_allocated_irqresource(dev, | 312 | pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); |
253 | irq->interrupts[i], | 313 | else { |
254 | irq->triggering, | 314 | for (i = 0; i < irq->interrupt_count; i++) { |
255 | irq->polarity, | 315 | pnpacpi_parse_allocated_irqresource(dev, |
256 | irq->sharable); | 316 | irq->interrupts[i], |
317 | irq->triggering, | ||
318 | irq->polarity, | ||
319 | irq->sharable); | ||
320 | } | ||
321 | |||
322 | /* | ||
323 | * The IRQ encoder puts a single interrupt in each | ||
324 | * descriptor, so if a _CRS descriptor has more than | ||
325 | * one interrupt, we won't be able to re-encode it. | ||
326 | */ | ||
327 | if (pnp_can_write(dev) && irq->interrupt_count > 1) { | ||
328 | dev_warn(&dev->dev, "multiple interrupts in " | ||
329 | "_CRS descriptor; configuration can't " | ||
330 | "be changed\n"); | ||
331 | dev->capabilities &= ~PNP_WRITE; | ||
332 | } | ||
257 | } | 333 | } |
258 | break; | 334 | break; |
259 | 335 | ||
260 | case ACPI_RESOURCE_TYPE_DMA: | 336 | case ACPI_RESOURCE_TYPE_DMA: |
261 | dma = &res->data.dma; | 337 | dma = &res->data.dma; |
262 | if (dma->channel_count > 0) { | 338 | if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) |
263 | flags = dma_flags(dma->type, dma->bus_master, | 339 | flags = dma_flags(dma->type, dma->bus_master, |
264 | dma->transfer); | 340 | dma->transfer); |
265 | if (dma->channels[0] == (u8) -1) | 341 | else |
266 | flags |= IORESOURCE_DISABLED; | 342 | flags = IORESOURCE_DISABLED; |
267 | pnp_add_dma_resource(dev, dma->channels[0], flags); | 343 | pnp_add_dma_resource(dev, dma->channels[0], flags); |
268 | } | ||
269 | break; | 344 | break; |
270 | 345 | ||
271 | case ACPI_RESOURCE_TYPE_IO: | 346 | case ACPI_RESOURCE_TYPE_IO: |
@@ -289,6 +364,8 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, | |||
289 | break; | 364 | break; |
290 | 365 | ||
291 | case ACPI_RESOURCE_TYPE_VENDOR: | 366 | case ACPI_RESOURCE_TYPE_VENDOR: |
367 | vendor_typed = &res->data.vendor_typed; | ||
368 | pnpacpi_parse_allocated_vendor(dev, vendor_typed); | ||
292 | break; | 369 | break; |
293 | 370 | ||
294 | case ACPI_RESOURCE_TYPE_END_TAG: | 371 | case ACPI_RESOURCE_TYPE_END_TAG: |
@@ -331,12 +408,29 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, | |||
331 | if (extended_irq->producer_consumer == ACPI_PRODUCER) | 408 | if (extended_irq->producer_consumer == ACPI_PRODUCER) |
332 | return AE_OK; | 409 | return AE_OK; |
333 | 410 | ||
334 | for (i = 0; i < extended_irq->interrupt_count; i++) { | 411 | if (extended_irq->interrupt_count == 0) |
335 | pnpacpi_parse_allocated_irqresource(dev, | 412 | pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); |
336 | extended_irq->interrupts[i], | 413 | else { |
337 | extended_irq->triggering, | 414 | for (i = 0; i < extended_irq->interrupt_count; i++) { |
338 | extended_irq->polarity, | 415 | pnpacpi_parse_allocated_irqresource(dev, |
339 | extended_irq->sharable); | 416 | extended_irq->interrupts[i], |
417 | extended_irq->triggering, | ||
418 | extended_irq->polarity, | ||
419 | extended_irq->sharable); | ||
420 | } | ||
421 | |||
422 | /* | ||
423 | * The IRQ encoder puts a single interrupt in each | ||
424 | * descriptor, so if a _CRS descriptor has more than | ||
425 | * one interrupt, we won't be able to re-encode it. | ||
426 | */ | ||
427 | if (pnp_can_write(dev) && | ||
428 | extended_irq->interrupt_count > 1) { | ||
429 | dev_warn(&dev->dev, "multiple interrupts in " | ||
430 | "_CRS descriptor; configuration can't " | ||
431 | "be changed\n"); | ||
432 | dev->capabilities &= ~PNP_WRITE; | ||
433 | } | ||
340 | } | 434 | } |
341 | break; | 435 | break; |
342 | 436 | ||
@@ -373,179 +467,147 @@ int pnpacpi_parse_allocated_resource(struct pnp_dev *dev) | |||
373 | } | 467 | } |
374 | 468 | ||
375 | static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev, | 469 | static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev, |
376 | struct pnp_option *option, | 470 | unsigned int option_flags, |
377 | struct acpi_resource_dma *p) | 471 | struct acpi_resource_dma *p) |
378 | { | 472 | { |
379 | int i; | 473 | int i; |
380 | struct pnp_dma *dma; | 474 | unsigned char map = 0, flags; |
381 | 475 | ||
382 | if (p->channel_count == 0) | 476 | if (p->channel_count == 0) |
383 | return; | 477 | return; |
384 | dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); | ||
385 | if (!dma) | ||
386 | return; | ||
387 | 478 | ||
388 | for (i = 0; i < p->channel_count; i++) | 479 | for (i = 0; i < p->channel_count; i++) |
389 | dma->map |= 1 << p->channels[i]; | 480 | map |= 1 << p->channels[i]; |
390 | |||
391 | dma->flags = dma_flags(p->type, p->bus_master, p->transfer); | ||
392 | 481 | ||
393 | pnp_register_dma_resource(dev, option, dma); | 482 | flags = dma_flags(p->type, p->bus_master, p->transfer); |
483 | pnp_register_dma_resource(dev, option_flags, map, flags); | ||
394 | } | 484 | } |
395 | 485 | ||
396 | static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev, | 486 | static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev, |
397 | struct pnp_option *option, | 487 | unsigned int option_flags, |
398 | struct acpi_resource_irq *p) | 488 | struct acpi_resource_irq *p) |
399 | { | 489 | { |
400 | int i; | 490 | int i; |
401 | struct pnp_irq *irq; | 491 | pnp_irq_mask_t map; |
492 | unsigned char flags; | ||
402 | 493 | ||
403 | if (p->interrupt_count == 0) | 494 | if (p->interrupt_count == 0) |
404 | return; | 495 | return; |
405 | irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); | ||
406 | if (!irq) | ||
407 | return; | ||
408 | 496 | ||
497 | bitmap_zero(map.bits, PNP_IRQ_NR); | ||
409 | for (i = 0; i < p->interrupt_count; i++) | 498 | for (i = 0; i < p->interrupt_count; i++) |
410 | if (p->interrupts[i]) | 499 | if (p->interrupts[i]) |
411 | __set_bit(p->interrupts[i], irq->map); | 500 | __set_bit(p->interrupts[i], map.bits); |
412 | irq->flags = irq_flags(p->triggering, p->polarity, p->sharable); | ||
413 | 501 | ||
414 | pnp_register_irq_resource(dev, option, irq); | 502 | flags = irq_flags(p->triggering, p->polarity, p->sharable); |
503 | pnp_register_irq_resource(dev, option_flags, &map, flags); | ||
415 | } | 504 | } |
416 | 505 | ||
417 | static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev, | 506 | static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev, |
418 | struct pnp_option *option, | 507 | unsigned int option_flags, |
419 | struct acpi_resource_extended_irq *p) | 508 | struct acpi_resource_extended_irq *p) |
420 | { | 509 | { |
421 | int i; | 510 | int i; |
422 | struct pnp_irq *irq; | 511 | pnp_irq_mask_t map; |
512 | unsigned char flags; | ||
423 | 513 | ||
424 | if (p->interrupt_count == 0) | 514 | if (p->interrupt_count == 0) |
425 | return; | 515 | return; |
426 | irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); | ||
427 | if (!irq) | ||
428 | return; | ||
429 | 516 | ||
430 | for (i = 0; i < p->interrupt_count; i++) | 517 | bitmap_zero(map.bits, PNP_IRQ_NR); |
431 | if (p->interrupts[i]) | 518 | for (i = 0; i < p->interrupt_count; i++) { |
432 | __set_bit(p->interrupts[i], irq->map); | 519 | if (p->interrupts[i]) { |
433 | irq->flags = irq_flags(p->triggering, p->polarity, p->sharable); | 520 | if (p->interrupts[i] < PNP_IRQ_NR) |
521 | __set_bit(p->interrupts[i], map.bits); | ||
522 | else | ||
523 | dev_err(&dev->dev, "ignoring IRQ %d option " | ||
524 | "(too large for %d entry bitmap)\n", | ||
525 | p->interrupts[i], PNP_IRQ_NR); | ||
526 | } | ||
527 | } | ||
434 | 528 | ||
435 | pnp_register_irq_resource(dev, option, irq); | 529 | flags = irq_flags(p->triggering, p->polarity, p->sharable); |
530 | pnp_register_irq_resource(dev, option_flags, &map, flags); | ||
436 | } | 531 | } |
437 | 532 | ||
438 | static __init void pnpacpi_parse_port_option(struct pnp_dev *dev, | 533 | static __init void pnpacpi_parse_port_option(struct pnp_dev *dev, |
439 | struct pnp_option *option, | 534 | unsigned int option_flags, |
440 | struct acpi_resource_io *io) | 535 | struct acpi_resource_io *io) |
441 | { | 536 | { |
442 | struct pnp_port *port; | 537 | unsigned char flags = 0; |
443 | 538 | ||
444 | if (io->address_length == 0) | 539 | if (io->address_length == 0) |
445 | return; | 540 | return; |
446 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | 541 | |
447 | if (!port) | 542 | if (io->io_decode == ACPI_DECODE_16) |
448 | return; | 543 | flags = IORESOURCE_IO_16BIT_ADDR; |
449 | port->min = io->minimum; | 544 | pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum, |
450 | port->max = io->maximum; | 545 | io->alignment, io->address_length, flags); |
451 | port->align = io->alignment; | ||
452 | port->size = io->address_length; | ||
453 | port->flags = ACPI_DECODE_16 == io->io_decode ? | ||
454 | PNP_PORT_FLAG_16BITADDR : 0; | ||
455 | pnp_register_port_resource(dev, option, port); | ||
456 | } | 546 | } |
457 | 547 | ||
458 | static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev, | 548 | static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev, |
459 | struct pnp_option *option, | 549 | unsigned int option_flags, |
460 | struct acpi_resource_fixed_io *io) | 550 | struct acpi_resource_fixed_io *io) |
461 | { | 551 | { |
462 | struct pnp_port *port; | ||
463 | |||
464 | if (io->address_length == 0) | 552 | if (io->address_length == 0) |
465 | return; | 553 | return; |
466 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | 554 | |
467 | if (!port) | 555 | pnp_register_port_resource(dev, option_flags, io->address, io->address, |
468 | return; | 556 | 0, io->address_length, IORESOURCE_IO_FIXED); |
469 | port->min = port->max = io->address; | ||
470 | port->size = io->address_length; | ||
471 | port->align = 0; | ||
472 | port->flags = PNP_PORT_FLAG_FIXED; | ||
473 | pnp_register_port_resource(dev, option, port); | ||
474 | } | 557 | } |
475 | 558 | ||
476 | static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev, | 559 | static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev, |
477 | struct pnp_option *option, | 560 | unsigned int option_flags, |
478 | struct acpi_resource_memory24 *p) | 561 | struct acpi_resource_memory24 *p) |
479 | { | 562 | { |
480 | struct pnp_mem *mem; | 563 | unsigned char flags = 0; |
481 | 564 | ||
482 | if (p->address_length == 0) | 565 | if (p->address_length == 0) |
483 | return; | 566 | return; |
484 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | ||
485 | if (!mem) | ||
486 | return; | ||
487 | mem->min = p->minimum; | ||
488 | mem->max = p->maximum; | ||
489 | mem->align = p->alignment; | ||
490 | mem->size = p->address_length; | ||
491 | |||
492 | mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? | ||
493 | IORESOURCE_MEM_WRITEABLE : 0; | ||
494 | 567 | ||
495 | pnp_register_mem_resource(dev, option, mem); | 568 | if (p->write_protect == ACPI_READ_WRITE_MEMORY) |
569 | flags = IORESOURCE_MEM_WRITEABLE; | ||
570 | pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, | ||
571 | p->alignment, p->address_length, flags); | ||
496 | } | 572 | } |
497 | 573 | ||
498 | static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev, | 574 | static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev, |
499 | struct pnp_option *option, | 575 | unsigned int option_flags, |
500 | struct acpi_resource_memory32 *p) | 576 | struct acpi_resource_memory32 *p) |
501 | { | 577 | { |
502 | struct pnp_mem *mem; | 578 | unsigned char flags = 0; |
503 | 579 | ||
504 | if (p->address_length == 0) | 580 | if (p->address_length == 0) |
505 | return; | 581 | return; |
506 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | ||
507 | if (!mem) | ||
508 | return; | ||
509 | mem->min = p->minimum; | ||
510 | mem->max = p->maximum; | ||
511 | mem->align = p->alignment; | ||
512 | mem->size = p->address_length; | ||
513 | |||
514 | mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? | ||
515 | IORESOURCE_MEM_WRITEABLE : 0; | ||
516 | 582 | ||
517 | pnp_register_mem_resource(dev, option, mem); | 583 | if (p->write_protect == ACPI_READ_WRITE_MEMORY) |
584 | flags = IORESOURCE_MEM_WRITEABLE; | ||
585 | pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, | ||
586 | p->alignment, p->address_length, flags); | ||
518 | } | 587 | } |
519 | 588 | ||
520 | static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev, | 589 | static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev, |
521 | struct pnp_option *option, | 590 | unsigned int option_flags, |
522 | struct acpi_resource_fixed_memory32 *p) | 591 | struct acpi_resource_fixed_memory32 *p) |
523 | { | 592 | { |
524 | struct pnp_mem *mem; | 593 | unsigned char flags = 0; |
525 | 594 | ||
526 | if (p->address_length == 0) | 595 | if (p->address_length == 0) |
527 | return; | 596 | return; |
528 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | ||
529 | if (!mem) | ||
530 | return; | ||
531 | mem->min = mem->max = p->address; | ||
532 | mem->size = p->address_length; | ||
533 | mem->align = 0; | ||
534 | |||
535 | mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? | ||
536 | IORESOURCE_MEM_WRITEABLE : 0; | ||
537 | 597 | ||
538 | pnp_register_mem_resource(dev, option, mem); | 598 | if (p->write_protect == ACPI_READ_WRITE_MEMORY) |
599 | flags = IORESOURCE_MEM_WRITEABLE; | ||
600 | pnp_register_mem_resource(dev, option_flags, p->address, p->address, | ||
601 | 0, p->address_length, flags); | ||
539 | } | 602 | } |
540 | 603 | ||
541 | static __init void pnpacpi_parse_address_option(struct pnp_dev *dev, | 604 | static __init void pnpacpi_parse_address_option(struct pnp_dev *dev, |
542 | struct pnp_option *option, | 605 | unsigned int option_flags, |
543 | struct acpi_resource *r) | 606 | struct acpi_resource *r) |
544 | { | 607 | { |
545 | struct acpi_resource_address64 addr, *p = &addr; | 608 | struct acpi_resource_address64 addr, *p = &addr; |
546 | acpi_status status; | 609 | acpi_status status; |
547 | struct pnp_mem *mem; | 610 | unsigned char flags = 0; |
548 | struct pnp_port *port; | ||
549 | 611 | ||
550 | status = acpi_resource_to_address64(r, p); | 612 | status = acpi_resource_to_address64(r, p); |
551 | if (!ACPI_SUCCESS(status)) { | 613 | if (!ACPI_SUCCESS(status)) { |
@@ -558,49 +620,37 @@ static __init void pnpacpi_parse_address_option(struct pnp_dev *dev, | |||
558 | return; | 620 | return; |
559 | 621 | ||
560 | if (p->resource_type == ACPI_MEMORY_RANGE) { | 622 | if (p->resource_type == ACPI_MEMORY_RANGE) { |
561 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 623 | if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) |
562 | if (!mem) | 624 | flags = IORESOURCE_MEM_WRITEABLE; |
563 | return; | 625 | pnp_register_mem_resource(dev, option_flags, p->minimum, |
564 | mem->min = mem->max = p->minimum; | 626 | p->minimum, 0, p->address_length, |
565 | mem->size = p->address_length; | 627 | flags); |
566 | mem->align = 0; | 628 | } else if (p->resource_type == ACPI_IO_RANGE) |
567 | mem->flags = (p->info.mem.write_protect == | 629 | pnp_register_port_resource(dev, option_flags, p->minimum, |
568 | ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE | 630 | p->minimum, 0, p->address_length, |
569 | : 0; | 631 | IORESOURCE_IO_FIXED); |
570 | pnp_register_mem_resource(dev, option, mem); | ||
571 | } else if (p->resource_type == ACPI_IO_RANGE) { | ||
572 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | ||
573 | if (!port) | ||
574 | return; | ||
575 | port->min = port->max = p->minimum; | ||
576 | port->size = p->address_length; | ||
577 | port->align = 0; | ||
578 | port->flags = PNP_PORT_FLAG_FIXED; | ||
579 | pnp_register_port_resource(dev, option, port); | ||
580 | } | ||
581 | } | 632 | } |
582 | 633 | ||
583 | struct acpipnp_parse_option_s { | 634 | struct acpipnp_parse_option_s { |
584 | struct pnp_option *option; | ||
585 | struct pnp_option *option_independent; | ||
586 | struct pnp_dev *dev; | 635 | struct pnp_dev *dev; |
636 | unsigned int option_flags; | ||
587 | }; | 637 | }; |
588 | 638 | ||
589 | static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res, | 639 | static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res, |
590 | void *data) | 640 | void *data) |
591 | { | 641 | { |
592 | int priority = 0; | 642 | int priority; |
593 | struct acpipnp_parse_option_s *parse_data = data; | 643 | struct acpipnp_parse_option_s *parse_data = data; |
594 | struct pnp_dev *dev = parse_data->dev; | 644 | struct pnp_dev *dev = parse_data->dev; |
595 | struct pnp_option *option = parse_data->option; | 645 | unsigned int option_flags = parse_data->option_flags; |
596 | 646 | ||
597 | switch (res->type) { | 647 | switch (res->type) { |
598 | case ACPI_RESOURCE_TYPE_IRQ: | 648 | case ACPI_RESOURCE_TYPE_IRQ: |
599 | pnpacpi_parse_irq_option(dev, option, &res->data.irq); | 649 | pnpacpi_parse_irq_option(dev, option_flags, &res->data.irq); |
600 | break; | 650 | break; |
601 | 651 | ||
602 | case ACPI_RESOURCE_TYPE_DMA: | 652 | case ACPI_RESOURCE_TYPE_DMA: |
603 | pnpacpi_parse_dma_option(dev, option, &res->data.dma); | 653 | pnpacpi_parse_dma_option(dev, option_flags, &res->data.dma); |
604 | break; | 654 | break; |
605 | 655 | ||
606 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: | 656 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
@@ -620,31 +670,19 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res, | |||
620 | priority = PNP_RES_PRIORITY_INVALID; | 670 | priority = PNP_RES_PRIORITY_INVALID; |
621 | break; | 671 | break; |
622 | } | 672 | } |
623 | /* TBD: Consider performance/robustness bits */ | 673 | parse_data->option_flags = pnp_new_dependent_set(dev, priority); |
624 | option = pnp_register_dependent_option(dev, priority); | ||
625 | if (!option) | ||
626 | return AE_ERROR; | ||
627 | parse_data->option = option; | ||
628 | break; | 674 | break; |
629 | 675 | ||
630 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: | 676 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: |
631 | /*only one EndDependentFn is allowed */ | 677 | parse_data->option_flags = 0; |
632 | if (!parse_data->option_independent) { | ||
633 | dev_warn(&dev->dev, "more than one EndDependentFn " | ||
634 | "in _PRS\n"); | ||
635 | return AE_ERROR; | ||
636 | } | ||
637 | parse_data->option = parse_data->option_independent; | ||
638 | parse_data->option_independent = NULL; | ||
639 | dev_dbg(&dev->dev, "end dependent options\n"); | ||
640 | break; | 678 | break; |
641 | 679 | ||
642 | case ACPI_RESOURCE_TYPE_IO: | 680 | case ACPI_RESOURCE_TYPE_IO: |
643 | pnpacpi_parse_port_option(dev, option, &res->data.io); | 681 | pnpacpi_parse_port_option(dev, option_flags, &res->data.io); |
644 | break; | 682 | break; |
645 | 683 | ||
646 | case ACPI_RESOURCE_TYPE_FIXED_IO: | 684 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
647 | pnpacpi_parse_fixed_port_option(dev, option, | 685 | pnpacpi_parse_fixed_port_option(dev, option_flags, |
648 | &res->data.fixed_io); | 686 | &res->data.fixed_io); |
649 | break; | 687 | break; |
650 | 688 | ||
@@ -653,29 +691,31 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res, | |||
653 | break; | 691 | break; |
654 | 692 | ||
655 | case ACPI_RESOURCE_TYPE_MEMORY24: | 693 | case ACPI_RESOURCE_TYPE_MEMORY24: |
656 | pnpacpi_parse_mem24_option(dev, option, &res->data.memory24); | 694 | pnpacpi_parse_mem24_option(dev, option_flags, |
695 | &res->data.memory24); | ||
657 | break; | 696 | break; |
658 | 697 | ||
659 | case ACPI_RESOURCE_TYPE_MEMORY32: | 698 | case ACPI_RESOURCE_TYPE_MEMORY32: |
660 | pnpacpi_parse_mem32_option(dev, option, &res->data.memory32); | 699 | pnpacpi_parse_mem32_option(dev, option_flags, |
700 | &res->data.memory32); | ||
661 | break; | 701 | break; |
662 | 702 | ||
663 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: | 703 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
664 | pnpacpi_parse_fixed_mem32_option(dev, option, | 704 | pnpacpi_parse_fixed_mem32_option(dev, option_flags, |
665 | &res->data.fixed_memory32); | 705 | &res->data.fixed_memory32); |
666 | break; | 706 | break; |
667 | 707 | ||
668 | case ACPI_RESOURCE_TYPE_ADDRESS16: | 708 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
669 | case ACPI_RESOURCE_TYPE_ADDRESS32: | 709 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
670 | case ACPI_RESOURCE_TYPE_ADDRESS64: | 710 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
671 | pnpacpi_parse_address_option(dev, option, res); | 711 | pnpacpi_parse_address_option(dev, option_flags, res); |
672 | break; | 712 | break; |
673 | 713 | ||
674 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: | 714 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: |
675 | break; | 715 | break; |
676 | 716 | ||
677 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | 717 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
678 | pnpacpi_parse_ext_irq_option(dev, option, | 718 | pnpacpi_parse_ext_irq_option(dev, option_flags, |
679 | &res->data.extended_irq); | 719 | &res->data.extended_irq); |
680 | break; | 720 | break; |
681 | 721 | ||
@@ -699,12 +739,9 @@ int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev) | |||
699 | 739 | ||
700 | dev_dbg(&dev->dev, "parse resource options\n"); | 740 | dev_dbg(&dev->dev, "parse resource options\n"); |
701 | 741 | ||
702 | parse_data.option = pnp_register_independent_option(dev); | ||
703 | if (!parse_data.option) | ||
704 | return -ENOMEM; | ||
705 | |||
706 | parse_data.option_independent = parse_data.option; | ||
707 | parse_data.dev = dev; | 742 | parse_data.dev = dev; |
743 | parse_data.option_flags = 0; | ||
744 | |||
708 | status = acpi_walk_resources(handle, METHOD_NAME__PRS, | 745 | status = acpi_walk_resources(handle, METHOD_NAME__PRS, |
709 | pnpacpi_option_resource, &parse_data); | 746 | pnpacpi_option_resource, &parse_data); |
710 | 747 | ||
@@ -806,6 +843,13 @@ static void pnpacpi_encode_irq(struct pnp_dev *dev, | |||
806 | struct acpi_resource_irq *irq = &resource->data.irq; | 843 | struct acpi_resource_irq *irq = &resource->data.irq; |
807 | int triggering, polarity, shareable; | 844 | int triggering, polarity, shareable; |
808 | 845 | ||
846 | if (!pnp_resource_enabled(p)) { | ||
847 | irq->interrupt_count = 0; | ||
848 | dev_dbg(&dev->dev, " encode irq (%s)\n", | ||
849 | p ? "disabled" : "missing"); | ||
850 | return; | ||
851 | } | ||
852 | |||
809 | decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); | 853 | decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); |
810 | irq->triggering = triggering; | 854 | irq->triggering = triggering; |
811 | irq->polarity = polarity; | 855 | irq->polarity = polarity; |
@@ -828,6 +872,13 @@ static void pnpacpi_encode_ext_irq(struct pnp_dev *dev, | |||
828 | struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq; | 872 | struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq; |
829 | int triggering, polarity, shareable; | 873 | int triggering, polarity, shareable; |
830 | 874 | ||
875 | if (!pnp_resource_enabled(p)) { | ||
876 | extended_irq->interrupt_count = 0; | ||
877 | dev_dbg(&dev->dev, " encode extended irq (%s)\n", | ||
878 | p ? "disabled" : "missing"); | ||
879 | return; | ||
880 | } | ||
881 | |||
831 | decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); | 882 | decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); |
832 | extended_irq->producer_consumer = ACPI_CONSUMER; | 883 | extended_irq->producer_consumer = ACPI_CONSUMER; |
833 | extended_irq->triggering = triggering; | 884 | extended_irq->triggering = triggering; |
@@ -848,6 +899,13 @@ static void pnpacpi_encode_dma(struct pnp_dev *dev, | |||
848 | { | 899 | { |
849 | struct acpi_resource_dma *dma = &resource->data.dma; | 900 | struct acpi_resource_dma *dma = &resource->data.dma; |
850 | 901 | ||
902 | if (!pnp_resource_enabled(p)) { | ||
903 | dma->channel_count = 0; | ||
904 | dev_dbg(&dev->dev, " encode dma (%s)\n", | ||
905 | p ? "disabled" : "missing"); | ||
906 | return; | ||
907 | } | ||
908 | |||
851 | /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ | 909 | /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ |
852 | switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { | 910 | switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { |
853 | case IORESOURCE_DMA_TYPEA: | 911 | case IORESOURCE_DMA_TYPEA: |
@@ -889,17 +947,21 @@ static void pnpacpi_encode_io(struct pnp_dev *dev, | |||
889 | { | 947 | { |
890 | struct acpi_resource_io *io = &resource->data.io; | 948 | struct acpi_resource_io *io = &resource->data.io; |
891 | 949 | ||
892 | /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ | 950 | if (pnp_resource_enabled(p)) { |
893 | io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ? | 951 | /* Note: pnp_assign_port copies pnp_port->flags into p->flags */ |
894 | ACPI_DECODE_16 : ACPI_DECODE_10; | 952 | io->io_decode = (p->flags & IORESOURCE_IO_16BIT_ADDR) ? |
895 | io->minimum = p->start; | 953 | ACPI_DECODE_16 : ACPI_DECODE_10; |
896 | io->maximum = p->end; | 954 | io->minimum = p->start; |
897 | io->alignment = 0; /* Correct? */ | 955 | io->maximum = p->end; |
898 | io->address_length = p->end - p->start + 1; | 956 | io->alignment = 0; /* Correct? */ |
899 | 957 | io->address_length = p->end - p->start + 1; | |
900 | dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n", | 958 | } else { |
901 | (unsigned long long) p->start, (unsigned long long) p->end, | 959 | io->minimum = 0; |
902 | io->io_decode); | 960 | io->address_length = 0; |
961 | } | ||
962 | |||
963 | dev_dbg(&dev->dev, " encode io %#x-%#x decode %#x\n", io->minimum, | ||
964 | io->minimum + io->address_length - 1, io->io_decode); | ||
903 | } | 965 | } |
904 | 966 | ||
905 | static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, | 967 | static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, |
@@ -908,11 +970,16 @@ static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, | |||
908 | { | 970 | { |
909 | struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io; | 971 | struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io; |
910 | 972 | ||
911 | fixed_io->address = p->start; | 973 | if (pnp_resource_enabled(p)) { |
912 | fixed_io->address_length = p->end - p->start + 1; | 974 | fixed_io->address = p->start; |
975 | fixed_io->address_length = p->end - p->start + 1; | ||
976 | } else { | ||
977 | fixed_io->address = 0; | ||
978 | fixed_io->address_length = 0; | ||
979 | } | ||
913 | 980 | ||
914 | dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", | 981 | dev_dbg(&dev->dev, " encode fixed_io %#x-%#x\n", fixed_io->address, |
915 | (unsigned long long) p->start, (unsigned long long) p->end); | 982 | fixed_io->address + fixed_io->address_length - 1); |
916 | } | 983 | } |
917 | 984 | ||
918 | static void pnpacpi_encode_mem24(struct pnp_dev *dev, | 985 | static void pnpacpi_encode_mem24(struct pnp_dev *dev, |
@@ -921,17 +988,22 @@ static void pnpacpi_encode_mem24(struct pnp_dev *dev, | |||
921 | { | 988 | { |
922 | struct acpi_resource_memory24 *memory24 = &resource->data.memory24; | 989 | struct acpi_resource_memory24 *memory24 = &resource->data.memory24; |
923 | 990 | ||
924 | /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ | 991 | if (pnp_resource_enabled(p)) { |
925 | memory24->write_protect = | 992 | /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */ |
926 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? | 993 | memory24->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ? |
927 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | 994 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
928 | memory24->minimum = p->start; | 995 | memory24->minimum = p->start; |
929 | memory24->maximum = p->end; | 996 | memory24->maximum = p->end; |
930 | memory24->alignment = 0; | 997 | memory24->alignment = 0; |
931 | memory24->address_length = p->end - p->start + 1; | 998 | memory24->address_length = p->end - p->start + 1; |
932 | 999 | } else { | |
933 | dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n", | 1000 | memory24->minimum = 0; |
934 | (unsigned long long) p->start, (unsigned long long) p->end, | 1001 | memory24->address_length = 0; |
1002 | } | ||
1003 | |||
1004 | dev_dbg(&dev->dev, " encode mem24 %#x-%#x write_protect %#x\n", | ||
1005 | memory24->minimum, | ||
1006 | memory24->minimum + memory24->address_length - 1, | ||
935 | memory24->write_protect); | 1007 | memory24->write_protect); |
936 | } | 1008 | } |
937 | 1009 | ||
@@ -941,16 +1013,21 @@ static void pnpacpi_encode_mem32(struct pnp_dev *dev, | |||
941 | { | 1013 | { |
942 | struct acpi_resource_memory32 *memory32 = &resource->data.memory32; | 1014 | struct acpi_resource_memory32 *memory32 = &resource->data.memory32; |
943 | 1015 | ||
944 | memory32->write_protect = | 1016 | if (pnp_resource_enabled(p)) { |
945 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? | 1017 | memory32->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ? |
946 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | 1018 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
947 | memory32->minimum = p->start; | 1019 | memory32->minimum = p->start; |
948 | memory32->maximum = p->end; | 1020 | memory32->maximum = p->end; |
949 | memory32->alignment = 0; | 1021 | memory32->alignment = 0; |
950 | memory32->address_length = p->end - p->start + 1; | 1022 | memory32->address_length = p->end - p->start + 1; |
1023 | } else { | ||
1024 | memory32->minimum = 0; | ||
1025 | memory32->alignment = 0; | ||
1026 | } | ||
951 | 1027 | ||
952 | dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n", | 1028 | dev_dbg(&dev->dev, " encode mem32 %#x-%#x write_protect %#x\n", |
953 | (unsigned long long) p->start, (unsigned long long) p->end, | 1029 | memory32->minimum, |
1030 | memory32->minimum + memory32->address_length - 1, | ||
954 | memory32->write_protect); | 1031 | memory32->write_protect); |
955 | } | 1032 | } |
956 | 1033 | ||
@@ -960,15 +1037,20 @@ static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev, | |||
960 | { | 1037 | { |
961 | struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32; | 1038 | struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32; |
962 | 1039 | ||
963 | fixed_memory32->write_protect = | 1040 | if (pnp_resource_enabled(p)) { |
964 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? | 1041 | fixed_memory32->write_protect = |
965 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | 1042 | p->flags & IORESOURCE_MEM_WRITEABLE ? |
966 | fixed_memory32->address = p->start; | 1043 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
967 | fixed_memory32->address_length = p->end - p->start + 1; | 1044 | fixed_memory32->address = p->start; |
1045 | fixed_memory32->address_length = p->end - p->start + 1; | ||
1046 | } else { | ||
1047 | fixed_memory32->address = 0; | ||
1048 | fixed_memory32->address_length = 0; | ||
1049 | } | ||
968 | 1050 | ||
969 | dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx " | 1051 | dev_dbg(&dev->dev, " encode fixed_mem32 %#x-%#x write_protect %#x\n", |
970 | "write_protect %#x\n", | 1052 | fixed_memory32->address, |
971 | (unsigned long long) p->start, (unsigned long long) p->end, | 1053 | fixed_memory32->address + fixed_memory32->address_length - 1, |
972 | fixed_memory32->write_protect); | 1054 | fixed_memory32->write_protect); |
973 | } | 1055 | } |
974 | 1056 | ||
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c index 5ff9a4c0447e..ca567671379e 100644 --- a/drivers/pnp/pnpbios/rsparser.c +++ b/drivers/pnp/pnpbios/rsparser.c | |||
@@ -216,137 +216,116 @@ len_err: | |||
216 | 216 | ||
217 | static __init void pnpbios_parse_mem_option(struct pnp_dev *dev, | 217 | static __init void pnpbios_parse_mem_option(struct pnp_dev *dev, |
218 | unsigned char *p, int size, | 218 | unsigned char *p, int size, |
219 | struct pnp_option *option) | 219 | unsigned int option_flags) |
220 | { | 220 | { |
221 | struct pnp_mem *mem; | 221 | resource_size_t min, max, align, len; |
222 | 222 | unsigned char flags; | |
223 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 223 | |
224 | if (!mem) | 224 | min = ((p[5] << 8) | p[4]) << 8; |
225 | return; | 225 | max = ((p[7] << 8) | p[6]) << 8; |
226 | mem->min = ((p[5] << 8) | p[4]) << 8; | 226 | align = (p[9] << 8) | p[8]; |
227 | mem->max = ((p[7] << 8) | p[6]) << 8; | 227 | len = ((p[11] << 8) | p[10]) << 8; |
228 | mem->align = (p[9] << 8) | p[8]; | 228 | flags = p[3]; |
229 | mem->size = ((p[11] << 8) | p[10]) << 8; | 229 | pnp_register_mem_resource(dev, option_flags, min, max, align, len, |
230 | mem->flags = p[3]; | 230 | flags); |
231 | pnp_register_mem_resource(dev, option, mem); | ||
232 | } | 231 | } |
233 | 232 | ||
234 | static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev, | 233 | static __init void pnpbios_parse_mem32_option(struct pnp_dev *dev, |
235 | unsigned char *p, int size, | 234 | unsigned char *p, int size, |
236 | struct pnp_option *option) | 235 | unsigned int option_flags) |
237 | { | 236 | { |
238 | struct pnp_mem *mem; | 237 | resource_size_t min, max, align, len; |
239 | 238 | unsigned char flags; | |
240 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 239 | |
241 | if (!mem) | 240 | min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; |
242 | return; | 241 | max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; |
243 | mem->min = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; | 242 | align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12]; |
244 | mem->max = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; | 243 | len = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16]; |
245 | mem->align = (p[15] << 24) | (p[14] << 16) | (p[13] << 8) | p[12]; | 244 | flags = p[3]; |
246 | mem->size = (p[19] << 24) | (p[18] << 16) | (p[17] << 8) | p[16]; | 245 | pnp_register_mem_resource(dev, option_flags, min, max, align, len, |
247 | mem->flags = p[3]; | 246 | flags); |
248 | pnp_register_mem_resource(dev, option, mem); | ||
249 | } | 247 | } |
250 | 248 | ||
251 | static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev, | 249 | static __init void pnpbios_parse_fixed_mem32_option(struct pnp_dev *dev, |
252 | unsigned char *p, int size, | 250 | unsigned char *p, int size, |
253 | struct pnp_option *option) | 251 | unsigned int option_flags) |
254 | { | 252 | { |
255 | struct pnp_mem *mem; | 253 | resource_size_t base, len; |
256 | 254 | unsigned char flags; | |
257 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); | 255 | |
258 | if (!mem) | 256 | base = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; |
259 | return; | 257 | len = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; |
260 | mem->min = mem->max = (p[7] << 24) | (p[6] << 16) | (p[5] << 8) | p[4]; | 258 | flags = p[3]; |
261 | mem->size = (p[11] << 24) | (p[10] << 16) | (p[9] << 8) | p[8]; | 259 | pnp_register_mem_resource(dev, option_flags, base, base, 0, len, flags); |
262 | mem->align = 0; | ||
263 | mem->flags = p[3]; | ||
264 | pnp_register_mem_resource(dev, option, mem); | ||
265 | } | 260 | } |
266 | 261 | ||
267 | static __init void pnpbios_parse_irq_option(struct pnp_dev *dev, | 262 | static __init void pnpbios_parse_irq_option(struct pnp_dev *dev, |
268 | unsigned char *p, int size, | 263 | unsigned char *p, int size, |
269 | struct pnp_option *option) | 264 | unsigned int option_flags) |
270 | { | 265 | { |
271 | struct pnp_irq *irq; | ||
272 | unsigned long bits; | 266 | unsigned long bits; |
267 | pnp_irq_mask_t map; | ||
268 | unsigned char flags = IORESOURCE_IRQ_HIGHEDGE; | ||
273 | 269 | ||
274 | irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); | ||
275 | if (!irq) | ||
276 | return; | ||
277 | bits = (p[2] << 8) | p[1]; | 270 | bits = (p[2] << 8) | p[1]; |
278 | bitmap_copy(irq->map, &bits, 16); | 271 | |
272 | bitmap_zero(map.bits, PNP_IRQ_NR); | ||
273 | bitmap_copy(map.bits, &bits, 16); | ||
274 | |||
279 | if (size > 2) | 275 | if (size > 2) |
280 | irq->flags = p[3]; | 276 | flags = p[3]; |
281 | else | 277 | |
282 | irq->flags = IORESOURCE_IRQ_HIGHEDGE; | 278 | pnp_register_irq_resource(dev, option_flags, &map, flags); |
283 | pnp_register_irq_resource(dev, option, irq); | ||
284 | } | 279 | } |
285 | 280 | ||
286 | static __init void pnpbios_parse_dma_option(struct pnp_dev *dev, | 281 | static __init void pnpbios_parse_dma_option(struct pnp_dev *dev, |
287 | unsigned char *p, int size, | 282 | unsigned char *p, int size, |
288 | struct pnp_option *option) | 283 | unsigned int option_flags) |
289 | { | 284 | { |
290 | struct pnp_dma *dma; | 285 | pnp_register_dma_resource(dev, option_flags, p[1], p[2]); |
291 | |||
292 | dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); | ||
293 | if (!dma) | ||
294 | return; | ||
295 | dma->map = p[1]; | ||
296 | dma->flags = p[2]; | ||
297 | pnp_register_dma_resource(dev, option, dma); | ||
298 | } | 286 | } |
299 | 287 | ||
300 | static __init void pnpbios_parse_port_option(struct pnp_dev *dev, | 288 | static __init void pnpbios_parse_port_option(struct pnp_dev *dev, |
301 | unsigned char *p, int size, | 289 | unsigned char *p, int size, |
302 | struct pnp_option *option) | 290 | unsigned int option_flags) |
303 | { | 291 | { |
304 | struct pnp_port *port; | 292 | resource_size_t min, max, align, len; |
305 | 293 | unsigned char flags; | |
306 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | 294 | |
307 | if (!port) | 295 | min = (p[3] << 8) | p[2]; |
308 | return; | 296 | max = (p[5] << 8) | p[4]; |
309 | port->min = (p[3] << 8) | p[2]; | 297 | align = p[6]; |
310 | port->max = (p[5] << 8) | p[4]; | 298 | len = p[7]; |
311 | port->align = p[6]; | 299 | flags = p[1] ? IORESOURCE_IO_16BIT_ADDR : 0; |
312 | port->size = p[7]; | 300 | pnp_register_port_resource(dev, option_flags, min, max, align, len, |
313 | port->flags = p[1] ? PNP_PORT_FLAG_16BITADDR : 0; | 301 | flags); |
314 | pnp_register_port_resource(dev, option, port); | ||
315 | } | 302 | } |
316 | 303 | ||
317 | static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev, | 304 | static __init void pnpbios_parse_fixed_port_option(struct pnp_dev *dev, |
318 | unsigned char *p, int size, | 305 | unsigned char *p, int size, |
319 | struct pnp_option *option) | 306 | unsigned int option_flags) |
320 | { | 307 | { |
321 | struct pnp_port *port; | 308 | resource_size_t base, len; |
322 | 309 | ||
323 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); | 310 | base = (p[2] << 8) | p[1]; |
324 | if (!port) | 311 | len = p[3]; |
325 | return; | 312 | pnp_register_port_resource(dev, option_flags, base, base, 0, len, |
326 | port->min = port->max = (p[2] << 8) | p[1]; | 313 | IORESOURCE_IO_FIXED); |
327 | port->size = p[3]; | ||
328 | port->align = 0; | ||
329 | port->flags = PNP_PORT_FLAG_FIXED; | ||
330 | pnp_register_port_resource(dev, option, port); | ||
331 | } | 314 | } |
332 | 315 | ||
333 | static __init unsigned char * | 316 | static __init unsigned char * |
334 | pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end, | 317 | pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end, |
335 | struct pnp_dev *dev) | 318 | struct pnp_dev *dev) |
336 | { | 319 | { |
337 | unsigned int len, tag; | 320 | unsigned int len, tag; |
338 | int priority = 0; | 321 | int priority; |
339 | struct pnp_option *option, *option_independent; | 322 | unsigned int option_flags; |
340 | 323 | ||
341 | if (!p) | 324 | if (!p) |
342 | return NULL; | 325 | return NULL; |
343 | 326 | ||
344 | dev_dbg(&dev->dev, "parse resource options\n"); | 327 | dev_dbg(&dev->dev, "parse resource options\n"); |
345 | 328 | option_flags = 0; | |
346 | option_independent = option = pnp_register_independent_option(dev); | ||
347 | if (!option) | ||
348 | return NULL; | ||
349 | |||
350 | while ((char *)p < (char *)end) { | 329 | while ((char *)p < (char *)end) { |
351 | 330 | ||
352 | /* determine the type of tag */ | 331 | /* determine the type of tag */ |
@@ -363,37 +342,38 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end, | |||
363 | case LARGE_TAG_MEM: | 342 | case LARGE_TAG_MEM: |
364 | if (len != 9) | 343 | if (len != 9) |
365 | goto len_err; | 344 | goto len_err; |
366 | pnpbios_parse_mem_option(dev, p, len, option); | 345 | pnpbios_parse_mem_option(dev, p, len, option_flags); |
367 | break; | 346 | break; |
368 | 347 | ||
369 | case LARGE_TAG_MEM32: | 348 | case LARGE_TAG_MEM32: |
370 | if (len != 17) | 349 | if (len != 17) |
371 | goto len_err; | 350 | goto len_err; |
372 | pnpbios_parse_mem32_option(dev, p, len, option); | 351 | pnpbios_parse_mem32_option(dev, p, len, option_flags); |
373 | break; | 352 | break; |
374 | 353 | ||
375 | case LARGE_TAG_FIXEDMEM32: | 354 | case LARGE_TAG_FIXEDMEM32: |
376 | if (len != 9) | 355 | if (len != 9) |
377 | goto len_err; | 356 | goto len_err; |
378 | pnpbios_parse_fixed_mem32_option(dev, p, len, option); | 357 | pnpbios_parse_fixed_mem32_option(dev, p, len, |
358 | option_flags); | ||
379 | break; | 359 | break; |
380 | 360 | ||
381 | case SMALL_TAG_IRQ: | 361 | case SMALL_TAG_IRQ: |
382 | if (len < 2 || len > 3) | 362 | if (len < 2 || len > 3) |
383 | goto len_err; | 363 | goto len_err; |
384 | pnpbios_parse_irq_option(dev, p, len, option); | 364 | pnpbios_parse_irq_option(dev, p, len, option_flags); |
385 | break; | 365 | break; |
386 | 366 | ||
387 | case SMALL_TAG_DMA: | 367 | case SMALL_TAG_DMA: |
388 | if (len != 2) | 368 | if (len != 2) |
389 | goto len_err; | 369 | goto len_err; |
390 | pnpbios_parse_dma_option(dev, p, len, option); | 370 | pnpbios_parse_dma_option(dev, p, len, option_flags); |
391 | break; | 371 | break; |
392 | 372 | ||
393 | case SMALL_TAG_PORT: | 373 | case SMALL_TAG_PORT: |
394 | if (len != 7) | 374 | if (len != 7) |
395 | goto len_err; | 375 | goto len_err; |
396 | pnpbios_parse_port_option(dev, p, len, option); | 376 | pnpbios_parse_port_option(dev, p, len, option_flags); |
397 | break; | 377 | break; |
398 | 378 | ||
399 | case SMALL_TAG_VENDOR: | 379 | case SMALL_TAG_VENDOR: |
@@ -403,28 +383,23 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end, | |||
403 | case SMALL_TAG_FIXEDPORT: | 383 | case SMALL_TAG_FIXEDPORT: |
404 | if (len != 3) | 384 | if (len != 3) |
405 | goto len_err; | 385 | goto len_err; |
406 | pnpbios_parse_fixed_port_option(dev, p, len, option); | 386 | pnpbios_parse_fixed_port_option(dev, p, len, |
387 | option_flags); | ||
407 | break; | 388 | break; |
408 | 389 | ||
409 | case SMALL_TAG_STARTDEP: | 390 | case SMALL_TAG_STARTDEP: |
410 | if (len > 1) | 391 | if (len > 1) |
411 | goto len_err; | 392 | goto len_err; |
412 | priority = 0x100 | PNP_RES_PRIORITY_ACCEPTABLE; | 393 | priority = PNP_RES_PRIORITY_ACCEPTABLE; |
413 | if (len > 0) | 394 | if (len > 0) |
414 | priority = 0x100 | p[1]; | 395 | priority = p[1]; |
415 | option = pnp_register_dependent_option(dev, priority); | 396 | option_flags = pnp_new_dependent_set(dev, priority); |
416 | if (!option) | ||
417 | return NULL; | ||
418 | break; | 397 | break; |
419 | 398 | ||
420 | case SMALL_TAG_ENDDEP: | 399 | case SMALL_TAG_ENDDEP: |
421 | if (len != 0) | 400 | if (len != 0) |
422 | goto len_err; | 401 | goto len_err; |
423 | if (option_independent == option) | 402 | option_flags = 0; |
424 | dev_warn(&dev->dev, "missing " | ||
425 | "SMALL_TAG_STARTDEP tag\n"); | ||
426 | option = option_independent; | ||
427 | dev_dbg(&dev->dev, "end dependent options\n"); | ||
428 | break; | 403 | break; |
429 | 404 | ||
430 | case SMALL_TAG_END: | 405 | case SMALL_TAG_END: |
@@ -526,8 +501,16 @@ len_err: | |||
526 | static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, | 501 | static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, |
527 | struct resource *res) | 502 | struct resource *res) |
528 | { | 503 | { |
529 | unsigned long base = res->start; | 504 | unsigned long base; |
530 | unsigned long len = res->end - res->start + 1; | 505 | unsigned long len; |
506 | |||
507 | if (pnp_resource_enabled(res)) { | ||
508 | base = res->start; | ||
509 | len = res->end - res->start + 1; | ||
510 | } else { | ||
511 | base = 0; | ||
512 | len = 0; | ||
513 | } | ||
531 | 514 | ||
532 | p[4] = (base >> 8) & 0xff; | 515 | p[4] = (base >> 8) & 0xff; |
533 | p[5] = ((base >> 8) >> 8) & 0xff; | 516 | p[5] = ((base >> 8) >> 8) & 0xff; |
@@ -536,15 +519,22 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, | |||
536 | p[10] = (len >> 8) & 0xff; | 519 | p[10] = (len >> 8) & 0xff; |
537 | p[11] = ((len >> 8) >> 8) & 0xff; | 520 | p[11] = ((len >> 8) >> 8) & 0xff; |
538 | 521 | ||
539 | dev_dbg(&dev->dev, " encode mem %#llx-%#llx\n", | 522 | dev_dbg(&dev->dev, " encode mem %#lx-%#lx\n", base, base + len - 1); |
540 | (unsigned long long) res->start, (unsigned long long) res->end); | ||
541 | } | 523 | } |
542 | 524 | ||
543 | static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, | 525 | static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, |
544 | struct resource *res) | 526 | struct resource *res) |
545 | { | 527 | { |
546 | unsigned long base = res->start; | 528 | unsigned long base; |
547 | unsigned long len = res->end - res->start + 1; | 529 | unsigned long len; |
530 | |||
531 | if (pnp_resource_enabled(res)) { | ||
532 | base = res->start; | ||
533 | len = res->end - res->start + 1; | ||
534 | } else { | ||
535 | base = 0; | ||
536 | len = 0; | ||
537 | } | ||
548 | 538 | ||
549 | p[4] = base & 0xff; | 539 | p[4] = base & 0xff; |
550 | p[5] = (base >> 8) & 0xff; | 540 | p[5] = (base >> 8) & 0xff; |
@@ -559,15 +549,22 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, | |||
559 | p[18] = (len >> 16) & 0xff; | 549 | p[18] = (len >> 16) & 0xff; |
560 | p[19] = (len >> 24) & 0xff; | 550 | p[19] = (len >> 24) & 0xff; |
561 | 551 | ||
562 | dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx\n", | 552 | dev_dbg(&dev->dev, " encode mem32 %#lx-%#lx\n", base, base + len - 1); |
563 | (unsigned long long) res->start, (unsigned long long) res->end); | ||
564 | } | 553 | } |
565 | 554 | ||
566 | static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, | 555 | static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, |
567 | struct resource *res) | 556 | struct resource *res) |
568 | { | 557 | { |
569 | unsigned long base = res->start; | 558 | unsigned long base; |
570 | unsigned long len = res->end - res->start + 1; | 559 | unsigned long len; |
560 | |||
561 | if (pnp_resource_enabled(res)) { | ||
562 | base = res->start; | ||
563 | len = res->end - res->start + 1; | ||
564 | } else { | ||
565 | base = 0; | ||
566 | len = 0; | ||
567 | } | ||
571 | 568 | ||
572 | p[4] = base & 0xff; | 569 | p[4] = base & 0xff; |
573 | p[5] = (base >> 8) & 0xff; | 570 | p[5] = (base >> 8) & 0xff; |
@@ -578,40 +575,54 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, | |||
578 | p[10] = (len >> 16) & 0xff; | 575 | p[10] = (len >> 16) & 0xff; |
579 | p[11] = (len >> 24) & 0xff; | 576 | p[11] = (len >> 24) & 0xff; |
580 | 577 | ||
581 | dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx\n", | 578 | dev_dbg(&dev->dev, " encode fixed_mem32 %#lx-%#lx\n", base, |
582 | (unsigned long long) res->start, (unsigned long long) res->end); | 579 | base + len - 1); |
583 | } | 580 | } |
584 | 581 | ||
585 | static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p, | 582 | static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p, |
586 | struct resource *res) | 583 | struct resource *res) |
587 | { | 584 | { |
588 | unsigned long map = 0; | 585 | unsigned long map; |
586 | |||
587 | if (pnp_resource_enabled(res)) | ||
588 | map = 1 << res->start; | ||
589 | else | ||
590 | map = 0; | ||
589 | 591 | ||
590 | map = 1 << res->start; | ||
591 | p[1] = map & 0xff; | 592 | p[1] = map & 0xff; |
592 | p[2] = (map >> 8) & 0xff; | 593 | p[2] = (map >> 8) & 0xff; |
593 | 594 | ||
594 | dev_dbg(&dev->dev, " encode irq %llu\n", | 595 | dev_dbg(&dev->dev, " encode irq mask %#lx\n", map); |
595 | (unsigned long long)res->start); | ||
596 | } | 596 | } |
597 | 597 | ||
598 | static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p, | 598 | static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p, |
599 | struct resource *res) | 599 | struct resource *res) |
600 | { | 600 | { |
601 | unsigned long map = 0; | 601 | unsigned long map; |
602 | |||
603 | if (pnp_resource_enabled(res)) | ||
604 | map = 1 << res->start; | ||
605 | else | ||
606 | map = 0; | ||
602 | 607 | ||
603 | map = 1 << res->start; | ||
604 | p[1] = map & 0xff; | 608 | p[1] = map & 0xff; |
605 | 609 | ||
606 | dev_dbg(&dev->dev, " encode dma %llu\n", | 610 | dev_dbg(&dev->dev, " encode dma mask %#lx\n", map); |
607 | (unsigned long long)res->start); | ||
608 | } | 611 | } |
609 | 612 | ||
610 | static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, | 613 | static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, |
611 | struct resource *res) | 614 | struct resource *res) |
612 | { | 615 | { |
613 | unsigned long base = res->start; | 616 | unsigned long base; |
614 | unsigned long len = res->end - res->start + 1; | 617 | unsigned long len; |
618 | |||
619 | if (pnp_resource_enabled(res)) { | ||
620 | base = res->start; | ||
621 | len = res->end - res->start + 1; | ||
622 | } else { | ||
623 | base = 0; | ||
624 | len = 0; | ||
625 | } | ||
615 | 626 | ||
616 | p[2] = base & 0xff; | 627 | p[2] = base & 0xff; |
617 | p[3] = (base >> 8) & 0xff; | 628 | p[3] = (base >> 8) & 0xff; |
@@ -619,8 +630,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, | |||
619 | p[5] = (base >> 8) & 0xff; | 630 | p[5] = (base >> 8) & 0xff; |
620 | p[7] = len & 0xff; | 631 | p[7] = len & 0xff; |
621 | 632 | ||
622 | dev_dbg(&dev->dev, " encode io %#llx-%#llx\n", | 633 | dev_dbg(&dev->dev, " encode io %#lx-%#lx\n", base, base + len - 1); |
623 | (unsigned long long) res->start, (unsigned long long) res->end); | ||
624 | } | 634 | } |
625 | 635 | ||
626 | static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, | 636 | static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, |
@@ -629,12 +639,20 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, | |||
629 | unsigned long base = res->start; | 639 | unsigned long base = res->start; |
630 | unsigned long len = res->end - res->start + 1; | 640 | unsigned long len = res->end - res->start + 1; |
631 | 641 | ||
642 | if (pnp_resource_enabled(res)) { | ||
643 | base = res->start; | ||
644 | len = res->end - res->start + 1; | ||
645 | } else { | ||
646 | base = 0; | ||
647 | len = 0; | ||
648 | } | ||
649 | |||
632 | p[1] = base & 0xff; | 650 | p[1] = base & 0xff; |
633 | p[2] = (base >> 8) & 0xff; | 651 | p[2] = (base >> 8) & 0xff; |
634 | p[3] = len & 0xff; | 652 | p[3] = len & 0xff; |
635 | 653 | ||
636 | dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", | 654 | dev_dbg(&dev->dev, " encode fixed_io %#lx-%#lx\n", base, |
637 | (unsigned long long) res->start, (unsigned long long) res->end); | 655 | base + len - 1); |
638 | } | 656 | } |
639 | 657 | ||
640 | static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev | 658 | static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev |
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c index 1ff3bb585ab2..55f55ed72dc7 100644 --- a/drivers/pnp/quirks.c +++ b/drivers/pnp/quirks.c | |||
@@ -5,6 +5,8 @@ | |||
5 | * when building up the resource structure for the first time. | 5 | * when building up the resource structure for the first time. |
6 | * | 6 | * |
7 | * Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk> | 7 | * Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk> |
8 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
9 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
8 | * | 10 | * |
9 | * Heavily based on PCI quirks handling which is | 11 | * Heavily based on PCI quirks handling which is |
10 | * | 12 | * |
@@ -20,203 +22,207 @@ | |||
20 | #include <linux/kallsyms.h> | 22 | #include <linux/kallsyms.h> |
21 | #include "base.h" | 23 | #include "base.h" |
22 | 24 | ||
25 | static void quirk_awe32_add_ports(struct pnp_dev *dev, | ||
26 | struct pnp_option *option, | ||
27 | unsigned int offset) | ||
28 | { | ||
29 | struct pnp_option *new_option; | ||
30 | |||
31 | new_option = kmalloc(sizeof(struct pnp_option), GFP_KERNEL); | ||
32 | if (!new_option) { | ||
33 | dev_err(&dev->dev, "couldn't add ioport region to option set " | ||
34 | "%d\n", pnp_option_set(option)); | ||
35 | return; | ||
36 | } | ||
37 | |||
38 | *new_option = *option; | ||
39 | new_option->u.port.min += offset; | ||
40 | new_option->u.port.max += offset; | ||
41 | list_add(&new_option->list, &option->list); | ||
42 | |||
43 | dev_info(&dev->dev, "added ioport region %#llx-%#llx to set %d\n", | ||
44 | (unsigned long long) new_option->u.port.min, | ||
45 | (unsigned long long) new_option->u.port.max, | ||
46 | pnp_option_set(option)); | ||
47 | } | ||
48 | |||
23 | static void quirk_awe32_resources(struct pnp_dev *dev) | 49 | static void quirk_awe32_resources(struct pnp_dev *dev) |
24 | { | 50 | { |
25 | struct pnp_port *port, *port2, *port3; | 51 | struct pnp_option *option; |
26 | struct pnp_option *res = dev->dependent; | 52 | unsigned int set = ~0; |
27 | 53 | ||
28 | /* | 54 | /* |
29 | * Unfortunately the isapnp_add_port_resource is too tightly bound | 55 | * Add two extra ioport regions (at offset 0x400 and 0x800 from the |
30 | * into the PnP discovery sequence, and cannot be used. Link in the | 56 | * one given) to every dependent option set. |
31 | * two extra ports (at offset 0x400 and 0x800 from the one given) by | ||
32 | * hand. | ||
33 | */ | 57 | */ |
34 | for (; res; res = res->next) { | 58 | list_for_each_entry(option, &dev->options, list) { |
35 | port2 = pnp_alloc(sizeof(struct pnp_port)); | 59 | if (pnp_option_is_dependent(option) && |
36 | if (!port2) | 60 | pnp_option_set(option) != set) { |
37 | return; | 61 | set = pnp_option_set(option); |
38 | port3 = pnp_alloc(sizeof(struct pnp_port)); | 62 | quirk_awe32_add_ports(dev, option, 0x800); |
39 | if (!port3) { | 63 | quirk_awe32_add_ports(dev, option, 0x400); |
40 | kfree(port2); | ||
41 | return; | ||
42 | } | 64 | } |
43 | port = res->port; | ||
44 | memcpy(port2, port, sizeof(struct pnp_port)); | ||
45 | memcpy(port3, port, sizeof(struct pnp_port)); | ||
46 | port->next = port2; | ||
47 | port2->next = port3; | ||
48 | port2->min += 0x400; | ||
49 | port2->max += 0x400; | ||
50 | port3->min += 0x800; | ||
51 | port3->max += 0x800; | ||
52 | dev_info(&dev->dev, | ||
53 | "AWE32 quirk - added ioports 0x%lx and 0x%lx\n", | ||
54 | (unsigned long)port2->min, | ||
55 | (unsigned long)port3->min); | ||
56 | } | 65 | } |
57 | } | 66 | } |
58 | 67 | ||
59 | static void quirk_cmi8330_resources(struct pnp_dev *dev) | 68 | static void quirk_cmi8330_resources(struct pnp_dev *dev) |
60 | { | 69 | { |
61 | struct pnp_option *res = dev->dependent; | 70 | struct pnp_option *option; |
62 | unsigned long tmp; | 71 | struct pnp_irq *irq; |
63 | 72 | struct pnp_dma *dma; | |
64 | for (; res; res = res->next) { | ||
65 | |||
66 | struct pnp_irq *irq; | ||
67 | struct pnp_dma *dma; | ||
68 | 73 | ||
69 | for (irq = res->irq; irq; irq = irq->next) { // Valid irqs are 5, 7, 10 | 74 | list_for_each_entry(option, &dev->options, list) { |
70 | tmp = 0x04A0; | 75 | if (!pnp_option_is_dependent(option)) |
71 | bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000 | 76 | continue; |
72 | } | ||
73 | 77 | ||
74 | for (dma = res->dma; dma; dma = dma->next) // Valid 8bit dma channels are 1,3 | 78 | if (option->type == IORESOURCE_IRQ) { |
79 | irq = &option->u.irq; | ||
80 | bitmap_zero(irq->map.bits, PNP_IRQ_NR); | ||
81 | __set_bit(5, irq->map.bits); | ||
82 | __set_bit(7, irq->map.bits); | ||
83 | __set_bit(10, irq->map.bits); | ||
84 | dev_info(&dev->dev, "set possible IRQs in " | ||
85 | "option set %d to 5, 7, 10\n", | ||
86 | pnp_option_set(option)); | ||
87 | } else if (option->type == IORESOURCE_DMA) { | ||
88 | dma = &option->u.dma; | ||
75 | if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) == | 89 | if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) == |
76 | IORESOURCE_DMA_8BIT) | 90 | IORESOURCE_DMA_8BIT && |
77 | dma->map = 0x000A; | 91 | dma->map != 0x0A) { |
92 | dev_info(&dev->dev, "changing possible " | ||
93 | "DMA channel mask in option set %d " | ||
94 | "from %#02x to 0x0A (1, 3)\n", | ||
95 | pnp_option_set(option), dma->map); | ||
96 | dma->map = 0x0A; | ||
97 | } | ||
98 | } | ||
78 | } | 99 | } |
79 | dev_info(&dev->dev, "CMI8330 quirk - forced possible IRQs to 5, 7, 10 " | ||
80 | "and DMA channels to 1, 3\n"); | ||
81 | } | 100 | } |
82 | 101 | ||
83 | static void quirk_sb16audio_resources(struct pnp_dev *dev) | 102 | static void quirk_sb16audio_resources(struct pnp_dev *dev) |
84 | { | 103 | { |
104 | struct pnp_option *option; | ||
105 | unsigned int prev_option_flags = ~0, n = 0; | ||
85 | struct pnp_port *port; | 106 | struct pnp_port *port; |
86 | struct pnp_option *res = dev->dependent; | ||
87 | int changed = 0; | ||
88 | 107 | ||
89 | /* | 108 | /* |
90 | * The default range on the mpu port for these devices is 0x388-0x388. | 109 | * The default range on the OPL port for these devices is 0x388-0x388. |
91 | * Here we increase that range so that two such cards can be | 110 | * Here we increase that range so that two such cards can be |
92 | * auto-configured. | 111 | * auto-configured. |
93 | */ | 112 | */ |
113 | list_for_each_entry(option, &dev->options, list) { | ||
114 | if (prev_option_flags != option->flags) { | ||
115 | prev_option_flags = option->flags; | ||
116 | n = 0; | ||
117 | } | ||
94 | 118 | ||
95 | for (; res; res = res->next) { | 119 | if (pnp_option_is_dependent(option) && |
96 | port = res->port; | 120 | option->type == IORESOURCE_IO) { |
97 | if (!port) | 121 | n++; |
98 | continue; | 122 | port = &option->u.port; |
99 | port = port->next; | 123 | if (n == 3 && port->min == port->max) { |
100 | if (!port) | 124 | port->max += 0x70; |
101 | continue; | 125 | dev_info(&dev->dev, "increased option port " |
102 | port = port->next; | 126 | "range from %#llx-%#llx to " |
103 | if (!port) | 127 | "%#llx-%#llx\n", |
104 | continue; | 128 | (unsigned long long) port->min, |
105 | if (port->min != port->max) | 129 | (unsigned long long) port->min, |
106 | continue; | 130 | (unsigned long long) port->min, |
107 | port->max += 0x70; | 131 | (unsigned long long) port->max); |
108 | changed = 1; | 132 | } |
133 | } | ||
109 | } | 134 | } |
110 | if (changed) | ||
111 | dev_info(&dev->dev, "SB audio device quirk - increased port range\n"); | ||
112 | } | 135 | } |
113 | 136 | ||
114 | static struct pnp_option *quirk_isapnp_mpu_options(struct pnp_dev *dev) | 137 | static struct pnp_option *pnp_clone_dependent_set(struct pnp_dev *dev, |
138 | unsigned int set) | ||
115 | { | 139 | { |
116 | struct pnp_option *head = NULL; | 140 | struct pnp_option *tail = NULL, *first_new_option = NULL; |
117 | struct pnp_option *prev = NULL; | 141 | struct pnp_option *option, *new_option; |
118 | struct pnp_option *res; | 142 | unsigned int flags; |
119 | |||
120 | /* | ||
121 | * Build a functional IRQ-less variant of each MPU option. | ||
122 | */ | ||
123 | |||
124 | for (res = dev->dependent; res; res = res->next) { | ||
125 | struct pnp_option *curr; | ||
126 | struct pnp_port *port; | ||
127 | struct pnp_port *copy; | ||
128 | 143 | ||
129 | port = res->port; | 144 | list_for_each_entry(option, &dev->options, list) { |
130 | if (!port || !res->irq) | 145 | if (pnp_option_is_dependent(option)) |
131 | continue; | 146 | tail = option; |
147 | } | ||
148 | if (!tail) { | ||
149 | dev_err(&dev->dev, "no dependent option sets\n"); | ||
150 | return NULL; | ||
151 | } | ||
132 | 152 | ||
133 | copy = pnp_alloc(sizeof *copy); | 153 | flags = pnp_new_dependent_set(dev, PNP_RES_PRIORITY_FUNCTIONAL); |
134 | if (!copy) | 154 | list_for_each_entry(option, &dev->options, list) { |
135 | break; | 155 | if (pnp_option_is_dependent(option) && |
156 | pnp_option_set(option) == set) { | ||
157 | new_option = kmalloc(sizeof(struct pnp_option), | ||
158 | GFP_KERNEL); | ||
159 | if (!new_option) { | ||
160 | dev_err(&dev->dev, "couldn't clone dependent " | ||
161 | "set %d\n", set); | ||
162 | return NULL; | ||
163 | } | ||
136 | 164 | ||
137 | copy->min = port->min; | 165 | *new_option = *option; |
138 | copy->max = port->max; | 166 | new_option->flags = flags; |
139 | copy->align = port->align; | 167 | if (!first_new_option) |
140 | copy->size = port->size; | 168 | first_new_option = new_option; |
141 | copy->flags = port->flags; | ||
142 | 169 | ||
143 | curr = pnp_build_option(PNP_RES_PRIORITY_FUNCTIONAL); | 170 | list_add(&new_option->list, &tail->list); |
144 | if (!curr) { | 171 | tail = new_option; |
145 | kfree(copy); | ||
146 | break; | ||
147 | } | 172 | } |
148 | curr->port = copy; | ||
149 | |||
150 | if (prev) | ||
151 | prev->next = curr; | ||
152 | else | ||
153 | head = curr; | ||
154 | prev = curr; | ||
155 | } | 173 | } |
156 | if (head) | ||
157 | dev_info(&dev->dev, "adding IRQ-less MPU options\n"); | ||
158 | 174 | ||
159 | return head; | 175 | return first_new_option; |
160 | } | 176 | } |
161 | 177 | ||
162 | static void quirk_ad1815_mpu_resources(struct pnp_dev *dev) | 178 | |
179 | static void quirk_add_irq_optional_dependent_sets(struct pnp_dev *dev) | ||
163 | { | 180 | { |
164 | struct pnp_option *res; | 181 | struct pnp_option *new_option; |
182 | unsigned int num_sets, i, set; | ||
165 | struct pnp_irq *irq; | 183 | struct pnp_irq *irq; |
166 | 184 | ||
167 | /* | 185 | num_sets = dev->num_dependent_sets; |
168 | * Distribute the independent IRQ over the dependent options | 186 | for (i = 0; i < num_sets; i++) { |
169 | */ | 187 | new_option = pnp_clone_dependent_set(dev, i); |
170 | 188 | if (!new_option) | |
171 | res = dev->independent; | 189 | return; |
172 | if (!res) | ||
173 | return; | ||
174 | |||
175 | irq = res->irq; | ||
176 | if (!irq || irq->next) | ||
177 | return; | ||
178 | |||
179 | res = dev->dependent; | ||
180 | if (!res) | ||
181 | return; | ||
182 | |||
183 | while (1) { | ||
184 | struct pnp_irq *copy; | ||
185 | |||
186 | copy = pnp_alloc(sizeof *copy); | ||
187 | if (!copy) | ||
188 | break; | ||
189 | |||
190 | memcpy(copy->map, irq->map, sizeof copy->map); | ||
191 | copy->flags = irq->flags; | ||
192 | 190 | ||
193 | copy->next = res->irq; /* Yes, this is NULL */ | 191 | set = pnp_option_set(new_option); |
194 | res->irq = copy; | 192 | while (new_option && pnp_option_set(new_option) == set) { |
193 | if (new_option->type == IORESOURCE_IRQ) { | ||
194 | irq = &new_option->u.irq; | ||
195 | irq->flags |= IORESOURCE_IRQ_OPTIONAL; | ||
196 | } | ||
197 | dbg_pnp_show_option(dev, new_option); | ||
198 | new_option = list_entry(new_option->list.next, | ||
199 | struct pnp_option, list); | ||
200 | } | ||
195 | 201 | ||
196 | if (!res->next) | 202 | dev_info(&dev->dev, "added dependent option set %d (same as " |
197 | break; | 203 | "set %d except IRQ optional)\n", set, i); |
198 | res = res->next; | ||
199 | } | 204 | } |
200 | kfree(irq); | ||
201 | |||
202 | res->next = quirk_isapnp_mpu_options(dev); | ||
203 | |||
204 | res = dev->independent; | ||
205 | res->irq = NULL; | ||
206 | } | 205 | } |
207 | 206 | ||
208 | static void quirk_isapnp_mpu_resources(struct pnp_dev *dev) | 207 | static void quirk_ad1815_mpu_resources(struct pnp_dev *dev) |
209 | { | 208 | { |
210 | struct pnp_option *res; | 209 | struct pnp_option *option; |
210 | struct pnp_irq *irq = NULL; | ||
211 | unsigned int independent_irqs = 0; | ||
212 | |||
213 | list_for_each_entry(option, &dev->options, list) { | ||
214 | if (option->type == IORESOURCE_IRQ && | ||
215 | !pnp_option_is_dependent(option)) { | ||
216 | independent_irqs++; | ||
217 | irq = &option->u.irq; | ||
218 | } | ||
219 | } | ||
211 | 220 | ||
212 | res = dev->dependent; | 221 | if (independent_irqs != 1) |
213 | if (!res) | ||
214 | return; | 222 | return; |
215 | 223 | ||
216 | while (res->next) | 224 | irq->flags |= IORESOURCE_IRQ_OPTIONAL; |
217 | res = res->next; | 225 | dev_info(&dev->dev, "made independent IRQ optional\n"); |
218 | |||
219 | res->next = quirk_isapnp_mpu_options(dev); | ||
220 | } | 226 | } |
221 | 227 | ||
222 | #include <linux/pci.h> | 228 | #include <linux/pci.h> |
@@ -248,8 +254,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev) | |||
248 | for (j = 0; | 254 | for (j = 0; |
249 | (res = pnp_get_resource(dev, IORESOURCE_MEM, j)); | 255 | (res = pnp_get_resource(dev, IORESOURCE_MEM, j)); |
250 | j++) { | 256 | j++) { |
251 | if (res->flags & IORESOURCE_UNSET || | 257 | if (res->start == 0 && res->end == 0) |
252 | (res->start == 0 && res->end == 0)) | ||
253 | continue; | 258 | continue; |
254 | 259 | ||
255 | pnp_start = res->start; | 260 | pnp_start = res->start; |
@@ -312,10 +317,10 @@ static struct pnp_fixup pnp_fixups[] = { | |||
312 | {"CTL0043", quirk_sb16audio_resources}, | 317 | {"CTL0043", quirk_sb16audio_resources}, |
313 | {"CTL0044", quirk_sb16audio_resources}, | 318 | {"CTL0044", quirk_sb16audio_resources}, |
314 | {"CTL0045", quirk_sb16audio_resources}, | 319 | {"CTL0045", quirk_sb16audio_resources}, |
315 | /* Add IRQ-less MPU options */ | 320 | /* Add IRQ-optional MPU options */ |
316 | {"ADS7151", quirk_ad1815_mpu_resources}, | 321 | {"ADS7151", quirk_ad1815_mpu_resources}, |
317 | {"ADS7181", quirk_isapnp_mpu_resources}, | 322 | {"ADS7181", quirk_add_irq_optional_dependent_sets}, |
318 | {"AZT0002", quirk_isapnp_mpu_resources}, | 323 | {"AZT0002", quirk_add_irq_optional_dependent_sets}, |
319 | /* PnP resources that might overlap PCI BARs */ | 324 | /* PnP resources that might overlap PCI BARs */ |
320 | {"PNP0c01", quirk_system_pci_resources}, | 325 | {"PNP0c01", quirk_system_pci_resources}, |
321 | {"PNP0c02", quirk_system_pci_resources}, | 326 | {"PNP0c02", quirk_system_pci_resources}, |
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 390b50096e30..4cfe3a1efdfb 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * | 3 | * |
4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> | 4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> |
5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> | 5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
6 | */ | 8 | */ |
7 | 9 | ||
8 | #include <linux/module.h> | 10 | #include <linux/module.h> |
@@ -28,201 +30,121 @@ static int pnp_reserve_mem[16] = {[0 ... 15] = -1 }; /* reserve (don't use) some | |||
28 | * option registration | 30 | * option registration |
29 | */ | 31 | */ |
30 | 32 | ||
31 | struct pnp_option *pnp_build_option(int priority) | 33 | struct pnp_option *pnp_build_option(struct pnp_dev *dev, unsigned long type, |
34 | unsigned int option_flags) | ||
32 | { | 35 | { |
33 | struct pnp_option *option = pnp_alloc(sizeof(struct pnp_option)); | 36 | struct pnp_option *option; |
34 | 37 | ||
38 | option = kzalloc(sizeof(struct pnp_option), GFP_KERNEL); | ||
35 | if (!option) | 39 | if (!option) |
36 | return NULL; | 40 | return NULL; |
37 | 41 | ||
38 | option->priority = priority & 0xff; | 42 | option->flags = option_flags; |
39 | /* make sure the priority is valid */ | 43 | option->type = type; |
40 | if (option->priority > PNP_RES_PRIORITY_FUNCTIONAL) | ||
41 | option->priority = PNP_RES_PRIORITY_INVALID; | ||
42 | |||
43 | return option; | ||
44 | } | ||
45 | |||
46 | struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev) | ||
47 | { | ||
48 | struct pnp_option *option; | ||
49 | |||
50 | option = pnp_build_option(PNP_RES_PRIORITY_PREFERRED); | ||
51 | |||
52 | /* this should never happen but if it does we'll try to continue */ | ||
53 | if (dev->independent) | ||
54 | dev_err(&dev->dev, "independent resource already registered\n"); | ||
55 | dev->independent = option; | ||
56 | 44 | ||
57 | dev_dbg(&dev->dev, "new independent option\n"); | 45 | list_add_tail(&option->list, &dev->options); |
58 | return option; | 46 | return option; |
59 | } | 47 | } |
60 | 48 | ||
61 | struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, | 49 | int pnp_register_irq_resource(struct pnp_dev *dev, unsigned int option_flags, |
62 | int priority) | 50 | pnp_irq_mask_t *map, unsigned char flags) |
63 | { | 51 | { |
64 | struct pnp_option *option; | 52 | struct pnp_option *option; |
53 | struct pnp_irq *irq; | ||
65 | 54 | ||
66 | option = pnp_build_option(priority); | 55 | option = pnp_build_option(dev, IORESOURCE_IRQ, option_flags); |
67 | 56 | if (!option) | |
68 | if (dev->dependent) { | 57 | return -ENOMEM; |
69 | struct pnp_option *parent = dev->dependent; | ||
70 | while (parent->next) | ||
71 | parent = parent->next; | ||
72 | parent->next = option; | ||
73 | } else | ||
74 | dev->dependent = option; | ||
75 | |||
76 | dev_dbg(&dev->dev, "new dependent option (priority %#x)\n", priority); | ||
77 | return option; | ||
78 | } | ||
79 | |||
80 | int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, | ||
81 | struct pnp_irq *data) | ||
82 | { | ||
83 | struct pnp_irq *ptr; | ||
84 | #ifdef DEBUG | ||
85 | char buf[PNP_IRQ_NR]; /* hex-encoded, so this is overkill but safe */ | ||
86 | #endif | ||
87 | 58 | ||
88 | ptr = option->irq; | 59 | irq = &option->u.irq; |
89 | while (ptr && ptr->next) | 60 | irq->map = *map; |
90 | ptr = ptr->next; | 61 | irq->flags = flags; |
91 | if (ptr) | ||
92 | ptr->next = data; | ||
93 | else | ||
94 | option->irq = data; | ||
95 | 62 | ||
96 | #ifdef CONFIG_PCI | 63 | #ifdef CONFIG_PCI |
97 | { | 64 | { |
98 | int i; | 65 | int i; |
99 | 66 | ||
100 | for (i = 0; i < 16; i++) | 67 | for (i = 0; i < 16; i++) |
101 | if (test_bit(i, data->map)) | 68 | if (test_bit(i, irq->map.bits)) |
102 | pcibios_penalize_isa_irq(i, 0); | 69 | pcibios_penalize_isa_irq(i, 0); |
103 | } | 70 | } |
104 | #endif | 71 | #endif |
105 | 72 | ||
106 | #ifdef DEBUG | 73 | dbg_pnp_show_option(dev, option); |
107 | bitmap_scnprintf(buf, sizeof(buf), data->map, PNP_IRQ_NR); | ||
108 | dev_dbg(&dev->dev, " irq bitmask %s flags %#x\n", buf, | ||
109 | data->flags); | ||
110 | #endif | ||
111 | return 0; | 74 | return 0; |
112 | } | 75 | } |
113 | 76 | ||
114 | int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, | 77 | int pnp_register_dma_resource(struct pnp_dev *dev, unsigned int option_flags, |
115 | struct pnp_dma *data) | 78 | unsigned char map, unsigned char flags) |
116 | { | 79 | { |
117 | struct pnp_dma *ptr; | 80 | struct pnp_option *option; |
118 | 81 | struct pnp_dma *dma; | |
119 | ptr = option->dma; | ||
120 | while (ptr && ptr->next) | ||
121 | ptr = ptr->next; | ||
122 | if (ptr) | ||
123 | ptr->next = data; | ||
124 | else | ||
125 | option->dma = data; | ||
126 | |||
127 | dev_dbg(&dev->dev, " dma bitmask %#x flags %#x\n", data->map, | ||
128 | data->flags); | ||
129 | return 0; | ||
130 | } | ||
131 | 82 | ||
132 | int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, | 83 | option = pnp_build_option(dev, IORESOURCE_DMA, option_flags); |
133 | struct pnp_port *data) | 84 | if (!option) |
134 | { | 85 | return -ENOMEM; |
135 | struct pnp_port *ptr; | ||
136 | |||
137 | ptr = option->port; | ||
138 | while (ptr && ptr->next) | ||
139 | ptr = ptr->next; | ||
140 | if (ptr) | ||
141 | ptr->next = data; | ||
142 | else | ||
143 | option->port = data; | ||
144 | |||
145 | dev_dbg(&dev->dev, " io " | ||
146 | "min %#x max %#x align %d size %d flags %#x\n", | ||
147 | data->min, data->max, data->align, data->size, data->flags); | ||
148 | return 0; | ||
149 | } | ||
150 | 86 | ||
151 | int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, | 87 | dma = &option->u.dma; |
152 | struct pnp_mem *data) | 88 | dma->map = map; |
153 | { | 89 | dma->flags = flags; |
154 | struct pnp_mem *ptr; | 90 | |
155 | 91 | dbg_pnp_show_option(dev, option); | |
156 | ptr = option->mem; | ||
157 | while (ptr && ptr->next) | ||
158 | ptr = ptr->next; | ||
159 | if (ptr) | ||
160 | ptr->next = data; | ||
161 | else | ||
162 | option->mem = data; | ||
163 | |||
164 | dev_dbg(&dev->dev, " mem " | ||
165 | "min %#x max %#x align %d size %d flags %#x\n", | ||
166 | data->min, data->max, data->align, data->size, data->flags); | ||
167 | return 0; | 92 | return 0; |
168 | } | 93 | } |
169 | 94 | ||
170 | static void pnp_free_port(struct pnp_port *port) | 95 | int pnp_register_port_resource(struct pnp_dev *dev, unsigned int option_flags, |
96 | resource_size_t min, resource_size_t max, | ||
97 | resource_size_t align, resource_size_t size, | ||
98 | unsigned char flags) | ||
171 | { | 99 | { |
172 | struct pnp_port *next; | 100 | struct pnp_option *option; |
101 | struct pnp_port *port; | ||
173 | 102 | ||
174 | while (port) { | 103 | option = pnp_build_option(dev, IORESOURCE_IO, option_flags); |
175 | next = port->next; | 104 | if (!option) |
176 | kfree(port); | 105 | return -ENOMEM; |
177 | port = next; | ||
178 | } | ||
179 | } | ||
180 | 106 | ||
181 | static void pnp_free_irq(struct pnp_irq *irq) | 107 | port = &option->u.port; |
182 | { | 108 | port->min = min; |
183 | struct pnp_irq *next; | 109 | port->max = max; |
110 | port->align = align; | ||
111 | port->size = size; | ||
112 | port->flags = flags; | ||
184 | 113 | ||
185 | while (irq) { | 114 | dbg_pnp_show_option(dev, option); |
186 | next = irq->next; | 115 | return 0; |
187 | kfree(irq); | ||
188 | irq = next; | ||
189 | } | ||
190 | } | 116 | } |
191 | 117 | ||
192 | static void pnp_free_dma(struct pnp_dma *dma) | 118 | int pnp_register_mem_resource(struct pnp_dev *dev, unsigned int option_flags, |
119 | resource_size_t min, resource_size_t max, | ||
120 | resource_size_t align, resource_size_t size, | ||
121 | unsigned char flags) | ||
193 | { | 122 | { |
194 | struct pnp_dma *next; | 123 | struct pnp_option *option; |
124 | struct pnp_mem *mem; | ||
195 | 125 | ||
196 | while (dma) { | 126 | option = pnp_build_option(dev, IORESOURCE_MEM, option_flags); |
197 | next = dma->next; | 127 | if (!option) |
198 | kfree(dma); | 128 | return -ENOMEM; |
199 | dma = next; | ||
200 | } | ||
201 | } | ||
202 | 129 | ||
203 | static void pnp_free_mem(struct pnp_mem *mem) | 130 | mem = &option->u.mem; |
204 | { | 131 | mem->min = min; |
205 | struct pnp_mem *next; | 132 | mem->max = max; |
133 | mem->align = align; | ||
134 | mem->size = size; | ||
135 | mem->flags = flags; | ||
206 | 136 | ||
207 | while (mem) { | 137 | dbg_pnp_show_option(dev, option); |
208 | next = mem->next; | 138 | return 0; |
209 | kfree(mem); | ||
210 | mem = next; | ||
211 | } | ||
212 | } | 139 | } |
213 | 140 | ||
214 | void pnp_free_option(struct pnp_option *option) | 141 | void pnp_free_options(struct pnp_dev *dev) |
215 | { | 142 | { |
216 | struct pnp_option *next; | 143 | struct pnp_option *option, *tmp; |
217 | 144 | ||
218 | while (option) { | 145 | list_for_each_entry_safe(option, tmp, &dev->options, list) { |
219 | next = option->next; | 146 | list_del(&option->list); |
220 | pnp_free_port(option->port); | ||
221 | pnp_free_irq(option->irq); | ||
222 | pnp_free_dma(option->dma); | ||
223 | pnp_free_mem(option->mem); | ||
224 | kfree(option); | 147 | kfree(option); |
225 | option = next; | ||
226 | } | 148 | } |
227 | } | 149 | } |
228 | 150 | ||
@@ -237,7 +159,7 @@ void pnp_free_option(struct pnp_option *option) | |||
237 | !((*(enda) < *(startb)) || (*(endb) < *(starta))) | 159 | !((*(enda) < *(startb)) || (*(endb) < *(starta))) |
238 | 160 | ||
239 | #define cannot_compare(flags) \ | 161 | #define cannot_compare(flags) \ |
240 | ((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) | 162 | ((flags) & IORESOURCE_DISABLED) |
241 | 163 | ||
242 | int pnp_check_port(struct pnp_dev *dev, struct resource *res) | 164 | int pnp_check_port(struct pnp_dev *dev, struct resource *res) |
243 | { | 165 | { |
@@ -364,6 +286,61 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id) | |||
364 | return IRQ_HANDLED; | 286 | return IRQ_HANDLED; |
365 | } | 287 | } |
366 | 288 | ||
289 | #ifdef CONFIG_PCI | ||
290 | static int pci_dev_uses_irq(struct pnp_dev *pnp, struct pci_dev *pci, | ||
291 | unsigned int irq) | ||
292 | { | ||
293 | u32 class; | ||
294 | u8 progif; | ||
295 | |||
296 | if (pci->irq == irq) { | ||
297 | dev_dbg(&pnp->dev, "device %s using irq %d\n", | ||
298 | pci_name(pci), irq); | ||
299 | return 1; | ||
300 | } | ||
301 | |||
302 | /* | ||
303 | * See pci_setup_device() and ata_pci_sff_activate_host() for | ||
304 | * similar IDE legacy detection. | ||
305 | */ | ||
306 | pci_read_config_dword(pci, PCI_CLASS_REVISION, &class); | ||
307 | class >>= 8; /* discard revision ID */ | ||
308 | progif = class & 0xff; | ||
309 | class >>= 8; | ||
310 | |||
311 | if (class == PCI_CLASS_STORAGE_IDE) { | ||
312 | /* | ||
313 | * Unless both channels are native-PCI mode only, | ||
314 | * treat the compatibility IRQs as busy. | ||
315 | */ | ||
316 | if ((progif & 0x5) != 0x5) | ||
317 | if (pci_get_legacy_ide_irq(pci, 0) == irq || | ||
318 | pci_get_legacy_ide_irq(pci, 1) == irq) { | ||
319 | dev_dbg(&pnp->dev, "legacy IDE device %s " | ||
320 | "using irq %d\n", pci_name(pci), irq); | ||
321 | return 1; | ||
322 | } | ||
323 | } | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | #endif | ||
328 | |||
329 | static int pci_uses_irq(struct pnp_dev *pnp, unsigned int irq) | ||
330 | { | ||
331 | #ifdef CONFIG_PCI | ||
332 | struct pci_dev *pci = NULL; | ||
333 | |||
334 | for_each_pci_dev(pci) { | ||
335 | if (pci_dev_uses_irq(pnp, pci, irq)) { | ||
336 | pci_dev_put(pci); | ||
337 | return 1; | ||
338 | } | ||
339 | } | ||
340 | #endif | ||
341 | return 0; | ||
342 | } | ||
343 | |||
367 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res) | 344 | int pnp_check_irq(struct pnp_dev *dev, struct resource *res) |
368 | { | 345 | { |
369 | int i; | 346 | int i; |
@@ -395,18 +372,9 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res) | |||
395 | } | 372 | } |
396 | } | 373 | } |
397 | 374 | ||
398 | #ifdef CONFIG_PCI | ||
399 | /* check if the resource is being used by a pci device */ | 375 | /* check if the resource is being used by a pci device */ |
400 | { | 376 | if (pci_uses_irq(dev, *irq)) |
401 | struct pci_dev *pci = NULL; | 377 | return 0; |
402 | for_each_pci_dev(pci) { | ||
403 | if (pci->irq == *irq) { | ||
404 | pci_dev_put(pci); | ||
405 | return 0; | ||
406 | } | ||
407 | } | ||
408 | } | ||
409 | #endif | ||
410 | 378 | ||
411 | /* check if the resource is already in use, skip if the | 379 | /* check if the resource is already in use, skip if the |
412 | * device is active because it itself may be in use */ | 380 | * device is active because it itself may be in use */ |
@@ -499,81 +467,37 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) | |||
499 | #endif | 467 | #endif |
500 | } | 468 | } |
501 | 469 | ||
502 | struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev, | 470 | int pnp_resource_type(struct resource *res) |
503 | unsigned int type, unsigned int num) | ||
504 | { | 471 | { |
505 | struct pnp_resource_table *res = dev->res; | 472 | return res->flags & (IORESOURCE_IO | IORESOURCE_MEM | |
506 | 473 | IORESOURCE_IRQ | IORESOURCE_DMA); | |
507 | switch (type) { | ||
508 | case IORESOURCE_IO: | ||
509 | if (num >= PNP_MAX_PORT) | ||
510 | return NULL; | ||
511 | return &res->port[num]; | ||
512 | case IORESOURCE_MEM: | ||
513 | if (num >= PNP_MAX_MEM) | ||
514 | return NULL; | ||
515 | return &res->mem[num]; | ||
516 | case IORESOURCE_IRQ: | ||
517 | if (num >= PNP_MAX_IRQ) | ||
518 | return NULL; | ||
519 | return &res->irq[num]; | ||
520 | case IORESOURCE_DMA: | ||
521 | if (num >= PNP_MAX_DMA) | ||
522 | return NULL; | ||
523 | return &res->dma[num]; | ||
524 | } | ||
525 | return NULL; | ||
526 | } | 474 | } |
527 | 475 | ||
528 | struct resource *pnp_get_resource(struct pnp_dev *dev, | 476 | struct resource *pnp_get_resource(struct pnp_dev *dev, |
529 | unsigned int type, unsigned int num) | 477 | unsigned int type, unsigned int num) |
530 | { | 478 | { |
531 | struct pnp_resource *pnp_res; | 479 | struct pnp_resource *pnp_res; |
480 | struct resource *res; | ||
532 | 481 | ||
533 | pnp_res = pnp_get_pnp_resource(dev, type, num); | 482 | list_for_each_entry(pnp_res, &dev->resources, list) { |
534 | if (pnp_res) | 483 | res = &pnp_res->res; |
535 | return &pnp_res->res; | 484 | if (pnp_resource_type(res) == type && num-- == 0) |
536 | 485 | return res; | |
486 | } | ||
537 | return NULL; | 487 | return NULL; |
538 | } | 488 | } |
539 | EXPORT_SYMBOL(pnp_get_resource); | 489 | EXPORT_SYMBOL(pnp_get_resource); |
540 | 490 | ||
541 | static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type) | 491 | static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev) |
542 | { | 492 | { |
543 | struct pnp_resource *pnp_res; | 493 | struct pnp_resource *pnp_res; |
544 | int i; | ||
545 | 494 | ||
546 | switch (type) { | 495 | pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL); |
547 | case IORESOURCE_IO: | 496 | if (!pnp_res) |
548 | for (i = 0; i < PNP_MAX_PORT; i++) { | 497 | return NULL; |
549 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, i); | 498 | |
550 | if (pnp_res && !pnp_resource_valid(&pnp_res->res)) | 499 | list_add_tail(&pnp_res->list, &dev->resources); |
551 | return pnp_res; | 500 | return pnp_res; |
552 | } | ||
553 | break; | ||
554 | case IORESOURCE_MEM: | ||
555 | for (i = 0; i < PNP_MAX_MEM; i++) { | ||
556 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, i); | ||
557 | if (pnp_res && !pnp_resource_valid(&pnp_res->res)) | ||
558 | return pnp_res; | ||
559 | } | ||
560 | break; | ||
561 | case IORESOURCE_IRQ: | ||
562 | for (i = 0; i < PNP_MAX_IRQ; i++) { | ||
563 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, i); | ||
564 | if (pnp_res && !pnp_resource_valid(&pnp_res->res)) | ||
565 | return pnp_res; | ||
566 | } | ||
567 | break; | ||
568 | case IORESOURCE_DMA: | ||
569 | for (i = 0; i < PNP_MAX_DMA; i++) { | ||
570 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, i); | ||
571 | if (pnp_res && !pnp_resource_valid(&pnp_res->res)) | ||
572 | return pnp_res; | ||
573 | } | ||
574 | break; | ||
575 | } | ||
576 | return NULL; | ||
577 | } | 501 | } |
578 | 502 | ||
579 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, | 503 | struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, |
@@ -581,15 +505,10 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, | |||
581 | { | 505 | { |
582 | struct pnp_resource *pnp_res; | 506 | struct pnp_resource *pnp_res; |
583 | struct resource *res; | 507 | struct resource *res; |
584 | static unsigned char warned; | ||
585 | 508 | ||
586 | pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ); | 509 | pnp_res = pnp_new_resource(dev); |
587 | if (!pnp_res) { | 510 | if (!pnp_res) { |
588 | if (!warned) { | 511 | dev_err(&dev->dev, "can't add resource for IRQ %d\n", irq); |
589 | dev_err(&dev->dev, "can't add resource for IRQ %d\n", | ||
590 | irq); | ||
591 | warned = 1; | ||
592 | } | ||
593 | return NULL; | 512 | return NULL; |
594 | } | 513 | } |
595 | 514 | ||
@@ -607,15 +526,10 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, | |||
607 | { | 526 | { |
608 | struct pnp_resource *pnp_res; | 527 | struct pnp_resource *pnp_res; |
609 | struct resource *res; | 528 | struct resource *res; |
610 | static unsigned char warned; | ||
611 | 529 | ||
612 | pnp_res = pnp_new_resource(dev, IORESOURCE_DMA); | 530 | pnp_res = pnp_new_resource(dev); |
613 | if (!pnp_res) { | 531 | if (!pnp_res) { |
614 | if (!warned) { | 532 | dev_err(&dev->dev, "can't add resource for DMA %d\n", dma); |
615 | dev_err(&dev->dev, "can't add resource for DMA %d\n", | ||
616 | dma); | ||
617 | warned = 1; | ||
618 | } | ||
619 | return NULL; | 533 | return NULL; |
620 | } | 534 | } |
621 | 535 | ||
@@ -634,16 +548,12 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, | |||
634 | { | 548 | { |
635 | struct pnp_resource *pnp_res; | 549 | struct pnp_resource *pnp_res; |
636 | struct resource *res; | 550 | struct resource *res; |
637 | static unsigned char warned; | ||
638 | 551 | ||
639 | pnp_res = pnp_new_resource(dev, IORESOURCE_IO); | 552 | pnp_res = pnp_new_resource(dev); |
640 | if (!pnp_res) { | 553 | if (!pnp_res) { |
641 | if (!warned) { | 554 | dev_err(&dev->dev, "can't add resource for IO %#llx-%#llx\n", |
642 | dev_err(&dev->dev, "can't add resource for IO " | 555 | (unsigned long long) start, |
643 | "%#llx-%#llx\n",(unsigned long long) start, | 556 | (unsigned long long) end); |
644 | (unsigned long long) end); | ||
645 | warned = 1; | ||
646 | } | ||
647 | return NULL; | 557 | return NULL; |
648 | } | 558 | } |
649 | 559 | ||
@@ -663,16 +573,12 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, | |||
663 | { | 573 | { |
664 | struct pnp_resource *pnp_res; | 574 | struct pnp_resource *pnp_res; |
665 | struct resource *res; | 575 | struct resource *res; |
666 | static unsigned char warned; | ||
667 | 576 | ||
668 | pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); | 577 | pnp_res = pnp_new_resource(dev); |
669 | if (!pnp_res) { | 578 | if (!pnp_res) { |
670 | if (!warned) { | 579 | dev_err(&dev->dev, "can't add resource for MEM %#llx-%#llx\n", |
671 | dev_err(&dev->dev, "can't add resource for MEM " | 580 | (unsigned long long) start, |
672 | "%#llx-%#llx\n",(unsigned long long) start, | 581 | (unsigned long long) end); |
673 | (unsigned long long) end); | ||
674 | warned = 1; | ||
675 | } | ||
676 | return NULL; | 582 | return NULL; |
677 | } | 583 | } |
678 | 584 | ||
@@ -686,6 +592,52 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, | |||
686 | return pnp_res; | 592 | return pnp_res; |
687 | } | 593 | } |
688 | 594 | ||
595 | /* | ||
596 | * Determine whether the specified resource is a possible configuration | ||
597 | * for this device. | ||
598 | */ | ||
599 | int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t start, | ||
600 | resource_size_t size) | ||
601 | { | ||
602 | struct pnp_option *option; | ||
603 | struct pnp_port *port; | ||
604 | struct pnp_mem *mem; | ||
605 | struct pnp_irq *irq; | ||
606 | struct pnp_dma *dma; | ||
607 | |||
608 | list_for_each_entry(option, &dev->options, list) { | ||
609 | if (option->type != type) | ||
610 | continue; | ||
611 | |||
612 | switch (option->type) { | ||
613 | case IORESOURCE_IO: | ||
614 | port = &option->u.port; | ||
615 | if (port->min == start && port->size == size) | ||
616 | return 1; | ||
617 | break; | ||
618 | case IORESOURCE_MEM: | ||
619 | mem = &option->u.mem; | ||
620 | if (mem->min == start && mem->size == size) | ||
621 | return 1; | ||
622 | break; | ||
623 | case IORESOURCE_IRQ: | ||
624 | irq = &option->u.irq; | ||
625 | if (start < PNP_IRQ_NR && | ||
626 | test_bit(start, irq->map.bits)) | ||
627 | return 1; | ||
628 | break; | ||
629 | case IORESOURCE_DMA: | ||
630 | dma = &option->u.dma; | ||
631 | if (dma->map & (1 << start)) | ||
632 | return 1; | ||
633 | break; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | return 0; | ||
638 | } | ||
639 | EXPORT_SYMBOL(pnp_possible_config); | ||
640 | |||
689 | /* format is: pnp_reserve_irq=irq1[,irq2] .... */ | 641 | /* format is: pnp_reserve_irq=irq1[,irq2] .... */ |
690 | static int __init pnp_setup_reserve_irq(char *str) | 642 | static int __init pnp_setup_reserve_irq(char *str) |
691 | { | 643 | { |
diff --git a/drivers/pnp/support.c b/drivers/pnp/support.c index 95b076c18c07..bbf78ef4ba02 100644 --- a/drivers/pnp/support.c +++ b/drivers/pnp/support.c | |||
@@ -2,6 +2,8 @@ | |||
2 | * support.c - standard functions for the use of pnp protocol drivers | 2 | * support.c - standard functions for the use of pnp protocol drivers |
3 | * | 3 | * |
4 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> | 4 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
5 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
6 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
5 | */ | 7 | */ |
6 | 8 | ||
7 | #include <linux/module.h> | 9 | #include <linux/module.h> |
@@ -16,6 +18,10 @@ | |||
16 | */ | 18 | */ |
17 | int pnp_is_active(struct pnp_dev *dev) | 19 | int pnp_is_active(struct pnp_dev *dev) |
18 | { | 20 | { |
21 | /* | ||
22 | * I don't think this is very reliable because pnp_disable_dev() | ||
23 | * only clears out auto-assigned resources. | ||
24 | */ | ||
19 | if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 && | 25 | if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 && |
20 | !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 && | 26 | !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 && |
21 | pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1) | 27 | pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1) |
@@ -52,39 +58,154 @@ void pnp_eisa_id_to_string(u32 id, char *str) | |||
52 | str[7] = '\0'; | 58 | str[7] = '\0'; |
53 | } | 59 | } |
54 | 60 | ||
61 | char *pnp_resource_type_name(struct resource *res) | ||
62 | { | ||
63 | switch (pnp_resource_type(res)) { | ||
64 | case IORESOURCE_IO: | ||
65 | return "io"; | ||
66 | case IORESOURCE_MEM: | ||
67 | return "mem"; | ||
68 | case IORESOURCE_IRQ: | ||
69 | return "irq"; | ||
70 | case IORESOURCE_DMA: | ||
71 | return "dma"; | ||
72 | } | ||
73 | return NULL; | ||
74 | } | ||
75 | |||
55 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc) | 76 | void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc) |
56 | { | 77 | { |
57 | #ifdef DEBUG | 78 | #ifdef DEBUG |
79 | char buf[128]; | ||
80 | int len = 0; | ||
81 | struct pnp_resource *pnp_res; | ||
58 | struct resource *res; | 82 | struct resource *res; |
59 | int i; | ||
60 | 83 | ||
61 | dev_dbg(&dev->dev, "current resources: %s\n", desc); | 84 | if (list_empty(&dev->resources)) { |
62 | 85 | dev_dbg(&dev->dev, "%s: no current resources\n", desc); | |
63 | for (i = 0; i < PNP_MAX_IRQ; i++) { | 86 | return; |
64 | res = pnp_get_resource(dev, IORESOURCE_IRQ, i); | ||
65 | if (res && !(res->flags & IORESOURCE_UNSET)) | ||
66 | dev_dbg(&dev->dev, " irq %lld flags %#lx\n", | ||
67 | (unsigned long long) res->start, res->flags); | ||
68 | } | 87 | } |
69 | for (i = 0; i < PNP_MAX_DMA; i++) { | 88 | |
70 | res = pnp_get_resource(dev, IORESOURCE_DMA, i); | 89 | dev_dbg(&dev->dev, "%s: current resources:\n", desc); |
71 | if (res && !(res->flags & IORESOURCE_UNSET)) | 90 | list_for_each_entry(pnp_res, &dev->resources, list) { |
72 | dev_dbg(&dev->dev, " dma %lld flags %#lx\n", | 91 | res = &pnp_res->res; |
73 | (unsigned long long) res->start, res->flags); | 92 | |
93 | len += snprintf(buf + len, sizeof(buf) - len, " %-3s ", | ||
94 | pnp_resource_type_name(res)); | ||
95 | |||
96 | if (res->flags & IORESOURCE_DISABLED) { | ||
97 | dev_dbg(&dev->dev, "%sdisabled\n", buf); | ||
98 | continue; | ||
99 | } | ||
100 | |||
101 | switch (pnp_resource_type(res)) { | ||
102 | case IORESOURCE_IO: | ||
103 | case IORESOURCE_MEM: | ||
104 | len += snprintf(buf + len, sizeof(buf) - len, | ||
105 | "%#llx-%#llx flags %#lx", | ||
106 | (unsigned long long) res->start, | ||
107 | (unsigned long long) res->end, | ||
108 | res->flags); | ||
109 | break; | ||
110 | case IORESOURCE_IRQ: | ||
111 | case IORESOURCE_DMA: | ||
112 | len += snprintf(buf + len, sizeof(buf) - len, | ||
113 | "%lld flags %#lx", | ||
114 | (unsigned long long) res->start, | ||
115 | res->flags); | ||
116 | break; | ||
117 | } | ||
118 | dev_dbg(&dev->dev, "%s\n", buf); | ||
74 | } | 119 | } |
75 | for (i = 0; i < PNP_MAX_PORT; i++) { | 120 | #endif |
76 | res = pnp_get_resource(dev, IORESOURCE_IO, i); | 121 | } |
77 | if (res && !(res->flags & IORESOURCE_UNSET)) | 122 | |
78 | dev_dbg(&dev->dev, " io %#llx-%#llx flags %#lx\n", | 123 | char *pnp_option_priority_name(struct pnp_option *option) |
79 | (unsigned long long) res->start, | 124 | { |
80 | (unsigned long long) res->end, res->flags); | 125 | switch (pnp_option_priority(option)) { |
126 | case PNP_RES_PRIORITY_PREFERRED: | ||
127 | return "preferred"; | ||
128 | case PNP_RES_PRIORITY_ACCEPTABLE: | ||
129 | return "acceptable"; | ||
130 | case PNP_RES_PRIORITY_FUNCTIONAL: | ||
131 | return "functional"; | ||
81 | } | 132 | } |
82 | for (i = 0; i < PNP_MAX_MEM; i++) { | 133 | return "invalid"; |
83 | res = pnp_get_resource(dev, IORESOURCE_MEM, i); | 134 | } |
84 | if (res && !(res->flags & IORESOURCE_UNSET)) | 135 | |
85 | dev_dbg(&dev->dev, " mem %#llx-%#llx flags %#lx\n", | 136 | void dbg_pnp_show_option(struct pnp_dev *dev, struct pnp_option *option) |
86 | (unsigned long long) res->start, | 137 | { |
87 | (unsigned long long) res->end, res->flags); | 138 | #ifdef DEBUG |
139 | char buf[128]; | ||
140 | int len = 0, i; | ||
141 | struct pnp_port *port; | ||
142 | struct pnp_mem *mem; | ||
143 | struct pnp_irq *irq; | ||
144 | struct pnp_dma *dma; | ||
145 | |||
146 | if (pnp_option_is_dependent(option)) | ||
147 | len += snprintf(buf + len, sizeof(buf) - len, | ||
148 | " dependent set %d (%s) ", | ||
149 | pnp_option_set(option), | ||
150 | pnp_option_priority_name(option)); | ||
151 | else | ||
152 | len += snprintf(buf + len, sizeof(buf) - len, " independent "); | ||
153 | |||
154 | switch (option->type) { | ||
155 | case IORESOURCE_IO: | ||
156 | port = &option->u.port; | ||
157 | len += snprintf(buf + len, sizeof(buf) - len, "io min %#llx " | ||
158 | "max %#llx align %lld size %lld flags %#x", | ||
159 | (unsigned long long) port->min, | ||
160 | (unsigned long long) port->max, | ||
161 | (unsigned long long) port->align, | ||
162 | (unsigned long long) port->size, port->flags); | ||
163 | break; | ||
164 | case IORESOURCE_MEM: | ||
165 | mem = &option->u.mem; | ||
166 | len += snprintf(buf + len, sizeof(buf) - len, "mem min %#llx " | ||
167 | "max %#llx align %lld size %lld flags %#x", | ||
168 | (unsigned long long) mem->min, | ||
169 | (unsigned long long) mem->max, | ||
170 | (unsigned long long) mem->align, | ||
171 | (unsigned long long) mem->size, mem->flags); | ||
172 | break; | ||
173 | case IORESOURCE_IRQ: | ||
174 | irq = &option->u.irq; | ||
175 | len += snprintf(buf + len, sizeof(buf) - len, "irq"); | ||
176 | if (bitmap_empty(irq->map.bits, PNP_IRQ_NR)) | ||
177 | len += snprintf(buf + len, sizeof(buf) - len, | ||
178 | " <none>"); | ||
179 | else { | ||
180 | for (i = 0; i < PNP_IRQ_NR; i++) | ||
181 | if (test_bit(i, irq->map.bits)) | ||
182 | len += snprintf(buf + len, | ||
183 | sizeof(buf) - len, | ||
184 | " %d", i); | ||
185 | } | ||
186 | len += snprintf(buf + len, sizeof(buf) - len, " flags %#x", | ||
187 | irq->flags); | ||
188 | if (irq->flags & IORESOURCE_IRQ_OPTIONAL) | ||
189 | len += snprintf(buf + len, sizeof(buf) - len, | ||
190 | " (optional)"); | ||
191 | break; | ||
192 | case IORESOURCE_DMA: | ||
193 | dma = &option->u.dma; | ||
194 | len += snprintf(buf + len, sizeof(buf) - len, "dma"); | ||
195 | if (!dma->map) | ||
196 | len += snprintf(buf + len, sizeof(buf) - len, | ||
197 | " <none>"); | ||
198 | else { | ||
199 | for (i = 0; i < 8; i++) | ||
200 | if (dma->map & (1 << i)) | ||
201 | len += snprintf(buf + len, | ||
202 | sizeof(buf) - len, | ||
203 | " %d", i); | ||
204 | } | ||
205 | len += snprintf(buf + len, sizeof(buf) - len, " (bitmask %#x) " | ||
206 | "flags %#x", dma->map, dma->flags); | ||
207 | break; | ||
88 | } | 208 | } |
209 | dev_dbg(&dev->dev, "%s\n", buf); | ||
89 | #endif | 210 | #endif |
90 | } | 211 | } |
diff --git a/drivers/pnp/system.c b/drivers/pnp/system.c index cf4e07b01d48..764f3a310685 100644 --- a/drivers/pnp/system.c +++ b/drivers/pnp/system.c | |||
@@ -60,7 +60,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev) | |||
60 | int i; | 60 | int i; |
61 | 61 | ||
62 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { | 62 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { |
63 | if (res->flags & IORESOURCE_UNSET) | 63 | if (res->flags & IORESOURCE_DISABLED) |
64 | continue; | 64 | continue; |
65 | if (res->start == 0) | 65 | if (res->start == 0) |
66 | continue; /* disabled */ | 66 | continue; /* disabled */ |
@@ -81,7 +81,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev) | |||
81 | } | 81 | } |
82 | 82 | ||
83 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { | 83 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { |
84 | if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) | 84 | if (res->flags & IORESOURCE_DISABLED) |
85 | continue; | 85 | continue; |
86 | 86 | ||
87 | reserve_range(dev, res->start, res->end, 0); | 87 | reserve_range(dev, res->start, res->end, 0); |
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c index d91df38ee4f7..85fcb4371054 100644 --- a/drivers/s390/block/dasd_diag.c +++ b/drivers/s390/block/dasd_diag.c | |||
@@ -333,7 +333,8 @@ dasd_diag_check_device(struct dasd_device *device) | |||
333 | if (IS_ERR(block)) { | 333 | if (IS_ERR(block)) { |
334 | DEV_MESSAGE(KERN_WARNING, device, "%s", | 334 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
335 | "could not allocate dasd block structure"); | 335 | "could not allocate dasd block structure"); |
336 | kfree(device->private); | 336 | device->private = NULL; |
337 | kfree(private); | ||
337 | return PTR_ERR(block); | 338 | return PTR_ERR(block); |
338 | } | 339 | } |
339 | device->block = block; | 340 | device->block = block; |
@@ -348,7 +349,8 @@ dasd_diag_check_device(struct dasd_device *device) | |||
348 | if (rc) { | 349 | if (rc) { |
349 | DEV_MESSAGE(KERN_WARNING, device, "failed to retrieve device " | 350 | DEV_MESSAGE(KERN_WARNING, device, "failed to retrieve device " |
350 | "information (rc=%d)", rc); | 351 | "information (rc=%d)", rc); |
351 | return -ENOTSUPP; | 352 | rc = -EOPNOTSUPP; |
353 | goto out; | ||
352 | } | 354 | } |
353 | 355 | ||
354 | /* Figure out position of label block */ | 356 | /* Figure out position of label block */ |
@@ -362,7 +364,8 @@ dasd_diag_check_device(struct dasd_device *device) | |||
362 | default: | 364 | default: |
363 | DEV_MESSAGE(KERN_WARNING, device, "unsupported device class " | 365 | DEV_MESSAGE(KERN_WARNING, device, "unsupported device class " |
364 | "(class=%d)", private->rdc_data.vdev_class); | 366 | "(class=%d)", private->rdc_data.vdev_class); |
365 | return -ENOTSUPP; | 367 | rc = -EOPNOTSUPP; |
368 | goto out; | ||
366 | } | 369 | } |
367 | 370 | ||
368 | DBF_DEV_EVENT(DBF_INFO, device, | 371 | DBF_DEV_EVENT(DBF_INFO, device, |
@@ -379,7 +382,8 @@ dasd_diag_check_device(struct dasd_device *device) | |||
379 | if (label == NULL) { | 382 | if (label == NULL) { |
380 | DEV_MESSAGE(KERN_WARNING, device, "%s", | 383 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
381 | "No memory to allocate initialization request"); | 384 | "No memory to allocate initialization request"); |
382 | return -ENOMEM; | 385 | rc = -ENOMEM; |
386 | goto out; | ||
383 | } | 387 | } |
384 | rc = 0; | 388 | rc = 0; |
385 | end_block = 0; | 389 | end_block = 0; |
@@ -403,7 +407,7 @@ dasd_diag_check_device(struct dasd_device *device) | |||
403 | DEV_MESSAGE(KERN_WARNING, device, "%s", | 407 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
404 | "DIAG call failed"); | 408 | "DIAG call failed"); |
405 | rc = -EOPNOTSUPP; | 409 | rc = -EOPNOTSUPP; |
406 | goto out; | 410 | goto out_label; |
407 | } | 411 | } |
408 | mdsk_term_io(device); | 412 | mdsk_term_io(device); |
409 | if (rc == 0) | 413 | if (rc == 0) |
@@ -413,7 +417,7 @@ dasd_diag_check_device(struct dasd_device *device) | |||
413 | DEV_MESSAGE(KERN_WARNING, device, "device access failed " | 417 | DEV_MESSAGE(KERN_WARNING, device, "device access failed " |
414 | "(rc=%d)", rc); | 418 | "(rc=%d)", rc); |
415 | rc = -EIO; | 419 | rc = -EIO; |
416 | goto out; | 420 | goto out_label; |
417 | } | 421 | } |
418 | /* check for label block */ | 422 | /* check for label block */ |
419 | if (memcmp(label->label_id, DASD_DIAG_CMS1, | 423 | if (memcmp(label->label_id, DASD_DIAG_CMS1, |
@@ -439,8 +443,15 @@ dasd_diag_check_device(struct dasd_device *device) | |||
439 | (unsigned long) (block->blocks << | 443 | (unsigned long) (block->blocks << |
440 | block->s2b_shift) >> 1); | 444 | block->s2b_shift) >> 1); |
441 | } | 445 | } |
442 | out: | 446 | out_label: |
443 | free_page((long) label); | 447 | free_page((long) label); |
448 | out: | ||
449 | if (rc) { | ||
450 | device->block = NULL; | ||
451 | dasd_free_block(block); | ||
452 | device->private = NULL; | ||
453 | kfree(private); | ||
454 | } | ||
444 | return rc; | 455 | return rc; |
445 | } | 456 | } |
446 | 457 | ||
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index e0b77210d37a..3590fdb5b2fd 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c | |||
@@ -1418,8 +1418,10 @@ static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device, | |||
1418 | 1418 | ||
1419 | 1419 | ||
1420 | /* service information message SIM */ | 1420 | /* service information message SIM */ |
1421 | if ((irb->ecw[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE) { | 1421 | if (irb->esw.esw0.erw.cons && (irb->ecw[27] & DASD_SENSE_BIT_0) && |
1422 | ((irb->ecw[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) { | ||
1422 | dasd_3990_erp_handle_sim(device, irb->ecw); | 1423 | dasd_3990_erp_handle_sim(device, irb->ecw); |
1424 | dasd_schedule_device_bh(device); | ||
1423 | return; | 1425 | return; |
1424 | } | 1426 | } |
1425 | 1427 | ||
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c index aee4656127f7..aa0c533423a5 100644 --- a/drivers/s390/block/dasd_fba.c +++ b/drivers/s390/block/dasd_fba.c | |||
@@ -139,7 +139,8 @@ dasd_fba_check_characteristics(struct dasd_device *device) | |||
139 | if (IS_ERR(block)) { | 139 | if (IS_ERR(block)) { |
140 | DEV_MESSAGE(KERN_WARNING, device, "%s", | 140 | DEV_MESSAGE(KERN_WARNING, device, "%s", |
141 | "could not allocate dasd block structure"); | 141 | "could not allocate dasd block structure"); |
142 | kfree(device->private); | 142 | device->private = NULL; |
143 | kfree(private); | ||
143 | return PTR_ERR(block); | 144 | return PTR_ERR(block); |
144 | } | 145 | } |
145 | device->block = block; | 146 | device->block = block; |
@@ -152,6 +153,10 @@ dasd_fba_check_characteristics(struct dasd_device *device) | |||
152 | DEV_MESSAGE(KERN_WARNING, device, | 153 | DEV_MESSAGE(KERN_WARNING, device, |
153 | "Read device characteristics returned error %d", | 154 | "Read device characteristics returned error %d", |
154 | rc); | 155 | rc); |
156 | device->block = NULL; | ||
157 | dasd_free_block(block); | ||
158 | device->private = NULL; | ||
159 | kfree(private); | ||
155 | return rc; | 160 | return rc; |
156 | } | 161 | } |
157 | 162 | ||
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c index 0a9f1cccbe58..b0ac44b27127 100644 --- a/drivers/s390/char/vmur.c +++ b/drivers/s390/char/vmur.c | |||
@@ -345,7 +345,7 @@ static int get_urd_class(struct urdev *urd) | |||
345 | cc = diag210(&ur_diag210); | 345 | cc = diag210(&ur_diag210); |
346 | switch (cc) { | 346 | switch (cc) { |
347 | case 0: | 347 | case 0: |
348 | return -ENOTSUPP; | 348 | return -EOPNOTSUPP; |
349 | case 2: | 349 | case 2: |
350 | return ur_diag210.vrdcvcla; /* virtual device class */ | 350 | return ur_diag210.vrdcvcla; /* virtual device class */ |
351 | case 3: | 351 | case 3: |
@@ -621,7 +621,7 @@ static int verify_device(struct urdev *urd) | |||
621 | case DEV_CLASS_UR_I: | 621 | case DEV_CLASS_UR_I: |
622 | return verify_uri_device(urd); | 622 | return verify_uri_device(urd); |
623 | default: | 623 | default: |
624 | return -ENOTSUPP; | 624 | return -EOPNOTSUPP; |
625 | } | 625 | } |
626 | } | 626 | } |
627 | 627 | ||
@@ -654,7 +654,7 @@ static int get_file_reclen(struct urdev *urd) | |||
654 | case DEV_CLASS_UR_I: | 654 | case DEV_CLASS_UR_I: |
655 | return get_uri_file_reclen(urd); | 655 | return get_uri_file_reclen(urd); |
656 | default: | 656 | default: |
657 | return -ENOTSUPP; | 657 | return -EOPNOTSUPP; |
658 | } | 658 | } |
659 | } | 659 | } |
660 | 660 | ||
@@ -827,7 +827,7 @@ static int ur_probe(struct ccw_device *cdev) | |||
827 | goto fail_remove_attr; | 827 | goto fail_remove_attr; |
828 | } | 828 | } |
829 | if ((urd->class != DEV_CLASS_UR_I) && (urd->class != DEV_CLASS_UR_O)) { | 829 | if ((urd->class != DEV_CLASS_UR_I) && (urd->class != DEV_CLASS_UR_O)) { |
830 | rc = -ENOTSUPP; | 830 | rc = -EOPNOTSUPP; |
831 | goto fail_remove_attr; | 831 | goto fail_remove_attr; |
832 | } | 832 | } |
833 | spin_lock_irq(get_ccwdev_lock(cdev)); | 833 | spin_lock_irq(get_ccwdev_lock(cdev)); |
@@ -892,7 +892,7 @@ static int ur_set_online(struct ccw_device *cdev) | |||
892 | } else if (urd->cdev->id.cu_type == PRINTER_DEVTYPE) { | 892 | } else if (urd->cdev->id.cu_type == PRINTER_DEVTYPE) { |
893 | sprintf(node_id, "vmprt-%s", cdev->dev.bus_id); | 893 | sprintf(node_id, "vmprt-%s", cdev->dev.bus_id); |
894 | } else { | 894 | } else { |
895 | rc = -ENOTSUPP; | 895 | rc = -EOPNOTSUPP; |
896 | goto fail_free_cdev; | 896 | goto fail_free_cdev; |
897 | } | 897 | } |
898 | 898 | ||
diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c index 047dd92ae804..7fd84be11931 100644 --- a/drivers/s390/char/zcore.c +++ b/drivers/s390/char/zcore.c | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #define TO_USER 0 | 30 | #define TO_USER 0 |
31 | #define TO_KERNEL 1 | 31 | #define TO_KERNEL 1 |
32 | #define CHUNK_INFO_SIZE 34 /* 2 16-byte char, each followed by blank */ | ||
32 | 33 | ||
33 | enum arch_id { | 34 | enum arch_id { |
34 | ARCH_S390 = 0, | 35 | ARCH_S390 = 0, |
@@ -51,6 +52,7 @@ static struct debug_info *zcore_dbf; | |||
51 | static int hsa_available; | 52 | static int hsa_available; |
52 | static struct dentry *zcore_dir; | 53 | static struct dentry *zcore_dir; |
53 | static struct dentry *zcore_file; | 54 | static struct dentry *zcore_file; |
55 | static struct dentry *zcore_memmap_file; | ||
54 | 56 | ||
55 | /* | 57 | /* |
56 | * Copy memory from HSA to kernel or user memory (not reentrant): | 58 | * Copy memory from HSA to kernel or user memory (not reentrant): |
@@ -476,6 +478,54 @@ static const struct file_operations zcore_fops = { | |||
476 | .release = zcore_release, | 478 | .release = zcore_release, |
477 | }; | 479 | }; |
478 | 480 | ||
481 | static ssize_t zcore_memmap_read(struct file *filp, char __user *buf, | ||
482 | size_t count, loff_t *ppos) | ||
483 | { | ||
484 | return simple_read_from_buffer(buf, count, ppos, filp->private_data, | ||
485 | MEMORY_CHUNKS * CHUNK_INFO_SIZE); | ||
486 | } | ||
487 | |||
488 | static int zcore_memmap_open(struct inode *inode, struct file *filp) | ||
489 | { | ||
490 | int i; | ||
491 | char *buf; | ||
492 | struct mem_chunk *chunk_array; | ||
493 | |||
494 | chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk), | ||
495 | GFP_KERNEL); | ||
496 | if (!chunk_array) | ||
497 | return -ENOMEM; | ||
498 | detect_memory_layout(chunk_array); | ||
499 | buf = kzalloc(MEMORY_CHUNKS * CHUNK_INFO_SIZE, GFP_KERNEL); | ||
500 | if (!buf) { | ||
501 | kfree(chunk_array); | ||
502 | return -ENOMEM; | ||
503 | } | ||
504 | for (i = 0; i < MEMORY_CHUNKS; i++) { | ||
505 | sprintf(buf + (i * CHUNK_INFO_SIZE), "%016llx %016llx ", | ||
506 | (unsigned long long) chunk_array[i].addr, | ||
507 | (unsigned long long) chunk_array[i].size); | ||
508 | if (chunk_array[i].size == 0) | ||
509 | break; | ||
510 | } | ||
511 | kfree(chunk_array); | ||
512 | filp->private_data = buf; | ||
513 | return 0; | ||
514 | } | ||
515 | |||
516 | static int zcore_memmap_release(struct inode *inode, struct file *filp) | ||
517 | { | ||
518 | kfree(filp->private_data); | ||
519 | return 0; | ||
520 | } | ||
521 | |||
522 | static const struct file_operations zcore_memmap_fops = { | ||
523 | .owner = THIS_MODULE, | ||
524 | .read = zcore_memmap_read, | ||
525 | .open = zcore_memmap_open, | ||
526 | .release = zcore_memmap_release, | ||
527 | }; | ||
528 | |||
479 | 529 | ||
480 | static void __init set_s390_lc_mask(union save_area *map) | 530 | static void __init set_s390_lc_mask(union save_area *map) |
481 | { | 531 | { |
@@ -554,18 +604,44 @@ static int __init check_sdias(void) | |||
554 | return 0; | 604 | return 0; |
555 | } | 605 | } |
556 | 606 | ||
557 | static void __init zcore_header_init(int arch, struct zcore_header *hdr) | 607 | static int __init get_mem_size(unsigned long *mem) |
608 | { | ||
609 | int i; | ||
610 | struct mem_chunk *chunk_array; | ||
611 | |||
612 | chunk_array = kzalloc(MEMORY_CHUNKS * sizeof(struct mem_chunk), | ||
613 | GFP_KERNEL); | ||
614 | if (!chunk_array) | ||
615 | return -ENOMEM; | ||
616 | detect_memory_layout(chunk_array); | ||
617 | for (i = 0; i < MEMORY_CHUNKS; i++) { | ||
618 | if (chunk_array[i].size == 0) | ||
619 | break; | ||
620 | *mem += chunk_array[i].size; | ||
621 | } | ||
622 | kfree(chunk_array); | ||
623 | return 0; | ||
624 | } | ||
625 | |||
626 | static int __init zcore_header_init(int arch, struct zcore_header *hdr) | ||
558 | { | 627 | { |
628 | int rc; | ||
629 | unsigned long memory = 0; | ||
630 | |||
559 | if (arch == ARCH_S390X) | 631 | if (arch == ARCH_S390X) |
560 | hdr->arch_id = DUMP_ARCH_S390X; | 632 | hdr->arch_id = DUMP_ARCH_S390X; |
561 | else | 633 | else |
562 | hdr->arch_id = DUMP_ARCH_S390; | 634 | hdr->arch_id = DUMP_ARCH_S390; |
563 | hdr->mem_size = sys_info.mem_size; | 635 | rc = get_mem_size(&memory); |
564 | hdr->rmem_size = sys_info.mem_size; | 636 | if (rc) |
637 | return rc; | ||
638 | hdr->mem_size = memory; | ||
639 | hdr->rmem_size = memory; | ||
565 | hdr->mem_end = sys_info.mem_size; | 640 | hdr->mem_end = sys_info.mem_size; |
566 | hdr->num_pages = sys_info.mem_size / PAGE_SIZE; | 641 | hdr->num_pages = memory / PAGE_SIZE; |
567 | hdr->tod = get_clock(); | 642 | hdr->tod = get_clock(); |
568 | get_cpu_id(&hdr->cpu_id); | 643 | get_cpu_id(&hdr->cpu_id); |
644 | return 0; | ||
569 | } | 645 | } |
570 | 646 | ||
571 | static int __init zcore_init(void) | 647 | static int __init zcore_init(void) |
@@ -608,7 +684,9 @@ static int __init zcore_init(void) | |||
608 | if (rc) | 684 | if (rc) |
609 | goto fail; | 685 | goto fail; |
610 | 686 | ||
611 | zcore_header_init(arch, &zcore_header); | 687 | rc = zcore_header_init(arch, &zcore_header); |
688 | if (rc) | ||
689 | goto fail; | ||
612 | 690 | ||
613 | zcore_dir = debugfs_create_dir("zcore" , NULL); | 691 | zcore_dir = debugfs_create_dir("zcore" , NULL); |
614 | if (!zcore_dir) { | 692 | if (!zcore_dir) { |
@@ -618,13 +696,22 @@ static int __init zcore_init(void) | |||
618 | zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL, | 696 | zcore_file = debugfs_create_file("mem", S_IRUSR, zcore_dir, NULL, |
619 | &zcore_fops); | 697 | &zcore_fops); |
620 | if (!zcore_file) { | 698 | if (!zcore_file) { |
621 | debugfs_remove(zcore_dir); | ||
622 | rc = -ENOMEM; | 699 | rc = -ENOMEM; |
623 | goto fail; | 700 | goto fail_dir; |
701 | } | ||
702 | zcore_memmap_file = debugfs_create_file("memmap", S_IRUSR, zcore_dir, | ||
703 | NULL, &zcore_memmap_fops); | ||
704 | if (!zcore_memmap_file) { | ||
705 | rc = -ENOMEM; | ||
706 | goto fail_file; | ||
624 | } | 707 | } |
625 | hsa_available = 1; | 708 | hsa_available = 1; |
626 | return 0; | 709 | return 0; |
627 | 710 | ||
711 | fail_file: | ||
712 | debugfs_remove(zcore_file); | ||
713 | fail_dir: | ||
714 | debugfs_remove(zcore_dir); | ||
628 | fail: | 715 | fail: |
629 | diag308(DIAG308_REL_HSA, NULL); | 716 | diag308(DIAG308_REL_HSA, NULL); |
630 | return rc; | 717 | return rc; |
diff --git a/drivers/s390/cio/Makefile b/drivers/s390/cio/Makefile index 91e9e3f3073a..bd79bd165396 100644 --- a/drivers/s390/cio/Makefile +++ b/drivers/s390/cio/Makefile | |||
@@ -9,4 +9,6 @@ ccw_device-objs += device_id.o device_pgid.o device_status.o | |||
9 | obj-y += ccw_device.o cmf.o | 9 | obj-y += ccw_device.o cmf.o |
10 | obj-$(CONFIG_CHSC_SCH) += chsc_sch.o | 10 | obj-$(CONFIG_CHSC_SCH) += chsc_sch.o |
11 | obj-$(CONFIG_CCWGROUP) += ccwgroup.o | 11 | obj-$(CONFIG_CCWGROUP) += ccwgroup.o |
12 | |||
13 | qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_perf.o qdio_setup.o | ||
12 | obj-$(CONFIG_QDIO) += qdio.o | 14 | obj-$(CONFIG_QDIO) += qdio.o |
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c index 65264a38057d..29826fdd47b8 100644 --- a/drivers/s390/cio/chsc.c +++ b/drivers/s390/cio/chsc.c | |||
@@ -27,7 +27,13 @@ | |||
27 | 27 | ||
28 | static void *sei_page; | 28 | static void *sei_page; |
29 | 29 | ||
30 | static int chsc_error_from_response(int response) | 30 | /** |
31 | * chsc_error_from_response() - convert a chsc response to an error | ||
32 | * @response: chsc response code | ||
33 | * | ||
34 | * Returns an appropriate Linux error code for @response. | ||
35 | */ | ||
36 | int chsc_error_from_response(int response) | ||
31 | { | 37 | { |
32 | switch (response) { | 38 | switch (response) { |
33 | case 0x0001: | 39 | case 0x0001: |
@@ -45,6 +51,7 @@ static int chsc_error_from_response(int response) | |||
45 | return -EIO; | 51 | return -EIO; |
46 | } | 52 | } |
47 | } | 53 | } |
54 | EXPORT_SYMBOL_GPL(chsc_error_from_response); | ||
48 | 55 | ||
49 | struct chsc_ssd_area { | 56 | struct chsc_ssd_area { |
50 | struct chsc_header request; | 57 | struct chsc_header request; |
diff --git a/drivers/s390/cio/chsc.h b/drivers/s390/cio/chsc.h index fb6c4d6c45b4..ba59bceace98 100644 --- a/drivers/s390/cio/chsc.h +++ b/drivers/s390/cio/chsc.h | |||
@@ -101,4 +101,6 @@ void chsc_chp_online(struct chp_id chpid); | |||
101 | void chsc_chp_offline(struct chp_id chpid); | 101 | void chsc_chp_offline(struct chp_id chpid); |
102 | int chsc_get_channel_measurement_chars(struct channel_path *chp); | 102 | int chsc_get_channel_measurement_chars(struct channel_path *chp); |
103 | 103 | ||
104 | int chsc_error_from_response(int response); | ||
105 | |||
104 | #endif | 106 | #endif |
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c deleted file mode 100644 index 2bf36e14b102..000000000000 --- a/drivers/s390/cio/qdio.c +++ /dev/null | |||
@@ -1,3929 +0,0 @@ | |||
1 | /* | ||
2 | * | ||
3 | * linux/drivers/s390/cio/qdio.c | ||
4 | * | ||
5 | * Linux for S/390 QDIO base support, Hipersocket base support | ||
6 | * version 2 | ||
7 | * | ||
8 | * Copyright 2000,2002 IBM Corporation | ||
9 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com> | ||
10 | * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com> | ||
11 | * | ||
12 | * Restriction: only 63 iqdio subchannels would have its own indicator, | ||
13 | * after that, subsequent subchannels share one indicator | ||
14 | * | ||
15 | * | ||
16 | * | ||
17 | * | ||
18 | * This program is free software; you can redistribute it and/or modify | ||
19 | * it under the terms of the GNU General Public License as published by | ||
20 | * the Free Software Foundation; either version 2, or (at your option) | ||
21 | * any later version. | ||
22 | * | ||
23 | * This program is distributed in the hope that it will be useful, | ||
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
26 | * GNU General Public License for more details. | ||
27 | * | ||
28 | * You should have received a copy of the GNU General Public License | ||
29 | * along with this program; if not, write to the Free Software | ||
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
31 | */ | ||
32 | |||
33 | #include <linux/module.h> | ||
34 | #include <linux/init.h> | ||
35 | #include <linux/delay.h> | ||
36 | #include <linux/slab.h> | ||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/proc_fs.h> | ||
39 | #include <linux/timer.h> | ||
40 | #include <linux/mempool.h> | ||
41 | #include <linux/semaphore.h> | ||
42 | |||
43 | #include <asm/ccwdev.h> | ||
44 | #include <asm/io.h> | ||
45 | #include <asm/atomic.h> | ||
46 | #include <asm/timex.h> | ||
47 | |||
48 | #include <asm/debug.h> | ||
49 | #include <asm/s390_rdev.h> | ||
50 | #include <asm/qdio.h> | ||
51 | #include <asm/airq.h> | ||
52 | |||
53 | #include "cio.h" | ||
54 | #include "css.h" | ||
55 | #include "device.h" | ||
56 | #include "qdio.h" | ||
57 | #include "ioasm.h" | ||
58 | #include "chsc.h" | ||
59 | |||
60 | /****************** MODULE PARAMETER VARIABLES ********************/ | ||
61 | MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>"); | ||
62 | MODULE_DESCRIPTION("QDIO base support version 2, " \ | ||
63 | "Copyright 2000 IBM Corporation"); | ||
64 | MODULE_LICENSE("GPL"); | ||
65 | |||
66 | /******************** HERE WE GO ***********************************/ | ||
67 | |||
68 | static const char version[] = "QDIO base support version 2"; | ||
69 | |||
70 | static int qdio_performance_stats = 0; | ||
71 | static int proc_perf_file_registration; | ||
72 | static struct qdio_perf_stats perf_stats; | ||
73 | |||
74 | static int hydra_thinints; | ||
75 | static int is_passthrough = 0; | ||
76 | static int omit_svs; | ||
77 | |||
78 | static int indicator_used[INDICATORS_PER_CACHELINE]; | ||
79 | static __u32 * volatile indicators; | ||
80 | static __u32 volatile spare_indicator; | ||
81 | static atomic_t spare_indicator_usecount; | ||
82 | #define QDIO_MEMPOOL_SCSSC_ELEMENTS 2 | ||
83 | static mempool_t *qdio_mempool_scssc; | ||
84 | static struct kmem_cache *qdio_q_cache; | ||
85 | |||
86 | static debug_info_t *qdio_dbf_setup; | ||
87 | static debug_info_t *qdio_dbf_sbal; | ||
88 | static debug_info_t *qdio_dbf_trace; | ||
89 | static debug_info_t *qdio_dbf_sense; | ||
90 | #ifdef CONFIG_QDIO_DEBUG | ||
91 | static debug_info_t *qdio_dbf_slsb_out; | ||
92 | static debug_info_t *qdio_dbf_slsb_in; | ||
93 | #endif /* CONFIG_QDIO_DEBUG */ | ||
94 | |||
95 | /* iQDIO stuff: */ | ||
96 | static volatile struct qdio_q *tiq_list=NULL; /* volatile as it could change | ||
97 | during a while loop */ | ||
98 | static DEFINE_SPINLOCK(ttiq_list_lock); | ||
99 | static void *tiqdio_ind; | ||
100 | static void tiqdio_tl(unsigned long); | ||
101 | static DECLARE_TASKLET(tiqdio_tasklet,tiqdio_tl,0); | ||
102 | |||
103 | /* not a macro, as one of the arguments is atomic_read */ | ||
104 | static inline int | ||
105 | qdio_min(int a,int b) | ||
106 | { | ||
107 | if (a<b) | ||
108 | return a; | ||
109 | else | ||
110 | return b; | ||
111 | } | ||
112 | |||
113 | /***************** SCRUBBER HELPER ROUTINES **********************/ | ||
114 | #ifdef CONFIG_64BIT | ||
115 | static inline void qdio_perf_stat_inc(atomic64_t *count) | ||
116 | { | ||
117 | if (qdio_performance_stats) | ||
118 | atomic64_inc(count); | ||
119 | } | ||
120 | |||
121 | static inline void qdio_perf_stat_dec(atomic64_t *count) | ||
122 | { | ||
123 | if (qdio_performance_stats) | ||
124 | atomic64_dec(count); | ||
125 | } | ||
126 | #else /* CONFIG_64BIT */ | ||
127 | static inline void qdio_perf_stat_inc(atomic_t *count) | ||
128 | { | ||
129 | if (qdio_performance_stats) | ||
130 | atomic_inc(count); | ||
131 | } | ||
132 | |||
133 | static inline void qdio_perf_stat_dec(atomic_t *count) | ||
134 | { | ||
135 | if (qdio_performance_stats) | ||
136 | atomic_dec(count); | ||
137 | } | ||
138 | #endif /* CONFIG_64BIT */ | ||
139 | |||
140 | static inline __u64 | ||
141 | qdio_get_micros(void) | ||
142 | { | ||
143 | return (get_clock() >> 12); /* time>>12 is microseconds */ | ||
144 | } | ||
145 | |||
146 | /* | ||
147 | * unfortunately, we can't just xchg the values; in do_QDIO we want to reserve | ||
148 | * the q in any case, so that we'll not be interrupted when we are in | ||
149 | * qdio_mark_tiq... shouldn't have a really bad impact, as reserving almost | ||
150 | * ever works (last famous words) | ||
151 | */ | ||
152 | static inline int | ||
153 | qdio_reserve_q(struct qdio_q *q) | ||
154 | { | ||
155 | return atomic_add_return(1,&q->use_count) - 1; | ||
156 | } | ||
157 | |||
158 | static inline void | ||
159 | qdio_release_q(struct qdio_q *q) | ||
160 | { | ||
161 | atomic_dec(&q->use_count); | ||
162 | } | ||
163 | |||
164 | /*check ccq */ | ||
165 | static int | ||
166 | qdio_check_ccq(struct qdio_q *q, unsigned int ccq) | ||
167 | { | ||
168 | char dbf_text[15]; | ||
169 | |||
170 | if (ccq == 0 || ccq == 32) | ||
171 | return 0; | ||
172 | if (ccq == 96 || ccq == 97) | ||
173 | return 1; | ||
174 | /*notify devices immediately*/ | ||
175 | sprintf(dbf_text,"%d", ccq); | ||
176 | QDIO_DBF_TEXT2(1,trace,dbf_text); | ||
177 | return -EIO; | ||
178 | } | ||
179 | /* EQBS: extract buffer states */ | ||
180 | static int | ||
181 | qdio_do_eqbs(struct qdio_q *q, unsigned char *state, | ||
182 | unsigned int *start, unsigned int *cnt) | ||
183 | { | ||
184 | struct qdio_irq *irq; | ||
185 | unsigned int tmp_cnt, q_no, ccq; | ||
186 | int rc ; | ||
187 | char dbf_text[15]; | ||
188 | |||
189 | ccq = 0; | ||
190 | tmp_cnt = *cnt; | ||
191 | irq = (struct qdio_irq*)q->irq_ptr; | ||
192 | q_no = q->q_no; | ||
193 | if(!q->is_input_q) | ||
194 | q_no += irq->no_input_qs; | ||
195 | again: | ||
196 | ccq = do_eqbs(irq->sch_token, state, q_no, start, cnt); | ||
197 | rc = qdio_check_ccq(q, ccq); | ||
198 | if ((ccq == 96) && (tmp_cnt != *cnt)) | ||
199 | rc = 0; | ||
200 | if (rc == 1) { | ||
201 | QDIO_DBF_TEXT5(1,trace,"eqAGAIN"); | ||
202 | goto again; | ||
203 | } | ||
204 | if (rc < 0) { | ||
205 | QDIO_DBF_TEXT2(1,trace,"eqberr"); | ||
206 | sprintf(dbf_text,"%2x,%2x,%d,%d",tmp_cnt, *cnt, ccq, q_no); | ||
207 | QDIO_DBF_TEXT2(1,trace,dbf_text); | ||
208 | q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION| | ||
209 | QDIO_STATUS_LOOK_FOR_ERROR, | ||
210 | 0, 0, 0, -1, -1, q->int_parm); | ||
211 | return 0; | ||
212 | } | ||
213 | return (tmp_cnt - *cnt); | ||
214 | } | ||
215 | |||
216 | /* SQBS: set buffer states */ | ||
217 | static int | ||
218 | qdio_do_sqbs(struct qdio_q *q, unsigned char state, | ||
219 | unsigned int *start, unsigned int *cnt) | ||
220 | { | ||
221 | struct qdio_irq *irq; | ||
222 | unsigned int tmp_cnt, q_no, ccq; | ||
223 | int rc; | ||
224 | char dbf_text[15]; | ||
225 | |||
226 | ccq = 0; | ||
227 | tmp_cnt = *cnt; | ||
228 | irq = (struct qdio_irq*)q->irq_ptr; | ||
229 | q_no = q->q_no; | ||
230 | if(!q->is_input_q) | ||
231 | q_no += irq->no_input_qs; | ||
232 | again: | ||
233 | ccq = do_sqbs(irq->sch_token, state, q_no, start, cnt); | ||
234 | rc = qdio_check_ccq(q, ccq); | ||
235 | if (rc == 1) { | ||
236 | QDIO_DBF_TEXT5(1,trace,"sqAGAIN"); | ||
237 | goto again; | ||
238 | } | ||
239 | if (rc < 0) { | ||
240 | QDIO_DBF_TEXT3(1,trace,"sqberr"); | ||
241 | sprintf(dbf_text,"%2x,%2x",tmp_cnt,*cnt); | ||
242 | QDIO_DBF_TEXT3(1,trace,dbf_text); | ||
243 | sprintf(dbf_text,"%d,%d",ccq,q_no); | ||
244 | QDIO_DBF_TEXT3(1,trace,dbf_text); | ||
245 | q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION| | ||
246 | QDIO_STATUS_LOOK_FOR_ERROR, | ||
247 | 0, 0, 0, -1, -1, q->int_parm); | ||
248 | return 0; | ||
249 | } | ||
250 | return (tmp_cnt - *cnt); | ||
251 | } | ||
252 | |||
253 | static inline int | ||
254 | qdio_set_slsb(struct qdio_q *q, unsigned int *bufno, | ||
255 | unsigned char state, unsigned int *count) | ||
256 | { | ||
257 | volatile char *slsb; | ||
258 | struct qdio_irq *irq; | ||
259 | |||
260 | irq = (struct qdio_irq*)q->irq_ptr; | ||
261 | if (!irq->is_qebsm) { | ||
262 | slsb = (char *)&q->slsb.acc.val[(*bufno)]; | ||
263 | xchg(slsb, state); | ||
264 | return 1; | ||
265 | } | ||
266 | return qdio_do_sqbs(q, state, bufno, count); | ||
267 | } | ||
268 | |||
269 | #ifdef CONFIG_QDIO_DEBUG | ||
270 | static inline void | ||
271 | qdio_trace_slsb(struct qdio_q *q) | ||
272 | { | ||
273 | if (q->queue_type==QDIO_TRACE_QTYPE) { | ||
274 | if (q->is_input_q) | ||
275 | QDIO_DBF_HEX2(0,slsb_in,&q->slsb, | ||
276 | QDIO_MAX_BUFFERS_PER_Q); | ||
277 | else | ||
278 | QDIO_DBF_HEX2(0,slsb_out,&q->slsb, | ||
279 | QDIO_MAX_BUFFERS_PER_Q); | ||
280 | } | ||
281 | } | ||
282 | #endif | ||
283 | |||
284 | static inline int | ||
285 | set_slsb(struct qdio_q *q, unsigned int *bufno, | ||
286 | unsigned char state, unsigned int *count) | ||
287 | { | ||
288 | int rc; | ||
289 | #ifdef CONFIG_QDIO_DEBUG | ||
290 | qdio_trace_slsb(q); | ||
291 | #endif | ||
292 | rc = qdio_set_slsb(q, bufno, state, count); | ||
293 | #ifdef CONFIG_QDIO_DEBUG | ||
294 | qdio_trace_slsb(q); | ||
295 | #endif | ||
296 | return rc; | ||
297 | } | ||
298 | static inline int | ||
299 | qdio_siga_sync(struct qdio_q *q, unsigned int gpr2, | ||
300 | unsigned int gpr3) | ||
301 | { | ||
302 | int cc; | ||
303 | |||
304 | QDIO_DBF_TEXT4(0,trace,"sigasync"); | ||
305 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
306 | |||
307 | qdio_perf_stat_inc(&perf_stats.siga_syncs); | ||
308 | |||
309 | cc = do_siga_sync(q->schid, gpr2, gpr3); | ||
310 | if (cc) | ||
311 | QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*)); | ||
312 | |||
313 | return cc; | ||
314 | } | ||
315 | |||
316 | static inline int | ||
317 | qdio_siga_sync_q(struct qdio_q *q) | ||
318 | { | ||
319 | if (q->is_input_q) | ||
320 | return qdio_siga_sync(q, 0, q->mask); | ||
321 | return qdio_siga_sync(q, q->mask, 0); | ||
322 | } | ||
323 | |||
324 | static int | ||
325 | __do_siga_output(struct qdio_q *q, unsigned int *busy_bit) | ||
326 | { | ||
327 | struct qdio_irq *irq; | ||
328 | unsigned int fc = 0; | ||
329 | unsigned long schid; | ||
330 | |||
331 | irq = (struct qdio_irq *) q->irq_ptr; | ||
332 | if (!irq->is_qebsm) | ||
333 | schid = *((u32 *)&q->schid); | ||
334 | else { | ||
335 | schid = irq->sch_token; | ||
336 | fc |= 0x80; | ||
337 | } | ||
338 | return do_siga_output(schid, q->mask, busy_bit, fc); | ||
339 | } | ||
340 | |||
341 | /* | ||
342 | * returns QDIO_SIGA_ERROR_ACCESS_EXCEPTION as cc, when SIGA returns | ||
343 | * an access exception | ||
344 | */ | ||
345 | static int | ||
346 | qdio_siga_output(struct qdio_q *q) | ||
347 | { | ||
348 | int cc; | ||
349 | __u32 busy_bit; | ||
350 | __u64 start_time=0; | ||
351 | |||
352 | qdio_perf_stat_inc(&perf_stats.siga_outs); | ||
353 | |||
354 | QDIO_DBF_TEXT4(0,trace,"sigaout"); | ||
355 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
356 | |||
357 | for (;;) { | ||
358 | cc = __do_siga_output(q, &busy_bit); | ||
359 | //QDIO_PRINT_ERR("cc=%x, busy=%x\n",cc,busy_bit); | ||
360 | if ((cc==2) && (busy_bit) && (q->is_iqdio_q)) { | ||
361 | if (!start_time) | ||
362 | start_time=NOW; | ||
363 | if ((NOW-start_time)>QDIO_BUSY_BIT_PATIENCE) | ||
364 | break; | ||
365 | } else | ||
366 | break; | ||
367 | } | ||
368 | |||
369 | if ((cc==2) && (busy_bit)) | ||
370 | cc |= QDIO_SIGA_ERROR_B_BIT_SET; | ||
371 | |||
372 | if (cc) | ||
373 | QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*)); | ||
374 | |||
375 | return cc; | ||
376 | } | ||
377 | |||
378 | static int | ||
379 | qdio_siga_input(struct qdio_q *q) | ||
380 | { | ||
381 | int cc; | ||
382 | |||
383 | QDIO_DBF_TEXT4(0,trace,"sigain"); | ||
384 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
385 | |||
386 | qdio_perf_stat_inc(&perf_stats.siga_ins); | ||
387 | |||
388 | cc = do_siga_input(q->schid, q->mask); | ||
389 | |||
390 | if (cc) | ||
391 | QDIO_DBF_HEX3(0,trace,&cc,sizeof(int*)); | ||
392 | |||
393 | return cc; | ||
394 | } | ||
395 | |||
396 | /* locked by the locks in qdio_activate and qdio_cleanup */ | ||
397 | static __u32 * | ||
398 | qdio_get_indicator(void) | ||
399 | { | ||
400 | int i; | ||
401 | |||
402 | for (i = 0; i < INDICATORS_PER_CACHELINE; i++) | ||
403 | if (!indicator_used[i]) { | ||
404 | indicator_used[i]=1; | ||
405 | return indicators+i; | ||
406 | } | ||
407 | atomic_inc(&spare_indicator_usecount); | ||
408 | return (__u32 * volatile) &spare_indicator; | ||
409 | } | ||
410 | |||
411 | /* locked by the locks in qdio_activate and qdio_cleanup */ | ||
412 | static void | ||
413 | qdio_put_indicator(__u32 *addr) | ||
414 | { | ||
415 | int i; | ||
416 | |||
417 | if ( (addr) && (addr!=&spare_indicator) ) { | ||
418 | i=addr-indicators; | ||
419 | indicator_used[i]=0; | ||
420 | } | ||
421 | if (addr == &spare_indicator) | ||
422 | atomic_dec(&spare_indicator_usecount); | ||
423 | } | ||
424 | |||
425 | static inline void | ||
426 | tiqdio_clear_summary_bit(__u32 *location) | ||
427 | { | ||
428 | QDIO_DBF_TEXT5(0,trace,"clrsummb"); | ||
429 | QDIO_DBF_HEX5(0,trace,&location,sizeof(void*)); | ||
430 | |||
431 | xchg(location,0); | ||
432 | } | ||
433 | |||
434 | static inline void | ||
435 | tiqdio_set_summary_bit(__u32 *location) | ||
436 | { | ||
437 | QDIO_DBF_TEXT5(0,trace,"setsummb"); | ||
438 | QDIO_DBF_HEX5(0,trace,&location,sizeof(void*)); | ||
439 | |||
440 | xchg(location,-1); | ||
441 | } | ||
442 | |||
443 | static inline void | ||
444 | tiqdio_sched_tl(void) | ||
445 | { | ||
446 | tasklet_hi_schedule(&tiqdio_tasklet); | ||
447 | } | ||
448 | |||
449 | static void | ||
450 | qdio_mark_tiq(struct qdio_q *q) | ||
451 | { | ||
452 | unsigned long flags; | ||
453 | |||
454 | QDIO_DBF_TEXT4(0,trace,"mark iq"); | ||
455 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
456 | |||
457 | spin_lock_irqsave(&ttiq_list_lock,flags); | ||
458 | if (unlikely(atomic_read(&q->is_in_shutdown))) | ||
459 | goto out_unlock; | ||
460 | |||
461 | if (!q->is_input_q) | ||
462 | goto out_unlock; | ||
463 | |||
464 | if ((q->list_prev) || (q->list_next)) | ||
465 | goto out_unlock; | ||
466 | |||
467 | if (!tiq_list) { | ||
468 | tiq_list=q; | ||
469 | q->list_prev=q; | ||
470 | q->list_next=q; | ||
471 | } else { | ||
472 | q->list_next=tiq_list; | ||
473 | q->list_prev=tiq_list->list_prev; | ||
474 | tiq_list->list_prev->list_next=q; | ||
475 | tiq_list->list_prev=q; | ||
476 | } | ||
477 | spin_unlock_irqrestore(&ttiq_list_lock,flags); | ||
478 | |||
479 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); | ||
480 | tiqdio_sched_tl(); | ||
481 | return; | ||
482 | out_unlock: | ||
483 | spin_unlock_irqrestore(&ttiq_list_lock,flags); | ||
484 | return; | ||
485 | } | ||
486 | |||
487 | static inline void | ||
488 | qdio_mark_q(struct qdio_q *q) | ||
489 | { | ||
490 | QDIO_DBF_TEXT4(0,trace,"mark q"); | ||
491 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
492 | |||
493 | if (unlikely(atomic_read(&q->is_in_shutdown))) | ||
494 | return; | ||
495 | |||
496 | tasklet_schedule(&q->tasklet); | ||
497 | } | ||
498 | |||
499 | static int | ||
500 | qdio_stop_polling(struct qdio_q *q) | ||
501 | { | ||
502 | #ifdef QDIO_USE_PROCESSING_STATE | ||
503 | unsigned int tmp, gsf, count = 1; | ||
504 | unsigned char state = 0; | ||
505 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; | ||
506 | |||
507 | if (!atomic_xchg(&q->polling,0)) | ||
508 | return 1; | ||
509 | |||
510 | QDIO_DBF_TEXT4(0,trace,"stoppoll"); | ||
511 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
512 | |||
513 | /* show the card that we are not polling anymore */ | ||
514 | if (!q->is_input_q) | ||
515 | return 1; | ||
516 | |||
517 | tmp = gsf = GET_SAVED_FRONTIER(q); | ||
518 | tmp = ((tmp + QDIO_MAX_BUFFERS_PER_Q-1) & (QDIO_MAX_BUFFERS_PER_Q-1) ); | ||
519 | set_slsb(q, &tmp, SLSB_P_INPUT_NOT_INIT, &count); | ||
520 | |||
521 | /* | ||
522 | * we don't issue this SYNC_MEMORY, as we trust Rick T and | ||
523 | * moreover will not use the PROCESSING state under VM, so | ||
524 | * q->polling was 0 anyway | ||
525 | */ | ||
526 | /*SYNC_MEMORY;*/ | ||
527 | if (irq->is_qebsm) { | ||
528 | count = 1; | ||
529 | qdio_do_eqbs(q, &state, &gsf, &count); | ||
530 | } else | ||
531 | state = q->slsb.acc.val[gsf]; | ||
532 | if (state != SLSB_P_INPUT_PRIMED) | ||
533 | return 1; | ||
534 | /* | ||
535 | * set our summary bit again, as otherwise there is a | ||
536 | * small window we can miss between resetting it and | ||
537 | * checking for PRIMED state | ||
538 | */ | ||
539 | if (q->is_thinint_q) | ||
540 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); | ||
541 | return 0; | ||
542 | |||
543 | #else /* QDIO_USE_PROCESSING_STATE */ | ||
544 | return 1; | ||
545 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
546 | } | ||
547 | |||
548 | /* | ||
549 | * see the comment in do_QDIO and before qdio_reserve_q about the | ||
550 | * sophisticated locking outside of unmark_q, so that we don't need to | ||
551 | * disable the interrupts :-) | ||
552 | */ | ||
553 | static void | ||
554 | qdio_unmark_q(struct qdio_q *q) | ||
555 | { | ||
556 | unsigned long flags; | ||
557 | |||
558 | QDIO_DBF_TEXT4(0,trace,"unmark q"); | ||
559 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
560 | |||
561 | if ((!q->list_prev)||(!q->list_next)) | ||
562 | return; | ||
563 | |||
564 | if ((q->is_thinint_q)&&(q->is_input_q)) { | ||
565 | /* iQDIO */ | ||
566 | spin_lock_irqsave(&ttiq_list_lock,flags); | ||
567 | /* in case cleanup has done this already and simultanously | ||
568 | * qdio_unmark_q is called from the interrupt handler, we've | ||
569 | * got to check this in this specific case again */ | ||
570 | if ((!q->list_prev)||(!q->list_next)) | ||
571 | goto out; | ||
572 | if (q->list_next==q) { | ||
573 | /* q was the only interesting q */ | ||
574 | tiq_list=NULL; | ||
575 | q->list_next=NULL; | ||
576 | q->list_prev=NULL; | ||
577 | } else { | ||
578 | q->list_next->list_prev=q->list_prev; | ||
579 | q->list_prev->list_next=q->list_next; | ||
580 | tiq_list=q->list_next; | ||
581 | q->list_next=NULL; | ||
582 | q->list_prev=NULL; | ||
583 | } | ||
584 | out: | ||
585 | spin_unlock_irqrestore(&ttiq_list_lock,flags); | ||
586 | } | ||
587 | } | ||
588 | |||
589 | static inline unsigned long | ||
590 | tiqdio_clear_global_summary(void) | ||
591 | { | ||
592 | unsigned long time; | ||
593 | |||
594 | QDIO_DBF_TEXT5(0,trace,"clrglobl"); | ||
595 | |||
596 | time = do_clear_global_summary(); | ||
597 | |||
598 | QDIO_DBF_HEX5(0,trace,&time,sizeof(unsigned long)); | ||
599 | |||
600 | return time; | ||
601 | } | ||
602 | |||
603 | |||
604 | /************************* OUTBOUND ROUTINES *******************************/ | ||
605 | static int | ||
606 | qdio_qebsm_get_outbound_buffer_frontier(struct qdio_q *q) | ||
607 | { | ||
608 | struct qdio_irq *irq; | ||
609 | unsigned char state; | ||
610 | unsigned int cnt, count, ftc; | ||
611 | |||
612 | irq = (struct qdio_irq *) q->irq_ptr; | ||
613 | if ((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis)) | ||
614 | SYNC_MEMORY; | ||
615 | |||
616 | ftc = q->first_to_check; | ||
617 | count = qdio_min(atomic_read(&q->number_of_buffers_used), | ||
618 | (QDIO_MAX_BUFFERS_PER_Q-1)); | ||
619 | if (count == 0) | ||
620 | return q->first_to_check; | ||
621 | cnt = qdio_do_eqbs(q, &state, &ftc, &count); | ||
622 | if (cnt == 0) | ||
623 | return q->first_to_check; | ||
624 | switch (state) { | ||
625 | case SLSB_P_OUTPUT_ERROR: | ||
626 | QDIO_DBF_TEXT3(0,trace,"outperr"); | ||
627 | atomic_sub(cnt , &q->number_of_buffers_used); | ||
628 | if (q->qdio_error) | ||
629 | q->error_status_flags |= | ||
630 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; | ||
631 | q->qdio_error = SLSB_P_OUTPUT_ERROR; | ||
632 | q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR; | ||
633 | q->first_to_check = ftc; | ||
634 | break; | ||
635 | case SLSB_P_OUTPUT_EMPTY: | ||
636 | QDIO_DBF_TEXT5(0,trace,"outpempt"); | ||
637 | atomic_sub(cnt, &q->number_of_buffers_used); | ||
638 | q->first_to_check = ftc; | ||
639 | break; | ||
640 | case SLSB_CU_OUTPUT_PRIMED: | ||
641 | /* all buffers primed */ | ||
642 | QDIO_DBF_TEXT5(0,trace,"outpprim"); | ||
643 | break; | ||
644 | default: | ||
645 | break; | ||
646 | } | ||
647 | QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int)); | ||
648 | return q->first_to_check; | ||
649 | } | ||
650 | |||
651 | static int | ||
652 | qdio_qebsm_get_inbound_buffer_frontier(struct qdio_q *q) | ||
653 | { | ||
654 | struct qdio_irq *irq; | ||
655 | unsigned char state; | ||
656 | int tmp, ftc, count, cnt; | ||
657 | char dbf_text[15]; | ||
658 | |||
659 | |||
660 | irq = (struct qdio_irq *) q->irq_ptr; | ||
661 | ftc = q->first_to_check; | ||
662 | count = qdio_min(atomic_read(&q->number_of_buffers_used), | ||
663 | (QDIO_MAX_BUFFERS_PER_Q-1)); | ||
664 | if (count == 0) | ||
665 | return q->first_to_check; | ||
666 | cnt = qdio_do_eqbs(q, &state, &ftc, &count); | ||
667 | if (cnt == 0) | ||
668 | return q->first_to_check; | ||
669 | switch (state) { | ||
670 | case SLSB_P_INPUT_ERROR : | ||
671 | #ifdef CONFIG_QDIO_DEBUG | ||
672 | QDIO_DBF_TEXT3(1,trace,"inperr"); | ||
673 | sprintf(dbf_text,"%2x,%2x",ftc,count); | ||
674 | QDIO_DBF_TEXT3(1,trace,dbf_text); | ||
675 | #endif /* CONFIG_QDIO_DEBUG */ | ||
676 | if (q->qdio_error) | ||
677 | q->error_status_flags |= | ||
678 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; | ||
679 | q->qdio_error = SLSB_P_INPUT_ERROR; | ||
680 | q->error_status_flags |= QDIO_STATUS_LOOK_FOR_ERROR; | ||
681 | atomic_sub(cnt, &q->number_of_buffers_used); | ||
682 | q->first_to_check = ftc; | ||
683 | break; | ||
684 | case SLSB_P_INPUT_PRIMED : | ||
685 | QDIO_DBF_TEXT3(0,trace,"inptprim"); | ||
686 | sprintf(dbf_text,"%2x,%2x",ftc,count); | ||
687 | QDIO_DBF_TEXT3(1,trace,dbf_text); | ||
688 | tmp = 0; | ||
689 | ftc = q->first_to_check; | ||
690 | #ifdef QDIO_USE_PROCESSING_STATE | ||
691 | if (cnt > 1) { | ||
692 | cnt -= 1; | ||
693 | tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt); | ||
694 | if (!tmp) | ||
695 | break; | ||
696 | } | ||
697 | cnt = 1; | ||
698 | tmp += set_slsb(q, &ftc, | ||
699 | SLSB_P_INPUT_PROCESSING, &cnt); | ||
700 | atomic_set(&q->polling, 1); | ||
701 | #else | ||
702 | tmp = set_slsb(q, &ftc, SLSB_P_INPUT_NOT_INIT, &cnt); | ||
703 | #endif | ||
704 | atomic_sub(tmp, &q->number_of_buffers_used); | ||
705 | q->first_to_check = ftc; | ||
706 | break; | ||
707 | case SLSB_CU_INPUT_EMPTY: | ||
708 | case SLSB_P_INPUT_NOT_INIT: | ||
709 | case SLSB_P_INPUT_PROCESSING: | ||
710 | QDIO_DBF_TEXT5(0,trace,"inpnipro"); | ||
711 | break; | ||
712 | default: | ||
713 | break; | ||
714 | } | ||
715 | QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int)); | ||
716 | return q->first_to_check; | ||
717 | } | ||
718 | |||
719 | static int | ||
720 | qdio_get_outbound_buffer_frontier(struct qdio_q *q) | ||
721 | { | ||
722 | struct qdio_irq *irq; | ||
723 | volatile char *slsb; | ||
724 | unsigned int count = 1; | ||
725 | int first_not_to_check, f, f_mod_no; | ||
726 | char dbf_text[15]; | ||
727 | |||
728 | QDIO_DBF_TEXT4(0,trace,"getobfro"); | ||
729 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
730 | |||
731 | irq = (struct qdio_irq *) q->irq_ptr; | ||
732 | if (irq->is_qebsm) | ||
733 | return qdio_qebsm_get_outbound_buffer_frontier(q); | ||
734 | |||
735 | slsb=&q->slsb.acc.val[0]; | ||
736 | f_mod_no=f=q->first_to_check; | ||
737 | /* | ||
738 | * f points to already processed elements, so f+no_used is correct... | ||
739 | * ... but: we don't check 128 buffers, as otherwise | ||
740 | * qdio_has_outbound_q_moved would return 0 | ||
741 | */ | ||
742 | first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used), | ||
743 | (QDIO_MAX_BUFFERS_PER_Q-1)); | ||
744 | |||
745 | if (((!q->is_iqdio_q) && (!q->hydra_gives_outbound_pcis)) || | ||
746 | (q->queue_type == QDIO_IQDIO_QFMT_ASYNCH)) | ||
747 | SYNC_MEMORY; | ||
748 | |||
749 | check_next: | ||
750 | if (f==first_not_to_check) | ||
751 | goto out; | ||
752 | |||
753 | switch(slsb[f_mod_no]) { | ||
754 | |||
755 | /* the adapter has not fetched the output yet */ | ||
756 | case SLSB_CU_OUTPUT_PRIMED: | ||
757 | QDIO_DBF_TEXT5(0,trace,"outpprim"); | ||
758 | break; | ||
759 | |||
760 | /* the adapter got it */ | ||
761 | case SLSB_P_OUTPUT_EMPTY: | ||
762 | atomic_dec(&q->number_of_buffers_used); | ||
763 | f++; | ||
764 | f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1); | ||
765 | QDIO_DBF_TEXT5(0,trace,"outpempt"); | ||
766 | goto check_next; | ||
767 | |||
768 | case SLSB_P_OUTPUT_ERROR: | ||
769 | QDIO_DBF_TEXT3(0,trace,"outperr"); | ||
770 | sprintf(dbf_text,"%x-%x-%x",f_mod_no, | ||
771 | q->sbal[f_mod_no]->element[14].sbalf.value, | ||
772 | q->sbal[f_mod_no]->element[15].sbalf.value); | ||
773 | QDIO_DBF_TEXT3(1,trace,dbf_text); | ||
774 | QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256); | ||
775 | |||
776 | /* kind of process the buffer */ | ||
777 | set_slsb(q, &f_mod_no, SLSB_P_OUTPUT_NOT_INIT, &count); | ||
778 | |||
779 | /* | ||
780 | * we increment the frontier, as this buffer | ||
781 | * was processed obviously | ||
782 | */ | ||
783 | atomic_dec(&q->number_of_buffers_used); | ||
784 | f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1); | ||
785 | |||
786 | if (q->qdio_error) | ||
787 | q->error_status_flags|= | ||
788 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; | ||
789 | q->qdio_error=SLSB_P_OUTPUT_ERROR; | ||
790 | q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR; | ||
791 | |||
792 | break; | ||
793 | |||
794 | /* no new buffers */ | ||
795 | default: | ||
796 | QDIO_DBF_TEXT5(0,trace,"outpni"); | ||
797 | } | ||
798 | out: | ||
799 | return (q->first_to_check=f_mod_no); | ||
800 | } | ||
801 | |||
802 | /* all buffers are processed */ | ||
803 | static int | ||
804 | qdio_is_outbound_q_done(struct qdio_q *q) | ||
805 | { | ||
806 | int no_used; | ||
807 | #ifdef CONFIG_QDIO_DEBUG | ||
808 | char dbf_text[15]; | ||
809 | #endif | ||
810 | |||
811 | no_used=atomic_read(&q->number_of_buffers_used); | ||
812 | |||
813 | #ifdef CONFIG_QDIO_DEBUG | ||
814 | if (no_used) { | ||
815 | sprintf(dbf_text,"oqisnt%02x",no_used); | ||
816 | QDIO_DBF_TEXT4(0,trace,dbf_text); | ||
817 | } else { | ||
818 | QDIO_DBF_TEXT4(0,trace,"oqisdone"); | ||
819 | } | ||
820 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
821 | #endif /* CONFIG_QDIO_DEBUG */ | ||
822 | return (no_used==0); | ||
823 | } | ||
824 | |||
825 | static int | ||
826 | qdio_has_outbound_q_moved(struct qdio_q *q) | ||
827 | { | ||
828 | int i; | ||
829 | |||
830 | i=qdio_get_outbound_buffer_frontier(q); | ||
831 | |||
832 | if ( (i!=GET_SAVED_FRONTIER(q)) || | ||
833 | (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) { | ||
834 | SAVE_FRONTIER(q,i); | ||
835 | QDIO_DBF_TEXT4(0,trace,"oqhasmvd"); | ||
836 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
837 | return 1; | ||
838 | } else { | ||
839 | QDIO_DBF_TEXT4(0,trace,"oqhsntmv"); | ||
840 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
841 | return 0; | ||
842 | } | ||
843 | } | ||
844 | |||
845 | static void | ||
846 | qdio_kick_outbound_q(struct qdio_q *q) | ||
847 | { | ||
848 | int result; | ||
849 | #ifdef CONFIG_QDIO_DEBUG | ||
850 | char dbf_text[15]; | ||
851 | |||
852 | QDIO_DBF_TEXT4(0,trace,"kickoutq"); | ||
853 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
854 | #endif /* CONFIG_QDIO_DEBUG */ | ||
855 | |||
856 | if (!q->siga_out) | ||
857 | return; | ||
858 | |||
859 | /* here's the story with cc=2 and busy bit set (thanks, Rick): | ||
860 | * VM's CP could present us cc=2 and busy bit set on SIGA-write | ||
861 | * during reconfiguration of their Guest LAN (only in HIPERS mode, | ||
862 | * QDIO mode is asynchronous -- cc=2 and busy bit there will take | ||
863 | * the queues down immediately; and not being under VM we have a | ||
864 | * problem on cc=2 and busy bit set right away). | ||
865 | * | ||
866 | * Therefore qdio_siga_output will try for a short time constantly, | ||
867 | * if such a condition occurs. If it doesn't change, it will | ||
868 | * increase the busy_siga_counter and save the timestamp, and | ||
869 | * schedule the queue for later processing (via mark_q, using the | ||
870 | * queue tasklet). __qdio_outbound_processing will check out the | ||
871 | * counter. If non-zero, it will call qdio_kick_outbound_q as often | ||
872 | * as the value of the counter. This will attempt further SIGA | ||
873 | * instructions. For each successful SIGA, the counter is | ||
874 | * decreased, for failing SIGAs the counter remains the same, after | ||
875 | * all. | ||
876 | * After some time of no movement, qdio_kick_outbound_q will | ||
877 | * finally fail and reflect corresponding error codes to call | ||
878 | * the upper layer module and have it take the queues down. | ||
879 | * | ||
880 | * Note that this is a change from the original HiperSockets design | ||
881 | * (saying cc=2 and busy bit means take the queues down), but in | ||
882 | * these days Guest LAN didn't exist... excessive cc=2 with busy bit | ||
883 | * conditions will still take the queues down, but the threshold is | ||
884 | * higher due to the Guest LAN environment. | ||
885 | */ | ||
886 | |||
887 | |||
888 | result=qdio_siga_output(q); | ||
889 | |||
890 | switch (result) { | ||
891 | case 0: | ||
892 | /* went smooth this time, reset timestamp */ | ||
893 | #ifdef CONFIG_QDIO_DEBUG | ||
894 | QDIO_DBF_TEXT3(0,trace,"cc2reslv"); | ||
895 | sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no, | ||
896 | atomic_read(&q->busy_siga_counter)); | ||
897 | QDIO_DBF_TEXT3(0,trace,dbf_text); | ||
898 | #endif /* CONFIG_QDIO_DEBUG */ | ||
899 | q->timing.busy_start=0; | ||
900 | break; | ||
901 | case (2|QDIO_SIGA_ERROR_B_BIT_SET): | ||
902 | /* cc=2 and busy bit: */ | ||
903 | atomic_inc(&q->busy_siga_counter); | ||
904 | |||
905 | /* if the last siga was successful, save | ||
906 | * timestamp here */ | ||
907 | if (!q->timing.busy_start) | ||
908 | q->timing.busy_start=NOW; | ||
909 | |||
910 | /* if we're in time, don't touch error_status_flags | ||
911 | * and siga_error */ | ||
912 | if (NOW-q->timing.busy_start<QDIO_BUSY_BIT_GIVE_UP) { | ||
913 | qdio_mark_q(q); | ||
914 | break; | ||
915 | } | ||
916 | QDIO_DBF_TEXT2(0,trace,"cc2REPRT"); | ||
917 | #ifdef CONFIG_QDIO_DEBUG | ||
918 | sprintf(dbf_text,"%4x%2x%2x",q->schid.sch_no,q->q_no, | ||
919 | atomic_read(&q->busy_siga_counter)); | ||
920 | QDIO_DBF_TEXT3(0,trace,dbf_text); | ||
921 | #endif /* CONFIG_QDIO_DEBUG */ | ||
922 | /* else fallthrough and report error */ | ||
923 | default: | ||
924 | /* for plain cc=1, 2 or 3: */ | ||
925 | if (q->siga_error) | ||
926 | q->error_status_flags|= | ||
927 | QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR; | ||
928 | q->error_status_flags|= | ||
929 | QDIO_STATUS_LOOK_FOR_ERROR; | ||
930 | q->siga_error=result; | ||
931 | } | ||
932 | } | ||
933 | |||
934 | static void | ||
935 | qdio_kick_outbound_handler(struct qdio_q *q) | ||
936 | { | ||
937 | int start, end, real_end, count; | ||
938 | #ifdef CONFIG_QDIO_DEBUG | ||
939 | char dbf_text[15]; | ||
940 | #endif | ||
941 | |||
942 | start = q->first_element_to_kick; | ||
943 | /* last_move_ftc was just updated */ | ||
944 | real_end = GET_SAVED_FRONTIER(q); | ||
945 | end = (real_end+QDIO_MAX_BUFFERS_PER_Q-1)& | ||
946 | (QDIO_MAX_BUFFERS_PER_Q-1); | ||
947 | count = (end+QDIO_MAX_BUFFERS_PER_Q+1-start)& | ||
948 | (QDIO_MAX_BUFFERS_PER_Q-1); | ||
949 | |||
950 | #ifdef CONFIG_QDIO_DEBUG | ||
951 | QDIO_DBF_TEXT4(0,trace,"kickouth"); | ||
952 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
953 | |||
954 | sprintf(dbf_text,"s=%2xc=%2x",start,count); | ||
955 | QDIO_DBF_TEXT4(0,trace,dbf_text); | ||
956 | #endif /* CONFIG_QDIO_DEBUG */ | ||
957 | |||
958 | if (q->state==QDIO_IRQ_STATE_ACTIVE) | ||
959 | q->handler(q->cdev,QDIO_STATUS_OUTBOUND_INT| | ||
960 | q->error_status_flags, | ||
961 | q->qdio_error,q->siga_error,q->q_no,start,count, | ||
962 | q->int_parm); | ||
963 | |||
964 | /* for the next time: */ | ||
965 | q->first_element_to_kick=real_end; | ||
966 | q->qdio_error=0; | ||
967 | q->siga_error=0; | ||
968 | q->error_status_flags=0; | ||
969 | } | ||
970 | |||
971 | static void | ||
972 | __qdio_outbound_processing(struct qdio_q *q) | ||
973 | { | ||
974 | int siga_attempts; | ||
975 | |||
976 | QDIO_DBF_TEXT4(0,trace,"qoutproc"); | ||
977 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
978 | |||
979 | if (unlikely(qdio_reserve_q(q))) { | ||
980 | qdio_release_q(q); | ||
981 | qdio_perf_stat_inc(&perf_stats.outbound_tl_runs_resched); | ||
982 | /* as we're sissies, we'll check next time */ | ||
983 | if (likely(!atomic_read(&q->is_in_shutdown))) { | ||
984 | qdio_mark_q(q); | ||
985 | QDIO_DBF_TEXT4(0,trace,"busy,agn"); | ||
986 | } | ||
987 | return; | ||
988 | } | ||
989 | qdio_perf_stat_inc(&perf_stats.outbound_tl_runs); | ||
990 | qdio_perf_stat_inc(&perf_stats.tl_runs); | ||
991 | |||
992 | /* see comment in qdio_kick_outbound_q */ | ||
993 | siga_attempts=atomic_read(&q->busy_siga_counter); | ||
994 | while (siga_attempts) { | ||
995 | atomic_dec(&q->busy_siga_counter); | ||
996 | qdio_kick_outbound_q(q); | ||
997 | siga_attempts--; | ||
998 | } | ||
999 | |||
1000 | if (qdio_has_outbound_q_moved(q)) | ||
1001 | qdio_kick_outbound_handler(q); | ||
1002 | |||
1003 | if (q->queue_type == QDIO_ZFCP_QFMT) { | ||
1004 | if ((!q->hydra_gives_outbound_pcis) && | ||
1005 | (!qdio_is_outbound_q_done(q))) | ||
1006 | qdio_mark_q(q); | ||
1007 | } | ||
1008 | else if (((!q->is_iqdio_q) && (!q->is_pci_out)) || | ||
1009 | (q->queue_type == QDIO_IQDIO_QFMT_ASYNCH)) { | ||
1010 | /* | ||
1011 | * make sure buffer switch from PRIMED to EMPTY is noticed | ||
1012 | * and outbound_handler is called | ||
1013 | */ | ||
1014 | if (qdio_is_outbound_q_done(q)) { | ||
1015 | del_timer(&q->timer); | ||
1016 | } else { | ||
1017 | if (!timer_pending(&q->timer)) | ||
1018 | mod_timer(&q->timer, jiffies + | ||
1019 | QDIO_FORCE_CHECK_TIMEOUT); | ||
1020 | } | ||
1021 | } | ||
1022 | |||
1023 | qdio_release_q(q); | ||
1024 | } | ||
1025 | |||
1026 | static void | ||
1027 | qdio_outbound_processing(unsigned long q) | ||
1028 | { | ||
1029 | __qdio_outbound_processing((struct qdio_q *) q); | ||
1030 | } | ||
1031 | |||
1032 | /************************* INBOUND ROUTINES *******************************/ | ||
1033 | |||
1034 | |||
1035 | static int | ||
1036 | qdio_get_inbound_buffer_frontier(struct qdio_q *q) | ||
1037 | { | ||
1038 | struct qdio_irq *irq; | ||
1039 | int f,f_mod_no; | ||
1040 | volatile char *slsb; | ||
1041 | unsigned int count = 1; | ||
1042 | int first_not_to_check; | ||
1043 | #ifdef CONFIG_QDIO_DEBUG | ||
1044 | char dbf_text[15]; | ||
1045 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1046 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1047 | int last_position=-1; | ||
1048 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1049 | |||
1050 | QDIO_DBF_TEXT4(0,trace,"getibfro"); | ||
1051 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1052 | |||
1053 | irq = (struct qdio_irq *) q->irq_ptr; | ||
1054 | if (irq->is_qebsm) | ||
1055 | return qdio_qebsm_get_inbound_buffer_frontier(q); | ||
1056 | |||
1057 | slsb=&q->slsb.acc.val[0]; | ||
1058 | f_mod_no=f=q->first_to_check; | ||
1059 | /* | ||
1060 | * we don't check 128 buffers, as otherwise qdio_has_inbound_q_moved | ||
1061 | * would return 0 | ||
1062 | */ | ||
1063 | first_not_to_check=f+qdio_min(atomic_read(&q->number_of_buffers_used), | ||
1064 | (QDIO_MAX_BUFFERS_PER_Q-1)); | ||
1065 | |||
1066 | /* | ||
1067 | * we don't use this one, as a PCI or we after a thin interrupt | ||
1068 | * will sync the queues | ||
1069 | */ | ||
1070 | /* SYNC_MEMORY;*/ | ||
1071 | |||
1072 | check_next: | ||
1073 | f_mod_no=f&(QDIO_MAX_BUFFERS_PER_Q-1); | ||
1074 | if (f==first_not_to_check) | ||
1075 | goto out; | ||
1076 | switch (slsb[f_mod_no]) { | ||
1077 | |||
1078 | /* CU_EMPTY means frontier is reached */ | ||
1079 | case SLSB_CU_INPUT_EMPTY: | ||
1080 | QDIO_DBF_TEXT5(0,trace,"inptempt"); | ||
1081 | break; | ||
1082 | |||
1083 | /* P_PRIMED means set slsb to P_PROCESSING and move on */ | ||
1084 | case SLSB_P_INPUT_PRIMED: | ||
1085 | QDIO_DBF_TEXT5(0,trace,"inptprim"); | ||
1086 | |||
1087 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1088 | /* | ||
1089 | * as soon as running under VM, polling the input queues will | ||
1090 | * kill VM in terms of CP overhead | ||
1091 | */ | ||
1092 | if (q->siga_sync) { | ||
1093 | set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count); | ||
1094 | } else { | ||
1095 | /* set the previous buffer to NOT_INIT. The current | ||
1096 | * buffer will be set to PROCESSING at the end of | ||
1097 | * this function to avoid further interrupts. */ | ||
1098 | if (last_position>=0) | ||
1099 | set_slsb(q, &last_position, | ||
1100 | SLSB_P_INPUT_NOT_INIT, &count); | ||
1101 | atomic_set(&q->polling,1); | ||
1102 | last_position=f_mod_no; | ||
1103 | } | ||
1104 | #else /* QDIO_USE_PROCESSING_STATE */ | ||
1105 | set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count); | ||
1106 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1107 | /* | ||
1108 | * not needed, as the inbound queue will be synced on the next | ||
1109 | * siga-r, resp. tiqdio_is_inbound_q_done will do the siga-s | ||
1110 | */ | ||
1111 | /*SYNC_MEMORY;*/ | ||
1112 | f++; | ||
1113 | atomic_dec(&q->number_of_buffers_used); | ||
1114 | goto check_next; | ||
1115 | |||
1116 | case SLSB_P_INPUT_NOT_INIT: | ||
1117 | case SLSB_P_INPUT_PROCESSING: | ||
1118 | QDIO_DBF_TEXT5(0,trace,"inpnipro"); | ||
1119 | break; | ||
1120 | |||
1121 | /* P_ERROR means frontier is reached, break and report error */ | ||
1122 | case SLSB_P_INPUT_ERROR: | ||
1123 | #ifdef CONFIG_QDIO_DEBUG | ||
1124 | sprintf(dbf_text,"inperr%2x",f_mod_no); | ||
1125 | QDIO_DBF_TEXT3(1,trace,dbf_text); | ||
1126 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1127 | QDIO_DBF_HEX2(1,sbal,q->sbal[f_mod_no],256); | ||
1128 | |||
1129 | /* kind of process the buffer */ | ||
1130 | set_slsb(q, &f_mod_no, SLSB_P_INPUT_NOT_INIT, &count); | ||
1131 | |||
1132 | if (q->qdio_error) | ||
1133 | q->error_status_flags|= | ||
1134 | QDIO_STATUS_MORE_THAN_ONE_QDIO_ERROR; | ||
1135 | q->qdio_error=SLSB_P_INPUT_ERROR; | ||
1136 | q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR; | ||
1137 | |||
1138 | /* we increment the frontier, as this buffer | ||
1139 | * was processed obviously */ | ||
1140 | f_mod_no=(f_mod_no+1)&(QDIO_MAX_BUFFERS_PER_Q-1); | ||
1141 | atomic_dec(&q->number_of_buffers_used); | ||
1142 | |||
1143 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1144 | last_position=-1; | ||
1145 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1146 | |||
1147 | break; | ||
1148 | |||
1149 | /* everything else means frontier not changed (HALTED or so) */ | ||
1150 | default: | ||
1151 | break; | ||
1152 | } | ||
1153 | out: | ||
1154 | q->first_to_check=f_mod_no; | ||
1155 | |||
1156 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1157 | if (last_position>=0) | ||
1158 | set_slsb(q, &last_position, SLSB_P_INPUT_PROCESSING, &count); | ||
1159 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1160 | |||
1161 | QDIO_DBF_HEX4(0,trace,&q->first_to_check,sizeof(int)); | ||
1162 | |||
1163 | return q->first_to_check; | ||
1164 | } | ||
1165 | |||
1166 | static int | ||
1167 | qdio_has_inbound_q_moved(struct qdio_q *q) | ||
1168 | { | ||
1169 | int i; | ||
1170 | |||
1171 | i=qdio_get_inbound_buffer_frontier(q); | ||
1172 | if ( (i!=GET_SAVED_FRONTIER(q)) || | ||
1173 | (q->error_status_flags&QDIO_STATUS_LOOK_FOR_ERROR) ) { | ||
1174 | SAVE_FRONTIER(q,i); | ||
1175 | if ((!q->siga_sync)&&(!q->hydra_gives_outbound_pcis)) | ||
1176 | SAVE_TIMESTAMP(q); | ||
1177 | |||
1178 | QDIO_DBF_TEXT4(0,trace,"inhasmvd"); | ||
1179 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1180 | return 1; | ||
1181 | } else { | ||
1182 | QDIO_DBF_TEXT4(0,trace,"inhsntmv"); | ||
1183 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1184 | return 0; | ||
1185 | } | ||
1186 | } | ||
1187 | |||
1188 | /* means, no more buffers to be filled */ | ||
1189 | static int | ||
1190 | tiqdio_is_inbound_q_done(struct qdio_q *q) | ||
1191 | { | ||
1192 | int no_used; | ||
1193 | unsigned int start_buf, count; | ||
1194 | unsigned char state = 0; | ||
1195 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; | ||
1196 | |||
1197 | #ifdef CONFIG_QDIO_DEBUG | ||
1198 | char dbf_text[15]; | ||
1199 | #endif | ||
1200 | |||
1201 | no_used=atomic_read(&q->number_of_buffers_used); | ||
1202 | |||
1203 | /* propagate the change from 82 to 80 through VM */ | ||
1204 | SYNC_MEMORY; | ||
1205 | |||
1206 | #ifdef CONFIG_QDIO_DEBUG | ||
1207 | if (no_used) { | ||
1208 | sprintf(dbf_text,"iqisnt%02x",no_used); | ||
1209 | QDIO_DBF_TEXT4(0,trace,dbf_text); | ||
1210 | } else { | ||
1211 | QDIO_DBF_TEXT4(0,trace,"iniqisdo"); | ||
1212 | } | ||
1213 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1214 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1215 | |||
1216 | if (!no_used) | ||
1217 | return 1; | ||
1218 | if (irq->is_qebsm) { | ||
1219 | count = 1; | ||
1220 | start_buf = q->first_to_check; | ||
1221 | qdio_do_eqbs(q, &state, &start_buf, &count); | ||
1222 | } else | ||
1223 | state = q->slsb.acc.val[q->first_to_check]; | ||
1224 | if (state != SLSB_P_INPUT_PRIMED) | ||
1225 | /* | ||
1226 | * nothing more to do, if next buffer is not PRIMED. | ||
1227 | * note that we did a SYNC_MEMORY before, that there | ||
1228 | * has been a sychnronization. | ||
1229 | * we will return 0 below, as there is nothing to do | ||
1230 | * (stop_polling not necessary, as we have not been | ||
1231 | * using the PROCESSING state | ||
1232 | */ | ||
1233 | return 0; | ||
1234 | |||
1235 | /* | ||
1236 | * ok, the next input buffer is primed. that means, that device state | ||
1237 | * change indicator and adapter local summary are set, so we will find | ||
1238 | * it next time. | ||
1239 | * we will return 0 below, as there is nothing to do, except scheduling | ||
1240 | * ourselves for the next time. | ||
1241 | */ | ||
1242 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); | ||
1243 | tiqdio_sched_tl(); | ||
1244 | return 0; | ||
1245 | } | ||
1246 | |||
1247 | static int | ||
1248 | qdio_is_inbound_q_done(struct qdio_q *q) | ||
1249 | { | ||
1250 | int no_used; | ||
1251 | unsigned int start_buf, count; | ||
1252 | unsigned char state = 0; | ||
1253 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; | ||
1254 | |||
1255 | #ifdef CONFIG_QDIO_DEBUG | ||
1256 | char dbf_text[15]; | ||
1257 | #endif | ||
1258 | |||
1259 | no_used=atomic_read(&q->number_of_buffers_used); | ||
1260 | |||
1261 | /* | ||
1262 | * we need that one for synchronization with the adapter, as it | ||
1263 | * does a kind of PCI avoidance | ||
1264 | */ | ||
1265 | SYNC_MEMORY; | ||
1266 | |||
1267 | if (!no_used) { | ||
1268 | QDIO_DBF_TEXT4(0,trace,"inqisdnA"); | ||
1269 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1270 | return 1; | ||
1271 | } | ||
1272 | if (irq->is_qebsm) { | ||
1273 | count = 1; | ||
1274 | start_buf = q->first_to_check; | ||
1275 | qdio_do_eqbs(q, &state, &start_buf, &count); | ||
1276 | } else | ||
1277 | state = q->slsb.acc.val[q->first_to_check]; | ||
1278 | if (state == SLSB_P_INPUT_PRIMED) { | ||
1279 | /* we got something to do */ | ||
1280 | QDIO_DBF_TEXT4(0,trace,"inqisntA"); | ||
1281 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1282 | return 0; | ||
1283 | } | ||
1284 | |||
1285 | /* on VM, we don't poll, so the q is always done here */ | ||
1286 | if (q->siga_sync) | ||
1287 | return 1; | ||
1288 | if (q->hydra_gives_outbound_pcis) | ||
1289 | return 1; | ||
1290 | |||
1291 | /* | ||
1292 | * at this point we know, that inbound first_to_check | ||
1293 | * has (probably) not moved (see qdio_inbound_processing) | ||
1294 | */ | ||
1295 | if (NOW>GET_SAVED_TIMESTAMP(q)+q->timing.threshold) { | ||
1296 | #ifdef CONFIG_QDIO_DEBUG | ||
1297 | QDIO_DBF_TEXT4(0,trace,"inqisdon"); | ||
1298 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1299 | sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used); | ||
1300 | QDIO_DBF_TEXT4(0,trace,dbf_text); | ||
1301 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1302 | return 1; | ||
1303 | } else { | ||
1304 | #ifdef CONFIG_QDIO_DEBUG | ||
1305 | QDIO_DBF_TEXT4(0,trace,"inqisntd"); | ||
1306 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1307 | sprintf(dbf_text,"pf%02xcn%02x",q->first_to_check,no_used); | ||
1308 | QDIO_DBF_TEXT4(0,trace,dbf_text); | ||
1309 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1310 | return 0; | ||
1311 | } | ||
1312 | } | ||
1313 | |||
1314 | static void | ||
1315 | qdio_kick_inbound_handler(struct qdio_q *q) | ||
1316 | { | ||
1317 | int count, start, end, real_end, i; | ||
1318 | #ifdef CONFIG_QDIO_DEBUG | ||
1319 | char dbf_text[15]; | ||
1320 | #endif | ||
1321 | |||
1322 | QDIO_DBF_TEXT4(0,trace,"kickinh"); | ||
1323 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1324 | |||
1325 | start=q->first_element_to_kick; | ||
1326 | real_end=q->first_to_check; | ||
1327 | end=(real_end+QDIO_MAX_BUFFERS_PER_Q-1)&(QDIO_MAX_BUFFERS_PER_Q-1); | ||
1328 | |||
1329 | i=start; | ||
1330 | count=0; | ||
1331 | while (1) { | ||
1332 | count++; | ||
1333 | if (i==end) | ||
1334 | break; | ||
1335 | i=(i+1)&(QDIO_MAX_BUFFERS_PER_Q-1); | ||
1336 | } | ||
1337 | |||
1338 | #ifdef CONFIG_QDIO_DEBUG | ||
1339 | sprintf(dbf_text,"s=%2xc=%2x",start,count); | ||
1340 | QDIO_DBF_TEXT4(0,trace,dbf_text); | ||
1341 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1342 | |||
1343 | if (likely(q->state==QDIO_IRQ_STATE_ACTIVE)) | ||
1344 | q->handler(q->cdev, | ||
1345 | QDIO_STATUS_INBOUND_INT|q->error_status_flags, | ||
1346 | q->qdio_error,q->siga_error,q->q_no,start,count, | ||
1347 | q->int_parm); | ||
1348 | |||
1349 | /* for the next time: */ | ||
1350 | q->first_element_to_kick=real_end; | ||
1351 | q->qdio_error=0; | ||
1352 | q->siga_error=0; | ||
1353 | q->error_status_flags=0; | ||
1354 | |||
1355 | qdio_perf_stat_inc(&perf_stats.inbound_cnt); | ||
1356 | } | ||
1357 | |||
1358 | static void | ||
1359 | __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set) | ||
1360 | { | ||
1361 | struct qdio_irq *irq_ptr; | ||
1362 | struct qdio_q *oq; | ||
1363 | int i; | ||
1364 | |||
1365 | QDIO_DBF_TEXT4(0,trace,"iqinproc"); | ||
1366 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1367 | |||
1368 | /* | ||
1369 | * we first want to reserve the q, so that we know, that we don't | ||
1370 | * interrupt ourselves and call qdio_unmark_q, as is_in_shutdown might | ||
1371 | * be set | ||
1372 | */ | ||
1373 | if (unlikely(qdio_reserve_q(q))) { | ||
1374 | qdio_release_q(q); | ||
1375 | qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched); | ||
1376 | /* | ||
1377 | * as we might just be about to stop polling, we make | ||
1378 | * sure that we check again at least once more | ||
1379 | */ | ||
1380 | tiqdio_sched_tl(); | ||
1381 | return; | ||
1382 | } | ||
1383 | qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs); | ||
1384 | if (unlikely(atomic_read(&q->is_in_shutdown))) { | ||
1385 | qdio_unmark_q(q); | ||
1386 | goto out; | ||
1387 | } | ||
1388 | |||
1389 | /* | ||
1390 | * we reset spare_ind_was_set, when the queue does not use the | ||
1391 | * spare indicator | ||
1392 | */ | ||
1393 | if (spare_ind_was_set) | ||
1394 | spare_ind_was_set = (q->dev_st_chg_ind == &spare_indicator); | ||
1395 | |||
1396 | if (!(*(q->dev_st_chg_ind)) && !spare_ind_was_set) | ||
1397 | goto out; | ||
1398 | /* | ||
1399 | * q->dev_st_chg_ind is the indicator, be it shared or not. | ||
1400 | * only clear it, if indicator is non-shared | ||
1401 | */ | ||
1402 | if (q->dev_st_chg_ind != &spare_indicator) | ||
1403 | tiqdio_clear_summary_bit((__u32*)q->dev_st_chg_ind); | ||
1404 | |||
1405 | if (q->hydra_gives_outbound_pcis) { | ||
1406 | if (!q->siga_sync_done_on_thinints) { | ||
1407 | SYNC_MEMORY_ALL; | ||
1408 | } else if (!q->siga_sync_done_on_outb_tis) { | ||
1409 | SYNC_MEMORY_ALL_OUTB; | ||
1410 | } | ||
1411 | } else { | ||
1412 | SYNC_MEMORY; | ||
1413 | } | ||
1414 | /* | ||
1415 | * maybe we have to do work on our outbound queues... at least | ||
1416 | * we have to check the outbound-int-capable thinint-capable | ||
1417 | * queues | ||
1418 | */ | ||
1419 | if (q->hydra_gives_outbound_pcis) { | ||
1420 | irq_ptr = (struct qdio_irq*)q->irq_ptr; | ||
1421 | for (i=0;i<irq_ptr->no_output_qs;i++) { | ||
1422 | oq = irq_ptr->output_qs[i]; | ||
1423 | if (!qdio_is_outbound_q_done(oq)) { | ||
1424 | qdio_perf_stat_dec(&perf_stats.tl_runs); | ||
1425 | __qdio_outbound_processing(oq); | ||
1426 | } | ||
1427 | } | ||
1428 | } | ||
1429 | |||
1430 | if (!qdio_has_inbound_q_moved(q)) | ||
1431 | goto out; | ||
1432 | |||
1433 | qdio_kick_inbound_handler(q); | ||
1434 | if (tiqdio_is_inbound_q_done(q)) | ||
1435 | if (!qdio_stop_polling(q)) { | ||
1436 | /* | ||
1437 | * we set the flags to get into the stuff next time, | ||
1438 | * see also comment in qdio_stop_polling | ||
1439 | */ | ||
1440 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); | ||
1441 | tiqdio_sched_tl(); | ||
1442 | } | ||
1443 | out: | ||
1444 | qdio_release_q(q); | ||
1445 | } | ||
1446 | |||
1447 | static void | ||
1448 | tiqdio_inbound_processing(unsigned long q) | ||
1449 | { | ||
1450 | __tiqdio_inbound_processing((struct qdio_q *) q, | ||
1451 | atomic_read(&spare_indicator_usecount)); | ||
1452 | } | ||
1453 | |||
1454 | static void | ||
1455 | __qdio_inbound_processing(struct qdio_q *q) | ||
1456 | { | ||
1457 | int q_laps=0; | ||
1458 | |||
1459 | QDIO_DBF_TEXT4(0,trace,"qinproc"); | ||
1460 | QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); | ||
1461 | |||
1462 | if (unlikely(qdio_reserve_q(q))) { | ||
1463 | qdio_release_q(q); | ||
1464 | qdio_perf_stat_inc(&perf_stats.inbound_tl_runs_resched); | ||
1465 | /* as we're sissies, we'll check next time */ | ||
1466 | if (likely(!atomic_read(&q->is_in_shutdown))) { | ||
1467 | qdio_mark_q(q); | ||
1468 | QDIO_DBF_TEXT4(0,trace,"busy,agn"); | ||
1469 | } | ||
1470 | return; | ||
1471 | } | ||
1472 | qdio_perf_stat_inc(&perf_stats.inbound_tl_runs); | ||
1473 | qdio_perf_stat_inc(&perf_stats.tl_runs); | ||
1474 | |||
1475 | again: | ||
1476 | if (qdio_has_inbound_q_moved(q)) { | ||
1477 | qdio_kick_inbound_handler(q); | ||
1478 | if (!qdio_stop_polling(q)) { | ||
1479 | q_laps++; | ||
1480 | if (q_laps<QDIO_Q_LAPS) | ||
1481 | goto again; | ||
1482 | } | ||
1483 | qdio_mark_q(q); | ||
1484 | } else { | ||
1485 | if (!qdio_is_inbound_q_done(q)) | ||
1486 | /* means poll time is not yet over */ | ||
1487 | qdio_mark_q(q); | ||
1488 | } | ||
1489 | |||
1490 | qdio_release_q(q); | ||
1491 | } | ||
1492 | |||
1493 | static void | ||
1494 | qdio_inbound_processing(unsigned long q) | ||
1495 | { | ||
1496 | __qdio_inbound_processing((struct qdio_q *) q); | ||
1497 | } | ||
1498 | |||
1499 | /************************* MAIN ROUTINES *******************************/ | ||
1500 | |||
1501 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1502 | static int | ||
1503 | tiqdio_reset_processing_state(struct qdio_q *q, int q_laps) | ||
1504 | { | ||
1505 | if (!q) { | ||
1506 | tiqdio_sched_tl(); | ||
1507 | return 0; | ||
1508 | } | ||
1509 | |||
1510 | /* | ||
1511 | * under VM, we have not used the PROCESSING state, so no | ||
1512 | * need to stop polling | ||
1513 | */ | ||
1514 | if (q->siga_sync) | ||
1515 | return 2; | ||
1516 | |||
1517 | if (unlikely(qdio_reserve_q(q))) { | ||
1518 | qdio_release_q(q); | ||
1519 | qdio_perf_stat_inc(&perf_stats.inbound_thin_tl_runs_resched); | ||
1520 | /* | ||
1521 | * as we might just be about to stop polling, we make | ||
1522 | * sure that we check again at least once more | ||
1523 | */ | ||
1524 | |||
1525 | /* | ||
1526 | * sanity -- we'd get here without setting the | ||
1527 | * dev st chg ind | ||
1528 | */ | ||
1529 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); | ||
1530 | tiqdio_sched_tl(); | ||
1531 | return 0; | ||
1532 | } | ||
1533 | if (qdio_stop_polling(q)) { | ||
1534 | qdio_release_q(q); | ||
1535 | return 2; | ||
1536 | } | ||
1537 | if (q_laps<QDIO_Q_LAPS-1) { | ||
1538 | qdio_release_q(q); | ||
1539 | return 3; | ||
1540 | } | ||
1541 | /* | ||
1542 | * we set the flags to get into the stuff | ||
1543 | * next time, see also comment in qdio_stop_polling | ||
1544 | */ | ||
1545 | tiqdio_set_summary_bit((__u32*)q->dev_st_chg_ind); | ||
1546 | tiqdio_sched_tl(); | ||
1547 | qdio_release_q(q); | ||
1548 | return 1; | ||
1549 | |||
1550 | } | ||
1551 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1552 | |||
1553 | static void | ||
1554 | tiqdio_inbound_checks(void) | ||
1555 | { | ||
1556 | struct qdio_q *q; | ||
1557 | int spare_ind_was_set=0; | ||
1558 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1559 | int q_laps=0; | ||
1560 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1561 | |||
1562 | QDIO_DBF_TEXT4(0,trace,"iqdinbck"); | ||
1563 | QDIO_DBF_TEXT5(0,trace,"iqlocsum"); | ||
1564 | |||
1565 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1566 | again: | ||
1567 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1568 | |||
1569 | /* when the spare indicator is used and set, save that and clear it */ | ||
1570 | if ((atomic_read(&spare_indicator_usecount)) && spare_indicator) { | ||
1571 | spare_ind_was_set = 1; | ||
1572 | tiqdio_clear_summary_bit((__u32*)&spare_indicator); | ||
1573 | } | ||
1574 | |||
1575 | q=(struct qdio_q*)tiq_list; | ||
1576 | do { | ||
1577 | if (!q) | ||
1578 | break; | ||
1579 | __tiqdio_inbound_processing(q, spare_ind_was_set); | ||
1580 | q=(struct qdio_q*)q->list_next; | ||
1581 | } while (q!=(struct qdio_q*)tiq_list); | ||
1582 | |||
1583 | #ifdef QDIO_USE_PROCESSING_STATE | ||
1584 | q=(struct qdio_q*)tiq_list; | ||
1585 | do { | ||
1586 | int ret; | ||
1587 | |||
1588 | ret = tiqdio_reset_processing_state(q, q_laps); | ||
1589 | switch (ret) { | ||
1590 | case 0: | ||
1591 | return; | ||
1592 | case 1: | ||
1593 | q_laps++; | ||
1594 | case 2: | ||
1595 | q = (struct qdio_q*)q->list_next; | ||
1596 | break; | ||
1597 | default: | ||
1598 | q_laps++; | ||
1599 | goto again; | ||
1600 | } | ||
1601 | } while (q!=(struct qdio_q*)tiq_list); | ||
1602 | #endif /* QDIO_USE_PROCESSING_STATE */ | ||
1603 | } | ||
1604 | |||
1605 | static void | ||
1606 | tiqdio_tl(unsigned long data) | ||
1607 | { | ||
1608 | QDIO_DBF_TEXT4(0,trace,"iqdio_tl"); | ||
1609 | |||
1610 | qdio_perf_stat_inc(&perf_stats.tl_runs); | ||
1611 | |||
1612 | tiqdio_inbound_checks(); | ||
1613 | } | ||
1614 | |||
1615 | /********************* GENERAL HELPER_ROUTINES ***********************/ | ||
1616 | |||
1617 | static void | ||
1618 | qdio_release_irq_memory(struct qdio_irq *irq_ptr) | ||
1619 | { | ||
1620 | int i; | ||
1621 | struct qdio_q *q; | ||
1622 | |||
1623 | for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) { | ||
1624 | q = irq_ptr->input_qs[i]; | ||
1625 | if (q) { | ||
1626 | free_page((unsigned long) q->slib); | ||
1627 | kmem_cache_free(qdio_q_cache, q); | ||
1628 | } | ||
1629 | q = irq_ptr->output_qs[i]; | ||
1630 | if (q) { | ||
1631 | free_page((unsigned long) q->slib); | ||
1632 | kmem_cache_free(qdio_q_cache, q); | ||
1633 | } | ||
1634 | } | ||
1635 | free_page((unsigned long) irq_ptr->qdr); | ||
1636 | free_page((unsigned long) irq_ptr); | ||
1637 | } | ||
1638 | |||
1639 | static void | ||
1640 | qdio_set_impl_params(struct qdio_irq *irq_ptr, | ||
1641 | unsigned int qib_param_field_format, | ||
1642 | /* pointer to 128 bytes or NULL, if no param field */ | ||
1643 | unsigned char *qib_param_field, | ||
1644 | /* pointer to no_queues*128 words of data or NULL */ | ||
1645 | unsigned int no_input_qs, | ||
1646 | unsigned int no_output_qs, | ||
1647 | unsigned long *input_slib_elements, | ||
1648 | unsigned long *output_slib_elements) | ||
1649 | { | ||
1650 | int i,j; | ||
1651 | |||
1652 | if (!irq_ptr) | ||
1653 | return; | ||
1654 | |||
1655 | irq_ptr->qib.pfmt=qib_param_field_format; | ||
1656 | if (qib_param_field) | ||
1657 | memcpy(irq_ptr->qib.parm,qib_param_field, | ||
1658 | QDIO_MAX_BUFFERS_PER_Q); | ||
1659 | |||
1660 | if (input_slib_elements) | ||
1661 | for (i=0;i<no_input_qs;i++) { | ||
1662 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) | ||
1663 | irq_ptr->input_qs[i]->slib->slibe[j].parms= | ||
1664 | input_slib_elements[ | ||
1665 | i*QDIO_MAX_BUFFERS_PER_Q+j]; | ||
1666 | } | ||
1667 | if (output_slib_elements) | ||
1668 | for (i=0;i<no_output_qs;i++) { | ||
1669 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) | ||
1670 | irq_ptr->output_qs[i]->slib->slibe[j].parms= | ||
1671 | output_slib_elements[ | ||
1672 | i*QDIO_MAX_BUFFERS_PER_Q+j]; | ||
1673 | } | ||
1674 | } | ||
1675 | |||
1676 | static int | ||
1677 | qdio_alloc_qs(struct qdio_irq *irq_ptr, | ||
1678 | int no_input_qs, int no_output_qs) | ||
1679 | { | ||
1680 | int i; | ||
1681 | struct qdio_q *q; | ||
1682 | |||
1683 | for (i = 0; i < no_input_qs; i++) { | ||
1684 | q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL); | ||
1685 | if (!q) | ||
1686 | return -ENOMEM; | ||
1687 | memset(q, 0, sizeof(*q)); | ||
1688 | |||
1689 | q->slib = (struct slib *) __get_free_page(GFP_KERNEL); | ||
1690 | if (!q->slib) { | ||
1691 | kmem_cache_free(qdio_q_cache, q); | ||
1692 | return -ENOMEM; | ||
1693 | } | ||
1694 | irq_ptr->input_qs[i]=q; | ||
1695 | } | ||
1696 | |||
1697 | for (i = 0; i < no_output_qs; i++) { | ||
1698 | q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL); | ||
1699 | if (!q) | ||
1700 | return -ENOMEM; | ||
1701 | memset(q, 0, sizeof(*q)); | ||
1702 | |||
1703 | q->slib = (struct slib *) __get_free_page(GFP_KERNEL); | ||
1704 | if (!q->slib) { | ||
1705 | kmem_cache_free(qdio_q_cache, q); | ||
1706 | return -ENOMEM; | ||
1707 | } | ||
1708 | irq_ptr->output_qs[i]=q; | ||
1709 | } | ||
1710 | return 0; | ||
1711 | } | ||
1712 | |||
1713 | static void | ||
1714 | qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev, | ||
1715 | int no_input_qs, int no_output_qs, | ||
1716 | qdio_handler_t *input_handler, | ||
1717 | qdio_handler_t *output_handler, | ||
1718 | unsigned long int_parm,int q_format, | ||
1719 | unsigned long flags, | ||
1720 | void **inbound_sbals_array, | ||
1721 | void **outbound_sbals_array) | ||
1722 | { | ||
1723 | struct qdio_q *q; | ||
1724 | int i,j; | ||
1725 | char dbf_text[20]; /* see qdio_initialize */ | ||
1726 | void *ptr; | ||
1727 | int available; | ||
1728 | |||
1729 | sprintf(dbf_text,"qfqs%4x",cdev->private->schid.sch_no); | ||
1730 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
1731 | for (i=0;i<no_input_qs;i++) { | ||
1732 | q=irq_ptr->input_qs[i]; | ||
1733 | |||
1734 | memset(q,0,((char*)&q->slib)-((char*)q)); | ||
1735 | sprintf(dbf_text,"in-q%4x",i); | ||
1736 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
1737 | QDIO_DBF_HEX0(0,setup,&q,sizeof(void*)); | ||
1738 | |||
1739 | memset(q->slib,0,PAGE_SIZE); | ||
1740 | q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2); | ||
1741 | |||
1742 | available=0; | ||
1743 | |||
1744 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) | ||
1745 | q->sbal[j]=*(inbound_sbals_array++); | ||
1746 | |||
1747 | q->queue_type=q_format; | ||
1748 | q->int_parm=int_parm; | ||
1749 | q->schid = irq_ptr->schid; | ||
1750 | q->irq_ptr = irq_ptr; | ||
1751 | q->cdev = cdev; | ||
1752 | q->mask=1<<(31-i); | ||
1753 | q->q_no=i; | ||
1754 | q->is_input_q=1; | ||
1755 | q->first_to_check=0; | ||
1756 | q->last_move_ftc=0; | ||
1757 | q->handler=input_handler; | ||
1758 | q->dev_st_chg_ind=irq_ptr->dev_st_chg_ind; | ||
1759 | |||
1760 | /* q->is_thinint_q isn't valid at this time, but | ||
1761 | * irq_ptr->is_thinint_irq is | ||
1762 | */ | ||
1763 | if (irq_ptr->is_thinint_irq) | ||
1764 | tasklet_init(&q->tasklet, tiqdio_inbound_processing, | ||
1765 | (unsigned long) q); | ||
1766 | else | ||
1767 | tasklet_init(&q->tasklet, qdio_inbound_processing, | ||
1768 | (unsigned long) q); | ||
1769 | |||
1770 | /* actually this is not used for inbound queues. yet. */ | ||
1771 | atomic_set(&q->busy_siga_counter,0); | ||
1772 | q->timing.busy_start=0; | ||
1773 | |||
1774 | /* for (j=0;j<QDIO_STATS_NUMBER;j++) | ||
1775 | q->timing.last_transfer_times[j]=(qdio_get_micros()/ | ||
1776 | QDIO_STATS_NUMBER)*j; | ||
1777 | q->timing.last_transfer_index=QDIO_STATS_NUMBER-1; | ||
1778 | */ | ||
1779 | |||
1780 | /* fill in slib */ | ||
1781 | if (i>0) irq_ptr->input_qs[i-1]->slib->nsliba= | ||
1782 | (unsigned long)(q->slib); | ||
1783 | q->slib->sla=(unsigned long)(q->sl); | ||
1784 | q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]); | ||
1785 | |||
1786 | /* fill in sl */ | ||
1787 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) | ||
1788 | q->sl->element[j].sbal=(unsigned long)(q->sbal[j]); | ||
1789 | |||
1790 | QDIO_DBF_TEXT2(0,setup,"sl-sb-b0"); | ||
1791 | ptr=(void*)q->sl; | ||
1792 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); | ||
1793 | ptr=(void*)&q->slsb; | ||
1794 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); | ||
1795 | ptr=(void*)q->sbal[0]; | ||
1796 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); | ||
1797 | |||
1798 | /* fill in slsb */ | ||
1799 | if (!irq_ptr->is_qebsm) { | ||
1800 | unsigned int count = 1; | ||
1801 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) | ||
1802 | set_slsb(q, &j, SLSB_P_INPUT_NOT_INIT, &count); | ||
1803 | } | ||
1804 | } | ||
1805 | |||
1806 | for (i=0;i<no_output_qs;i++) { | ||
1807 | q=irq_ptr->output_qs[i]; | ||
1808 | memset(q,0,((char*)&q->slib)-((char*)q)); | ||
1809 | |||
1810 | sprintf(dbf_text,"outq%4x",i); | ||
1811 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
1812 | QDIO_DBF_HEX0(0,setup,&q,sizeof(void*)); | ||
1813 | |||
1814 | memset(q->slib,0,PAGE_SIZE); | ||
1815 | q->sl=(struct sl*)(((char*)q->slib)+PAGE_SIZE/2); | ||
1816 | |||
1817 | available=0; | ||
1818 | |||
1819 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) | ||
1820 | q->sbal[j]=*(outbound_sbals_array++); | ||
1821 | |||
1822 | q->queue_type=q_format; | ||
1823 | if ((q->queue_type == QDIO_IQDIO_QFMT) && | ||
1824 | (no_output_qs > 1) && | ||
1825 | (i == no_output_qs-1)) | ||
1826 | q->queue_type = QDIO_IQDIO_QFMT_ASYNCH; | ||
1827 | q->int_parm=int_parm; | ||
1828 | q->is_input_q=0; | ||
1829 | q->is_pci_out = 0; | ||
1830 | q->schid = irq_ptr->schid; | ||
1831 | q->cdev = cdev; | ||
1832 | q->irq_ptr = irq_ptr; | ||
1833 | q->mask=1<<(31-i); | ||
1834 | q->q_no=i; | ||
1835 | q->first_to_check=0; | ||
1836 | q->last_move_ftc=0; | ||
1837 | q->handler=output_handler; | ||
1838 | |||
1839 | tasklet_init(&q->tasklet, qdio_outbound_processing, | ||
1840 | (unsigned long) q); | ||
1841 | setup_timer(&q->timer, qdio_outbound_processing, | ||
1842 | (unsigned long) q); | ||
1843 | |||
1844 | atomic_set(&q->busy_siga_counter,0); | ||
1845 | q->timing.busy_start=0; | ||
1846 | |||
1847 | /* fill in slib */ | ||
1848 | if (i>0) irq_ptr->output_qs[i-1]->slib->nsliba= | ||
1849 | (unsigned long)(q->slib); | ||
1850 | q->slib->sla=(unsigned long)(q->sl); | ||
1851 | q->slib->slsba=(unsigned long)(&q->slsb.acc.val[0]); | ||
1852 | |||
1853 | /* fill in sl */ | ||
1854 | for (j=0;j<QDIO_MAX_BUFFERS_PER_Q;j++) | ||
1855 | q->sl->element[j].sbal=(unsigned long)(q->sbal[j]); | ||
1856 | |||
1857 | QDIO_DBF_TEXT2(0,setup,"sl-sb-b0"); | ||
1858 | ptr=(void*)q->sl; | ||
1859 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); | ||
1860 | ptr=(void*)&q->slsb; | ||
1861 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); | ||
1862 | ptr=(void*)q->sbal[0]; | ||
1863 | QDIO_DBF_HEX2(0,setup,&ptr,sizeof(void*)); | ||
1864 | |||
1865 | /* fill in slsb */ | ||
1866 | if (!irq_ptr->is_qebsm) { | ||
1867 | unsigned int count = 1; | ||
1868 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) | ||
1869 | set_slsb(q, &j, SLSB_P_OUTPUT_NOT_INIT, &count); | ||
1870 | } | ||
1871 | } | ||
1872 | } | ||
1873 | |||
1874 | static void | ||
1875 | qdio_fill_thresholds(struct qdio_irq *irq_ptr, | ||
1876 | unsigned int no_input_qs, | ||
1877 | unsigned int no_output_qs, | ||
1878 | unsigned int min_input_threshold, | ||
1879 | unsigned int max_input_threshold, | ||
1880 | unsigned int min_output_threshold, | ||
1881 | unsigned int max_output_threshold) | ||
1882 | { | ||
1883 | int i; | ||
1884 | struct qdio_q *q; | ||
1885 | |||
1886 | for (i=0;i<no_input_qs;i++) { | ||
1887 | q=irq_ptr->input_qs[i]; | ||
1888 | q->timing.threshold=max_input_threshold; | ||
1889 | /* for (j=0;j<QDIO_STATS_CLASSES;j++) { | ||
1890 | q->threshold_classes[j].threshold= | ||
1891 | min_input_threshold+ | ||
1892 | (max_input_threshold-min_input_threshold)/ | ||
1893 | QDIO_STATS_CLASSES; | ||
1894 | } | ||
1895 | qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/ | ||
1896 | } | ||
1897 | for (i=0;i<no_output_qs;i++) { | ||
1898 | q=irq_ptr->output_qs[i]; | ||
1899 | q->timing.threshold=max_output_threshold; | ||
1900 | /* for (j=0;j<QDIO_STATS_CLASSES;j++) { | ||
1901 | q->threshold_classes[j].threshold= | ||
1902 | min_output_threshold+ | ||
1903 | (max_output_threshold-min_output_threshold)/ | ||
1904 | QDIO_STATS_CLASSES; | ||
1905 | } | ||
1906 | qdio_use_thresholds(q,QDIO_STATS_CLASSES/2);*/ | ||
1907 | } | ||
1908 | } | ||
1909 | |||
1910 | static void tiqdio_thinint_handler(void *ind, void *drv_data) | ||
1911 | { | ||
1912 | QDIO_DBF_TEXT4(0,trace,"thin_int"); | ||
1913 | |||
1914 | qdio_perf_stat_inc(&perf_stats.thinints); | ||
1915 | |||
1916 | /* SVS only when needed: | ||
1917 | * issue SVS to benefit from iqdio interrupt avoidance | ||
1918 | * (SVS clears AISOI)*/ | ||
1919 | if (!omit_svs) | ||
1920 | tiqdio_clear_global_summary(); | ||
1921 | |||
1922 | tiqdio_inbound_checks(); | ||
1923 | } | ||
1924 | |||
1925 | static void | ||
1926 | qdio_set_state(struct qdio_irq *irq_ptr, enum qdio_irq_states state) | ||
1927 | { | ||
1928 | int i; | ||
1929 | #ifdef CONFIG_QDIO_DEBUG | ||
1930 | char dbf_text[15]; | ||
1931 | |||
1932 | QDIO_DBF_TEXT5(0,trace,"newstate"); | ||
1933 | sprintf(dbf_text,"%4x%4x",irq_ptr->schid.sch_no,state); | ||
1934 | QDIO_DBF_TEXT5(0,trace,dbf_text); | ||
1935 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1936 | |||
1937 | irq_ptr->state=state; | ||
1938 | for (i=0;i<irq_ptr->no_input_qs;i++) | ||
1939 | irq_ptr->input_qs[i]->state=state; | ||
1940 | for (i=0;i<irq_ptr->no_output_qs;i++) | ||
1941 | irq_ptr->output_qs[i]->state=state; | ||
1942 | mb(); | ||
1943 | } | ||
1944 | |||
1945 | static void | ||
1946 | qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb) | ||
1947 | { | ||
1948 | char dbf_text[15]; | ||
1949 | |||
1950 | if (irb->esw.esw0.erw.cons) { | ||
1951 | sprintf(dbf_text,"sens%4x",schid.sch_no); | ||
1952 | QDIO_DBF_TEXT2(1,trace,dbf_text); | ||
1953 | QDIO_DBF_HEX0(0,sense,irb,QDIO_DBF_SENSE_LEN); | ||
1954 | |||
1955 | QDIO_PRINT_WARN("sense data available on qdio channel.\n"); | ||
1956 | QDIO_HEXDUMP16(WARN,"irb: ",irb); | ||
1957 | QDIO_HEXDUMP16(WARN,"sense data: ",irb->ecw); | ||
1958 | } | ||
1959 | |||
1960 | } | ||
1961 | |||
1962 | static void | ||
1963 | qdio_handle_pci(struct qdio_irq *irq_ptr) | ||
1964 | { | ||
1965 | int i; | ||
1966 | struct qdio_q *q; | ||
1967 | |||
1968 | qdio_perf_stat_inc(&perf_stats.pcis); | ||
1969 | for (i=0;i<irq_ptr->no_input_qs;i++) { | ||
1970 | q=irq_ptr->input_qs[i]; | ||
1971 | if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) | ||
1972 | qdio_mark_q(q); | ||
1973 | else { | ||
1974 | qdio_perf_stat_dec(&perf_stats.tl_runs); | ||
1975 | __qdio_inbound_processing(q); | ||
1976 | } | ||
1977 | } | ||
1978 | if (!irq_ptr->hydra_gives_outbound_pcis) | ||
1979 | return; | ||
1980 | for (i=0;i<irq_ptr->no_output_qs;i++) { | ||
1981 | q=irq_ptr->output_qs[i]; | ||
1982 | if (qdio_is_outbound_q_done(q)) | ||
1983 | continue; | ||
1984 | qdio_perf_stat_dec(&perf_stats.tl_runs); | ||
1985 | if (!irq_ptr->sync_done_on_outb_pcis) | ||
1986 | SYNC_MEMORY; | ||
1987 | __qdio_outbound_processing(q); | ||
1988 | } | ||
1989 | } | ||
1990 | |||
1991 | static void qdio_establish_handle_irq(struct ccw_device*, int, int); | ||
1992 | |||
1993 | static void | ||
1994 | qdio_handle_activate_check(struct ccw_device *cdev, unsigned long intparm, | ||
1995 | int cstat, int dstat) | ||
1996 | { | ||
1997 | struct qdio_irq *irq_ptr; | ||
1998 | struct qdio_q *q; | ||
1999 | char dbf_text[15]; | ||
2000 | |||
2001 | irq_ptr = cdev->private->qdio_data; | ||
2002 | |||
2003 | QDIO_DBF_TEXT2(1, trace, "ick2"); | ||
2004 | sprintf(dbf_text,"%s", cdev->dev.bus_id); | ||
2005 | QDIO_DBF_TEXT2(1,trace,dbf_text); | ||
2006 | QDIO_DBF_HEX2(0,trace,&intparm,sizeof(int)); | ||
2007 | QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int)); | ||
2008 | QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int)); | ||
2009 | QDIO_PRINT_ERR("received check condition on activate " \ | ||
2010 | "queues on device %s (cs=x%x, ds=x%x).\n", | ||
2011 | cdev->dev.bus_id, cstat, dstat); | ||
2012 | if (irq_ptr->no_input_qs) { | ||
2013 | q=irq_ptr->input_qs[0]; | ||
2014 | } else if (irq_ptr->no_output_qs) { | ||
2015 | q=irq_ptr->output_qs[0]; | ||
2016 | } else { | ||
2017 | QDIO_PRINT_ERR("oops... no queue registered for device %s!?\n", | ||
2018 | cdev->dev.bus_id); | ||
2019 | goto omit_handler_call; | ||
2020 | } | ||
2021 | q->handler(q->cdev,QDIO_STATUS_ACTIVATE_CHECK_CONDITION| | ||
2022 | QDIO_STATUS_LOOK_FOR_ERROR, | ||
2023 | 0,0,0,-1,-1,q->int_parm); | ||
2024 | omit_handler_call: | ||
2025 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_STOPPED); | ||
2026 | |||
2027 | } | ||
2028 | |||
2029 | static void | ||
2030 | qdio_call_shutdown(struct work_struct *work) | ||
2031 | { | ||
2032 | struct ccw_device_private *priv; | ||
2033 | struct ccw_device *cdev; | ||
2034 | |||
2035 | priv = container_of(work, struct ccw_device_private, kick_work); | ||
2036 | cdev = priv->cdev; | ||
2037 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
2038 | put_device(&cdev->dev); | ||
2039 | } | ||
2040 | |||
2041 | static void | ||
2042 | qdio_timeout_handler(struct ccw_device *cdev) | ||
2043 | { | ||
2044 | struct qdio_irq *irq_ptr; | ||
2045 | char dbf_text[15]; | ||
2046 | |||
2047 | QDIO_DBF_TEXT2(0, trace, "qtoh"); | ||
2048 | sprintf(dbf_text, "%s", cdev->dev.bus_id); | ||
2049 | QDIO_DBF_TEXT2(0, trace, dbf_text); | ||
2050 | |||
2051 | irq_ptr = cdev->private->qdio_data; | ||
2052 | sprintf(dbf_text, "state:%d", irq_ptr->state); | ||
2053 | QDIO_DBF_TEXT2(0, trace, dbf_text); | ||
2054 | |||
2055 | switch (irq_ptr->state) { | ||
2056 | case QDIO_IRQ_STATE_INACTIVE: | ||
2057 | QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: timed out\n", | ||
2058 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); | ||
2059 | QDIO_DBF_TEXT2(1,setup,"eq:timeo"); | ||
2060 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
2061 | break; | ||
2062 | case QDIO_IRQ_STATE_CLEANUP: | ||
2063 | QDIO_PRINT_INFO("Did not get interrupt on cleanup, " | ||
2064 | "irq=0.%x.%x.\n", | ||
2065 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); | ||
2066 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
2067 | break; | ||
2068 | case QDIO_IRQ_STATE_ESTABLISHED: | ||
2069 | case QDIO_IRQ_STATE_ACTIVE: | ||
2070 | /* I/O has been terminated by common I/O layer. */ | ||
2071 | QDIO_PRINT_INFO("Queues on irq 0.%x.%04x killed by cio.\n", | ||
2072 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); | ||
2073 | QDIO_DBF_TEXT2(1, trace, "cio:term"); | ||
2074 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED); | ||
2075 | if (get_device(&cdev->dev)) { | ||
2076 | /* Can't call shutdown from interrupt context. */ | ||
2077 | PREPARE_WORK(&cdev->private->kick_work, | ||
2078 | qdio_call_shutdown); | ||
2079 | queue_work(ccw_device_work, &cdev->private->kick_work); | ||
2080 | } | ||
2081 | break; | ||
2082 | default: | ||
2083 | BUG(); | ||
2084 | } | ||
2085 | wake_up(&cdev->private->wait_q); | ||
2086 | } | ||
2087 | |||
2088 | static void | ||
2089 | qdio_handler(struct ccw_device *cdev, unsigned long intparm, struct irb *irb) | ||
2090 | { | ||
2091 | struct qdio_irq *irq_ptr; | ||
2092 | int cstat,dstat; | ||
2093 | char dbf_text[15]; | ||
2094 | |||
2095 | #ifdef CONFIG_QDIO_DEBUG | ||
2096 | QDIO_DBF_TEXT4(0, trace, "qint"); | ||
2097 | sprintf(dbf_text, "%s", cdev->dev.bus_id); | ||
2098 | QDIO_DBF_TEXT4(0, trace, dbf_text); | ||
2099 | #endif /* CONFIG_QDIO_DEBUG */ | ||
2100 | |||
2101 | if (!intparm) { | ||
2102 | QDIO_PRINT_ERR("got unsolicited interrupt in qdio " \ | ||
2103 | "handler, device %s\n", cdev->dev.bus_id); | ||
2104 | return; | ||
2105 | } | ||
2106 | |||
2107 | irq_ptr = cdev->private->qdio_data; | ||
2108 | if (!irq_ptr) { | ||
2109 | QDIO_DBF_TEXT2(1, trace, "uint"); | ||
2110 | sprintf(dbf_text,"%s", cdev->dev.bus_id); | ||
2111 | QDIO_DBF_TEXT2(1,trace,dbf_text); | ||
2112 | QDIO_PRINT_ERR("received interrupt on unused device %s!\n", | ||
2113 | cdev->dev.bus_id); | ||
2114 | return; | ||
2115 | } | ||
2116 | |||
2117 | if (IS_ERR(irb)) { | ||
2118 | /* Currently running i/o is in error. */ | ||
2119 | switch (PTR_ERR(irb)) { | ||
2120 | case -EIO: | ||
2121 | QDIO_PRINT_ERR("i/o error on device %s\n", | ||
2122 | cdev->dev.bus_id); | ||
2123 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
2124 | wake_up(&cdev->private->wait_q); | ||
2125 | return; | ||
2126 | case -ETIMEDOUT: | ||
2127 | qdio_timeout_handler(cdev); | ||
2128 | return; | ||
2129 | default: | ||
2130 | QDIO_PRINT_ERR("unknown error state %ld on device %s\n", | ||
2131 | PTR_ERR(irb), cdev->dev.bus_id); | ||
2132 | return; | ||
2133 | } | ||
2134 | } | ||
2135 | |||
2136 | qdio_irq_check_sense(irq_ptr->schid, irb); | ||
2137 | |||
2138 | #ifdef CONFIG_QDIO_DEBUG | ||
2139 | sprintf(dbf_text, "state:%d", irq_ptr->state); | ||
2140 | QDIO_DBF_TEXT4(0, trace, dbf_text); | ||
2141 | #endif /* CONFIG_QDIO_DEBUG */ | ||
2142 | |||
2143 | cstat = irb->scsw.cmd.cstat; | ||
2144 | dstat = irb->scsw.cmd.dstat; | ||
2145 | |||
2146 | switch (irq_ptr->state) { | ||
2147 | case QDIO_IRQ_STATE_INACTIVE: | ||
2148 | qdio_establish_handle_irq(cdev, cstat, dstat); | ||
2149 | break; | ||
2150 | |||
2151 | case QDIO_IRQ_STATE_CLEANUP: | ||
2152 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
2153 | break; | ||
2154 | |||
2155 | case QDIO_IRQ_STATE_ESTABLISHED: | ||
2156 | case QDIO_IRQ_STATE_ACTIVE: | ||
2157 | if (cstat & SCHN_STAT_PCI) { | ||
2158 | qdio_handle_pci(irq_ptr); | ||
2159 | break; | ||
2160 | } | ||
2161 | |||
2162 | if ((cstat&~SCHN_STAT_PCI)||dstat) { | ||
2163 | qdio_handle_activate_check(cdev, intparm, cstat, dstat); | ||
2164 | break; | ||
2165 | } | ||
2166 | default: | ||
2167 | QDIO_PRINT_ERR("got interrupt for queues in state %d on " \ | ||
2168 | "device %s?!\n", | ||
2169 | irq_ptr->state, cdev->dev.bus_id); | ||
2170 | } | ||
2171 | wake_up(&cdev->private->wait_q); | ||
2172 | |||
2173 | } | ||
2174 | |||
2175 | int | ||
2176 | qdio_synchronize(struct ccw_device *cdev, unsigned int flags, | ||
2177 | unsigned int queue_number) | ||
2178 | { | ||
2179 | int cc = 0; | ||
2180 | struct qdio_q *q; | ||
2181 | struct qdio_irq *irq_ptr; | ||
2182 | void *ptr; | ||
2183 | #ifdef CONFIG_QDIO_DEBUG | ||
2184 | char dbf_text[15]="SyncXXXX"; | ||
2185 | #endif | ||
2186 | |||
2187 | irq_ptr = cdev->private->qdio_data; | ||
2188 | if (!irq_ptr) | ||
2189 | return -ENODEV; | ||
2190 | |||
2191 | #ifdef CONFIG_QDIO_DEBUG | ||
2192 | *((int*)(&dbf_text[4])) = irq_ptr->schid.sch_no; | ||
2193 | QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN); | ||
2194 | *((int*)(&dbf_text[0]))=flags; | ||
2195 | *((int*)(&dbf_text[4]))=queue_number; | ||
2196 | QDIO_DBF_HEX4(0,trace,dbf_text,QDIO_DBF_TRACE_LEN); | ||
2197 | #endif /* CONFIG_QDIO_DEBUG */ | ||
2198 | |||
2199 | if (flags&QDIO_FLAG_SYNC_INPUT) { | ||
2200 | q=irq_ptr->input_qs[queue_number]; | ||
2201 | if (!q) | ||
2202 | return -EINVAL; | ||
2203 | if (!(irq_ptr->is_qebsm)) | ||
2204 | cc = do_siga_sync(q->schid, 0, q->mask); | ||
2205 | } else if (flags&QDIO_FLAG_SYNC_OUTPUT) { | ||
2206 | q=irq_ptr->output_qs[queue_number]; | ||
2207 | if (!q) | ||
2208 | return -EINVAL; | ||
2209 | if (!(irq_ptr->is_qebsm)) | ||
2210 | cc = do_siga_sync(q->schid, q->mask, 0); | ||
2211 | } else | ||
2212 | return -EINVAL; | ||
2213 | |||
2214 | ptr=&cc; | ||
2215 | if (cc) | ||
2216 | QDIO_DBF_HEX3(0,trace,&ptr,sizeof(int)); | ||
2217 | |||
2218 | return cc; | ||
2219 | } | ||
2220 | |||
2221 | static int | ||
2222 | qdio_get_ssqd_information(struct subchannel_id *schid, | ||
2223 | struct qdio_chsc_ssqd **ssqd_area) | ||
2224 | { | ||
2225 | int result; | ||
2226 | |||
2227 | QDIO_DBF_TEXT0(0, setup, "getssqd"); | ||
2228 | *ssqd_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC); | ||
2229 | if (!ssqd_area) { | ||
2230 | QDIO_PRINT_WARN("Could not get memory for chsc on sch x%x.\n", | ||
2231 | schid->sch_no); | ||
2232 | return -ENOMEM; | ||
2233 | } | ||
2234 | |||
2235 | (*ssqd_area)->request = (struct chsc_header) { | ||
2236 | .length = 0x0010, | ||
2237 | .code = 0x0024, | ||
2238 | }; | ||
2239 | (*ssqd_area)->first_sch = schid->sch_no; | ||
2240 | (*ssqd_area)->last_sch = schid->sch_no; | ||
2241 | (*ssqd_area)->ssid = schid->ssid; | ||
2242 | result = chsc(*ssqd_area); | ||
2243 | |||
2244 | if (result) { | ||
2245 | QDIO_PRINT_WARN("CHSC returned cc %i on sch 0.%x.%x.\n", | ||
2246 | result, schid->ssid, schid->sch_no); | ||
2247 | goto out; | ||
2248 | } | ||
2249 | |||
2250 | if ((*ssqd_area)->response.code != QDIO_CHSC_RESPONSE_CODE_OK) { | ||
2251 | QDIO_PRINT_WARN("CHSC response is 0x%x on sch 0.%x.%x.\n", | ||
2252 | (*ssqd_area)->response.code, | ||
2253 | schid->ssid, schid->sch_no); | ||
2254 | goto out; | ||
2255 | } | ||
2256 | if (!((*ssqd_area)->flags & CHSC_FLAG_QDIO_CAPABILITY) || | ||
2257 | !((*ssqd_area)->flags & CHSC_FLAG_VALIDITY) || | ||
2258 | ((*ssqd_area)->sch != schid->sch_no)) { | ||
2259 | QDIO_PRINT_WARN("huh? problems checking out sch 0.%x.%x... " \ | ||
2260 | "using all SIGAs.\n", | ||
2261 | schid->ssid, schid->sch_no); | ||
2262 | goto out; | ||
2263 | } | ||
2264 | return 0; | ||
2265 | out: | ||
2266 | return -EINVAL; | ||
2267 | } | ||
2268 | |||
2269 | int | ||
2270 | qdio_get_ssqd_pct(struct ccw_device *cdev) | ||
2271 | { | ||
2272 | struct qdio_chsc_ssqd *ssqd_area; | ||
2273 | struct subchannel_id schid; | ||
2274 | char dbf_text[15]; | ||
2275 | int rc; | ||
2276 | int pct = 0; | ||
2277 | |||
2278 | QDIO_DBF_TEXT0(0, setup, "getpct"); | ||
2279 | schid = ccw_device_get_subchannel_id(cdev); | ||
2280 | rc = qdio_get_ssqd_information(&schid, &ssqd_area); | ||
2281 | if (!rc) | ||
2282 | pct = (int)ssqd_area->pct; | ||
2283 | if (rc != -ENOMEM) | ||
2284 | mempool_free(ssqd_area, qdio_mempool_scssc); | ||
2285 | sprintf(dbf_text, "pct: %d", pct); | ||
2286 | QDIO_DBF_TEXT2(0, setup, dbf_text); | ||
2287 | return pct; | ||
2288 | } | ||
2289 | EXPORT_SYMBOL(qdio_get_ssqd_pct); | ||
2290 | |||
2291 | static void | ||
2292 | qdio_check_subchannel_qebsm(struct qdio_irq *irq_ptr, unsigned long token) | ||
2293 | { | ||
2294 | struct qdio_q *q; | ||
2295 | int i; | ||
2296 | unsigned int count, start_buf; | ||
2297 | char dbf_text[15]; | ||
2298 | |||
2299 | /*check if QEBSM is disabled */ | ||
2300 | if (!(irq_ptr->is_qebsm) || !(irq_ptr->qdioac & 0x01)) { | ||
2301 | irq_ptr->is_qebsm = 0; | ||
2302 | irq_ptr->sch_token = 0; | ||
2303 | irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM; | ||
2304 | QDIO_DBF_TEXT0(0,setup,"noV=V"); | ||
2305 | return; | ||
2306 | } | ||
2307 | irq_ptr->sch_token = token; | ||
2308 | /*input queue*/ | ||
2309 | for (i = 0; i < irq_ptr->no_input_qs;i++) { | ||
2310 | q = irq_ptr->input_qs[i]; | ||
2311 | count = QDIO_MAX_BUFFERS_PER_Q; | ||
2312 | start_buf = 0; | ||
2313 | set_slsb(q, &start_buf, SLSB_P_INPUT_NOT_INIT, &count); | ||
2314 | } | ||
2315 | sprintf(dbf_text,"V=V:%2x",irq_ptr->is_qebsm); | ||
2316 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2317 | sprintf(dbf_text,"%8lx",irq_ptr->sch_token); | ||
2318 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2319 | /*output queue*/ | ||
2320 | for (i = 0; i < irq_ptr->no_output_qs; i++) { | ||
2321 | q = irq_ptr->output_qs[i]; | ||
2322 | count = QDIO_MAX_BUFFERS_PER_Q; | ||
2323 | start_buf = 0; | ||
2324 | set_slsb(q, &start_buf, SLSB_P_OUTPUT_NOT_INIT, &count); | ||
2325 | } | ||
2326 | } | ||
2327 | |||
2328 | static void | ||
2329 | qdio_get_ssqd_siga(struct qdio_irq *irq_ptr) | ||
2330 | { | ||
2331 | int rc; | ||
2332 | struct qdio_chsc_ssqd *ssqd_area; | ||
2333 | |||
2334 | QDIO_DBF_TEXT0(0,setup,"getssqd"); | ||
2335 | irq_ptr->qdioac = 0; | ||
2336 | rc = qdio_get_ssqd_information(&irq_ptr->schid, &ssqd_area); | ||
2337 | if (rc) { | ||
2338 | QDIO_PRINT_WARN("using all SIGAs for sch x%x.n", | ||
2339 | irq_ptr->schid.sch_no); | ||
2340 | irq_ptr->qdioac = CHSC_FLAG_SIGA_INPUT_NECESSARY | | ||
2341 | CHSC_FLAG_SIGA_OUTPUT_NECESSARY | | ||
2342 | CHSC_FLAG_SIGA_SYNC_NECESSARY; /* all flags set */ | ||
2343 | irq_ptr->is_qebsm = 0; | ||
2344 | } else | ||
2345 | irq_ptr->qdioac = ssqd_area->qdioac1; | ||
2346 | |||
2347 | qdio_check_subchannel_qebsm(irq_ptr, ssqd_area->sch_token); | ||
2348 | if (rc != -ENOMEM) | ||
2349 | mempool_free(ssqd_area, qdio_mempool_scssc); | ||
2350 | } | ||
2351 | |||
2352 | static unsigned int | ||
2353 | tiqdio_check_chsc_availability(void) | ||
2354 | { | ||
2355 | char dbf_text[15]; | ||
2356 | |||
2357 | /* Check for bit 41. */ | ||
2358 | if (!css_general_characteristics.aif) { | ||
2359 | QDIO_PRINT_WARN("Adapter interruption facility not " \ | ||
2360 | "installed.\n"); | ||
2361 | return -ENOENT; | ||
2362 | } | ||
2363 | |||
2364 | /* Check for bits 107 and 108. */ | ||
2365 | if (!css_chsc_characteristics.scssc || | ||
2366 | !css_chsc_characteristics.scsscf) { | ||
2367 | QDIO_PRINT_WARN("Set Chan Subsys. Char. & Fast-CHSCs " \ | ||
2368 | "not available.\n"); | ||
2369 | return -ENOENT; | ||
2370 | } | ||
2371 | |||
2372 | /* Check for OSA/FCP thin interrupts (bit 67). */ | ||
2373 | hydra_thinints = css_general_characteristics.aif_osa; | ||
2374 | sprintf(dbf_text,"hydrati%1x", hydra_thinints); | ||
2375 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2376 | |||
2377 | #ifdef CONFIG_64BIT | ||
2378 | /* Check for QEBSM support in general (bit 58). */ | ||
2379 | is_passthrough = css_general_characteristics.qebsm; | ||
2380 | #endif | ||
2381 | sprintf(dbf_text,"cssQBS:%1x", is_passthrough); | ||
2382 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2383 | |||
2384 | /* Check for aif time delay disablement fac (bit 56). If installed, | ||
2385 | * omit svs even under lpar (good point by rick again) */ | ||
2386 | omit_svs = css_general_characteristics.aif_tdd; | ||
2387 | sprintf(dbf_text,"omitsvs%1x", omit_svs); | ||
2388 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2389 | return 0; | ||
2390 | } | ||
2391 | |||
2392 | |||
2393 | static unsigned int | ||
2394 | tiqdio_set_subchannel_ind(struct qdio_irq *irq_ptr, int reset_to_zero) | ||
2395 | { | ||
2396 | unsigned long real_addr_local_summary_bit; | ||
2397 | unsigned long real_addr_dev_st_chg_ind; | ||
2398 | void *ptr; | ||
2399 | char dbf_text[15]; | ||
2400 | |||
2401 | unsigned int resp_code; | ||
2402 | int result; | ||
2403 | |||
2404 | struct { | ||
2405 | struct chsc_header request; | ||
2406 | u16 operation_code; | ||
2407 | u16 reserved1; | ||
2408 | u32 reserved2; | ||
2409 | u32 reserved3; | ||
2410 | u64 summary_indicator_addr; | ||
2411 | u64 subchannel_indicator_addr; | ||
2412 | u32 ks:4; | ||
2413 | u32 kc:4; | ||
2414 | u32 reserved4:21; | ||
2415 | u32 isc:3; | ||
2416 | u32 word_with_d_bit; | ||
2417 | /* set to 0x10000000 to enable | ||
2418 | * time delay disablement facility */ | ||
2419 | u32 reserved5; | ||
2420 | struct subchannel_id schid; | ||
2421 | u32 reserved6[1004]; | ||
2422 | struct chsc_header response; | ||
2423 | u32 reserved7; | ||
2424 | } *scssc_area; | ||
2425 | |||
2426 | if (!irq_ptr->is_thinint_irq) | ||
2427 | return -ENODEV; | ||
2428 | |||
2429 | if (reset_to_zero) { | ||
2430 | real_addr_local_summary_bit=0; | ||
2431 | real_addr_dev_st_chg_ind=0; | ||
2432 | } else { | ||
2433 | real_addr_local_summary_bit= | ||
2434 | virt_to_phys((volatile void *)tiqdio_ind); | ||
2435 | real_addr_dev_st_chg_ind= | ||
2436 | virt_to_phys((volatile void *)irq_ptr->dev_st_chg_ind); | ||
2437 | } | ||
2438 | |||
2439 | scssc_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC); | ||
2440 | if (!scssc_area) { | ||
2441 | QDIO_PRINT_WARN("No memory for setting indicators on " \ | ||
2442 | "subchannel 0.%x.%x.\n", | ||
2443 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); | ||
2444 | return -ENOMEM; | ||
2445 | } | ||
2446 | scssc_area->request = (struct chsc_header) { | ||
2447 | .length = 0x0fe0, | ||
2448 | .code = 0x0021, | ||
2449 | }; | ||
2450 | scssc_area->operation_code = 0; | ||
2451 | |||
2452 | scssc_area->summary_indicator_addr = real_addr_local_summary_bit; | ||
2453 | scssc_area->subchannel_indicator_addr = real_addr_dev_st_chg_ind; | ||
2454 | scssc_area->ks = QDIO_STORAGE_KEY; | ||
2455 | scssc_area->kc = QDIO_STORAGE_KEY; | ||
2456 | scssc_area->isc = TIQDIO_THININT_ISC; | ||
2457 | scssc_area->schid = irq_ptr->schid; | ||
2458 | /* enables the time delay disablement facility. Don't care | ||
2459 | * whether it is really there (i.e. we haven't checked for | ||
2460 | * it) */ | ||
2461 | if (css_general_characteristics.aif_tdd) | ||
2462 | scssc_area->word_with_d_bit = 0x10000000; | ||
2463 | else | ||
2464 | QDIO_PRINT_WARN("Time delay disablement facility " \ | ||
2465 | "not available\n"); | ||
2466 | |||
2467 | result = chsc(scssc_area); | ||
2468 | if (result) { | ||
2469 | QDIO_PRINT_WARN("could not set indicators on irq 0.%x.%x, " \ | ||
2470 | "cc=%i.\n", | ||
2471 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no,result); | ||
2472 | result = -EIO; | ||
2473 | goto out; | ||
2474 | } | ||
2475 | |||
2476 | resp_code = scssc_area->response.code; | ||
2477 | if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) { | ||
2478 | QDIO_PRINT_WARN("response upon setting indicators " \ | ||
2479 | "is 0x%x.\n",resp_code); | ||
2480 | sprintf(dbf_text,"sidR%4x",resp_code); | ||
2481 | QDIO_DBF_TEXT1(0,trace,dbf_text); | ||
2482 | QDIO_DBF_TEXT1(0,setup,dbf_text); | ||
2483 | ptr=&scssc_area->response; | ||
2484 | QDIO_DBF_HEX2(1,setup,&ptr,QDIO_DBF_SETUP_LEN); | ||
2485 | result = -EIO; | ||
2486 | goto out; | ||
2487 | } | ||
2488 | |||
2489 | QDIO_DBF_TEXT2(0,setup,"setscind"); | ||
2490 | QDIO_DBF_HEX2(0,setup,&real_addr_local_summary_bit, | ||
2491 | sizeof(unsigned long)); | ||
2492 | QDIO_DBF_HEX2(0,setup,&real_addr_dev_st_chg_ind,sizeof(unsigned long)); | ||
2493 | result = 0; | ||
2494 | out: | ||
2495 | mempool_free(scssc_area, qdio_mempool_scssc); | ||
2496 | return result; | ||
2497 | |||
2498 | } | ||
2499 | |||
2500 | static unsigned int | ||
2501 | tiqdio_set_delay_target(struct qdio_irq *irq_ptr, unsigned long delay_target) | ||
2502 | { | ||
2503 | unsigned int resp_code; | ||
2504 | int result; | ||
2505 | void *ptr; | ||
2506 | char dbf_text[15]; | ||
2507 | |||
2508 | struct { | ||
2509 | struct chsc_header request; | ||
2510 | u16 operation_code; | ||
2511 | u16 reserved1; | ||
2512 | u32 reserved2; | ||
2513 | u32 reserved3; | ||
2514 | u32 reserved4[2]; | ||
2515 | u32 delay_target; | ||
2516 | u32 reserved5[1009]; | ||
2517 | struct chsc_header response; | ||
2518 | u32 reserved6; | ||
2519 | } *scsscf_area; | ||
2520 | |||
2521 | if (!irq_ptr->is_thinint_irq) | ||
2522 | return -ENODEV; | ||
2523 | |||
2524 | scsscf_area = mempool_alloc(qdio_mempool_scssc, GFP_ATOMIC); | ||
2525 | if (!scsscf_area) { | ||
2526 | QDIO_PRINT_WARN("No memory for setting delay target on " \ | ||
2527 | "subchannel 0.%x.%x.\n", | ||
2528 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); | ||
2529 | return -ENOMEM; | ||
2530 | } | ||
2531 | scsscf_area->request = (struct chsc_header) { | ||
2532 | .length = 0x0fe0, | ||
2533 | .code = 0x1027, | ||
2534 | }; | ||
2535 | |||
2536 | scsscf_area->delay_target = delay_target<<16; | ||
2537 | |||
2538 | result=chsc(scsscf_area); | ||
2539 | if (result) { | ||
2540 | QDIO_PRINT_WARN("could not set delay target on irq 0.%x.%x, " \ | ||
2541 | "cc=%i. Continuing.\n", | ||
2542 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, | ||
2543 | result); | ||
2544 | result = -EIO; | ||
2545 | goto out; | ||
2546 | } | ||
2547 | |||
2548 | resp_code = scsscf_area->response.code; | ||
2549 | if (resp_code!=QDIO_CHSC_RESPONSE_CODE_OK) { | ||
2550 | QDIO_PRINT_WARN("response upon setting delay target " \ | ||
2551 | "is 0x%x. Continuing.\n",resp_code); | ||
2552 | sprintf(dbf_text,"sdtR%4x",resp_code); | ||
2553 | QDIO_DBF_TEXT1(0,trace,dbf_text); | ||
2554 | QDIO_DBF_TEXT1(0,setup,dbf_text); | ||
2555 | ptr=&scsscf_area->response; | ||
2556 | QDIO_DBF_HEX2(1,trace,&ptr,QDIO_DBF_TRACE_LEN); | ||
2557 | } | ||
2558 | QDIO_DBF_TEXT2(0,trace,"delytrgt"); | ||
2559 | QDIO_DBF_HEX2(0,trace,&delay_target,sizeof(unsigned long)); | ||
2560 | result = 0; /* not critical */ | ||
2561 | out: | ||
2562 | mempool_free(scsscf_area, qdio_mempool_scssc); | ||
2563 | return result; | ||
2564 | } | ||
2565 | |||
2566 | int | ||
2567 | qdio_cleanup(struct ccw_device *cdev, int how) | ||
2568 | { | ||
2569 | struct qdio_irq *irq_ptr; | ||
2570 | char dbf_text[15]; | ||
2571 | int rc; | ||
2572 | |||
2573 | irq_ptr = cdev->private->qdio_data; | ||
2574 | if (!irq_ptr) | ||
2575 | return -ENODEV; | ||
2576 | |||
2577 | sprintf(dbf_text,"qcln%4x",irq_ptr->schid.sch_no); | ||
2578 | QDIO_DBF_TEXT1(0,trace,dbf_text); | ||
2579 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2580 | |||
2581 | rc = qdio_shutdown(cdev, how); | ||
2582 | if ((rc == 0) || (rc == -EINPROGRESS)) | ||
2583 | rc = qdio_free(cdev); | ||
2584 | return rc; | ||
2585 | } | ||
2586 | |||
2587 | int | ||
2588 | qdio_shutdown(struct ccw_device *cdev, int how) | ||
2589 | { | ||
2590 | struct qdio_irq *irq_ptr; | ||
2591 | int i; | ||
2592 | int result = 0; | ||
2593 | int rc; | ||
2594 | unsigned long flags; | ||
2595 | int timeout; | ||
2596 | char dbf_text[15]; | ||
2597 | |||
2598 | irq_ptr = cdev->private->qdio_data; | ||
2599 | if (!irq_ptr) | ||
2600 | return -ENODEV; | ||
2601 | |||
2602 | down(&irq_ptr->setting_up_sema); | ||
2603 | |||
2604 | sprintf(dbf_text,"qsqs%4x",irq_ptr->schid.sch_no); | ||
2605 | QDIO_DBF_TEXT1(0,trace,dbf_text); | ||
2606 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2607 | |||
2608 | /* mark all qs as uninteresting */ | ||
2609 | for (i=0;i<irq_ptr->no_input_qs;i++) | ||
2610 | atomic_set(&irq_ptr->input_qs[i]->is_in_shutdown,1); | ||
2611 | |||
2612 | for (i=0;i<irq_ptr->no_output_qs;i++) | ||
2613 | atomic_set(&irq_ptr->output_qs[i]->is_in_shutdown,1); | ||
2614 | |||
2615 | tasklet_kill(&tiqdio_tasklet); | ||
2616 | |||
2617 | for (i=0;i<irq_ptr->no_input_qs;i++) { | ||
2618 | qdio_unmark_q(irq_ptr->input_qs[i]); | ||
2619 | tasklet_kill(&irq_ptr->input_qs[i]->tasklet); | ||
2620 | wait_event_interruptible_timeout(cdev->private->wait_q, | ||
2621 | !atomic_read(&irq_ptr-> | ||
2622 | input_qs[i]-> | ||
2623 | use_count), | ||
2624 | QDIO_NO_USE_COUNT_TIMEOUT); | ||
2625 | if (atomic_read(&irq_ptr->input_qs[i]->use_count)) | ||
2626 | result=-EINPROGRESS; | ||
2627 | } | ||
2628 | |||
2629 | for (i=0;i<irq_ptr->no_output_qs;i++) { | ||
2630 | tasklet_kill(&irq_ptr->output_qs[i]->tasklet); | ||
2631 | del_timer(&irq_ptr->output_qs[i]->timer); | ||
2632 | wait_event_interruptible_timeout(cdev->private->wait_q, | ||
2633 | !atomic_read(&irq_ptr-> | ||
2634 | output_qs[i]-> | ||
2635 | use_count), | ||
2636 | QDIO_NO_USE_COUNT_TIMEOUT); | ||
2637 | if (atomic_read(&irq_ptr->output_qs[i]->use_count)) | ||
2638 | result=-EINPROGRESS; | ||
2639 | } | ||
2640 | |||
2641 | /* cleanup subchannel */ | ||
2642 | spin_lock_irqsave(get_ccwdev_lock(cdev),flags); | ||
2643 | if (how&QDIO_FLAG_CLEANUP_USING_CLEAR) { | ||
2644 | rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); | ||
2645 | timeout=QDIO_CLEANUP_CLEAR_TIMEOUT; | ||
2646 | } else if (how&QDIO_FLAG_CLEANUP_USING_HALT) { | ||
2647 | rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); | ||
2648 | timeout=QDIO_CLEANUP_HALT_TIMEOUT; | ||
2649 | } else { /* default behaviour */ | ||
2650 | rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); | ||
2651 | timeout=QDIO_CLEANUP_HALT_TIMEOUT; | ||
2652 | } | ||
2653 | if (rc == -ENODEV) { | ||
2654 | /* No need to wait for device no longer present. */ | ||
2655 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
2656 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | ||
2657 | } else if (((void *)cdev->handler != (void *)qdio_handler) && rc == 0) { | ||
2658 | /* | ||
2659 | * Whoever put another handler there, has to cope with the | ||
2660 | * interrupt theirself. Might happen if qdio_shutdown was | ||
2661 | * called on already shutdown queues, but this shouldn't have | ||
2662 | * bad side effects. | ||
2663 | */ | ||
2664 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
2665 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | ||
2666 | } else if (rc == 0) { | ||
2667 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP); | ||
2668 | spin_unlock_irqrestore(get_ccwdev_lock(cdev),flags); | ||
2669 | |||
2670 | wait_event_interruptible_timeout(cdev->private->wait_q, | ||
2671 | irq_ptr->state == QDIO_IRQ_STATE_INACTIVE || | ||
2672 | irq_ptr->state == QDIO_IRQ_STATE_ERR, | ||
2673 | timeout); | ||
2674 | } else { | ||
2675 | QDIO_PRINT_INFO("ccw_device_{halt,clear} returned %d for " | ||
2676 | "device %s\n", result, cdev->dev.bus_id); | ||
2677 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | ||
2678 | result = rc; | ||
2679 | goto out; | ||
2680 | } | ||
2681 | if (irq_ptr->is_thinint_irq) { | ||
2682 | qdio_put_indicator((__u32*)irq_ptr->dev_st_chg_ind); | ||
2683 | tiqdio_set_subchannel_ind(irq_ptr,1); | ||
2684 | /* reset adapter interrupt indicators */ | ||
2685 | } | ||
2686 | |||
2687 | /* exchange int handlers, if necessary */ | ||
2688 | if ((void*)cdev->handler == (void*)qdio_handler) | ||
2689 | cdev->handler=irq_ptr->original_int_handler; | ||
2690 | |||
2691 | /* Ignore errors. */ | ||
2692 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
2693 | out: | ||
2694 | up(&irq_ptr->setting_up_sema); | ||
2695 | return result; | ||
2696 | } | ||
2697 | |||
2698 | int | ||
2699 | qdio_free(struct ccw_device *cdev) | ||
2700 | { | ||
2701 | struct qdio_irq *irq_ptr; | ||
2702 | char dbf_text[15]; | ||
2703 | |||
2704 | irq_ptr = cdev->private->qdio_data; | ||
2705 | if (!irq_ptr) | ||
2706 | return -ENODEV; | ||
2707 | |||
2708 | down(&irq_ptr->setting_up_sema); | ||
2709 | |||
2710 | sprintf(dbf_text,"qfqs%4x",irq_ptr->schid.sch_no); | ||
2711 | QDIO_DBF_TEXT1(0,trace,dbf_text); | ||
2712 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2713 | |||
2714 | cdev->private->qdio_data = NULL; | ||
2715 | |||
2716 | up(&irq_ptr->setting_up_sema); | ||
2717 | |||
2718 | qdio_release_irq_memory(irq_ptr); | ||
2719 | module_put(THIS_MODULE); | ||
2720 | return 0; | ||
2721 | } | ||
2722 | |||
2723 | static void | ||
2724 | qdio_allocate_do_dbf(struct qdio_initialize *init_data) | ||
2725 | { | ||
2726 | char dbf_text[20]; /* if a printf printed out more than 8 chars */ | ||
2727 | |||
2728 | sprintf(dbf_text,"qfmt:%x",init_data->q_format); | ||
2729 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2730 | QDIO_DBF_HEX0(0,setup,init_data->adapter_name,8); | ||
2731 | sprintf(dbf_text,"qpff%4x",init_data->qib_param_field_format); | ||
2732 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2733 | QDIO_DBF_HEX0(0,setup,&init_data->qib_param_field,sizeof(char*)); | ||
2734 | QDIO_DBF_HEX0(0,setup,&init_data->input_slib_elements,sizeof(long*)); | ||
2735 | QDIO_DBF_HEX0(0,setup,&init_data->output_slib_elements,sizeof(long*)); | ||
2736 | sprintf(dbf_text,"miit%4x",init_data->min_input_threshold); | ||
2737 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2738 | sprintf(dbf_text,"mait%4x",init_data->max_input_threshold); | ||
2739 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2740 | sprintf(dbf_text,"miot%4x",init_data->min_output_threshold); | ||
2741 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2742 | sprintf(dbf_text,"maot%4x",init_data->max_output_threshold); | ||
2743 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2744 | sprintf(dbf_text,"niq:%4x",init_data->no_input_qs); | ||
2745 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2746 | sprintf(dbf_text,"noq:%4x",init_data->no_output_qs); | ||
2747 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2748 | QDIO_DBF_HEX0(0,setup,&init_data->input_handler,sizeof(void*)); | ||
2749 | QDIO_DBF_HEX0(0,setup,&init_data->output_handler,sizeof(void*)); | ||
2750 | QDIO_DBF_HEX0(0,setup,&init_data->int_parm,sizeof(long)); | ||
2751 | QDIO_DBF_HEX0(0,setup,&init_data->flags,sizeof(long)); | ||
2752 | QDIO_DBF_HEX0(0,setup,&init_data->input_sbal_addr_array,sizeof(void*)); | ||
2753 | QDIO_DBF_HEX0(0,setup,&init_data->output_sbal_addr_array,sizeof(void*)); | ||
2754 | } | ||
2755 | |||
2756 | static void | ||
2757 | qdio_allocate_fill_input_desc(struct qdio_irq *irq_ptr, int i, int iqfmt) | ||
2758 | { | ||
2759 | irq_ptr->input_qs[i]->is_iqdio_q = iqfmt; | ||
2760 | irq_ptr->input_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq; | ||
2761 | |||
2762 | irq_ptr->qdr->qdf0[i].sliba=(unsigned long)(irq_ptr->input_qs[i]->slib); | ||
2763 | |||
2764 | irq_ptr->qdr->qdf0[i].sla=(unsigned long)(irq_ptr->input_qs[i]->sl); | ||
2765 | |||
2766 | irq_ptr->qdr->qdf0[i].slsba= | ||
2767 | (unsigned long)(&irq_ptr->input_qs[i]->slsb.acc.val[0]); | ||
2768 | |||
2769 | irq_ptr->qdr->qdf0[i].akey=QDIO_STORAGE_KEY; | ||
2770 | irq_ptr->qdr->qdf0[i].bkey=QDIO_STORAGE_KEY; | ||
2771 | irq_ptr->qdr->qdf0[i].ckey=QDIO_STORAGE_KEY; | ||
2772 | irq_ptr->qdr->qdf0[i].dkey=QDIO_STORAGE_KEY; | ||
2773 | } | ||
2774 | |||
2775 | static void | ||
2776 | qdio_allocate_fill_output_desc(struct qdio_irq *irq_ptr, int i, | ||
2777 | int j, int iqfmt) | ||
2778 | { | ||
2779 | irq_ptr->output_qs[i]->is_iqdio_q = iqfmt; | ||
2780 | irq_ptr->output_qs[i]->is_thinint_q = irq_ptr->is_thinint_irq; | ||
2781 | |||
2782 | irq_ptr->qdr->qdf0[i+j].sliba=(unsigned long)(irq_ptr->output_qs[i]->slib); | ||
2783 | |||
2784 | irq_ptr->qdr->qdf0[i+j].sla=(unsigned long)(irq_ptr->output_qs[i]->sl); | ||
2785 | |||
2786 | irq_ptr->qdr->qdf0[i+j].slsba= | ||
2787 | (unsigned long)(&irq_ptr->output_qs[i]->slsb.acc.val[0]); | ||
2788 | |||
2789 | irq_ptr->qdr->qdf0[i+j].akey=QDIO_STORAGE_KEY; | ||
2790 | irq_ptr->qdr->qdf0[i+j].bkey=QDIO_STORAGE_KEY; | ||
2791 | irq_ptr->qdr->qdf0[i+j].ckey=QDIO_STORAGE_KEY; | ||
2792 | irq_ptr->qdr->qdf0[i+j].dkey=QDIO_STORAGE_KEY; | ||
2793 | } | ||
2794 | |||
2795 | |||
2796 | static void | ||
2797 | qdio_initialize_set_siga_flags_input(struct qdio_irq *irq_ptr) | ||
2798 | { | ||
2799 | int i; | ||
2800 | |||
2801 | for (i=0;i<irq_ptr->no_input_qs;i++) { | ||
2802 | irq_ptr->input_qs[i]->siga_sync= | ||
2803 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY; | ||
2804 | irq_ptr->input_qs[i]->siga_in= | ||
2805 | irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY; | ||
2806 | irq_ptr->input_qs[i]->siga_out= | ||
2807 | irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY; | ||
2808 | irq_ptr->input_qs[i]->siga_sync_done_on_thinints= | ||
2809 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS; | ||
2810 | irq_ptr->input_qs[i]->hydra_gives_outbound_pcis= | ||
2811 | irq_ptr->hydra_gives_outbound_pcis; | ||
2812 | irq_ptr->input_qs[i]->siga_sync_done_on_outb_tis= | ||
2813 | ((irq_ptr->qdioac& | ||
2814 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| | ||
2815 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))== | ||
2816 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| | ||
2817 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS)); | ||
2818 | |||
2819 | } | ||
2820 | } | ||
2821 | |||
2822 | static void | ||
2823 | qdio_initialize_set_siga_flags_output(struct qdio_irq *irq_ptr) | ||
2824 | { | ||
2825 | int i; | ||
2826 | |||
2827 | for (i=0;i<irq_ptr->no_output_qs;i++) { | ||
2828 | irq_ptr->output_qs[i]->siga_sync= | ||
2829 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY; | ||
2830 | irq_ptr->output_qs[i]->siga_in= | ||
2831 | irq_ptr->qdioac&CHSC_FLAG_SIGA_INPUT_NECESSARY; | ||
2832 | irq_ptr->output_qs[i]->siga_out= | ||
2833 | irq_ptr->qdioac&CHSC_FLAG_SIGA_OUTPUT_NECESSARY; | ||
2834 | irq_ptr->output_qs[i]->siga_sync_done_on_thinints= | ||
2835 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS; | ||
2836 | irq_ptr->output_qs[i]->hydra_gives_outbound_pcis= | ||
2837 | irq_ptr->hydra_gives_outbound_pcis; | ||
2838 | irq_ptr->output_qs[i]->siga_sync_done_on_outb_tis= | ||
2839 | ((irq_ptr->qdioac& | ||
2840 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| | ||
2841 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS))== | ||
2842 | (CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS| | ||
2843 | CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS)); | ||
2844 | |||
2845 | } | ||
2846 | } | ||
2847 | |||
2848 | static int | ||
2849 | qdio_establish_irq_check_for_errors(struct ccw_device *cdev, int cstat, | ||
2850 | int dstat) | ||
2851 | { | ||
2852 | char dbf_text[15]; | ||
2853 | struct qdio_irq *irq_ptr; | ||
2854 | |||
2855 | irq_ptr = cdev->private->qdio_data; | ||
2856 | |||
2857 | if (cstat || (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END))) { | ||
2858 | sprintf(dbf_text,"ick1%4x",irq_ptr->schid.sch_no); | ||
2859 | QDIO_DBF_TEXT2(1,trace,dbf_text); | ||
2860 | QDIO_DBF_HEX2(0,trace,&dstat,sizeof(int)); | ||
2861 | QDIO_DBF_HEX2(0,trace,&cstat,sizeof(int)); | ||
2862 | QDIO_PRINT_ERR("received check condition on establish " \ | ||
2863 | "queues on irq 0.%x.%x (cs=x%x, ds=x%x).\n", | ||
2864 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, | ||
2865 | cstat,dstat); | ||
2866 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ERR); | ||
2867 | } | ||
2868 | |||
2869 | if (!(dstat & DEV_STAT_DEV_END)) { | ||
2870 | QDIO_DBF_TEXT2(1,setup,"eq:no de"); | ||
2871 | QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat)); | ||
2872 | QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat)); | ||
2873 | QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: didn't get " | ||
2874 | "device end: dstat=%02x, cstat=%02x\n", | ||
2875 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, | ||
2876 | dstat, cstat); | ||
2877 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
2878 | return 1; | ||
2879 | } | ||
2880 | |||
2881 | if (dstat & ~(DEV_STAT_CHN_END|DEV_STAT_DEV_END)) { | ||
2882 | QDIO_DBF_TEXT2(1,setup,"eq:badio"); | ||
2883 | QDIO_DBF_HEX2(0,setup,&dstat, sizeof(dstat)); | ||
2884 | QDIO_DBF_HEX2(0,setup,&cstat, sizeof(cstat)); | ||
2885 | QDIO_PRINT_ERR("establish queues on irq 0.%x.%04x: got " | ||
2886 | "the following devstat: dstat=%02x, " | ||
2887 | "cstat=%02x\n", irq_ptr->schid.ssid, | ||
2888 | irq_ptr->schid.sch_no, dstat, cstat); | ||
2889 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
2890 | return 1; | ||
2891 | } | ||
2892 | return 0; | ||
2893 | } | ||
2894 | |||
2895 | static void | ||
2896 | qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, int dstat) | ||
2897 | { | ||
2898 | struct qdio_irq *irq_ptr; | ||
2899 | char dbf_text[15]; | ||
2900 | |||
2901 | irq_ptr = cdev->private->qdio_data; | ||
2902 | |||
2903 | sprintf(dbf_text,"qehi%4x",cdev->private->schid.sch_no); | ||
2904 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2905 | QDIO_DBF_TEXT0(0,trace,dbf_text); | ||
2906 | |||
2907 | if (qdio_establish_irq_check_for_errors(cdev, cstat, dstat)) | ||
2908 | return; | ||
2909 | |||
2910 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_ESTABLISHED); | ||
2911 | } | ||
2912 | |||
2913 | int | ||
2914 | qdio_initialize(struct qdio_initialize *init_data) | ||
2915 | { | ||
2916 | int rc; | ||
2917 | char dbf_text[15]; | ||
2918 | |||
2919 | sprintf(dbf_text,"qini%4x",init_data->cdev->private->schid.sch_no); | ||
2920 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2921 | QDIO_DBF_TEXT0(0,trace,dbf_text); | ||
2922 | |||
2923 | rc = qdio_allocate(init_data); | ||
2924 | if (rc == 0) { | ||
2925 | rc = qdio_establish(init_data); | ||
2926 | if (rc != 0) | ||
2927 | qdio_free(init_data->cdev); | ||
2928 | } | ||
2929 | |||
2930 | return rc; | ||
2931 | } | ||
2932 | |||
2933 | |||
2934 | int | ||
2935 | qdio_allocate(struct qdio_initialize *init_data) | ||
2936 | { | ||
2937 | struct qdio_irq *irq_ptr; | ||
2938 | char dbf_text[15]; | ||
2939 | |||
2940 | sprintf(dbf_text,"qalc%4x",init_data->cdev->private->schid.sch_no); | ||
2941 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
2942 | QDIO_DBF_TEXT0(0,trace,dbf_text); | ||
2943 | if ( (init_data->no_input_qs>QDIO_MAX_QUEUES_PER_IRQ) || | ||
2944 | (init_data->no_output_qs>QDIO_MAX_QUEUES_PER_IRQ) || | ||
2945 | ((init_data->no_input_qs) && (!init_data->input_handler)) || | ||
2946 | ((init_data->no_output_qs) && (!init_data->output_handler)) ) | ||
2947 | return -EINVAL; | ||
2948 | |||
2949 | if (!init_data->input_sbal_addr_array) | ||
2950 | return -EINVAL; | ||
2951 | |||
2952 | if (!init_data->output_sbal_addr_array) | ||
2953 | return -EINVAL; | ||
2954 | |||
2955 | qdio_allocate_do_dbf(init_data); | ||
2956 | |||
2957 | /* create irq */ | ||
2958 | irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | ||
2959 | |||
2960 | QDIO_DBF_TEXT0(0,setup,"irq_ptr:"); | ||
2961 | QDIO_DBF_HEX0(0,setup,&irq_ptr,sizeof(void*)); | ||
2962 | |||
2963 | if (!irq_ptr) { | ||
2964 | QDIO_PRINT_ERR("allocation of irq_ptr failed!\n"); | ||
2965 | return -ENOMEM; | ||
2966 | } | ||
2967 | |||
2968 | init_MUTEX(&irq_ptr->setting_up_sema); | ||
2969 | |||
2970 | /* QDR must be in DMA area since CCW data address is only 32 bit */ | ||
2971 | irq_ptr->qdr = (struct qdr *) __get_free_page(GFP_KERNEL | GFP_DMA); | ||
2972 | if (!(irq_ptr->qdr)) { | ||
2973 | free_page((unsigned long) irq_ptr); | ||
2974 | QDIO_PRINT_ERR("allocation of irq_ptr->qdr failed!\n"); | ||
2975 | return -ENOMEM; | ||
2976 | } | ||
2977 | QDIO_DBF_TEXT0(0,setup,"qdr:"); | ||
2978 | QDIO_DBF_HEX0(0,setup,&irq_ptr->qdr,sizeof(void*)); | ||
2979 | |||
2980 | if (qdio_alloc_qs(irq_ptr, | ||
2981 | init_data->no_input_qs, | ||
2982 | init_data->no_output_qs)) { | ||
2983 | QDIO_PRINT_ERR("queue allocation failed!\n"); | ||
2984 | qdio_release_irq_memory(irq_ptr); | ||
2985 | return -ENOMEM; | ||
2986 | } | ||
2987 | |||
2988 | init_data->cdev->private->qdio_data = irq_ptr; | ||
2989 | |||
2990 | qdio_set_state(irq_ptr,QDIO_IRQ_STATE_INACTIVE); | ||
2991 | |||
2992 | return 0; | ||
2993 | } | ||
2994 | |||
2995 | static int qdio_fill_irq(struct qdio_initialize *init_data) | ||
2996 | { | ||
2997 | int i; | ||
2998 | char dbf_text[15]; | ||
2999 | struct ciw *ciw; | ||
3000 | int is_iqdio; | ||
3001 | struct qdio_irq *irq_ptr; | ||
3002 | |||
3003 | irq_ptr = init_data->cdev->private->qdio_data; | ||
3004 | |||
3005 | memset(irq_ptr,0,((char*)&irq_ptr->qdr)-((char*)irq_ptr)); | ||
3006 | |||
3007 | /* wipes qib.ac, required by ar7063 */ | ||
3008 | memset(irq_ptr->qdr,0,sizeof(struct qdr)); | ||
3009 | |||
3010 | irq_ptr->int_parm=init_data->int_parm; | ||
3011 | |||
3012 | irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev); | ||
3013 | irq_ptr->no_input_qs=init_data->no_input_qs; | ||
3014 | irq_ptr->no_output_qs=init_data->no_output_qs; | ||
3015 | |||
3016 | if (init_data->q_format==QDIO_IQDIO_QFMT) { | ||
3017 | irq_ptr->is_iqdio_irq=1; | ||
3018 | irq_ptr->is_thinint_irq=1; | ||
3019 | } else { | ||
3020 | irq_ptr->is_iqdio_irq=0; | ||
3021 | irq_ptr->is_thinint_irq=hydra_thinints; | ||
3022 | } | ||
3023 | sprintf(dbf_text,"is_i_t%1x%1x", | ||
3024 | irq_ptr->is_iqdio_irq,irq_ptr->is_thinint_irq); | ||
3025 | QDIO_DBF_TEXT2(0,setup,dbf_text); | ||
3026 | |||
3027 | if (irq_ptr->is_thinint_irq) { | ||
3028 | irq_ptr->dev_st_chg_ind = qdio_get_indicator(); | ||
3029 | QDIO_DBF_HEX1(0,setup,&irq_ptr->dev_st_chg_ind,sizeof(void*)); | ||
3030 | if (!irq_ptr->dev_st_chg_ind) { | ||
3031 | QDIO_PRINT_WARN("no indicator location available " \ | ||
3032 | "for irq 0.%x.%x\n", | ||
3033 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no); | ||
3034 | qdio_release_irq_memory(irq_ptr); | ||
3035 | return -ENOBUFS; | ||
3036 | } | ||
3037 | } | ||
3038 | |||
3039 | /* defaults */ | ||
3040 | irq_ptr->equeue.cmd=DEFAULT_ESTABLISH_QS_CMD; | ||
3041 | irq_ptr->equeue.count=DEFAULT_ESTABLISH_QS_COUNT; | ||
3042 | irq_ptr->aqueue.cmd=DEFAULT_ACTIVATE_QS_CMD; | ||
3043 | irq_ptr->aqueue.count=DEFAULT_ACTIVATE_QS_COUNT; | ||
3044 | |||
3045 | qdio_fill_qs(irq_ptr, init_data->cdev, | ||
3046 | init_data->no_input_qs, | ||
3047 | init_data->no_output_qs, | ||
3048 | init_data->input_handler, | ||
3049 | init_data->output_handler,init_data->int_parm, | ||
3050 | init_data->q_format,init_data->flags, | ||
3051 | init_data->input_sbal_addr_array, | ||
3052 | init_data->output_sbal_addr_array); | ||
3053 | |||
3054 | if (!try_module_get(THIS_MODULE)) { | ||
3055 | QDIO_PRINT_CRIT("try_module_get() failed!\n"); | ||
3056 | qdio_release_irq_memory(irq_ptr); | ||
3057 | return -EINVAL; | ||
3058 | } | ||
3059 | |||
3060 | qdio_fill_thresholds(irq_ptr,init_data->no_input_qs, | ||
3061 | init_data->no_output_qs, | ||
3062 | init_data->min_input_threshold, | ||
3063 | init_data->max_input_threshold, | ||
3064 | init_data->min_output_threshold, | ||
3065 | init_data->max_output_threshold); | ||
3066 | |||
3067 | /* fill in qdr */ | ||
3068 | irq_ptr->qdr->qfmt=init_data->q_format; | ||
3069 | irq_ptr->qdr->iqdcnt=init_data->no_input_qs; | ||
3070 | irq_ptr->qdr->oqdcnt=init_data->no_output_qs; | ||
3071 | irq_ptr->qdr->iqdsz=sizeof(struct qdesfmt0)/4; /* size in words */ | ||
3072 | irq_ptr->qdr->oqdsz=sizeof(struct qdesfmt0)/4; | ||
3073 | |||
3074 | irq_ptr->qdr->qiba=(unsigned long)&irq_ptr->qib; | ||
3075 | irq_ptr->qdr->qkey=QDIO_STORAGE_KEY; | ||
3076 | |||
3077 | /* fill in qib */ | ||
3078 | irq_ptr->is_qebsm = is_passthrough; | ||
3079 | if (irq_ptr->is_qebsm) | ||
3080 | irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM; | ||
3081 | |||
3082 | irq_ptr->qib.qfmt=init_data->q_format; | ||
3083 | if (init_data->no_input_qs) | ||
3084 | irq_ptr->qib.isliba=(unsigned long)(irq_ptr->input_qs[0]->slib); | ||
3085 | if (init_data->no_output_qs) | ||
3086 | irq_ptr->qib.osliba=(unsigned long)(irq_ptr->output_qs[0]->slib); | ||
3087 | memcpy(irq_ptr->qib.ebcnam,init_data->adapter_name,8); | ||
3088 | |||
3089 | qdio_set_impl_params(irq_ptr,init_data->qib_param_field_format, | ||
3090 | init_data->qib_param_field, | ||
3091 | init_data->no_input_qs, | ||
3092 | init_data->no_output_qs, | ||
3093 | init_data->input_slib_elements, | ||
3094 | init_data->output_slib_elements); | ||
3095 | |||
3096 | /* first input descriptors, then output descriptors */ | ||
3097 | is_iqdio = (init_data->q_format == QDIO_IQDIO_QFMT) ? 1 : 0; | ||
3098 | for (i=0;i<init_data->no_input_qs;i++) | ||
3099 | qdio_allocate_fill_input_desc(irq_ptr, i, is_iqdio); | ||
3100 | |||
3101 | for (i=0;i<init_data->no_output_qs;i++) | ||
3102 | qdio_allocate_fill_output_desc(irq_ptr, i, | ||
3103 | init_data->no_input_qs, | ||
3104 | is_iqdio); | ||
3105 | |||
3106 | /* qdr, qib, sls, slsbs, slibs, sbales filled. */ | ||
3107 | |||
3108 | /* get qdio commands */ | ||
3109 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE); | ||
3110 | if (!ciw) { | ||
3111 | QDIO_DBF_TEXT2(1,setup,"no eq"); | ||
3112 | QDIO_PRINT_INFO("No equeue CIW found for QDIO commands. " | ||
3113 | "Trying to use default.\n"); | ||
3114 | } else | ||
3115 | irq_ptr->equeue = *ciw; | ||
3116 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE); | ||
3117 | if (!ciw) { | ||
3118 | QDIO_DBF_TEXT2(1,setup,"no aq"); | ||
3119 | QDIO_PRINT_INFO("No aqueue CIW found for QDIO commands. " | ||
3120 | "Trying to use default.\n"); | ||
3121 | } else | ||
3122 | irq_ptr->aqueue = *ciw; | ||
3123 | |||
3124 | /* Set new interrupt handler. */ | ||
3125 | irq_ptr->original_int_handler = init_data->cdev->handler; | ||
3126 | init_data->cdev->handler = qdio_handler; | ||
3127 | |||
3128 | return 0; | ||
3129 | } | ||
3130 | |||
3131 | int | ||
3132 | qdio_establish(struct qdio_initialize *init_data) | ||
3133 | { | ||
3134 | struct qdio_irq *irq_ptr; | ||
3135 | unsigned long saveflags; | ||
3136 | int result, result2; | ||
3137 | struct ccw_device *cdev; | ||
3138 | char dbf_text[20]; | ||
3139 | |||
3140 | cdev=init_data->cdev; | ||
3141 | irq_ptr = cdev->private->qdio_data; | ||
3142 | if (!irq_ptr) | ||
3143 | return -EINVAL; | ||
3144 | |||
3145 | if (cdev->private->state != DEV_STATE_ONLINE) | ||
3146 | return -EINVAL; | ||
3147 | |||
3148 | down(&irq_ptr->setting_up_sema); | ||
3149 | |||
3150 | qdio_fill_irq(init_data); | ||
3151 | |||
3152 | /* the thinint CHSC stuff */ | ||
3153 | if (irq_ptr->is_thinint_irq) { | ||
3154 | |||
3155 | result = tiqdio_set_subchannel_ind(irq_ptr,0); | ||
3156 | if (result) { | ||
3157 | up(&irq_ptr->setting_up_sema); | ||
3158 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
3159 | return result; | ||
3160 | } | ||
3161 | tiqdio_set_delay_target(irq_ptr,TIQDIO_DELAY_TARGET); | ||
3162 | } | ||
3163 | |||
3164 | sprintf(dbf_text,"qest%4x",cdev->private->schid.sch_no); | ||
3165 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
3166 | QDIO_DBF_TEXT0(0,trace,dbf_text); | ||
3167 | |||
3168 | /* establish q */ | ||
3169 | irq_ptr->ccw.cmd_code=irq_ptr->equeue.cmd; | ||
3170 | irq_ptr->ccw.flags=CCW_FLAG_SLI; | ||
3171 | irq_ptr->ccw.count=irq_ptr->equeue.count; | ||
3172 | irq_ptr->ccw.cda=QDIO_GET_ADDR(irq_ptr->qdr); | ||
3173 | |||
3174 | spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags); | ||
3175 | |||
3176 | ccw_device_set_options_mask(cdev, 0); | ||
3177 | result = ccw_device_start(cdev, &irq_ptr->ccw, | ||
3178 | QDIO_DOING_ESTABLISH, 0, 0); | ||
3179 | if (result) { | ||
3180 | result2 = ccw_device_start(cdev, &irq_ptr->ccw, | ||
3181 | QDIO_DOING_ESTABLISH, 0, 0); | ||
3182 | sprintf(dbf_text,"eq:io%4x",result); | ||
3183 | QDIO_DBF_TEXT2(1,setup,dbf_text); | ||
3184 | if (result2) { | ||
3185 | sprintf(dbf_text,"eq:io%4x",result); | ||
3186 | QDIO_DBF_TEXT2(1,setup,dbf_text); | ||
3187 | } | ||
3188 | QDIO_PRINT_WARN("establish queues on irq 0.%x.%04x: do_IO " \ | ||
3189 | "returned %i, next try returned %i\n", | ||
3190 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, | ||
3191 | result, result2); | ||
3192 | result=result2; | ||
3193 | } | ||
3194 | |||
3195 | spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags); | ||
3196 | |||
3197 | if (result) { | ||
3198 | up(&irq_ptr->setting_up_sema); | ||
3199 | qdio_shutdown(cdev,QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
3200 | return result; | ||
3201 | } | ||
3202 | |||
3203 | wait_event_interruptible_timeout(cdev->private->wait_q, | ||
3204 | irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || | ||
3205 | irq_ptr->state == QDIO_IRQ_STATE_ERR, | ||
3206 | QDIO_ESTABLISH_TIMEOUT); | ||
3207 | |||
3208 | if (irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED) | ||
3209 | result = 0; | ||
3210 | else { | ||
3211 | up(&irq_ptr->setting_up_sema); | ||
3212 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
3213 | return -EIO; | ||
3214 | } | ||
3215 | |||
3216 | qdio_get_ssqd_siga(irq_ptr); | ||
3217 | /* if this gets set once, we're running under VM and can omit SVSes */ | ||
3218 | if (irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_NECESSARY) | ||
3219 | omit_svs=1; | ||
3220 | |||
3221 | sprintf(dbf_text,"qdioac%2x",irq_ptr->qdioac); | ||
3222 | QDIO_DBF_TEXT2(0,setup,dbf_text); | ||
3223 | |||
3224 | sprintf(dbf_text,"qib ac%2x",irq_ptr->qib.ac); | ||
3225 | QDIO_DBF_TEXT2(0,setup,dbf_text); | ||
3226 | |||
3227 | irq_ptr->hydra_gives_outbound_pcis= | ||
3228 | irq_ptr->qib.ac&QIB_AC_OUTBOUND_PCI_SUPPORTED; | ||
3229 | irq_ptr->sync_done_on_outb_pcis= | ||
3230 | irq_ptr->qdioac&CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS; | ||
3231 | |||
3232 | qdio_initialize_set_siga_flags_input(irq_ptr); | ||
3233 | qdio_initialize_set_siga_flags_output(irq_ptr); | ||
3234 | |||
3235 | up(&irq_ptr->setting_up_sema); | ||
3236 | |||
3237 | return result; | ||
3238 | |||
3239 | } | ||
3240 | |||
3241 | int | ||
3242 | qdio_activate(struct ccw_device *cdev, int flags) | ||
3243 | { | ||
3244 | struct qdio_irq *irq_ptr; | ||
3245 | int i,result=0,result2; | ||
3246 | unsigned long saveflags; | ||
3247 | char dbf_text[20]; /* see qdio_initialize */ | ||
3248 | |||
3249 | irq_ptr = cdev->private->qdio_data; | ||
3250 | if (!irq_ptr) | ||
3251 | return -ENODEV; | ||
3252 | |||
3253 | if (cdev->private->state != DEV_STATE_ONLINE) | ||
3254 | return -EINVAL; | ||
3255 | |||
3256 | down(&irq_ptr->setting_up_sema); | ||
3257 | if (irq_ptr->state==QDIO_IRQ_STATE_INACTIVE) { | ||
3258 | result=-EBUSY; | ||
3259 | goto out; | ||
3260 | } | ||
3261 | |||
3262 | sprintf(dbf_text,"qact%4x", irq_ptr->schid.sch_no); | ||
3263 | QDIO_DBF_TEXT2(0,setup,dbf_text); | ||
3264 | QDIO_DBF_TEXT2(0,trace,dbf_text); | ||
3265 | |||
3266 | /* activate q */ | ||
3267 | irq_ptr->ccw.cmd_code=irq_ptr->aqueue.cmd; | ||
3268 | irq_ptr->ccw.flags=CCW_FLAG_SLI; | ||
3269 | irq_ptr->ccw.count=irq_ptr->aqueue.count; | ||
3270 | irq_ptr->ccw.cda=QDIO_GET_ADDR(0); | ||
3271 | |||
3272 | spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags); | ||
3273 | |||
3274 | ccw_device_set_options(cdev, CCWDEV_REPORT_ALL); | ||
3275 | result=ccw_device_start(cdev,&irq_ptr->ccw,QDIO_DOING_ACTIVATE, | ||
3276 | 0, DOIO_DENY_PREFETCH); | ||
3277 | if (result) { | ||
3278 | result2=ccw_device_start(cdev,&irq_ptr->ccw, | ||
3279 | QDIO_DOING_ACTIVATE,0,0); | ||
3280 | sprintf(dbf_text,"aq:io%4x",result); | ||
3281 | QDIO_DBF_TEXT2(1,setup,dbf_text); | ||
3282 | if (result2) { | ||
3283 | sprintf(dbf_text,"aq:io%4x",result); | ||
3284 | QDIO_DBF_TEXT2(1,setup,dbf_text); | ||
3285 | } | ||
3286 | QDIO_PRINT_WARN("activate queues on irq 0.%x.%04x: do_IO " \ | ||
3287 | "returned %i, next try returned %i\n", | ||
3288 | irq_ptr->schid.ssid, irq_ptr->schid.sch_no, | ||
3289 | result, result2); | ||
3290 | result=result2; | ||
3291 | } | ||
3292 | |||
3293 | spin_unlock_irqrestore(get_ccwdev_lock(cdev),saveflags); | ||
3294 | if (result) | ||
3295 | goto out; | ||
3296 | |||
3297 | for (i=0;i<irq_ptr->no_input_qs;i++) { | ||
3298 | if (irq_ptr->is_thinint_irq) { | ||
3299 | /* | ||
3300 | * that way we know, that, if we will get interrupted | ||
3301 | * by tiqdio_inbound_processing, qdio_unmark_q will | ||
3302 | * not be called | ||
3303 | */ | ||
3304 | qdio_reserve_q(irq_ptr->input_qs[i]); | ||
3305 | qdio_mark_tiq(irq_ptr->input_qs[i]); | ||
3306 | qdio_release_q(irq_ptr->input_qs[i]); | ||
3307 | } | ||
3308 | } | ||
3309 | |||
3310 | if (flags&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) { | ||
3311 | for (i=0;i<irq_ptr->no_input_qs;i++) { | ||
3312 | irq_ptr->input_qs[i]->is_input_q|= | ||
3313 | QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT; | ||
3314 | } | ||
3315 | } | ||
3316 | |||
3317 | msleep(QDIO_ACTIVATE_TIMEOUT); | ||
3318 | switch (irq_ptr->state) { | ||
3319 | case QDIO_IRQ_STATE_STOPPED: | ||
3320 | case QDIO_IRQ_STATE_ERR: | ||
3321 | up(&irq_ptr->setting_up_sema); | ||
3322 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
3323 | down(&irq_ptr->setting_up_sema); | ||
3324 | result = -EIO; | ||
3325 | break; | ||
3326 | default: | ||
3327 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE); | ||
3328 | result = 0; | ||
3329 | } | ||
3330 | out: | ||
3331 | up(&irq_ptr->setting_up_sema); | ||
3332 | |||
3333 | return result; | ||
3334 | } | ||
3335 | |||
3336 | /* buffers filled forwards again to make Rick happy */ | ||
3337 | static void | ||
3338 | qdio_do_qdio_fill_input(struct qdio_q *q, unsigned int qidx, | ||
3339 | unsigned int count, struct qdio_buffer *buffers) | ||
3340 | { | ||
3341 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; | ||
3342 | int tmp = 0; | ||
3343 | |||
3344 | qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1); | ||
3345 | if (irq->is_qebsm) { | ||
3346 | while (count) { | ||
3347 | tmp = set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count); | ||
3348 | if (!tmp) | ||
3349 | return; | ||
3350 | } | ||
3351 | return; | ||
3352 | } | ||
3353 | for (;;) { | ||
3354 | set_slsb(q, &qidx, SLSB_CU_INPUT_EMPTY, &count); | ||
3355 | count--; | ||
3356 | if (!count) break; | ||
3357 | qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1); | ||
3358 | } | ||
3359 | } | ||
3360 | |||
3361 | static void | ||
3362 | qdio_do_qdio_fill_output(struct qdio_q *q, unsigned int qidx, | ||
3363 | unsigned int count, struct qdio_buffer *buffers) | ||
3364 | { | ||
3365 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; | ||
3366 | int tmp = 0; | ||
3367 | |||
3368 | qidx &= (QDIO_MAX_BUFFERS_PER_Q - 1); | ||
3369 | if (irq->is_qebsm) { | ||
3370 | while (count) { | ||
3371 | tmp = set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count); | ||
3372 | if (!tmp) | ||
3373 | return; | ||
3374 | } | ||
3375 | return; | ||
3376 | } | ||
3377 | |||
3378 | for (;;) { | ||
3379 | set_slsb(q, &qidx, SLSB_CU_OUTPUT_PRIMED, &count); | ||
3380 | count--; | ||
3381 | if (!count) break; | ||
3382 | qidx = (qidx + 1) & (QDIO_MAX_BUFFERS_PER_Q - 1); | ||
3383 | } | ||
3384 | } | ||
3385 | |||
3386 | static void | ||
3387 | do_qdio_handle_inbound(struct qdio_q *q, unsigned int callflags, | ||
3388 | unsigned int qidx, unsigned int count, | ||
3389 | struct qdio_buffer *buffers) | ||
3390 | { | ||
3391 | int used_elements; | ||
3392 | |||
3393 | /* This is the inbound handling of queues */ | ||
3394 | used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count; | ||
3395 | |||
3396 | qdio_do_qdio_fill_input(q,qidx,count,buffers); | ||
3397 | |||
3398 | if ((used_elements+count==QDIO_MAX_BUFFERS_PER_Q)&& | ||
3399 | (callflags&QDIO_FLAG_UNDER_INTERRUPT)) | ||
3400 | atomic_xchg(&q->polling,0); | ||
3401 | |||
3402 | if (used_elements) | ||
3403 | return; | ||
3404 | if (callflags&QDIO_FLAG_DONT_SIGA) | ||
3405 | return; | ||
3406 | if (q->siga_in) { | ||
3407 | int result; | ||
3408 | |||
3409 | result=qdio_siga_input(q); | ||
3410 | if (result) { | ||
3411 | if (q->siga_error) | ||
3412 | q->error_status_flags|= | ||
3413 | QDIO_STATUS_MORE_THAN_ONE_SIGA_ERROR; | ||
3414 | q->error_status_flags|=QDIO_STATUS_LOOK_FOR_ERROR; | ||
3415 | q->siga_error=result; | ||
3416 | } | ||
3417 | } | ||
3418 | |||
3419 | qdio_mark_q(q); | ||
3420 | } | ||
3421 | |||
3422 | static void | ||
3423 | do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags, | ||
3424 | unsigned int qidx, unsigned int count, | ||
3425 | struct qdio_buffer *buffers) | ||
3426 | { | ||
3427 | int used_elements; | ||
3428 | unsigned int cnt, start_buf; | ||
3429 | unsigned char state = 0; | ||
3430 | struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; | ||
3431 | |||
3432 | /* This is the outbound handling of queues */ | ||
3433 | qdio_do_qdio_fill_output(q,qidx,count,buffers); | ||
3434 | |||
3435 | used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count; | ||
3436 | |||
3437 | if (callflags&QDIO_FLAG_DONT_SIGA) { | ||
3438 | qdio_perf_stat_inc(&perf_stats.outbound_cnt); | ||
3439 | return; | ||
3440 | } | ||
3441 | if (callflags & QDIO_FLAG_PCI_OUT) | ||
3442 | q->is_pci_out = 1; | ||
3443 | else | ||
3444 | q->is_pci_out = 0; | ||
3445 | if (q->is_iqdio_q) { | ||
3446 | /* one siga for every sbal */ | ||
3447 | while (count--) | ||
3448 | qdio_kick_outbound_q(q); | ||
3449 | |||
3450 | __qdio_outbound_processing(q); | ||
3451 | } else { | ||
3452 | /* under VM, we do a SIGA sync unconditionally */ | ||
3453 | SYNC_MEMORY; | ||
3454 | else { | ||
3455 | /* | ||
3456 | * w/o shadow queues (else branch of | ||
3457 | * SYNC_MEMORY :-/ ), we try to | ||
3458 | * fast-requeue buffers | ||
3459 | */ | ||
3460 | if (irq->is_qebsm) { | ||
3461 | cnt = 1; | ||
3462 | start_buf = ((qidx+QDIO_MAX_BUFFERS_PER_Q-1) & | ||
3463 | (QDIO_MAX_BUFFERS_PER_Q-1)); | ||
3464 | qdio_do_eqbs(q, &state, &start_buf, &cnt); | ||
3465 | } else | ||
3466 | state = q->slsb.acc.val[(qidx+QDIO_MAX_BUFFERS_PER_Q-1) | ||
3467 | &(QDIO_MAX_BUFFERS_PER_Q-1) ]; | ||
3468 | if (state != SLSB_CU_OUTPUT_PRIMED) { | ||
3469 | qdio_kick_outbound_q(q); | ||
3470 | } else { | ||
3471 | QDIO_DBF_TEXT3(0,trace, "fast-req"); | ||
3472 | qdio_perf_stat_inc(&perf_stats.fast_reqs); | ||
3473 | } | ||
3474 | } | ||
3475 | /* | ||
3476 | * only marking the q could take too long, | ||
3477 | * the upper layer module could do a lot of | ||
3478 | * traffic in that time | ||
3479 | */ | ||
3480 | __qdio_outbound_processing(q); | ||
3481 | } | ||
3482 | |||
3483 | qdio_perf_stat_inc(&perf_stats.outbound_cnt); | ||
3484 | } | ||
3485 | |||
3486 | /* count must be 1 in iqdio */ | ||
3487 | int | ||
3488 | do_QDIO(struct ccw_device *cdev,unsigned int callflags, | ||
3489 | unsigned int queue_number, unsigned int qidx, | ||
3490 | unsigned int count,struct qdio_buffer *buffers) | ||
3491 | { | ||
3492 | struct qdio_irq *irq_ptr; | ||
3493 | #ifdef CONFIG_QDIO_DEBUG | ||
3494 | char dbf_text[20]; | ||
3495 | |||
3496 | sprintf(dbf_text,"doQD%04x",cdev->private->schid.sch_no); | ||
3497 | QDIO_DBF_TEXT3(0,trace,dbf_text); | ||
3498 | #endif /* CONFIG_QDIO_DEBUG */ | ||
3499 | |||
3500 | if ( (qidx>QDIO_MAX_BUFFERS_PER_Q) || | ||
3501 | (count>QDIO_MAX_BUFFERS_PER_Q) || | ||
3502 | (queue_number>QDIO_MAX_QUEUES_PER_IRQ) ) | ||
3503 | return -EINVAL; | ||
3504 | |||
3505 | if (count==0) | ||
3506 | return 0; | ||
3507 | |||
3508 | irq_ptr = cdev->private->qdio_data; | ||
3509 | if (!irq_ptr) | ||
3510 | return -ENODEV; | ||
3511 | |||
3512 | #ifdef CONFIG_QDIO_DEBUG | ||
3513 | if (callflags&QDIO_FLAG_SYNC_INPUT) | ||
3514 | QDIO_DBF_HEX3(0,trace,&irq_ptr->input_qs[queue_number], | ||
3515 | sizeof(void*)); | ||
3516 | else | ||
3517 | QDIO_DBF_HEX3(0,trace,&irq_ptr->output_qs[queue_number], | ||
3518 | sizeof(void*)); | ||
3519 | sprintf(dbf_text,"flag%04x",callflags); | ||
3520 | QDIO_DBF_TEXT3(0,trace,dbf_text); | ||
3521 | sprintf(dbf_text,"qi%02xct%02x",qidx,count); | ||
3522 | QDIO_DBF_TEXT3(0,trace,dbf_text); | ||
3523 | #endif /* CONFIG_QDIO_DEBUG */ | ||
3524 | |||
3525 | if (irq_ptr->state!=QDIO_IRQ_STATE_ACTIVE) | ||
3526 | return -EBUSY; | ||
3527 | |||
3528 | if (callflags&QDIO_FLAG_SYNC_INPUT) | ||
3529 | do_qdio_handle_inbound(irq_ptr->input_qs[queue_number], | ||
3530 | callflags, qidx, count, buffers); | ||
3531 | else if (callflags&QDIO_FLAG_SYNC_OUTPUT) | ||
3532 | do_qdio_handle_outbound(irq_ptr->output_qs[queue_number], | ||
3533 | callflags, qidx, count, buffers); | ||
3534 | else { | ||
3535 | QDIO_DBF_TEXT3(1,trace,"doQD:inv"); | ||
3536 | return -EINVAL; | ||
3537 | } | ||
3538 | return 0; | ||
3539 | } | ||
3540 | |||
3541 | static int | ||
3542 | qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset, | ||
3543 | int buffer_length, int *eof, void *data) | ||
3544 | { | ||
3545 | int c=0; | ||
3546 | |||
3547 | /* we are always called with buffer_length=4k, so we all | ||
3548 | deliver on the first read */ | ||
3549 | if (offset>0) | ||
3550 | return 0; | ||
3551 | |||
3552 | #define _OUTP_IT(x...) c+=sprintf(buffer+c,x) | ||
3553 | #ifdef CONFIG_64BIT | ||
3554 | _OUTP_IT("Number of tasklet runs (total) : %li\n", | ||
3555 | (long)atomic64_read(&perf_stats.tl_runs)); | ||
3556 | _OUTP_IT("Inbound tasklet runs tried/retried : %li/%li\n", | ||
3557 | (long)atomic64_read(&perf_stats.inbound_tl_runs), | ||
3558 | (long)atomic64_read(&perf_stats.inbound_tl_runs_resched)); | ||
3559 | _OUTP_IT("Inbound-thin tasklet runs tried/retried : %li/%li\n", | ||
3560 | (long)atomic64_read(&perf_stats.inbound_thin_tl_runs), | ||
3561 | (long)atomic64_read(&perf_stats.inbound_thin_tl_runs_resched)); | ||
3562 | _OUTP_IT("Outbound tasklet runs tried/retried : %li/%li\n", | ||
3563 | (long)atomic64_read(&perf_stats.outbound_tl_runs), | ||
3564 | (long)atomic64_read(&perf_stats.outbound_tl_runs_resched)); | ||
3565 | _OUTP_IT("\n"); | ||
3566 | _OUTP_IT("Number of SIGA sync's issued : %li\n", | ||
3567 | (long)atomic64_read(&perf_stats.siga_syncs)); | ||
3568 | _OUTP_IT("Number of SIGA in's issued : %li\n", | ||
3569 | (long)atomic64_read(&perf_stats.siga_ins)); | ||
3570 | _OUTP_IT("Number of SIGA out's issued : %li\n", | ||
3571 | (long)atomic64_read(&perf_stats.siga_outs)); | ||
3572 | _OUTP_IT("Number of PCIs caught : %li\n", | ||
3573 | (long)atomic64_read(&perf_stats.pcis)); | ||
3574 | _OUTP_IT("Number of adapter interrupts caught : %li\n", | ||
3575 | (long)atomic64_read(&perf_stats.thinints)); | ||
3576 | _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %li\n", | ||
3577 | (long)atomic64_read(&perf_stats.fast_reqs)); | ||
3578 | _OUTP_IT("\n"); | ||
3579 | _OUTP_IT("Number of inbound transfers : %li\n", | ||
3580 | (long)atomic64_read(&perf_stats.inbound_cnt)); | ||
3581 | _OUTP_IT("Number of do_QDIOs outbound : %li\n", | ||
3582 | (long)atomic64_read(&perf_stats.outbound_cnt)); | ||
3583 | #else /* CONFIG_64BIT */ | ||
3584 | _OUTP_IT("Number of tasklet runs (total) : %i\n", | ||
3585 | atomic_read(&perf_stats.tl_runs)); | ||
3586 | _OUTP_IT("Inbound tasklet runs tried/retried : %i/%i\n", | ||
3587 | atomic_read(&perf_stats.inbound_tl_runs), | ||
3588 | atomic_read(&perf_stats.inbound_tl_runs_resched)); | ||
3589 | _OUTP_IT("Inbound-thin tasklet runs tried/retried : %i/%i\n", | ||
3590 | atomic_read(&perf_stats.inbound_thin_tl_runs), | ||
3591 | atomic_read(&perf_stats.inbound_thin_tl_runs_resched)); | ||
3592 | _OUTP_IT("Outbound tasklet runs tried/retried : %i/%i\n", | ||
3593 | atomic_read(&perf_stats.outbound_tl_runs), | ||
3594 | atomic_read(&perf_stats.outbound_tl_runs_resched)); | ||
3595 | _OUTP_IT("\n"); | ||
3596 | _OUTP_IT("Number of SIGA sync's issued : %i\n", | ||
3597 | atomic_read(&perf_stats.siga_syncs)); | ||
3598 | _OUTP_IT("Number of SIGA in's issued : %i\n", | ||
3599 | atomic_read(&perf_stats.siga_ins)); | ||
3600 | _OUTP_IT("Number of SIGA out's issued : %i\n", | ||
3601 | atomic_read(&perf_stats.siga_outs)); | ||
3602 | _OUTP_IT("Number of PCIs caught : %i\n", | ||
3603 | atomic_read(&perf_stats.pcis)); | ||
3604 | _OUTP_IT("Number of adapter interrupts caught : %i\n", | ||
3605 | atomic_read(&perf_stats.thinints)); | ||
3606 | _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %i\n", | ||
3607 | atomic_read(&perf_stats.fast_reqs)); | ||
3608 | _OUTP_IT("\n"); | ||
3609 | _OUTP_IT("Number of inbound transfers : %i\n", | ||
3610 | atomic_read(&perf_stats.inbound_cnt)); | ||
3611 | _OUTP_IT("Number of do_QDIOs outbound : %i\n", | ||
3612 | atomic_read(&perf_stats.outbound_cnt)); | ||
3613 | #endif /* CONFIG_64BIT */ | ||
3614 | _OUTP_IT("\n"); | ||
3615 | |||
3616 | return c; | ||
3617 | } | ||
3618 | |||
3619 | static struct proc_dir_entry *qdio_perf_proc_file; | ||
3620 | |||
3621 | static void | ||
3622 | qdio_add_procfs_entry(void) | ||
3623 | { | ||
3624 | proc_perf_file_registration=0; | ||
3625 | qdio_perf_proc_file=create_proc_entry(QDIO_PERF, | ||
3626 | S_IFREG|0444,NULL); | ||
3627 | if (qdio_perf_proc_file) { | ||
3628 | qdio_perf_proc_file->read_proc=&qdio_perf_procfile_read; | ||
3629 | } else proc_perf_file_registration=-1; | ||
3630 | |||
3631 | if (proc_perf_file_registration) | ||
3632 | QDIO_PRINT_WARN("was not able to register perf. " \ | ||
3633 | "proc-file (%i).\n", | ||
3634 | proc_perf_file_registration); | ||
3635 | } | ||
3636 | |||
3637 | static void | ||
3638 | qdio_remove_procfs_entry(void) | ||
3639 | { | ||
3640 | if (!proc_perf_file_registration) /* means if it went ok earlier */ | ||
3641 | remove_proc_entry(QDIO_PERF,NULL); | ||
3642 | } | ||
3643 | |||
3644 | /** | ||
3645 | * attributes in sysfs | ||
3646 | *****************************************************************************/ | ||
3647 | |||
3648 | static ssize_t | ||
3649 | qdio_performance_stats_show(struct bus_type *bus, char *buf) | ||
3650 | { | ||
3651 | return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0); | ||
3652 | } | ||
3653 | |||
3654 | static ssize_t | ||
3655 | qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count) | ||
3656 | { | ||
3657 | unsigned long i; | ||
3658 | int ret; | ||
3659 | |||
3660 | ret = strict_strtoul(buf, 16, &i); | ||
3661 | if (!ret && ((i == 0) || (i == 1))) { | ||
3662 | if (i == qdio_performance_stats) | ||
3663 | return count; | ||
3664 | qdio_performance_stats = i; | ||
3665 | if (i==0) { | ||
3666 | /* reset perf. stat. info */ | ||
3667 | #ifdef CONFIG_64BIT | ||
3668 | atomic64_set(&perf_stats.tl_runs, 0); | ||
3669 | atomic64_set(&perf_stats.outbound_tl_runs, 0); | ||
3670 | atomic64_set(&perf_stats.inbound_tl_runs, 0); | ||
3671 | atomic64_set(&perf_stats.inbound_tl_runs_resched, 0); | ||
3672 | atomic64_set(&perf_stats.inbound_thin_tl_runs, 0); | ||
3673 | atomic64_set(&perf_stats.inbound_thin_tl_runs_resched, | ||
3674 | 0); | ||
3675 | atomic64_set(&perf_stats.siga_outs, 0); | ||
3676 | atomic64_set(&perf_stats.siga_ins, 0); | ||
3677 | atomic64_set(&perf_stats.siga_syncs, 0); | ||
3678 | atomic64_set(&perf_stats.pcis, 0); | ||
3679 | atomic64_set(&perf_stats.thinints, 0); | ||
3680 | atomic64_set(&perf_stats.fast_reqs, 0); | ||
3681 | atomic64_set(&perf_stats.outbound_cnt, 0); | ||
3682 | atomic64_set(&perf_stats.inbound_cnt, 0); | ||
3683 | #else /* CONFIG_64BIT */ | ||
3684 | atomic_set(&perf_stats.tl_runs, 0); | ||
3685 | atomic_set(&perf_stats.outbound_tl_runs, 0); | ||
3686 | atomic_set(&perf_stats.inbound_tl_runs, 0); | ||
3687 | atomic_set(&perf_stats.inbound_tl_runs_resched, 0); | ||
3688 | atomic_set(&perf_stats.inbound_thin_tl_runs, 0); | ||
3689 | atomic_set(&perf_stats.inbound_thin_tl_runs_resched, 0); | ||
3690 | atomic_set(&perf_stats.siga_outs, 0); | ||
3691 | atomic_set(&perf_stats.siga_ins, 0); | ||
3692 | atomic_set(&perf_stats.siga_syncs, 0); | ||
3693 | atomic_set(&perf_stats.pcis, 0); | ||
3694 | atomic_set(&perf_stats.thinints, 0); | ||
3695 | atomic_set(&perf_stats.fast_reqs, 0); | ||
3696 | atomic_set(&perf_stats.outbound_cnt, 0); | ||
3697 | atomic_set(&perf_stats.inbound_cnt, 0); | ||
3698 | #endif /* CONFIG_64BIT */ | ||
3699 | } | ||
3700 | } else { | ||
3701 | QDIO_PRINT_ERR("QDIO performance_stats: write 0 or 1 to this file!\n"); | ||
3702 | return -EINVAL; | ||
3703 | } | ||
3704 | return count; | ||
3705 | } | ||
3706 | |||
3707 | static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show, | ||
3708 | qdio_performance_stats_store); | ||
3709 | |||
3710 | static void | ||
3711 | tiqdio_register_thinints(void) | ||
3712 | { | ||
3713 | char dbf_text[20]; | ||
3714 | |||
3715 | tiqdio_ind = | ||
3716 | s390_register_adapter_interrupt(&tiqdio_thinint_handler, NULL, | ||
3717 | TIQDIO_THININT_ISC); | ||
3718 | if (IS_ERR(tiqdio_ind)) { | ||
3719 | sprintf(dbf_text, "regthn%lx", PTR_ERR(tiqdio_ind)); | ||
3720 | QDIO_DBF_TEXT0(0,setup,dbf_text); | ||
3721 | QDIO_PRINT_ERR("failed to register adapter handler " \ | ||
3722 | "(rc=%li).\nAdapter interrupts might " \ | ||
3723 | "not work. Continuing.\n", | ||
3724 | PTR_ERR(tiqdio_ind)); | ||
3725 | tiqdio_ind = NULL; | ||
3726 | } | ||
3727 | } | ||
3728 | |||
3729 | static void | ||
3730 | tiqdio_unregister_thinints(void) | ||
3731 | { | ||
3732 | if (tiqdio_ind) | ||
3733 | s390_unregister_adapter_interrupt(tiqdio_ind, | ||
3734 | TIQDIO_THININT_ISC); | ||
3735 | } | ||
3736 | |||
3737 | static int | ||
3738 | qdio_get_qdio_memory(void) | ||
3739 | { | ||
3740 | int i; | ||
3741 | indicator_used[0]=1; | ||
3742 | |||
3743 | for (i=1;i<INDICATORS_PER_CACHELINE;i++) | ||
3744 | indicator_used[i]=0; | ||
3745 | indicators = kzalloc(sizeof(__u32)*(INDICATORS_PER_CACHELINE), | ||
3746 | GFP_KERNEL); | ||
3747 | if (!indicators) | ||
3748 | return -ENOMEM; | ||
3749 | return 0; | ||
3750 | } | ||
3751 | |||
3752 | static void | ||
3753 | qdio_release_qdio_memory(void) | ||
3754 | { | ||
3755 | kfree(indicators); | ||
3756 | } | ||
3757 | |||
3758 | static void | ||
3759 | qdio_unregister_dbf_views(void) | ||
3760 | { | ||
3761 | if (qdio_dbf_setup) | ||
3762 | debug_unregister(qdio_dbf_setup); | ||
3763 | if (qdio_dbf_sbal) | ||
3764 | debug_unregister(qdio_dbf_sbal); | ||
3765 | if (qdio_dbf_sense) | ||
3766 | debug_unregister(qdio_dbf_sense); | ||
3767 | if (qdio_dbf_trace) | ||
3768 | debug_unregister(qdio_dbf_trace); | ||
3769 | #ifdef CONFIG_QDIO_DEBUG | ||
3770 | if (qdio_dbf_slsb_out) | ||
3771 | debug_unregister(qdio_dbf_slsb_out); | ||
3772 | if (qdio_dbf_slsb_in) | ||
3773 | debug_unregister(qdio_dbf_slsb_in); | ||
3774 | #endif /* CONFIG_QDIO_DEBUG */ | ||
3775 | } | ||
3776 | |||
3777 | static int | ||
3778 | qdio_register_dbf_views(void) | ||
3779 | { | ||
3780 | qdio_dbf_setup=debug_register(QDIO_DBF_SETUP_NAME, | ||
3781 | QDIO_DBF_SETUP_PAGES, | ||
3782 | QDIO_DBF_SETUP_NR_AREAS, | ||
3783 | QDIO_DBF_SETUP_LEN); | ||
3784 | if (!qdio_dbf_setup) | ||
3785 | goto oom; | ||
3786 | debug_register_view(qdio_dbf_setup,&debug_hex_ascii_view); | ||
3787 | debug_set_level(qdio_dbf_setup,QDIO_DBF_SETUP_LEVEL); | ||
3788 | |||
3789 | qdio_dbf_sbal=debug_register(QDIO_DBF_SBAL_NAME, | ||
3790 | QDIO_DBF_SBAL_PAGES, | ||
3791 | QDIO_DBF_SBAL_NR_AREAS, | ||
3792 | QDIO_DBF_SBAL_LEN); | ||
3793 | if (!qdio_dbf_sbal) | ||
3794 | goto oom; | ||
3795 | |||
3796 | debug_register_view(qdio_dbf_sbal,&debug_hex_ascii_view); | ||
3797 | debug_set_level(qdio_dbf_sbal,QDIO_DBF_SBAL_LEVEL); | ||
3798 | |||
3799 | qdio_dbf_sense=debug_register(QDIO_DBF_SENSE_NAME, | ||
3800 | QDIO_DBF_SENSE_PAGES, | ||
3801 | QDIO_DBF_SENSE_NR_AREAS, | ||
3802 | QDIO_DBF_SENSE_LEN); | ||
3803 | if (!qdio_dbf_sense) | ||
3804 | goto oom; | ||
3805 | |||
3806 | debug_register_view(qdio_dbf_sense,&debug_hex_ascii_view); | ||
3807 | debug_set_level(qdio_dbf_sense,QDIO_DBF_SENSE_LEVEL); | ||
3808 | |||
3809 | qdio_dbf_trace=debug_register(QDIO_DBF_TRACE_NAME, | ||
3810 | QDIO_DBF_TRACE_PAGES, | ||
3811 | QDIO_DBF_TRACE_NR_AREAS, | ||
3812 | QDIO_DBF_TRACE_LEN); | ||
3813 | if (!qdio_dbf_trace) | ||
3814 | goto oom; | ||
3815 | |||
3816 | debug_register_view(qdio_dbf_trace,&debug_hex_ascii_view); | ||
3817 | debug_set_level(qdio_dbf_trace,QDIO_DBF_TRACE_LEVEL); | ||
3818 | |||
3819 | #ifdef CONFIG_QDIO_DEBUG | ||
3820 | qdio_dbf_slsb_out=debug_register(QDIO_DBF_SLSB_OUT_NAME, | ||
3821 | QDIO_DBF_SLSB_OUT_PAGES, | ||
3822 | QDIO_DBF_SLSB_OUT_NR_AREAS, | ||
3823 | QDIO_DBF_SLSB_OUT_LEN); | ||
3824 | if (!qdio_dbf_slsb_out) | ||
3825 | goto oom; | ||
3826 | debug_register_view(qdio_dbf_slsb_out,&debug_hex_ascii_view); | ||
3827 | debug_set_level(qdio_dbf_slsb_out,QDIO_DBF_SLSB_OUT_LEVEL); | ||
3828 | |||
3829 | qdio_dbf_slsb_in=debug_register(QDIO_DBF_SLSB_IN_NAME, | ||
3830 | QDIO_DBF_SLSB_IN_PAGES, | ||
3831 | QDIO_DBF_SLSB_IN_NR_AREAS, | ||
3832 | QDIO_DBF_SLSB_IN_LEN); | ||
3833 | if (!qdio_dbf_slsb_in) | ||
3834 | goto oom; | ||
3835 | debug_register_view(qdio_dbf_slsb_in,&debug_hex_ascii_view); | ||
3836 | debug_set_level(qdio_dbf_slsb_in,QDIO_DBF_SLSB_IN_LEVEL); | ||
3837 | #endif /* CONFIG_QDIO_DEBUG */ | ||
3838 | return 0; | ||
3839 | oom: | ||
3840 | QDIO_PRINT_ERR("not enough memory for dbf.\n"); | ||
3841 | qdio_unregister_dbf_views(); | ||
3842 | return -ENOMEM; | ||
3843 | } | ||
3844 | |||
3845 | static void *qdio_mempool_alloc(gfp_t gfp_mask, void *size) | ||
3846 | { | ||
3847 | return (void *) get_zeroed_page(gfp_mask|GFP_DMA); | ||
3848 | } | ||
3849 | |||
3850 | static void qdio_mempool_free(void *element, void *size) | ||
3851 | { | ||
3852 | free_page((unsigned long) element); | ||
3853 | } | ||
3854 | |||
3855 | static int __init | ||
3856 | init_QDIO(void) | ||
3857 | { | ||
3858 | int res; | ||
3859 | void *ptr; | ||
3860 | |||
3861 | printk("qdio: loading %s\n",version); | ||
3862 | |||
3863 | res=qdio_get_qdio_memory(); | ||
3864 | if (res) | ||
3865 | return res; | ||
3866 | |||
3867 | qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q), | ||
3868 | 256, 0, NULL); | ||
3869 | if (!qdio_q_cache) { | ||
3870 | qdio_release_qdio_memory(); | ||
3871 | return -ENOMEM; | ||
3872 | } | ||
3873 | |||
3874 | res = qdio_register_dbf_views(); | ||
3875 | if (res) { | ||
3876 | kmem_cache_destroy(qdio_q_cache); | ||
3877 | qdio_release_qdio_memory(); | ||
3878 | return res; | ||
3879 | } | ||
3880 | |||
3881 | QDIO_DBF_TEXT0(0,setup,"initQDIO"); | ||
3882 | res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats); | ||
3883 | |||
3884 | memset((void*)&perf_stats,0,sizeof(perf_stats)); | ||
3885 | QDIO_DBF_TEXT0(0,setup,"perfstat"); | ||
3886 | ptr=&perf_stats; | ||
3887 | QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*)); | ||
3888 | |||
3889 | qdio_add_procfs_entry(); | ||
3890 | |||
3891 | qdio_mempool_scssc = mempool_create(QDIO_MEMPOOL_SCSSC_ELEMENTS, | ||
3892 | qdio_mempool_alloc, | ||
3893 | qdio_mempool_free, NULL); | ||
3894 | |||
3895 | isc_register(QDIO_AIRQ_ISC); | ||
3896 | if (tiqdio_check_chsc_availability()) | ||
3897 | QDIO_PRINT_ERR("Not all CHSCs supported. Continuing.\n"); | ||
3898 | |||
3899 | tiqdio_register_thinints(); | ||
3900 | |||
3901 | return 0; | ||
3902 | } | ||
3903 | |||
3904 | static void __exit | ||
3905 | cleanup_QDIO(void) | ||
3906 | { | ||
3907 | tiqdio_unregister_thinints(); | ||
3908 | isc_unregister(QDIO_AIRQ_ISC); | ||
3909 | qdio_remove_procfs_entry(); | ||
3910 | qdio_release_qdio_memory(); | ||
3911 | qdio_unregister_dbf_views(); | ||
3912 | mempool_destroy(qdio_mempool_scssc); | ||
3913 | kmem_cache_destroy(qdio_q_cache); | ||
3914 | bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats); | ||
3915 | printk("qdio: %s: module removed\n",version); | ||
3916 | } | ||
3917 | |||
3918 | module_init(init_QDIO); | ||
3919 | module_exit(cleanup_QDIO); | ||
3920 | |||
3921 | EXPORT_SYMBOL(qdio_allocate); | ||
3922 | EXPORT_SYMBOL(qdio_establish); | ||
3923 | EXPORT_SYMBOL(qdio_initialize); | ||
3924 | EXPORT_SYMBOL(qdio_activate); | ||
3925 | EXPORT_SYMBOL(do_QDIO); | ||
3926 | EXPORT_SYMBOL(qdio_shutdown); | ||
3927 | EXPORT_SYMBOL(qdio_free); | ||
3928 | EXPORT_SYMBOL(qdio_cleanup); | ||
3929 | EXPORT_SYMBOL(qdio_synchronize); | ||
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h index 7656081a24d2..c1a70985abfa 100644 --- a/drivers/s390/cio/qdio.h +++ b/drivers/s390/cio/qdio.h | |||
@@ -1,66 +1,20 @@ | |||
1 | /* | ||
2 | * linux/drivers/s390/cio/qdio.h | ||
3 | * | ||
4 | * Copyright 2000,2008 IBM Corp. | ||
5 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com> | ||
6 | * Jan Glauber <jang@linux.vnet.ibm.com> | ||
7 | */ | ||
1 | #ifndef _CIO_QDIO_H | 8 | #ifndef _CIO_QDIO_H |
2 | #define _CIO_QDIO_H | 9 | #define _CIO_QDIO_H |
3 | 10 | ||
4 | #include <asm/page.h> | 11 | #include <asm/page.h> |
5 | #include <asm/isc.h> | ||
6 | #include <asm/schid.h> | 12 | #include <asm/schid.h> |
13 | #include "chsc.h" | ||
7 | 14 | ||
8 | #ifdef CONFIG_QDIO_DEBUG | 15 | #define QDIO_BUSY_BIT_PATIENCE 100 /* 100 microseconds */ |
9 | #define QDIO_VERBOSE_LEVEL 9 | 16 | #define QDIO_BUSY_BIT_GIVE_UP 2000000 /* 2 seconds = eternity */ |
10 | #else /* CONFIG_QDIO_DEBUG */ | 17 | #define QDIO_INPUT_THRESHOLD 500 /* 500 microseconds */ |
11 | #define QDIO_VERBOSE_LEVEL 5 | ||
12 | #endif /* CONFIG_QDIO_DEBUG */ | ||
13 | #define QDIO_USE_PROCESSING_STATE | ||
14 | |||
15 | #define QDIO_MINIMAL_BH_RELIEF_TIME 16 | ||
16 | #define QDIO_TIMER_POLL_VALUE 1 | ||
17 | #define IQDIO_TIMER_POLL_VALUE 1 | ||
18 | |||
19 | /* | ||
20 | * unfortunately this can't be (QDIO_MAX_BUFFERS_PER_Q*4/3) or so -- as | ||
21 | * we never know, whether we'll get initiative again, e.g. to give the | ||
22 | * transmit skb's back to the stack, however the stack may be waiting for | ||
23 | * them... therefore we define 4 as threshold to start polling (which | ||
24 | * will stop as soon as the asynchronous queue catches up) | ||
25 | * btw, this only applies to the asynchronous HiperSockets queue | ||
26 | */ | ||
27 | #define IQDIO_FILL_LEVEL_TO_POLL 4 | ||
28 | |||
29 | #define TIQDIO_THININT_ISC QDIO_AIRQ_ISC | ||
30 | #define TIQDIO_DELAY_TARGET 0 | ||
31 | #define QDIO_BUSY_BIT_PATIENCE 100 /* in microsecs */ | ||
32 | #define QDIO_BUSY_BIT_GIVE_UP 10000000 /* 10 seconds */ | ||
33 | #define IQDIO_GLOBAL_LAPS 2 /* GLOBAL_LAPS are not used as we */ | ||
34 | #define IQDIO_GLOBAL_LAPS_INT 1 /* don't global summary */ | ||
35 | #define IQDIO_LOCAL_LAPS 4 | ||
36 | #define IQDIO_LOCAL_LAPS_INT 1 | ||
37 | #define IQDIO_GLOBAL_SUMMARY_CC_MASK 2 | ||
38 | /*#define IQDIO_IQDC_INT_PARM 0x1234*/ | ||
39 | |||
40 | #define QDIO_Q_LAPS 5 | ||
41 | |||
42 | #define QDIO_STORAGE_KEY PAGE_DEFAULT_KEY | ||
43 | |||
44 | #define L2_CACHELINE_SIZE 256 | ||
45 | #define INDICATORS_PER_CACHELINE (L2_CACHELINE_SIZE/sizeof(__u32)) | ||
46 | |||
47 | #define QDIO_PERF "qdio_perf" | ||
48 | |||
49 | /* must be a power of 2 */ | ||
50 | /*#define QDIO_STATS_NUMBER 4 | ||
51 | |||
52 | #define QDIO_STATS_CLASSES 2 | ||
53 | #define QDIO_STATS_COUNT_NEEDED 2*/ | ||
54 | |||
55 | #define QDIO_NO_USE_COUNT_TIMEOUT (1*HZ) /* wait for 1 sec on each q before | ||
56 | exiting without having use_count | ||
57 | of the queue to 0 */ | ||
58 | |||
59 | #define QDIO_ESTABLISH_TIMEOUT (1*HZ) | ||
60 | #define QDIO_CLEANUP_CLEAR_TIMEOUT (20*HZ) | ||
61 | #define QDIO_CLEANUP_HALT_TIMEOUT (10*HZ) | ||
62 | #define QDIO_FORCE_CHECK_TIMEOUT (10*HZ) | ||
63 | #define QDIO_ACTIVATE_TIMEOUT (5) /* 5 ms */ | ||
64 | 18 | ||
65 | enum qdio_irq_states { | 19 | enum qdio_irq_states { |
66 | QDIO_IRQ_STATE_INACTIVE, | 20 | QDIO_IRQ_STATE_INACTIVE, |
@@ -72,565 +26,352 @@ enum qdio_irq_states { | |||
72 | NR_QDIO_IRQ_STATES, | 26 | NR_QDIO_IRQ_STATES, |
73 | }; | 27 | }; |
74 | 28 | ||
75 | /* used as intparm in do_IO: */ | 29 | /* used as intparm in do_IO */ |
76 | #define QDIO_DOING_SENSEID 0 | 30 | #define QDIO_DOING_ESTABLISH 1 |
77 | #define QDIO_DOING_ESTABLISH 1 | 31 | #define QDIO_DOING_ACTIVATE 2 |
78 | #define QDIO_DOING_ACTIVATE 2 | 32 | #define QDIO_DOING_CLEANUP 3 |
79 | #define QDIO_DOING_CLEANUP 3 | 33 | |
80 | 34 | #define SLSB_STATE_NOT_INIT 0x0 | |
81 | /************************* DEBUG FACILITY STUFF *********************/ | 35 | #define SLSB_STATE_EMPTY 0x1 |
82 | 36 | #define SLSB_STATE_PRIMED 0x2 | |
83 | #define QDIO_DBF_HEX(ex,name,level,addr,len) \ | 37 | #define SLSB_STATE_HALTED 0xe |
84 | do { \ | 38 | #define SLSB_STATE_ERROR 0xf |
85 | if (ex) \ | 39 | #define SLSB_TYPE_INPUT 0x0 |
86 | debug_exception(qdio_dbf_##name,level,(void*)(addr),len); \ | 40 | #define SLSB_TYPE_OUTPUT 0x20 |
87 | else \ | 41 | #define SLSB_OWNER_PROG 0x80 |
88 | debug_event(qdio_dbf_##name,level,(void*)(addr),len); \ | 42 | #define SLSB_OWNER_CU 0x40 |
89 | } while (0) | 43 | |
90 | #define QDIO_DBF_TEXT(ex,name,level,text) \ | 44 | #define SLSB_P_INPUT_NOT_INIT \ |
91 | do { \ | 45 | (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_NOT_INIT) /* 0x80 */ |
92 | if (ex) \ | 46 | #define SLSB_P_INPUT_ACK \ |
93 | debug_text_exception(qdio_dbf_##name,level,text); \ | 47 | (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x81 */ |
94 | else \ | 48 | #define SLSB_CU_INPUT_EMPTY \ |
95 | debug_text_event(qdio_dbf_##name,level,text); \ | 49 | (SLSB_OWNER_CU | SLSB_TYPE_INPUT | SLSB_STATE_EMPTY) /* 0x41 */ |
96 | } while (0) | 50 | #define SLSB_P_INPUT_PRIMED \ |
97 | 51 | (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_PRIMED) /* 0x82 */ | |
98 | 52 | #define SLSB_P_INPUT_HALTED \ | |
99 | #define QDIO_DBF_HEX0(ex,name,addr,len) QDIO_DBF_HEX(ex,name,0,addr,len) | 53 | (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_HALTED) /* 0x8e */ |
100 | #define QDIO_DBF_HEX1(ex,name,addr,len) QDIO_DBF_HEX(ex,name,1,addr,len) | 54 | #define SLSB_P_INPUT_ERROR \ |
101 | #define QDIO_DBF_HEX2(ex,name,addr,len) QDIO_DBF_HEX(ex,name,2,addr,len) | 55 | (SLSB_OWNER_PROG | SLSB_TYPE_INPUT | SLSB_STATE_ERROR) /* 0x8f */ |
102 | #ifdef CONFIG_QDIO_DEBUG | 56 | #define SLSB_P_OUTPUT_NOT_INIT \ |
103 | #define QDIO_DBF_HEX3(ex,name,addr,len) QDIO_DBF_HEX(ex,name,3,addr,len) | 57 | (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_NOT_INIT) /* 0xa0 */ |
104 | #define QDIO_DBF_HEX4(ex,name,addr,len) QDIO_DBF_HEX(ex,name,4,addr,len) | 58 | #define SLSB_P_OUTPUT_EMPTY \ |
105 | #define QDIO_DBF_HEX5(ex,name,addr,len) QDIO_DBF_HEX(ex,name,5,addr,len) | 59 | (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_EMPTY) /* 0xa1 */ |
106 | #define QDIO_DBF_HEX6(ex,name,addr,len) QDIO_DBF_HEX(ex,name,6,addr,len) | 60 | #define SLSB_CU_OUTPUT_PRIMED \ |
107 | #else /* CONFIG_QDIO_DEBUG */ | 61 | (SLSB_OWNER_CU | SLSB_TYPE_OUTPUT | SLSB_STATE_PRIMED) /* 0x62 */ |
108 | #define QDIO_DBF_HEX3(ex,name,addr,len) do {} while (0) | 62 | #define SLSB_P_OUTPUT_HALTED \ |
109 | #define QDIO_DBF_HEX4(ex,name,addr,len) do {} while (0) | 63 | (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_HALTED) /* 0xae */ |
110 | #define QDIO_DBF_HEX5(ex,name,addr,len) do {} while (0) | 64 | #define SLSB_P_OUTPUT_ERROR \ |
111 | #define QDIO_DBF_HEX6(ex,name,addr,len) do {} while (0) | 65 | (SLSB_OWNER_PROG | SLSB_TYPE_OUTPUT | SLSB_STATE_ERROR) /* 0xaf */ |
112 | #endif /* CONFIG_QDIO_DEBUG */ | 66 | |
113 | 67 | #define SLSB_ERROR_DURING_LOOKUP 0xff | |
114 | #define QDIO_DBF_TEXT0(ex,name,text) QDIO_DBF_TEXT(ex,name,0,text) | 68 | |
115 | #define QDIO_DBF_TEXT1(ex,name,text) QDIO_DBF_TEXT(ex,name,1,text) | 69 | /* additional CIWs returned by extended Sense-ID */ |
116 | #define QDIO_DBF_TEXT2(ex,name,text) QDIO_DBF_TEXT(ex,name,2,text) | 70 | #define CIW_TYPE_EQUEUE 0x3 /* establish QDIO queues */ |
117 | #ifdef CONFIG_QDIO_DEBUG | 71 | #define CIW_TYPE_AQUEUE 0x4 /* activate QDIO queues */ |
118 | #define QDIO_DBF_TEXT3(ex,name,text) QDIO_DBF_TEXT(ex,name,3,text) | ||
119 | #define QDIO_DBF_TEXT4(ex,name,text) QDIO_DBF_TEXT(ex,name,4,text) | ||
120 | #define QDIO_DBF_TEXT5(ex,name,text) QDIO_DBF_TEXT(ex,name,5,text) | ||
121 | #define QDIO_DBF_TEXT6(ex,name,text) QDIO_DBF_TEXT(ex,name,6,text) | ||
122 | #else /* CONFIG_QDIO_DEBUG */ | ||
123 | #define QDIO_DBF_TEXT3(ex,name,text) do {} while (0) | ||
124 | #define QDIO_DBF_TEXT4(ex,name,text) do {} while (0) | ||
125 | #define QDIO_DBF_TEXT5(ex,name,text) do {} while (0) | ||
126 | #define QDIO_DBF_TEXT6(ex,name,text) do {} while (0) | ||
127 | #endif /* CONFIG_QDIO_DEBUG */ | ||
128 | |||
129 | #define QDIO_DBF_SETUP_NAME "qdio_setup" | ||
130 | #define QDIO_DBF_SETUP_LEN 8 | ||
131 | #define QDIO_DBF_SETUP_PAGES 4 | ||
132 | #define QDIO_DBF_SETUP_NR_AREAS 1 | ||
133 | #ifdef CONFIG_QDIO_DEBUG | ||
134 | #define QDIO_DBF_SETUP_LEVEL 6 | ||
135 | #else /* CONFIG_QDIO_DEBUG */ | ||
136 | #define QDIO_DBF_SETUP_LEVEL 2 | ||
137 | #endif /* CONFIG_QDIO_DEBUG */ | ||
138 | |||
139 | #define QDIO_DBF_SBAL_NAME "qdio_labs" /* sbal */ | ||
140 | #define QDIO_DBF_SBAL_LEN 256 | ||
141 | #define QDIO_DBF_SBAL_PAGES 4 | ||
142 | #define QDIO_DBF_SBAL_NR_AREAS 2 | ||
143 | #ifdef CONFIG_QDIO_DEBUG | ||
144 | #define QDIO_DBF_SBAL_LEVEL 6 | ||
145 | #else /* CONFIG_QDIO_DEBUG */ | ||
146 | #define QDIO_DBF_SBAL_LEVEL 2 | ||
147 | #endif /* CONFIG_QDIO_DEBUG */ | ||
148 | |||
149 | #define QDIO_DBF_TRACE_NAME "qdio_trace" | ||
150 | #define QDIO_DBF_TRACE_LEN 8 | ||
151 | #define QDIO_DBF_TRACE_NR_AREAS 2 | ||
152 | #ifdef CONFIG_QDIO_DEBUG | ||
153 | #define QDIO_DBF_TRACE_PAGES 16 | ||
154 | #define QDIO_DBF_TRACE_LEVEL 4 /* -------- could be even more verbose here */ | ||
155 | #else /* CONFIG_QDIO_DEBUG */ | ||
156 | #define QDIO_DBF_TRACE_PAGES 4 | ||
157 | #define QDIO_DBF_TRACE_LEVEL 2 | ||
158 | #endif /* CONFIG_QDIO_DEBUG */ | ||
159 | |||
160 | #define QDIO_DBF_SENSE_NAME "qdio_sense" | ||
161 | #define QDIO_DBF_SENSE_LEN 64 | ||
162 | #define QDIO_DBF_SENSE_PAGES 2 | ||
163 | #define QDIO_DBF_SENSE_NR_AREAS 1 | ||
164 | #ifdef CONFIG_QDIO_DEBUG | ||
165 | #define QDIO_DBF_SENSE_LEVEL 6 | ||
166 | #else /* CONFIG_QDIO_DEBUG */ | ||
167 | #define QDIO_DBF_SENSE_LEVEL 2 | ||
168 | #endif /* CONFIG_QDIO_DEBUG */ | ||
169 | |||
170 | #ifdef CONFIG_QDIO_DEBUG | ||
171 | #define QDIO_TRACE_QTYPE QDIO_ZFCP_QFMT | ||
172 | |||
173 | #define QDIO_DBF_SLSB_OUT_NAME "qdio_slsb_out" | ||
174 | #define QDIO_DBF_SLSB_OUT_LEN QDIO_MAX_BUFFERS_PER_Q | ||
175 | #define QDIO_DBF_SLSB_OUT_PAGES 256 | ||
176 | #define QDIO_DBF_SLSB_OUT_NR_AREAS 1 | ||
177 | #define QDIO_DBF_SLSB_OUT_LEVEL 6 | ||
178 | |||
179 | #define QDIO_DBF_SLSB_IN_NAME "qdio_slsb_in" | ||
180 | #define QDIO_DBF_SLSB_IN_LEN QDIO_MAX_BUFFERS_PER_Q | ||
181 | #define QDIO_DBF_SLSB_IN_PAGES 256 | ||
182 | #define QDIO_DBF_SLSB_IN_NR_AREAS 1 | ||
183 | #define QDIO_DBF_SLSB_IN_LEVEL 6 | ||
184 | #endif /* CONFIG_QDIO_DEBUG */ | ||
185 | |||
186 | #define QDIO_PRINTK_HEADER QDIO_NAME ": " | ||
187 | |||
188 | #if QDIO_VERBOSE_LEVEL>8 | ||
189 | #define QDIO_PRINT_STUPID(x...) printk( KERN_DEBUG QDIO_PRINTK_HEADER x) | ||
190 | #else | ||
191 | #define QDIO_PRINT_STUPID(x...) do { } while (0) | ||
192 | #endif | ||
193 | 72 | ||
194 | #if QDIO_VERBOSE_LEVEL>7 | 73 | /* flags for st qdio sch data */ |
195 | #define QDIO_PRINT_ALL(x...) printk( QDIO_PRINTK_HEADER x) | 74 | #define CHSC_FLAG_QDIO_CAPABILITY 0x80 |
196 | #else | 75 | #define CHSC_FLAG_VALIDITY 0x40 |
197 | #define QDIO_PRINT_ALL(x...) do { } while (0) | 76 | |
198 | #endif | 77 | /* qdio adapter-characteristics-1 flag */ |
199 | 78 | #define AC1_SIGA_INPUT_NEEDED 0x40 /* process input queues */ | |
200 | #if QDIO_VERBOSE_LEVEL>6 | 79 | #define AC1_SIGA_OUTPUT_NEEDED 0x20 /* process output queues */ |
201 | #define QDIO_PRINT_INFO(x...) printk( QDIO_PRINTK_HEADER x) | 80 | #define AC1_SIGA_SYNC_NEEDED 0x10 /* ask hypervisor to sync */ |
202 | #else | 81 | #define AC1_AUTOMATIC_SYNC_ON_THININT 0x08 /* set by hypervisor */ |
203 | #define QDIO_PRINT_INFO(x...) do { } while (0) | 82 | #define AC1_AUTOMATIC_SYNC_ON_OUT_PCI 0x04 /* set by hypervisor */ |
204 | #endif | 83 | #define AC1_SC_QEBSM_AVAILABLE 0x02 /* available for subchannel */ |
205 | 84 | #define AC1_SC_QEBSM_ENABLED 0x01 /* enabled for subchannel */ | |
206 | #if QDIO_VERBOSE_LEVEL>5 | ||
207 | #define QDIO_PRINT_WARN(x...) printk( QDIO_PRINTK_HEADER x) | ||
208 | #else | ||
209 | #define QDIO_PRINT_WARN(x...) do { } while (0) | ||
210 | #endif | ||
211 | |||
212 | #if QDIO_VERBOSE_LEVEL>4 | ||
213 | #define QDIO_PRINT_ERR(x...) printk( QDIO_PRINTK_HEADER x) | ||
214 | #else | ||
215 | #define QDIO_PRINT_ERR(x...) do { } while (0) | ||
216 | #endif | ||
217 | |||
218 | #if QDIO_VERBOSE_LEVEL>3 | ||
219 | #define QDIO_PRINT_CRIT(x...) printk( QDIO_PRINTK_HEADER x) | ||
220 | #else | ||
221 | #define QDIO_PRINT_CRIT(x...) do { } while (0) | ||
222 | #endif | ||
223 | |||
224 | #if QDIO_VERBOSE_LEVEL>2 | ||
225 | #define QDIO_PRINT_ALERT(x...) printk( QDIO_PRINTK_HEADER x) | ||
226 | #else | ||
227 | #define QDIO_PRINT_ALERT(x...) do { } while (0) | ||
228 | #endif | ||
229 | 85 | ||
230 | #if QDIO_VERBOSE_LEVEL>1 | 86 | #ifdef CONFIG_64BIT |
231 | #define QDIO_PRINT_EMERG(x...) printk( QDIO_PRINTK_HEADER x) | 87 | static inline int do_sqbs(u64 token, unsigned char state, int queue, |
232 | #else | 88 | int *start, int *count) |
233 | #define QDIO_PRINT_EMERG(x...) do { } while (0) | 89 | { |
234 | #endif | 90 | register unsigned long _ccq asm ("0") = *count; |
235 | 91 | register unsigned long _token asm ("1") = token; | |
236 | #define QDIO_HEXDUMP16(importance,header,ptr) \ | 92 | unsigned long _queuestart = ((unsigned long)queue << 32) | *start; |
237 | QDIO_PRINT_##importance(header "%02x %02x %02x %02x " \ | ||
238 | "%02x %02x %02x %02x %02x %02x %02x %02x " \ | ||
239 | "%02x %02x %02x %02x\n",*(((char*)ptr)), \ | ||
240 | *(((char*)ptr)+1),*(((char*)ptr)+2), \ | ||
241 | *(((char*)ptr)+3),*(((char*)ptr)+4), \ | ||
242 | *(((char*)ptr)+5),*(((char*)ptr)+6), \ | ||
243 | *(((char*)ptr)+7),*(((char*)ptr)+8), \ | ||
244 | *(((char*)ptr)+9),*(((char*)ptr)+10), \ | ||
245 | *(((char*)ptr)+11),*(((char*)ptr)+12), \ | ||
246 | *(((char*)ptr)+13),*(((char*)ptr)+14), \ | ||
247 | *(((char*)ptr)+15)); \ | ||
248 | QDIO_PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \ | ||
249 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", \ | ||
250 | *(((char*)ptr)+16),*(((char*)ptr)+17), \ | ||
251 | *(((char*)ptr)+18),*(((char*)ptr)+19), \ | ||
252 | *(((char*)ptr)+20),*(((char*)ptr)+21), \ | ||
253 | *(((char*)ptr)+22),*(((char*)ptr)+23), \ | ||
254 | *(((char*)ptr)+24),*(((char*)ptr)+25), \ | ||
255 | *(((char*)ptr)+26),*(((char*)ptr)+27), \ | ||
256 | *(((char*)ptr)+28),*(((char*)ptr)+29), \ | ||
257 | *(((char*)ptr)+30),*(((char*)ptr)+31)); | ||
258 | |||
259 | /****************** END OF DEBUG FACILITY STUFF *********************/ | ||
260 | 93 | ||
261 | /* | 94 | asm volatile( |
262 | * Some instructions as assembly | 95 | " .insn rsy,0xeb000000008A,%1,0,0(%2)" |
263 | */ | 96 | : "+d" (_ccq), "+d" (_queuestart) |
97 | : "d" ((unsigned long)state), "d" (_token) | ||
98 | : "memory", "cc"); | ||
99 | *count = _ccq & 0xff; | ||
100 | *start = _queuestart & 0xff; | ||
264 | 101 | ||
265 | static inline int | 102 | return (_ccq >> 32) & 0xff; |
266 | do_sqbs(unsigned long sch, unsigned char state, int queue, | ||
267 | unsigned int *start, unsigned int *count) | ||
268 | { | ||
269 | #ifdef CONFIG_64BIT | ||
270 | register unsigned long _ccq asm ("0") = *count; | ||
271 | register unsigned long _sch asm ("1") = sch; | ||
272 | unsigned long _queuestart = ((unsigned long)queue << 32) | *start; | ||
273 | |||
274 | asm volatile( | ||
275 | " .insn rsy,0xeb000000008A,%1,0,0(%2)" | ||
276 | : "+d" (_ccq), "+d" (_queuestart) | ||
277 | : "d" ((unsigned long)state), "d" (_sch) | ||
278 | : "memory", "cc"); | ||
279 | *count = _ccq & 0xff; | ||
280 | *start = _queuestart & 0xff; | ||
281 | |||
282 | return (_ccq >> 32) & 0xff; | ||
283 | #else | ||
284 | return 0; | ||
285 | #endif | ||
286 | } | 103 | } |
287 | 104 | ||
288 | static inline int | 105 | static inline int do_eqbs(u64 token, unsigned char *state, int queue, |
289 | do_eqbs(unsigned long sch, unsigned char *state, int queue, | 106 | int *start, int *count) |
290 | unsigned int *start, unsigned int *count) | ||
291 | { | 107 | { |
292 | #ifdef CONFIG_64BIT | ||
293 | register unsigned long _ccq asm ("0") = *count; | 108 | register unsigned long _ccq asm ("0") = *count; |
294 | register unsigned long _sch asm ("1") = sch; | 109 | register unsigned long _token asm ("1") = token; |
295 | unsigned long _queuestart = ((unsigned long)queue << 32) | *start; | 110 | unsigned long _queuestart = ((unsigned long)queue << 32) | *start; |
296 | unsigned long _state = 0; | 111 | unsigned long _state = 0; |
297 | 112 | ||
298 | asm volatile( | 113 | asm volatile( |
299 | " .insn rrf,0xB99c0000,%1,%2,0,0" | 114 | " .insn rrf,0xB99c0000,%1,%2,0,0" |
300 | : "+d" (_ccq), "+d" (_queuestart), "+d" (_state) | 115 | : "+d" (_ccq), "+d" (_queuestart), "+d" (_state) |
301 | : "d" (_sch) | 116 | : "d" (_token) |
302 | : "memory", "cc" ); | 117 | : "memory", "cc"); |
303 | *count = _ccq & 0xff; | 118 | *count = _ccq & 0xff; |
304 | *start = _queuestart & 0xff; | 119 | *start = _queuestart & 0xff; |
305 | *state = _state & 0xff; | 120 | *state = _state & 0xff; |
306 | 121 | ||
307 | return (_ccq >> 32) & 0xff; | 122 | return (_ccq >> 32) & 0xff; |
308 | #else | ||
309 | return 0; | ||
310 | #endif | ||
311 | } | ||
312 | |||
313 | |||
314 | static inline int | ||
315 | do_siga_sync(struct subchannel_id schid, unsigned int mask1, unsigned int mask2) | ||
316 | { | ||
317 | register unsigned long reg0 asm ("0") = 2; | ||
318 | register struct subchannel_id reg1 asm ("1") = schid; | ||
319 | register unsigned long reg2 asm ("2") = mask1; | ||
320 | register unsigned long reg3 asm ("3") = mask2; | ||
321 | int cc; | ||
322 | |||
323 | asm volatile( | ||
324 | " siga 0\n" | ||
325 | " ipm %0\n" | ||
326 | " srl %0,28\n" | ||
327 | : "=d" (cc) | ||
328 | : "d" (reg0), "d" (reg1), "d" (reg2), "d" (reg3) : "cc"); | ||
329 | return cc; | ||
330 | } | ||
331 | |||
332 | static inline int | ||
333 | do_siga_input(struct subchannel_id schid, unsigned int mask) | ||
334 | { | ||
335 | register unsigned long reg0 asm ("0") = 1; | ||
336 | register struct subchannel_id reg1 asm ("1") = schid; | ||
337 | register unsigned long reg2 asm ("2") = mask; | ||
338 | int cc; | ||
339 | |||
340 | asm volatile( | ||
341 | " siga 0\n" | ||
342 | " ipm %0\n" | ||
343 | " srl %0,28\n" | ||
344 | : "=d" (cc) | ||
345 | : "d" (reg0), "d" (reg1), "d" (reg2) : "cc", "memory"); | ||
346 | return cc; | ||
347 | } | ||
348 | |||
349 | static inline int | ||
350 | do_siga_output(unsigned long schid, unsigned long mask, __u32 *bb, | ||
351 | unsigned int fc) | ||
352 | { | ||
353 | register unsigned long __fc asm("0") = fc; | ||
354 | register unsigned long __schid asm("1") = schid; | ||
355 | register unsigned long __mask asm("2") = mask; | ||
356 | int cc; | ||
357 | |||
358 | asm volatile( | ||
359 | " siga 0\n" | ||
360 | "0: ipm %0\n" | ||
361 | " srl %0,28\n" | ||
362 | "1:\n" | ||
363 | EX_TABLE(0b,1b) | ||
364 | : "=d" (cc), "+d" (__fc), "+d" (__schid), "+d" (__mask) | ||
365 | : "0" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION) | ||
366 | : "cc", "memory"); | ||
367 | (*bb) = ((unsigned int) __fc) >> 31; | ||
368 | return cc; | ||
369 | } | ||
370 | |||
371 | static inline unsigned long | ||
372 | do_clear_global_summary(void) | ||
373 | { | ||
374 | register unsigned long __fn asm("1") = 3; | ||
375 | register unsigned long __tmp asm("2"); | ||
376 | register unsigned long __time asm("3"); | ||
377 | |||
378 | asm volatile( | ||
379 | " .insn rre,0xb2650000,2,0" | ||
380 | : "+d" (__fn), "=d" (__tmp), "=d" (__time)); | ||
381 | return __time; | ||
382 | } | 123 | } |
383 | 124 | #else | |
384 | /* | 125 | static inline int do_sqbs(u64 token, unsigned char state, int queue, |
385 | * QDIO device commands returned by extended Sense-ID | 126 | int *start, int *count) { return 0; } |
386 | */ | 127 | static inline int do_eqbs(u64 token, unsigned char *state, int queue, |
387 | #define DEFAULT_ESTABLISH_QS_CMD 0x1b | 128 | int *start, int *count) { return 0; } |
388 | #define DEFAULT_ESTABLISH_QS_COUNT 0x1000 | 129 | #endif /* CONFIG_64BIT */ |
389 | #define DEFAULT_ACTIVATE_QS_CMD 0x1f | ||
390 | #define DEFAULT_ACTIVATE_QS_COUNT 0 | ||
391 | |||
392 | /* | ||
393 | * additional CIWs returned by extended Sense-ID | ||
394 | */ | ||
395 | #define CIW_TYPE_EQUEUE 0x3 /* establish QDIO queues */ | ||
396 | #define CIW_TYPE_AQUEUE 0x4 /* activate QDIO queues */ | ||
397 | 130 | ||
398 | #define QDIO_CHSC_RESPONSE_CODE_OK 1 | 131 | struct qdio_irq; |
399 | /* flags for st qdio sch data */ | ||
400 | #define CHSC_FLAG_QDIO_CAPABILITY 0x80 | ||
401 | #define CHSC_FLAG_VALIDITY 0x40 | ||
402 | 132 | ||
403 | #define CHSC_FLAG_SIGA_INPUT_NECESSARY 0x40 | 133 | struct siga_flag { |
404 | #define CHSC_FLAG_SIGA_OUTPUT_NECESSARY 0x20 | 134 | u8 input:1; |
405 | #define CHSC_FLAG_SIGA_SYNC_NECESSARY 0x10 | 135 | u8 output:1; |
406 | #define CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS 0x08 | 136 | u8 sync:1; |
407 | #define CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS 0x04 | 137 | u8 no_sync_ti:1; |
138 | u8 no_sync_out_ti:1; | ||
139 | u8 no_sync_out_pci:1; | ||
140 | u8:2; | ||
141 | } __attribute__ ((packed)); | ||
408 | 142 | ||
409 | struct qdio_chsc_ssqd { | 143 | struct chsc_ssqd_area { |
410 | struct chsc_header request; | 144 | struct chsc_header request; |
411 | u16 reserved1:10; | 145 | u16:10; |
412 | u16 ssid:2; | 146 | u8 ssid:2; |
413 | u16 fmt:4; | 147 | u8 fmt:4; |
414 | u16 first_sch; | 148 | u16 first_sch; |
415 | u16 reserved2; | 149 | u16:16; |
416 | u16 last_sch; | 150 | u16 last_sch; |
417 | u32 reserved3; | 151 | u32:32; |
418 | struct chsc_header response; | 152 | struct chsc_header response; |
419 | u32 reserved4; | 153 | u32:32; |
420 | u8 flags; | 154 | struct qdio_ssqd_desc qdio_ssqd; |
421 | u8 reserved5; | 155 | } __attribute__ ((packed)); |
422 | u16 sch; | ||
423 | u8 qfmt; | ||
424 | u8 parm; | ||
425 | u8 qdioac1; | ||
426 | u8 sch_class; | ||
427 | u8 pct; | ||
428 | u8 icnt; | ||
429 | u8 reserved7; | ||
430 | u8 ocnt; | ||
431 | u8 reserved8; | ||
432 | u8 mbccnt; | ||
433 | u16 qdioac2; | ||
434 | u64 sch_token; | ||
435 | }; | ||
436 | 156 | ||
437 | struct qdio_perf_stats { | 157 | struct scssc_area { |
438 | #ifdef CONFIG_64BIT | 158 | struct chsc_header request; |
439 | atomic64_t tl_runs; | 159 | u16 operation_code; |
440 | atomic64_t outbound_tl_runs; | 160 | u16:16; |
441 | atomic64_t outbound_tl_runs_resched; | 161 | u32:32; |
442 | atomic64_t inbound_tl_runs; | 162 | u32:32; |
443 | atomic64_t inbound_tl_runs_resched; | 163 | u64 summary_indicator_addr; |
444 | atomic64_t inbound_thin_tl_runs; | 164 | u64 subchannel_indicator_addr; |
445 | atomic64_t inbound_thin_tl_runs_resched; | 165 | u32 ks:4; |
446 | 166 | u32 kc:4; | |
447 | atomic64_t siga_outs; | 167 | u32:21; |
448 | atomic64_t siga_ins; | 168 | u32 isc:3; |
449 | atomic64_t siga_syncs; | 169 | u32 word_with_d_bit; |
450 | atomic64_t pcis; | 170 | u32:32; |
451 | atomic64_t thinints; | 171 | struct subchannel_id schid; |
452 | atomic64_t fast_reqs; | 172 | u32 reserved[1004]; |
453 | 173 | struct chsc_header response; | |
454 | atomic64_t outbound_cnt; | 174 | u32:32; |
455 | atomic64_t inbound_cnt; | 175 | } __attribute__ ((packed)); |
456 | #else /* CONFIG_64BIT */ | 176 | |
457 | atomic_t tl_runs; | 177 | struct qdio_input_q { |
458 | atomic_t outbound_tl_runs; | 178 | /* input buffer acknowledgement flag */ |
459 | atomic_t outbound_tl_runs_resched; | 179 | int polling; |
460 | atomic_t inbound_tl_runs; | 180 | |
461 | atomic_t inbound_tl_runs_resched; | 181 | /* last time of noticing incoming data */ |
462 | atomic_t inbound_thin_tl_runs; | 182 | u64 timestamp; |
463 | atomic_t inbound_thin_tl_runs_resched; | 183 | |
464 | 184 | /* lock for clearing the acknowledgement */ | |
465 | atomic_t siga_outs; | 185 | spinlock_t lock; |
466 | atomic_t siga_ins; | ||
467 | atomic_t siga_syncs; | ||
468 | atomic_t pcis; | ||
469 | atomic_t thinints; | ||
470 | atomic_t fast_reqs; | ||
471 | |||
472 | atomic_t outbound_cnt; | ||
473 | atomic_t inbound_cnt; | ||
474 | #endif /* CONFIG_64BIT */ | ||
475 | }; | 186 | }; |
476 | 187 | ||
477 | /* unlikely as the later the better */ | 188 | struct qdio_output_q { |
478 | #define SYNC_MEMORY if (unlikely(q->siga_sync)) qdio_siga_sync_q(q) | 189 | /* failed siga-w attempts*/ |
479 | #define SYNC_MEMORY_ALL if (unlikely(q->siga_sync)) \ | 190 | atomic_t busy_siga_counter; |
480 | qdio_siga_sync(q,~0U,~0U) | ||
481 | #define SYNC_MEMORY_ALL_OUTB if (unlikely(q->siga_sync)) \ | ||
482 | qdio_siga_sync(q,~0U,0) | ||
483 | 191 | ||
484 | #define NOW qdio_get_micros() | 192 | /* start time of busy condition */ |
485 | #define SAVE_TIMESTAMP(q) q->timing.last_transfer_time=NOW | 193 | u64 timestamp; |
486 | #define GET_SAVED_TIMESTAMP(q) (q->timing.last_transfer_time) | ||
487 | #define SAVE_FRONTIER(q,val) q->last_move_ftc=val | ||
488 | #define GET_SAVED_FRONTIER(q) (q->last_move_ftc) | ||
489 | 194 | ||
490 | #define MY_MODULE_STRING(x) #x | 195 | /* PCIs are enabled for the queue */ |
196 | int pci_out_enabled; | ||
491 | 197 | ||
492 | #ifdef CONFIG_64BIT | 198 | /* timer to check for more outbound work */ |
493 | #define QDIO_GET_ADDR(x) ((__u32)(unsigned long)x) | 199 | struct timer_list timer; |
494 | #else /* CONFIG_64BIT */ | 200 | }; |
495 | #define QDIO_GET_ADDR(x) ((__u32)(long)x) | ||
496 | #endif /* CONFIG_64BIT */ | ||
497 | 201 | ||
498 | struct qdio_q { | 202 | struct qdio_q { |
499 | volatile struct slsb slsb; | 203 | struct slsb slsb; |
204 | union { | ||
205 | struct qdio_input_q in; | ||
206 | struct qdio_output_q out; | ||
207 | } u; | ||
500 | 208 | ||
501 | char unused[QDIO_MAX_BUFFERS_PER_Q]; | 209 | /* queue number */ |
210 | int nr; | ||
502 | 211 | ||
503 | __u32 * dev_st_chg_ind; | 212 | /* bitmask of queue number */ |
213 | int mask; | ||
504 | 214 | ||
215 | /* input or output queue */ | ||
505 | int is_input_q; | 216 | int is_input_q; |
506 | struct subchannel_id schid; | ||
507 | struct ccw_device *cdev; | ||
508 | |||
509 | unsigned int is_iqdio_q; | ||
510 | unsigned int is_thinint_q; | ||
511 | 217 | ||
512 | /* bit 0 means queue 0, bit 1 means queue 1, ... */ | 218 | /* list of thinint input queues */ |
513 | unsigned int mask; | 219 | struct list_head entry; |
514 | unsigned int q_no; | ||
515 | 220 | ||
221 | /* upper-layer program handler */ | ||
516 | qdio_handler_t (*handler); | 222 | qdio_handler_t (*handler); |
517 | 223 | ||
518 | /* points to the next buffer to be checked for having | 224 | /* |
519 | * been processed by the card (outbound) | 225 | * inbound: next buffer the program should check for |
520 | * or to the next buffer the program should check for (inbound) */ | 226 | * outbound: next buffer to check for having been processed |
521 | volatile int first_to_check; | 227 | * by the card |
522 | /* and the last time it was: */ | 228 | */ |
523 | volatile int last_move_ftc; | 229 | int first_to_check; |
524 | 230 | ||
525 | atomic_t number_of_buffers_used; | 231 | /* first_to_check of the last time */ |
526 | atomic_t polling; | 232 | int last_move_ftc; |
527 | 233 | ||
528 | unsigned int siga_in; | 234 | /* beginning position for calling the program */ |
529 | unsigned int siga_out; | 235 | int first_to_kick; |
530 | unsigned int siga_sync; | ||
531 | unsigned int siga_sync_done_on_thinints; | ||
532 | unsigned int siga_sync_done_on_outb_tis; | ||
533 | unsigned int hydra_gives_outbound_pcis; | ||
534 | 236 | ||
535 | /* used to save beginning position when calling dd_handlers */ | 237 | /* number of buffers in use by the adapter */ |
536 | int first_element_to_kick; | 238 | atomic_t nr_buf_used; |
537 | 239 | ||
538 | atomic_t use_count; | 240 | struct qdio_irq *irq_ptr; |
539 | atomic_t is_in_shutdown; | ||
540 | |||
541 | void *irq_ptr; | ||
542 | |||
543 | struct timer_list timer; | ||
544 | #ifdef QDIO_USE_TIMERS_FOR_POLLING | ||
545 | atomic_t timer_already_set; | ||
546 | spinlock_t timer_lock; | ||
547 | #else /* QDIO_USE_TIMERS_FOR_POLLING */ | ||
548 | struct tasklet_struct tasklet; | 241 | struct tasklet_struct tasklet; |
549 | #endif /* QDIO_USE_TIMERS_FOR_POLLING */ | ||
550 | 242 | ||
551 | 243 | /* error condition during a data transfer */ | |
552 | enum qdio_irq_states state; | ||
553 | |||
554 | /* used to store the error condition during a data transfer */ | ||
555 | unsigned int qdio_error; | 244 | unsigned int qdio_error; |
556 | unsigned int siga_error; | ||
557 | unsigned int error_status_flags; | ||
558 | |||
559 | /* list of interesting queues */ | ||
560 | volatile struct qdio_q *list_next; | ||
561 | volatile struct qdio_q *list_prev; | ||
562 | 245 | ||
563 | struct sl *sl; | 246 | struct sl *sl; |
564 | volatile struct sbal *sbal[QDIO_MAX_BUFFERS_PER_Q]; | 247 | struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; |
565 | 248 | ||
566 | struct qdio_buffer *qdio_buffers[QDIO_MAX_BUFFERS_PER_Q]; | 249 | /* |
567 | 250 | * Warning: Leave this member at the end so it won't be cleared in | |
568 | unsigned long int_parm; | 251 | * qdio_fill_qs. A page is allocated under this pointer and used for |
569 | 252 | * slib and sl. slib is 2048 bytes big and sl points to offset | |
570 | /*struct { | 253 | * PAGE_SIZE / 2. |
571 | int in_bh_check_limit; | 254 | */ |
572 | int threshold; | 255 | struct slib *slib; |
573 | } threshold_classes[QDIO_STATS_CLASSES];*/ | ||
574 | |||
575 | struct { | ||
576 | /* inbound: the time to stop polling | ||
577 | outbound: the time to kick peer */ | ||
578 | int threshold; /* the real value */ | ||
579 | |||
580 | /* outbound: last time of do_QDIO | ||
581 | inbound: last time of noticing incoming data */ | ||
582 | /*__u64 last_transfer_times[QDIO_STATS_NUMBER]; | ||
583 | int last_transfer_index; */ | ||
584 | |||
585 | __u64 last_transfer_time; | ||
586 | __u64 busy_start; | ||
587 | } timing; | ||
588 | atomic_t busy_siga_counter; | ||
589 | unsigned int queue_type; | ||
590 | unsigned int is_pci_out; | ||
591 | |||
592 | /* leave this member at the end. won't be cleared in qdio_fill_qs */ | ||
593 | struct slib *slib; /* a page is allocated under this pointer, | ||
594 | sl points into this page, offset PAGE_SIZE/2 | ||
595 | (after slib) */ | ||
596 | } __attribute__ ((aligned(256))); | 256 | } __attribute__ ((aligned(256))); |
597 | 257 | ||
598 | struct qdio_irq { | 258 | struct qdio_irq { |
599 | __u32 * volatile dev_st_chg_ind; | 259 | struct qib qib; |
260 | u32 *dsci; /* address of device state change indicator */ | ||
261 | struct ccw_device *cdev; | ||
600 | 262 | ||
601 | unsigned long int_parm; | 263 | unsigned long int_parm; |
602 | struct subchannel_id schid; | 264 | struct subchannel_id schid; |
603 | 265 | unsigned long sch_token; /* QEBSM facility */ | |
604 | unsigned int is_iqdio_irq; | ||
605 | unsigned int is_thinint_irq; | ||
606 | unsigned int hydra_gives_outbound_pcis; | ||
607 | unsigned int sync_done_on_outb_pcis; | ||
608 | |||
609 | /* QEBSM facility */ | ||
610 | unsigned int is_qebsm; | ||
611 | unsigned long sch_token; | ||
612 | 266 | ||
613 | enum qdio_irq_states state; | 267 | enum qdio_irq_states state; |
614 | 268 | ||
615 | unsigned int no_input_qs; | 269 | struct siga_flag siga_flag; /* siga sync information from qdioac */ |
616 | unsigned int no_output_qs; | ||
617 | 270 | ||
618 | unsigned char qdioac; | 271 | int nr_input_qs; |
272 | int nr_output_qs; | ||
619 | 273 | ||
620 | struct ccw1 ccw; | 274 | struct ccw1 ccw; |
621 | |||
622 | struct ciw equeue; | 275 | struct ciw equeue; |
623 | struct ciw aqueue; | 276 | struct ciw aqueue; |
624 | 277 | ||
625 | struct qib qib; | 278 | struct qdio_ssqd_desc ssqd_desc; |
626 | 279 | ||
627 | void (*original_int_handler) (struct ccw_device *, | 280 | void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *); |
628 | unsigned long, struct irb *); | ||
629 | 281 | ||
630 | /* leave these four members together at the end. won't be cleared in qdio_fill_irq */ | 282 | /* |
283 | * Warning: Leave these members together at the end so they won't be | ||
284 | * cleared in qdio_setup_irq. | ||
285 | */ | ||
631 | struct qdr *qdr; | 286 | struct qdr *qdr; |
287 | unsigned long chsc_page; | ||
288 | |||
632 | struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ]; | 289 | struct qdio_q *input_qs[QDIO_MAX_QUEUES_PER_IRQ]; |
633 | struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ]; | 290 | struct qdio_q *output_qs[QDIO_MAX_QUEUES_PER_IRQ]; |
634 | struct semaphore setting_up_sema; | 291 | |
292 | struct mutex setup_mutex; | ||
635 | }; | 293 | }; |
636 | #endif | 294 | |
295 | /* helper functions */ | ||
296 | #define queue_type(q) q->irq_ptr->qib.qfmt | ||
297 | |||
298 | #define is_thinint_irq(irq) \ | ||
299 | (irq->qib.qfmt == QDIO_IQDIO_QFMT || \ | ||
300 | css_general_characteristics.aif_osa) | ||
301 | |||
302 | /* the highest iqdio queue is used for multicast */ | ||
303 | static inline int multicast_outbound(struct qdio_q *q) | ||
304 | { | ||
305 | return (q->irq_ptr->nr_output_qs > 1) && | ||
306 | (q->nr == q->irq_ptr->nr_output_qs - 1); | ||
307 | } | ||
308 | |||
309 | static inline unsigned long long get_usecs(void) | ||
310 | { | ||
311 | return monotonic_clock() >> 12; | ||
312 | } | ||
313 | |||
314 | #define pci_out_supported(q) \ | ||
315 | (q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED) | ||
316 | #define is_qebsm(q) (q->irq_ptr->sch_token != 0) | ||
317 | |||
318 | #define need_siga_sync_thinint(q) (!q->irq_ptr->siga_flag.no_sync_ti) | ||
319 | #define need_siga_sync_out_thinint(q) (!q->irq_ptr->siga_flag.no_sync_out_ti) | ||
320 | #define need_siga_in(q) (q->irq_ptr->siga_flag.input) | ||
321 | #define need_siga_out(q) (q->irq_ptr->siga_flag.output) | ||
322 | #define need_siga_sync(q) (q->irq_ptr->siga_flag.sync) | ||
323 | #define siga_syncs_out_pci(q) (q->irq_ptr->siga_flag.no_sync_out_pci) | ||
324 | |||
325 | #define for_each_input_queue(irq_ptr, q, i) \ | ||
326 | for (i = 0, q = irq_ptr->input_qs[0]; \ | ||
327 | i < irq_ptr->nr_input_qs; \ | ||
328 | q = irq_ptr->input_qs[++i]) | ||
329 | #define for_each_output_queue(irq_ptr, q, i) \ | ||
330 | for (i = 0, q = irq_ptr->output_qs[0]; \ | ||
331 | i < irq_ptr->nr_output_qs; \ | ||
332 | q = irq_ptr->output_qs[++i]) | ||
333 | |||
334 | #define prev_buf(bufnr) \ | ||
335 | ((bufnr + QDIO_MAX_BUFFERS_MASK) & QDIO_MAX_BUFFERS_MASK) | ||
336 | #define next_buf(bufnr) \ | ||
337 | ((bufnr + 1) & QDIO_MAX_BUFFERS_MASK) | ||
338 | #define add_buf(bufnr, inc) \ | ||
339 | ((bufnr + inc) & QDIO_MAX_BUFFERS_MASK) | ||
340 | |||
341 | /* prototypes for thin interrupt */ | ||
342 | void qdio_sync_after_thinint(struct qdio_q *q); | ||
343 | int get_buf_state(struct qdio_q *q, unsigned int bufnr, unsigned char *state); | ||
344 | void qdio_check_outbound_after_thinint(struct qdio_q *q); | ||
345 | int qdio_inbound_q_moved(struct qdio_q *q); | ||
346 | void qdio_kick_inbound_handler(struct qdio_q *q); | ||
347 | void qdio_stop_polling(struct qdio_q *q); | ||
348 | int qdio_siga_sync_q(struct qdio_q *q); | ||
349 | |||
350 | void qdio_setup_thinint(struct qdio_irq *irq_ptr); | ||
351 | int qdio_establish_thinint(struct qdio_irq *irq_ptr); | ||
352 | void qdio_shutdown_thinint(struct qdio_irq *irq_ptr); | ||
353 | void tiqdio_add_input_queues(struct qdio_irq *irq_ptr); | ||
354 | void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr); | ||
355 | void tiqdio_inbound_processing(unsigned long q); | ||
356 | int tiqdio_allocate_memory(void); | ||
357 | void tiqdio_free_memory(void); | ||
358 | int tiqdio_register_thinints(void); | ||
359 | void tiqdio_unregister_thinints(void); | ||
360 | |||
361 | /* prototypes for setup */ | ||
362 | void qdio_inbound_processing(unsigned long data); | ||
363 | void qdio_outbound_processing(unsigned long data); | ||
364 | void qdio_outbound_timer(unsigned long data); | ||
365 | void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm, | ||
366 | struct irb *irb); | ||
367 | int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, | ||
368 | int nr_output_qs); | ||
369 | void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr); | ||
370 | int qdio_setup_irq(struct qdio_initialize *init_data); | ||
371 | void qdio_print_subchannel_info(struct qdio_irq *irq_ptr, | ||
372 | struct ccw_device *cdev); | ||
373 | void qdio_release_memory(struct qdio_irq *irq_ptr); | ||
374 | int qdio_setup_init(void); | ||
375 | void qdio_setup_exit(void); | ||
376 | |||
377 | #endif /* _CIO_QDIO_H */ | ||
diff --git a/drivers/s390/cio/qdio_debug.c b/drivers/s390/cio/qdio_debug.c new file mode 100644 index 000000000000..337aa3087a78 --- /dev/null +++ b/drivers/s390/cio/qdio_debug.c | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | * drivers/s390/cio/qdio_debug.c | ||
3 | * | ||
4 | * Copyright IBM Corp. 2008 | ||
5 | * | ||
6 | * Author: Jan Glauber (jang@linux.vnet.ibm.com) | ||
7 | */ | ||
8 | #include <linux/proc_fs.h> | ||
9 | #include <linux/seq_file.h> | ||
10 | #include <linux/debugfs.h> | ||
11 | #include <asm/qdio.h> | ||
12 | #include <asm/debug.h> | ||
13 | #include "qdio_debug.h" | ||
14 | #include "qdio.h" | ||
15 | |||
16 | debug_info_t *qdio_dbf_setup; | ||
17 | debug_info_t *qdio_dbf_trace; | ||
18 | |||
19 | static struct dentry *debugfs_root; | ||
20 | #define MAX_DEBUGFS_QUEUES 32 | ||
21 | static struct dentry *debugfs_queues[MAX_DEBUGFS_QUEUES] = { NULL }; | ||
22 | static DEFINE_MUTEX(debugfs_mutex); | ||
23 | |||
24 | void qdio_allocate_do_dbf(struct qdio_initialize *init_data) | ||
25 | { | ||
26 | char dbf_text[20]; | ||
27 | |||
28 | sprintf(dbf_text, "qfmt:%x", init_data->q_format); | ||
29 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
30 | QDIO_DBF_HEX0(0, setup, init_data->adapter_name, 8); | ||
31 | sprintf(dbf_text, "qpff%4x", init_data->qib_param_field_format); | ||
32 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
33 | QDIO_DBF_HEX0(0, setup, &init_data->qib_param_field, sizeof(void *)); | ||
34 | QDIO_DBF_HEX0(0, setup, &init_data->input_slib_elements, sizeof(void *)); | ||
35 | QDIO_DBF_HEX0(0, setup, &init_data->output_slib_elements, sizeof(void *)); | ||
36 | sprintf(dbf_text, "niq:%4x", init_data->no_input_qs); | ||
37 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
38 | sprintf(dbf_text, "noq:%4x", init_data->no_output_qs); | ||
39 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
40 | QDIO_DBF_HEX0(0, setup, &init_data->input_handler, sizeof(void *)); | ||
41 | QDIO_DBF_HEX0(0, setup, &init_data->output_handler, sizeof(void *)); | ||
42 | QDIO_DBF_HEX0(0, setup, &init_data->int_parm, sizeof(long)); | ||
43 | QDIO_DBF_HEX0(0, setup, &init_data->flags, sizeof(long)); | ||
44 | QDIO_DBF_HEX0(0, setup, &init_data->input_sbal_addr_array, sizeof(void *)); | ||
45 | QDIO_DBF_HEX0(0, setup, &init_data->output_sbal_addr_array, sizeof(void *)); | ||
46 | } | ||
47 | |||
48 | static void qdio_unregister_dbf_views(void) | ||
49 | { | ||
50 | if (qdio_dbf_setup) | ||
51 | debug_unregister(qdio_dbf_setup); | ||
52 | if (qdio_dbf_trace) | ||
53 | debug_unregister(qdio_dbf_trace); | ||
54 | } | ||
55 | |||
56 | static int qdio_register_dbf_views(void) | ||
57 | { | ||
58 | qdio_dbf_setup = debug_register("qdio_setup", QDIO_DBF_SETUP_PAGES, | ||
59 | QDIO_DBF_SETUP_NR_AREAS, | ||
60 | QDIO_DBF_SETUP_LEN); | ||
61 | if (!qdio_dbf_setup) | ||
62 | goto oom; | ||
63 | debug_register_view(qdio_dbf_setup, &debug_hex_ascii_view); | ||
64 | debug_set_level(qdio_dbf_setup, QDIO_DBF_SETUP_LEVEL); | ||
65 | |||
66 | qdio_dbf_trace = debug_register("qdio_trace", QDIO_DBF_TRACE_PAGES, | ||
67 | QDIO_DBF_TRACE_NR_AREAS, | ||
68 | QDIO_DBF_TRACE_LEN); | ||
69 | if (!qdio_dbf_trace) | ||
70 | goto oom; | ||
71 | debug_register_view(qdio_dbf_trace, &debug_hex_ascii_view); | ||
72 | debug_set_level(qdio_dbf_trace, QDIO_DBF_TRACE_LEVEL); | ||
73 | return 0; | ||
74 | oom: | ||
75 | qdio_unregister_dbf_views(); | ||
76 | return -ENOMEM; | ||
77 | } | ||
78 | |||
79 | static int qstat_show(struct seq_file *m, void *v) | ||
80 | { | ||
81 | unsigned char state; | ||
82 | struct qdio_q *q = m->private; | ||
83 | int i; | ||
84 | |||
85 | if (!q) | ||
86 | return 0; | ||
87 | |||
88 | seq_printf(m, "device state indicator: %d\n", *q->irq_ptr->dsci); | ||
89 | seq_printf(m, "nr_used: %d\n", atomic_read(&q->nr_buf_used)); | ||
90 | seq_printf(m, "ftc: %d\n", q->first_to_check); | ||
91 | seq_printf(m, "last_move_ftc: %d\n", q->last_move_ftc); | ||
92 | seq_printf(m, "polling: %d\n", q->u.in.polling); | ||
93 | seq_printf(m, "slsb buffer states:\n"); | ||
94 | |||
95 | qdio_siga_sync_q(q); | ||
96 | for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) { | ||
97 | get_buf_state(q, i, &state); | ||
98 | switch (state) { | ||
99 | case SLSB_P_INPUT_NOT_INIT: | ||
100 | case SLSB_P_OUTPUT_NOT_INIT: | ||
101 | seq_printf(m, "N"); | ||
102 | break; | ||
103 | case SLSB_P_INPUT_PRIMED: | ||
104 | case SLSB_CU_OUTPUT_PRIMED: | ||
105 | seq_printf(m, "+"); | ||
106 | break; | ||
107 | case SLSB_P_INPUT_ACK: | ||
108 | seq_printf(m, "A"); | ||
109 | break; | ||
110 | case SLSB_P_INPUT_ERROR: | ||
111 | case SLSB_P_OUTPUT_ERROR: | ||
112 | seq_printf(m, "x"); | ||
113 | break; | ||
114 | case SLSB_CU_INPUT_EMPTY: | ||
115 | case SLSB_P_OUTPUT_EMPTY: | ||
116 | seq_printf(m, "-"); | ||
117 | break; | ||
118 | case SLSB_P_INPUT_HALTED: | ||
119 | case SLSB_P_OUTPUT_HALTED: | ||
120 | seq_printf(m, "."); | ||
121 | break; | ||
122 | default: | ||
123 | seq_printf(m, "?"); | ||
124 | } | ||
125 | if (i == 63) | ||
126 | seq_printf(m, "\n"); | ||
127 | } | ||
128 | seq_printf(m, "\n"); | ||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | static ssize_t qstat_seq_write(struct file *file, const char __user *buf, | ||
133 | size_t count, loff_t *off) | ||
134 | { | ||
135 | struct seq_file *seq = file->private_data; | ||
136 | struct qdio_q *q = seq->private; | ||
137 | |||
138 | if (!q) | ||
139 | return 0; | ||
140 | |||
141 | if (q->is_input_q) | ||
142 | xchg(q->irq_ptr->dsci, 1); | ||
143 | local_bh_disable(); | ||
144 | tasklet_schedule(&q->tasklet); | ||
145 | local_bh_enable(); | ||
146 | return count; | ||
147 | } | ||
148 | |||
149 | static int qstat_seq_open(struct inode *inode, struct file *filp) | ||
150 | { | ||
151 | return single_open(filp, qstat_show, | ||
152 | filp->f_path.dentry->d_inode->i_private); | ||
153 | } | ||
154 | |||
155 | static void get_queue_name(struct qdio_q *q, struct ccw_device *cdev, char *name) | ||
156 | { | ||
157 | memset(name, 0, sizeof(name)); | ||
158 | sprintf(name, "%s", cdev->dev.bus_id); | ||
159 | if (q->is_input_q) | ||
160 | sprintf(name + strlen(name), "_input"); | ||
161 | else | ||
162 | sprintf(name + strlen(name), "_output"); | ||
163 | sprintf(name + strlen(name), "_%d", q->nr); | ||
164 | } | ||
165 | |||
166 | static void remove_debugfs_entry(struct qdio_q *q) | ||
167 | { | ||
168 | int i; | ||
169 | |||
170 | for (i = 0; i < MAX_DEBUGFS_QUEUES; i++) { | ||
171 | if (!debugfs_queues[i]) | ||
172 | continue; | ||
173 | if (debugfs_queues[i]->d_inode->i_private == q) { | ||
174 | debugfs_remove(debugfs_queues[i]); | ||
175 | debugfs_queues[i] = NULL; | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | static struct file_operations debugfs_fops = { | ||
181 | .owner = THIS_MODULE, | ||
182 | .open = qstat_seq_open, | ||
183 | .read = seq_read, | ||
184 | .write = qstat_seq_write, | ||
185 | .llseek = seq_lseek, | ||
186 | .release = single_release, | ||
187 | }; | ||
188 | |||
189 | static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev) | ||
190 | { | ||
191 | int i = 0; | ||
192 | char name[40]; | ||
193 | |||
194 | while (debugfs_queues[i] != NULL) { | ||
195 | i++; | ||
196 | if (i >= MAX_DEBUGFS_QUEUES) | ||
197 | return; | ||
198 | } | ||
199 | get_queue_name(q, cdev, name); | ||
200 | debugfs_queues[i] = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR, | ||
201 | debugfs_root, q, &debugfs_fops); | ||
202 | } | ||
203 | |||
204 | void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) | ||
205 | { | ||
206 | struct qdio_q *q; | ||
207 | int i; | ||
208 | |||
209 | mutex_lock(&debugfs_mutex); | ||
210 | for_each_input_queue(irq_ptr, q, i) | ||
211 | setup_debugfs_entry(q, cdev); | ||
212 | for_each_output_queue(irq_ptr, q, i) | ||
213 | setup_debugfs_entry(q, cdev); | ||
214 | mutex_unlock(&debugfs_mutex); | ||
215 | } | ||
216 | |||
217 | void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) | ||
218 | { | ||
219 | struct qdio_q *q; | ||
220 | int i; | ||
221 | |||
222 | mutex_lock(&debugfs_mutex); | ||
223 | for_each_input_queue(irq_ptr, q, i) | ||
224 | remove_debugfs_entry(q); | ||
225 | for_each_output_queue(irq_ptr, q, i) | ||
226 | remove_debugfs_entry(q); | ||
227 | mutex_unlock(&debugfs_mutex); | ||
228 | } | ||
229 | |||
230 | int __init qdio_debug_init(void) | ||
231 | { | ||
232 | debugfs_root = debugfs_create_dir("qdio_queues", NULL); | ||
233 | return qdio_register_dbf_views(); | ||
234 | } | ||
235 | |||
236 | void qdio_debug_exit(void) | ||
237 | { | ||
238 | debugfs_remove(debugfs_root); | ||
239 | qdio_unregister_dbf_views(); | ||
240 | } | ||
diff --git a/drivers/s390/cio/qdio_debug.h b/drivers/s390/cio/qdio_debug.h new file mode 100644 index 000000000000..8484b83698e1 --- /dev/null +++ b/drivers/s390/cio/qdio_debug.h | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * drivers/s390/cio/qdio_debug.h | ||
3 | * | ||
4 | * Copyright IBM Corp. 2008 | ||
5 | * | ||
6 | * Author: Jan Glauber (jang@linux.vnet.ibm.com) | ||
7 | */ | ||
8 | #ifndef QDIO_DEBUG_H | ||
9 | #define QDIO_DEBUG_H | ||
10 | |||
11 | #include <asm/debug.h> | ||
12 | #include <asm/qdio.h> | ||
13 | #include "qdio.h" | ||
14 | |||
15 | #define QDIO_DBF_HEX(ex, name, level, addr, len) \ | ||
16 | do { \ | ||
17 | if (ex) \ | ||
18 | debug_exception(qdio_dbf_##name, level, (void *)(addr), len); \ | ||
19 | else \ | ||
20 | debug_event(qdio_dbf_##name, level, (void *)(addr), len); \ | ||
21 | } while (0) | ||
22 | #define QDIO_DBF_TEXT(ex, name, level, text) \ | ||
23 | do { \ | ||
24 | if (ex) \ | ||
25 | debug_text_exception(qdio_dbf_##name, level, text); \ | ||
26 | else \ | ||
27 | debug_text_event(qdio_dbf_##name, level, text); \ | ||
28 | } while (0) | ||
29 | |||
30 | #define QDIO_DBF_HEX0(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 0, addr, len) | ||
31 | #define QDIO_DBF_HEX1(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 1, addr, len) | ||
32 | #define QDIO_DBF_HEX2(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 2, addr, len) | ||
33 | |||
34 | #ifdef CONFIG_QDIO_DEBUG | ||
35 | #define QDIO_DBF_HEX3(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 3, addr, len) | ||
36 | #define QDIO_DBF_HEX4(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 4, addr, len) | ||
37 | #define QDIO_DBF_HEX5(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 5, addr, len) | ||
38 | #define QDIO_DBF_HEX6(ex, name, addr, len) QDIO_DBF_HEX(ex, name, 6, addr, len) | ||
39 | #else | ||
40 | #define QDIO_DBF_HEX3(ex, name, addr, len) do {} while (0) | ||
41 | #define QDIO_DBF_HEX4(ex, name, addr, len) do {} while (0) | ||
42 | #define QDIO_DBF_HEX5(ex, name, addr, len) do {} while (0) | ||
43 | #define QDIO_DBF_HEX6(ex, name, addr, len) do {} while (0) | ||
44 | #endif /* CONFIG_QDIO_DEBUG */ | ||
45 | |||
46 | #define QDIO_DBF_TEXT0(ex, name, text) QDIO_DBF_TEXT(ex, name, 0, text) | ||
47 | #define QDIO_DBF_TEXT1(ex, name, text) QDIO_DBF_TEXT(ex, name, 1, text) | ||
48 | #define QDIO_DBF_TEXT2(ex, name, text) QDIO_DBF_TEXT(ex, name, 2, text) | ||
49 | |||
50 | #ifdef CONFIG_QDIO_DEBUG | ||
51 | #define QDIO_DBF_TEXT3(ex, name, text) QDIO_DBF_TEXT(ex, name, 3, text) | ||
52 | #define QDIO_DBF_TEXT4(ex, name, text) QDIO_DBF_TEXT(ex, name, 4, text) | ||
53 | #define QDIO_DBF_TEXT5(ex, name, text) QDIO_DBF_TEXT(ex, name, 5, text) | ||
54 | #define QDIO_DBF_TEXT6(ex, name, text) QDIO_DBF_TEXT(ex, name, 6, text) | ||
55 | #else | ||
56 | #define QDIO_DBF_TEXT3(ex, name, text) do {} while (0) | ||
57 | #define QDIO_DBF_TEXT4(ex, name, text) do {} while (0) | ||
58 | #define QDIO_DBF_TEXT5(ex, name, text) do {} while (0) | ||
59 | #define QDIO_DBF_TEXT6(ex, name, text) do {} while (0) | ||
60 | #endif /* CONFIG_QDIO_DEBUG */ | ||
61 | |||
62 | /* s390dbf views */ | ||
63 | #define QDIO_DBF_SETUP_LEN 8 | ||
64 | #define QDIO_DBF_SETUP_PAGES 4 | ||
65 | #define QDIO_DBF_SETUP_NR_AREAS 1 | ||
66 | |||
67 | #define QDIO_DBF_TRACE_LEN 8 | ||
68 | #define QDIO_DBF_TRACE_NR_AREAS 2 | ||
69 | |||
70 | #ifdef CONFIG_QDIO_DEBUG | ||
71 | #define QDIO_DBF_TRACE_PAGES 16 | ||
72 | #define QDIO_DBF_SETUP_LEVEL 6 | ||
73 | #define QDIO_DBF_TRACE_LEVEL 4 | ||
74 | #else /* !CONFIG_QDIO_DEBUG */ | ||
75 | #define QDIO_DBF_TRACE_PAGES 4 | ||
76 | #define QDIO_DBF_SETUP_LEVEL 2 | ||
77 | #define QDIO_DBF_TRACE_LEVEL 2 | ||
78 | #endif /* CONFIG_QDIO_DEBUG */ | ||
79 | |||
80 | extern debug_info_t *qdio_dbf_setup; | ||
81 | extern debug_info_t *qdio_dbf_trace; | ||
82 | |||
83 | void qdio_allocate_do_dbf(struct qdio_initialize *init_data); | ||
84 | void debug_print_bstat(struct qdio_q *q); | ||
85 | void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, | ||
86 | struct ccw_device *cdev); | ||
87 | void qdio_shutdown_debug_entries(struct qdio_irq *irq_ptr, | ||
88 | struct ccw_device *cdev); | ||
89 | int qdio_debug_init(void); | ||
90 | void qdio_debug_exit(void); | ||
91 | #endif | ||
diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c new file mode 100644 index 000000000000..d10c73cc1688 --- /dev/null +++ b/drivers/s390/cio/qdio_main.c | |||
@@ -0,0 +1,1755 @@ | |||
1 | /* | ||
2 | * linux/drivers/s390/cio/qdio_main.c | ||
3 | * | ||
4 | * Linux for s390 qdio support, buffer handling, qdio API and module support. | ||
5 | * | ||
6 | * Copyright 2000,2008 IBM Corp. | ||
7 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com> | ||
8 | * Jan Glauber <jang@linux.vnet.ibm.com> | ||
9 | * 2.6 cio integration by Cornelia Huck <cornelia.huck@de.ibm.com> | ||
10 | */ | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/timer.h> | ||
15 | #include <linux/delay.h> | ||
16 | #include <asm/atomic.h> | ||
17 | #include <asm/debug.h> | ||
18 | #include <asm/qdio.h> | ||
19 | |||
20 | #include "cio.h" | ||
21 | #include "css.h" | ||
22 | #include "device.h" | ||
23 | #include "qdio.h" | ||
24 | #include "qdio_debug.h" | ||
25 | #include "qdio_perf.h" | ||
26 | |||
27 | MODULE_AUTHOR("Utz Bacher <utz.bacher@de.ibm.com>,"\ | ||
28 | "Jan Glauber <jang@linux.vnet.ibm.com>"); | ||
29 | MODULE_DESCRIPTION("QDIO base support"); | ||
30 | MODULE_LICENSE("GPL"); | ||
31 | |||
32 | static inline int do_siga_sync(struct subchannel_id schid, | ||
33 | unsigned int out_mask, unsigned int in_mask) | ||
34 | { | ||
35 | register unsigned long __fc asm ("0") = 2; | ||
36 | register struct subchannel_id __schid asm ("1") = schid; | ||
37 | register unsigned long out asm ("2") = out_mask; | ||
38 | register unsigned long in asm ("3") = in_mask; | ||
39 | int cc; | ||
40 | |||
41 | asm volatile( | ||
42 | " siga 0\n" | ||
43 | " ipm %0\n" | ||
44 | " srl %0,28\n" | ||
45 | : "=d" (cc) | ||
46 | : "d" (__fc), "d" (__schid), "d" (out), "d" (in) : "cc"); | ||
47 | return cc; | ||
48 | } | ||
49 | |||
50 | static inline int do_siga_input(struct subchannel_id schid, unsigned int mask) | ||
51 | { | ||
52 | register unsigned long __fc asm ("0") = 1; | ||
53 | register struct subchannel_id __schid asm ("1") = schid; | ||
54 | register unsigned long __mask asm ("2") = mask; | ||
55 | int cc; | ||
56 | |||
57 | asm volatile( | ||
58 | " siga 0\n" | ||
59 | " ipm %0\n" | ||
60 | " srl %0,28\n" | ||
61 | : "=d" (cc) | ||
62 | : "d" (__fc), "d" (__schid), "d" (__mask) : "cc", "memory"); | ||
63 | return cc; | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * do_siga_output - perform SIGA-w/wt function | ||
68 | * @schid: subchannel id or in case of QEBSM the subchannel token | ||
69 | * @mask: which output queues to process | ||
70 | * @bb: busy bit indicator, set only if SIGA-w/wt could not access a buffer | ||
71 | * @fc: function code to perform | ||
72 | * | ||
73 | * Returns cc or QDIO_ERROR_SIGA_ACCESS_EXCEPTION. | ||
74 | * Note: For IQDC unicast queues only the highest priority queue is processed. | ||
75 | */ | ||
76 | static inline int do_siga_output(unsigned long schid, unsigned long mask, | ||
77 | u32 *bb, unsigned int fc) | ||
78 | { | ||
79 | register unsigned long __fc asm("0") = fc; | ||
80 | register unsigned long __schid asm("1") = schid; | ||
81 | register unsigned long __mask asm("2") = mask; | ||
82 | int cc = QDIO_ERROR_SIGA_ACCESS_EXCEPTION; | ||
83 | |||
84 | asm volatile( | ||
85 | " siga 0\n" | ||
86 | "0: ipm %0\n" | ||
87 | " srl %0,28\n" | ||
88 | "1:\n" | ||
89 | EX_TABLE(0b, 1b) | ||
90 | : "+d" (cc), "+d" (__fc), "+d" (__schid), "+d" (__mask) | ||
91 | : : "cc", "memory"); | ||
92 | *bb = ((unsigned int) __fc) >> 31; | ||
93 | return cc; | ||
94 | } | ||
95 | |||
96 | static inline int qdio_check_ccq(struct qdio_q *q, unsigned int ccq) | ||
97 | { | ||
98 | char dbf_text[15]; | ||
99 | |||
100 | /* all done or next buffer state different */ | ||
101 | if (ccq == 0 || ccq == 32) | ||
102 | return 0; | ||
103 | /* not all buffers processed */ | ||
104 | if (ccq == 96 || ccq == 97) | ||
105 | return 1; | ||
106 | /* notify devices immediately */ | ||
107 | sprintf(dbf_text, "%d", ccq); | ||
108 | QDIO_DBF_TEXT2(1, trace, dbf_text); | ||
109 | return -EIO; | ||
110 | } | ||
111 | |||
112 | /** | ||
113 | * qdio_do_eqbs - extract buffer states for QEBSM | ||
114 | * @q: queue to manipulate | ||
115 | * @state: state of the extracted buffers | ||
116 | * @start: buffer number to start at | ||
117 | * @count: count of buffers to examine | ||
118 | * | ||
119 | * Returns the number of successfull extracted equal buffer states. | ||
120 | * Stops processing if a state is different from the last buffers state. | ||
121 | */ | ||
122 | static int qdio_do_eqbs(struct qdio_q *q, unsigned char *state, | ||
123 | int start, int count) | ||
124 | { | ||
125 | unsigned int ccq = 0; | ||
126 | int tmp_count = count, tmp_start = start; | ||
127 | int nr = q->nr; | ||
128 | int rc; | ||
129 | char dbf_text[15]; | ||
130 | |||
131 | BUG_ON(!q->irq_ptr->sch_token); | ||
132 | |||
133 | if (!q->is_input_q) | ||
134 | nr += q->irq_ptr->nr_input_qs; | ||
135 | again: | ||
136 | ccq = do_eqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count); | ||
137 | rc = qdio_check_ccq(q, ccq); | ||
138 | |||
139 | /* At least one buffer was processed, return and extract the remaining | ||
140 | * buffers later. | ||
141 | */ | ||
142 | if ((ccq == 96) && (count != tmp_count)) | ||
143 | return (count - tmp_count); | ||
144 | if (rc == 1) { | ||
145 | QDIO_DBF_TEXT5(1, trace, "eqAGAIN"); | ||
146 | goto again; | ||
147 | } | ||
148 | |||
149 | if (rc < 0) { | ||
150 | QDIO_DBF_TEXT2(1, trace, "eqberr"); | ||
151 | sprintf(dbf_text, "%2x,%2x,%d,%d", count, tmp_count, ccq, nr); | ||
152 | QDIO_DBF_TEXT2(1, trace, dbf_text); | ||
153 | q->handler(q->irq_ptr->cdev, | ||
154 | QDIO_ERROR_ACTIVATE_CHECK_CONDITION, | ||
155 | 0, -1, -1, q->irq_ptr->int_parm); | ||
156 | return 0; | ||
157 | } | ||
158 | return count - tmp_count; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * qdio_do_sqbs - set buffer states for QEBSM | ||
163 | * @q: queue to manipulate | ||
164 | * @state: new state of the buffers | ||
165 | * @start: first buffer number to change | ||
166 | * @count: how many buffers to change | ||
167 | * | ||
168 | * Returns the number of successfully changed buffers. | ||
169 | * Does retrying until the specified count of buffer states is set or an | ||
170 | * error occurs. | ||
171 | */ | ||
172 | static int qdio_do_sqbs(struct qdio_q *q, unsigned char state, int start, | ||
173 | int count) | ||
174 | { | ||
175 | unsigned int ccq = 0; | ||
176 | int tmp_count = count, tmp_start = start; | ||
177 | int nr = q->nr; | ||
178 | int rc; | ||
179 | char dbf_text[15]; | ||
180 | |||
181 | BUG_ON(!q->irq_ptr->sch_token); | ||
182 | |||
183 | if (!q->is_input_q) | ||
184 | nr += q->irq_ptr->nr_input_qs; | ||
185 | again: | ||
186 | ccq = do_sqbs(q->irq_ptr->sch_token, state, nr, &tmp_start, &tmp_count); | ||
187 | rc = qdio_check_ccq(q, ccq); | ||
188 | if (rc == 1) { | ||
189 | QDIO_DBF_TEXT5(1, trace, "sqAGAIN"); | ||
190 | goto again; | ||
191 | } | ||
192 | if (rc < 0) { | ||
193 | QDIO_DBF_TEXT3(1, trace, "sqberr"); | ||
194 | sprintf(dbf_text, "%2x,%2x", count, tmp_count); | ||
195 | QDIO_DBF_TEXT3(1, trace, dbf_text); | ||
196 | sprintf(dbf_text, "%d,%d", ccq, nr); | ||
197 | QDIO_DBF_TEXT3(1, trace, dbf_text); | ||
198 | |||
199 | q->handler(q->irq_ptr->cdev, | ||
200 | QDIO_ERROR_ACTIVATE_CHECK_CONDITION, | ||
201 | 0, -1, -1, q->irq_ptr->int_parm); | ||
202 | return 0; | ||
203 | } | ||
204 | WARN_ON(tmp_count); | ||
205 | return count - tmp_count; | ||
206 | } | ||
207 | |||
208 | /* returns number of examined buffers and their common state in *state */ | ||
209 | static inline int get_buf_states(struct qdio_q *q, unsigned int bufnr, | ||
210 | unsigned char *state, unsigned int count) | ||
211 | { | ||
212 | unsigned char __state = 0; | ||
213 | int i; | ||
214 | |||
215 | BUG_ON(bufnr > QDIO_MAX_BUFFERS_MASK); | ||
216 | BUG_ON(count > QDIO_MAX_BUFFERS_PER_Q); | ||
217 | |||
218 | if (is_qebsm(q)) | ||
219 | return qdio_do_eqbs(q, state, bufnr, count); | ||
220 | |||
221 | for (i = 0; i < count; i++) { | ||
222 | if (!__state) | ||
223 | __state = q->slsb.val[bufnr]; | ||
224 | else if (q->slsb.val[bufnr] != __state) | ||
225 | break; | ||
226 | bufnr = next_buf(bufnr); | ||
227 | } | ||
228 | *state = __state; | ||
229 | return i; | ||
230 | } | ||
231 | |||
232 | inline int get_buf_state(struct qdio_q *q, unsigned int bufnr, | ||
233 | unsigned char *state) | ||
234 | { | ||
235 | return get_buf_states(q, bufnr, state, 1); | ||
236 | } | ||
237 | |||
238 | /* wrap-around safe setting of slsb states, returns number of changed buffers */ | ||
239 | static inline int set_buf_states(struct qdio_q *q, int bufnr, | ||
240 | unsigned char state, int count) | ||
241 | { | ||
242 | int i; | ||
243 | |||
244 | BUG_ON(bufnr > QDIO_MAX_BUFFERS_MASK); | ||
245 | BUG_ON(count > QDIO_MAX_BUFFERS_PER_Q); | ||
246 | |||
247 | if (is_qebsm(q)) | ||
248 | return qdio_do_sqbs(q, state, bufnr, count); | ||
249 | |||
250 | for (i = 0; i < count; i++) { | ||
251 | xchg(&q->slsb.val[bufnr], state); | ||
252 | bufnr = next_buf(bufnr); | ||
253 | } | ||
254 | return count; | ||
255 | } | ||
256 | |||
257 | static inline int set_buf_state(struct qdio_q *q, int bufnr, | ||
258 | unsigned char state) | ||
259 | { | ||
260 | return set_buf_states(q, bufnr, state, 1); | ||
261 | } | ||
262 | |||
263 | /* set slsb states to initial state */ | ||
264 | void qdio_init_buf_states(struct qdio_irq *irq_ptr) | ||
265 | { | ||
266 | struct qdio_q *q; | ||
267 | int i; | ||
268 | |||
269 | for_each_input_queue(irq_ptr, q, i) | ||
270 | set_buf_states(q, 0, SLSB_P_INPUT_NOT_INIT, | ||
271 | QDIO_MAX_BUFFERS_PER_Q); | ||
272 | for_each_output_queue(irq_ptr, q, i) | ||
273 | set_buf_states(q, 0, SLSB_P_OUTPUT_NOT_INIT, | ||
274 | QDIO_MAX_BUFFERS_PER_Q); | ||
275 | } | ||
276 | |||
277 | static int qdio_siga_sync(struct qdio_q *q, unsigned int output, | ||
278 | unsigned int input) | ||
279 | { | ||
280 | int cc; | ||
281 | |||
282 | if (!need_siga_sync(q)) | ||
283 | return 0; | ||
284 | |||
285 | qdio_perf_stat_inc(&perf_stats.siga_sync); | ||
286 | |||
287 | cc = do_siga_sync(q->irq_ptr->schid, output, input); | ||
288 | if (cc) { | ||
289 | QDIO_DBF_TEXT4(0, trace, "sigasync"); | ||
290 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
291 | QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *)); | ||
292 | } | ||
293 | return cc; | ||
294 | } | ||
295 | |||
296 | inline int qdio_siga_sync_q(struct qdio_q *q) | ||
297 | { | ||
298 | if (q->is_input_q) | ||
299 | return qdio_siga_sync(q, 0, q->mask); | ||
300 | else | ||
301 | return qdio_siga_sync(q, q->mask, 0); | ||
302 | } | ||
303 | |||
304 | static inline int qdio_siga_sync_out(struct qdio_q *q) | ||
305 | { | ||
306 | return qdio_siga_sync(q, ~0U, 0); | ||
307 | } | ||
308 | |||
309 | static inline int qdio_siga_sync_all(struct qdio_q *q) | ||
310 | { | ||
311 | return qdio_siga_sync(q, ~0U, ~0U); | ||
312 | } | ||
313 | |||
314 | static inline int qdio_do_siga_output(struct qdio_q *q, unsigned int *busy_bit) | ||
315 | { | ||
316 | unsigned int fc = 0; | ||
317 | unsigned long schid; | ||
318 | |||
319 | if (!is_qebsm(q)) | ||
320 | schid = *((u32 *)&q->irq_ptr->schid); | ||
321 | else { | ||
322 | schid = q->irq_ptr->sch_token; | ||
323 | fc |= 0x80; | ||
324 | } | ||
325 | return do_siga_output(schid, q->mask, busy_bit, fc); | ||
326 | } | ||
327 | |||
328 | static int qdio_siga_output(struct qdio_q *q) | ||
329 | { | ||
330 | int cc; | ||
331 | u32 busy_bit; | ||
332 | u64 start_time = 0; | ||
333 | |||
334 | QDIO_DBF_TEXT5(0, trace, "sigaout"); | ||
335 | QDIO_DBF_HEX5(0, trace, &q, sizeof(void *)); | ||
336 | |||
337 | qdio_perf_stat_inc(&perf_stats.siga_out); | ||
338 | again: | ||
339 | cc = qdio_do_siga_output(q, &busy_bit); | ||
340 | if (queue_type(q) == QDIO_IQDIO_QFMT && cc == 2 && busy_bit) { | ||
341 | if (!start_time) | ||
342 | start_time = get_usecs(); | ||
343 | else if ((get_usecs() - start_time) < QDIO_BUSY_BIT_PATIENCE) | ||
344 | goto again; | ||
345 | } | ||
346 | |||
347 | if (cc == 2 && busy_bit) | ||
348 | cc |= QDIO_ERROR_SIGA_BUSY; | ||
349 | if (cc) | ||
350 | QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *)); | ||
351 | return cc; | ||
352 | } | ||
353 | |||
354 | static inline int qdio_siga_input(struct qdio_q *q) | ||
355 | { | ||
356 | int cc; | ||
357 | |||
358 | QDIO_DBF_TEXT4(0, trace, "sigain"); | ||
359 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
360 | |||
361 | qdio_perf_stat_inc(&perf_stats.siga_in); | ||
362 | |||
363 | cc = do_siga_input(q->irq_ptr->schid, q->mask); | ||
364 | if (cc) | ||
365 | QDIO_DBF_HEX3(0, trace, &cc, sizeof(int *)); | ||
366 | return cc; | ||
367 | } | ||
368 | |||
369 | /* called from thinint inbound handler */ | ||
370 | void qdio_sync_after_thinint(struct qdio_q *q) | ||
371 | { | ||
372 | if (pci_out_supported(q)) { | ||
373 | if (need_siga_sync_thinint(q)) | ||
374 | qdio_siga_sync_all(q); | ||
375 | else if (need_siga_sync_out_thinint(q)) | ||
376 | qdio_siga_sync_out(q); | ||
377 | } else | ||
378 | qdio_siga_sync_q(q); | ||
379 | } | ||
380 | |||
381 | inline void qdio_stop_polling(struct qdio_q *q) | ||
382 | { | ||
383 | spin_lock_bh(&q->u.in.lock); | ||
384 | if (!q->u.in.polling) { | ||
385 | spin_unlock_bh(&q->u.in.lock); | ||
386 | return; | ||
387 | } | ||
388 | q->u.in.polling = 0; | ||
389 | qdio_perf_stat_inc(&perf_stats.debug_stop_polling); | ||
390 | |||
391 | /* show the card that we are not polling anymore */ | ||
392 | set_buf_state(q, q->last_move_ftc, SLSB_P_INPUT_NOT_INIT); | ||
393 | spin_unlock_bh(&q->u.in.lock); | ||
394 | } | ||
395 | |||
396 | static void announce_buffer_error(struct qdio_q *q) | ||
397 | { | ||
398 | char dbf_text[15]; | ||
399 | |||
400 | if (q->is_input_q) | ||
401 | QDIO_DBF_TEXT3(1, trace, "inperr"); | ||
402 | else | ||
403 | QDIO_DBF_TEXT3(0, trace, "outperr"); | ||
404 | |||
405 | sprintf(dbf_text, "%x-%x-%x", q->first_to_check, | ||
406 | q->sbal[q->first_to_check]->element[14].flags, | ||
407 | q->sbal[q->first_to_check]->element[15].flags); | ||
408 | QDIO_DBF_TEXT3(1, trace, dbf_text); | ||
409 | QDIO_DBF_HEX2(1, trace, q->sbal[q->first_to_check], 256); | ||
410 | |||
411 | q->qdio_error = QDIO_ERROR_SLSB_STATE; | ||
412 | } | ||
413 | |||
414 | static int get_inbound_buffer_frontier(struct qdio_q *q) | ||
415 | { | ||
416 | int count, stop; | ||
417 | unsigned char state; | ||
418 | |||
419 | /* | ||
420 | * If we still poll don't update last_move_ftc, keep the | ||
421 | * previously ACK buffer there. | ||
422 | */ | ||
423 | if (!q->u.in.polling) | ||
424 | q->last_move_ftc = q->first_to_check; | ||
425 | |||
426 | /* | ||
427 | * Don't check 128 buffers, as otherwise qdio_inbound_q_moved | ||
428 | * would return 0. | ||
429 | */ | ||
430 | count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK); | ||
431 | stop = add_buf(q->first_to_check, count); | ||
432 | |||
433 | /* | ||
434 | * No siga sync here, as a PCI or we after a thin interrupt | ||
435 | * will sync the queues. | ||
436 | */ | ||
437 | |||
438 | /* need to set count to 1 for non-qebsm */ | ||
439 | if (!is_qebsm(q)) | ||
440 | count = 1; | ||
441 | |||
442 | check_next: | ||
443 | if (q->first_to_check == stop) | ||
444 | goto out; | ||
445 | |||
446 | count = get_buf_states(q, q->first_to_check, &state, count); | ||
447 | if (!count) | ||
448 | goto out; | ||
449 | |||
450 | switch (state) { | ||
451 | case SLSB_P_INPUT_PRIMED: | ||
452 | QDIO_DBF_TEXT5(0, trace, "inptprim"); | ||
453 | |||
454 | /* | ||
455 | * Only ACK the first buffer. The ACK will be removed in | ||
456 | * qdio_stop_polling. | ||
457 | */ | ||
458 | if (q->u.in.polling) | ||
459 | state = SLSB_P_INPUT_NOT_INIT; | ||
460 | else { | ||
461 | q->u.in.polling = 1; | ||
462 | state = SLSB_P_INPUT_ACK; | ||
463 | } | ||
464 | set_buf_state(q, q->first_to_check, state); | ||
465 | |||
466 | /* | ||
467 | * Need to change all PRIMED buffers to NOT_INIT, otherwise | ||
468 | * we're loosing initiative in the thinint code. | ||
469 | */ | ||
470 | if (count > 1) | ||
471 | set_buf_states(q, next_buf(q->first_to_check), | ||
472 | SLSB_P_INPUT_NOT_INIT, count - 1); | ||
473 | |||
474 | /* | ||
475 | * No siga-sync needed for non-qebsm here, as the inbound queue | ||
476 | * will be synced on the next siga-r, resp. | ||
477 | * tiqdio_is_inbound_q_done will do the siga-sync. | ||
478 | */ | ||
479 | q->first_to_check = add_buf(q->first_to_check, count); | ||
480 | atomic_sub(count, &q->nr_buf_used); | ||
481 | goto check_next; | ||
482 | case SLSB_P_INPUT_ERROR: | ||
483 | announce_buffer_error(q); | ||
484 | /* process the buffer, the upper layer will take care of it */ | ||
485 | q->first_to_check = add_buf(q->first_to_check, count); | ||
486 | atomic_sub(count, &q->nr_buf_used); | ||
487 | break; | ||
488 | case SLSB_CU_INPUT_EMPTY: | ||
489 | case SLSB_P_INPUT_NOT_INIT: | ||
490 | case SLSB_P_INPUT_ACK: | ||
491 | QDIO_DBF_TEXT5(0, trace, "inpnipro"); | ||
492 | break; | ||
493 | default: | ||
494 | BUG(); | ||
495 | } | ||
496 | out: | ||
497 | QDIO_DBF_HEX4(0, trace, &q->first_to_check, sizeof(int)); | ||
498 | return q->first_to_check; | ||
499 | } | ||
500 | |||
501 | int qdio_inbound_q_moved(struct qdio_q *q) | ||
502 | { | ||
503 | int bufnr; | ||
504 | |||
505 | bufnr = get_inbound_buffer_frontier(q); | ||
506 | |||
507 | if ((bufnr != q->last_move_ftc) || q->qdio_error) { | ||
508 | if (!need_siga_sync(q) && !pci_out_supported(q)) | ||
509 | q->u.in.timestamp = get_usecs(); | ||
510 | |||
511 | QDIO_DBF_TEXT4(0, trace, "inhasmvd"); | ||
512 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
513 | return 1; | ||
514 | } else | ||
515 | return 0; | ||
516 | } | ||
517 | |||
518 | static int qdio_inbound_q_done(struct qdio_q *q) | ||
519 | { | ||
520 | unsigned char state; | ||
521 | #ifdef CONFIG_QDIO_DEBUG | ||
522 | char dbf_text[15]; | ||
523 | #endif | ||
524 | |||
525 | if (!atomic_read(&q->nr_buf_used)) | ||
526 | return 1; | ||
527 | |||
528 | /* | ||
529 | * We need that one for synchronization with the adapter, as it | ||
530 | * does a kind of PCI avoidance. | ||
531 | */ | ||
532 | qdio_siga_sync_q(q); | ||
533 | |||
534 | get_buf_state(q, q->first_to_check, &state); | ||
535 | if (state == SLSB_P_INPUT_PRIMED) | ||
536 | /* we got something to do */ | ||
537 | return 0; | ||
538 | |||
539 | /* on VM, we don't poll, so the q is always done here */ | ||
540 | if (need_siga_sync(q) || pci_out_supported(q)) | ||
541 | return 1; | ||
542 | |||
543 | /* | ||
544 | * At this point we know, that inbound first_to_check | ||
545 | * has (probably) not moved (see qdio_inbound_processing). | ||
546 | */ | ||
547 | if (get_usecs() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) { | ||
548 | #ifdef CONFIG_QDIO_DEBUG | ||
549 | QDIO_DBF_TEXT4(0, trace, "inqisdon"); | ||
550 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
551 | sprintf(dbf_text, "pf%02x", q->first_to_check); | ||
552 | QDIO_DBF_TEXT4(0, trace, dbf_text); | ||
553 | #endif /* CONFIG_QDIO_DEBUG */ | ||
554 | return 1; | ||
555 | } else { | ||
556 | #ifdef CONFIG_QDIO_DEBUG | ||
557 | QDIO_DBF_TEXT4(0, trace, "inqisntd"); | ||
558 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
559 | sprintf(dbf_text, "pf%02x", q->first_to_check); | ||
560 | QDIO_DBF_TEXT4(0, trace, dbf_text); | ||
561 | #endif /* CONFIG_QDIO_DEBUG */ | ||
562 | return 0; | ||
563 | } | ||
564 | } | ||
565 | |||
566 | void qdio_kick_inbound_handler(struct qdio_q *q) | ||
567 | { | ||
568 | int count, start, end; | ||
569 | #ifdef CONFIG_QDIO_DEBUG | ||
570 | char dbf_text[15]; | ||
571 | #endif | ||
572 | |||
573 | qdio_perf_stat_inc(&perf_stats.inbound_handler); | ||
574 | |||
575 | start = q->first_to_kick; | ||
576 | end = q->first_to_check; | ||
577 | if (end >= start) | ||
578 | count = end - start; | ||
579 | else | ||
580 | count = end + QDIO_MAX_BUFFERS_PER_Q - start; | ||
581 | |||
582 | #ifdef CONFIG_QDIO_DEBUG | ||
583 | sprintf(dbf_text, "s=%2xc=%2x", start, count); | ||
584 | QDIO_DBF_TEXT4(0, trace, dbf_text); | ||
585 | #endif /* CONFIG_QDIO_DEBUG */ | ||
586 | |||
587 | if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)) | ||
588 | return; | ||
589 | |||
590 | q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, | ||
591 | start, count, q->irq_ptr->int_parm); | ||
592 | |||
593 | /* for the next time */ | ||
594 | q->first_to_kick = q->first_to_check; | ||
595 | q->qdio_error = 0; | ||
596 | } | ||
597 | |||
598 | static void __qdio_inbound_processing(struct qdio_q *q) | ||
599 | { | ||
600 | qdio_perf_stat_inc(&perf_stats.tasklet_inbound); | ||
601 | again: | ||
602 | if (!qdio_inbound_q_moved(q)) | ||
603 | return; | ||
604 | |||
605 | qdio_kick_inbound_handler(q); | ||
606 | |||
607 | if (!qdio_inbound_q_done(q)) | ||
608 | /* means poll time is not yet over */ | ||
609 | goto again; | ||
610 | |||
611 | qdio_stop_polling(q); | ||
612 | /* | ||
613 | * We need to check again to not lose initiative after | ||
614 | * resetting the ACK state. | ||
615 | */ | ||
616 | if (!qdio_inbound_q_done(q)) | ||
617 | goto again; | ||
618 | } | ||
619 | |||
620 | /* inbound tasklet */ | ||
621 | void qdio_inbound_processing(unsigned long data) | ||
622 | { | ||
623 | struct qdio_q *q = (struct qdio_q *)data; | ||
624 | __qdio_inbound_processing(q); | ||
625 | } | ||
626 | |||
627 | static int get_outbound_buffer_frontier(struct qdio_q *q) | ||
628 | { | ||
629 | int count, stop; | ||
630 | unsigned char state; | ||
631 | |||
632 | if (((queue_type(q) != QDIO_IQDIO_QFMT) && !pci_out_supported(q)) || | ||
633 | (queue_type(q) == QDIO_IQDIO_QFMT && multicast_outbound(q))) | ||
634 | qdio_siga_sync_q(q); | ||
635 | |||
636 | /* | ||
637 | * Don't check 128 buffers, as otherwise qdio_inbound_q_moved | ||
638 | * would return 0. | ||
639 | */ | ||
640 | count = min(atomic_read(&q->nr_buf_used), QDIO_MAX_BUFFERS_MASK); | ||
641 | stop = add_buf(q->first_to_check, count); | ||
642 | |||
643 | /* need to set count to 1 for non-qebsm */ | ||
644 | if (!is_qebsm(q)) | ||
645 | count = 1; | ||
646 | |||
647 | check_next: | ||
648 | if (q->first_to_check == stop) | ||
649 | return q->first_to_check; | ||
650 | |||
651 | count = get_buf_states(q, q->first_to_check, &state, count); | ||
652 | if (!count) | ||
653 | return q->first_to_check; | ||
654 | |||
655 | switch (state) { | ||
656 | case SLSB_P_OUTPUT_EMPTY: | ||
657 | /* the adapter got it */ | ||
658 | QDIO_DBF_TEXT5(0, trace, "outpempt"); | ||
659 | |||
660 | atomic_sub(count, &q->nr_buf_used); | ||
661 | q->first_to_check = add_buf(q->first_to_check, count); | ||
662 | /* | ||
663 | * We fetch all buffer states at once. get_buf_states may | ||
664 | * return count < stop. For QEBSM we do not loop. | ||
665 | */ | ||
666 | if (is_qebsm(q)) | ||
667 | break; | ||
668 | goto check_next; | ||
669 | case SLSB_P_OUTPUT_ERROR: | ||
670 | announce_buffer_error(q); | ||
671 | /* process the buffer, the upper layer will take care of it */ | ||
672 | q->first_to_check = add_buf(q->first_to_check, count); | ||
673 | atomic_sub(count, &q->nr_buf_used); | ||
674 | break; | ||
675 | case SLSB_CU_OUTPUT_PRIMED: | ||
676 | /* the adapter has not fetched the output yet */ | ||
677 | QDIO_DBF_TEXT5(0, trace, "outpprim"); | ||
678 | break; | ||
679 | case SLSB_P_OUTPUT_NOT_INIT: | ||
680 | case SLSB_P_OUTPUT_HALTED: | ||
681 | break; | ||
682 | default: | ||
683 | BUG(); | ||
684 | } | ||
685 | return q->first_to_check; | ||
686 | } | ||
687 | |||
688 | /* all buffers processed? */ | ||
689 | static inline int qdio_outbound_q_done(struct qdio_q *q) | ||
690 | { | ||
691 | return atomic_read(&q->nr_buf_used) == 0; | ||
692 | } | ||
693 | |||
694 | static inline int qdio_outbound_q_moved(struct qdio_q *q) | ||
695 | { | ||
696 | int bufnr; | ||
697 | |||
698 | bufnr = get_outbound_buffer_frontier(q); | ||
699 | |||
700 | if ((bufnr != q->last_move_ftc) || q->qdio_error) { | ||
701 | q->last_move_ftc = bufnr; | ||
702 | QDIO_DBF_TEXT4(0, trace, "oqhasmvd"); | ||
703 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
704 | return 1; | ||
705 | } else | ||
706 | return 0; | ||
707 | } | ||
708 | |||
709 | /* | ||
710 | * VM could present us cc=2 and busy bit set on SIGA-write | ||
711 | * during reconfiguration of their Guest LAN (only in iqdio mode, | ||
712 | * otherwise qdio is asynchronous and cc=2 and busy bit there will take | ||
713 | * the queues down immediately). | ||
714 | * | ||
715 | * Therefore qdio_siga_output will try for a short time constantly, | ||
716 | * if such a condition occurs. If it doesn't change, it will | ||
717 | * increase the busy_siga_counter and save the timestamp, and | ||
718 | * schedule the queue for later processing. qdio_outbound_processing | ||
719 | * will check out the counter. If non-zero, it will call qdio_kick_outbound_q | ||
720 | * as often as the value of the counter. This will attempt further SIGA | ||
721 | * instructions. For each successful SIGA, the counter is | ||
722 | * decreased, for failing SIGAs the counter remains the same, after | ||
723 | * all. After some time of no movement, qdio_kick_outbound_q will | ||
724 | * finally fail and reflect corresponding error codes to call | ||
725 | * the upper layer module and have it take the queues down. | ||
726 | * | ||
727 | * Note that this is a change from the original HiperSockets design | ||
728 | * (saying cc=2 and busy bit means take the queues down), but in | ||
729 | * these days Guest LAN didn't exist... excessive cc=2 with busy bit | ||
730 | * conditions will still take the queues down, but the threshold is | ||
731 | * higher due to the Guest LAN environment. | ||
732 | * | ||
733 | * Called from outbound tasklet and do_QDIO handler. | ||
734 | */ | ||
735 | static void qdio_kick_outbound_q(struct qdio_q *q) | ||
736 | { | ||
737 | int rc; | ||
738 | #ifdef CONFIG_QDIO_DEBUG | ||
739 | char dbf_text[15]; | ||
740 | |||
741 | QDIO_DBF_TEXT5(0, trace, "kickoutq"); | ||
742 | QDIO_DBF_HEX5(0, trace, &q, sizeof(void *)); | ||
743 | #endif /* CONFIG_QDIO_DEBUG */ | ||
744 | |||
745 | if (!need_siga_out(q)) | ||
746 | return; | ||
747 | |||
748 | rc = qdio_siga_output(q); | ||
749 | switch (rc) { | ||
750 | case 0: | ||
751 | /* went smooth this time, reset timestamp */ | ||
752 | q->u.out.timestamp = 0; | ||
753 | |||
754 | /* TODO: improve error handling for CC=0 case */ | ||
755 | #ifdef CONFIG_QDIO_DEBUG | ||
756 | QDIO_DBF_TEXT3(0, trace, "cc2reslv"); | ||
757 | sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no, q->nr, | ||
758 | atomic_read(&q->u.out.busy_siga_counter)); | ||
759 | QDIO_DBF_TEXT3(0, trace, dbf_text); | ||
760 | #endif /* CONFIG_QDIO_DEBUG */ | ||
761 | break; | ||
762 | /* cc=2 and busy bit */ | ||
763 | case (2 | QDIO_ERROR_SIGA_BUSY): | ||
764 | atomic_inc(&q->u.out.busy_siga_counter); | ||
765 | |||
766 | /* if the last siga was successful, save timestamp here */ | ||
767 | if (!q->u.out.timestamp) | ||
768 | q->u.out.timestamp = get_usecs(); | ||
769 | |||
770 | /* if we're in time, don't touch qdio_error */ | ||
771 | if (get_usecs() - q->u.out.timestamp < QDIO_BUSY_BIT_GIVE_UP) { | ||
772 | tasklet_schedule(&q->tasklet); | ||
773 | break; | ||
774 | } | ||
775 | QDIO_DBF_TEXT2(0, trace, "cc2REPRT"); | ||
776 | #ifdef CONFIG_QDIO_DEBUG | ||
777 | sprintf(dbf_text, "%4x%2x%2x", q->irq_ptr->schid.sch_no, q->nr, | ||
778 | atomic_read(&q->u.out.busy_siga_counter)); | ||
779 | QDIO_DBF_TEXT3(0, trace, dbf_text); | ||
780 | #endif /* CONFIG_QDIO_DEBUG */ | ||
781 | default: | ||
782 | /* for plain cc=1, 2 or 3 */ | ||
783 | q->qdio_error = rc; | ||
784 | } | ||
785 | } | ||
786 | |||
787 | static void qdio_kick_outbound_handler(struct qdio_q *q) | ||
788 | { | ||
789 | int start, end, count; | ||
790 | #ifdef CONFIG_QDIO_DEBUG | ||
791 | char dbf_text[15]; | ||
792 | #endif | ||
793 | |||
794 | start = q->first_to_kick; | ||
795 | end = q->last_move_ftc; | ||
796 | if (end >= start) | ||
797 | count = end - start; | ||
798 | else | ||
799 | count = end + QDIO_MAX_BUFFERS_PER_Q - start; | ||
800 | |||
801 | #ifdef CONFIG_QDIO_DEBUG | ||
802 | QDIO_DBF_TEXT4(0, trace, "kickouth"); | ||
803 | QDIO_DBF_HEX4(0, trace, &q, sizeof(void *)); | ||
804 | |||
805 | sprintf(dbf_text, "s=%2xc=%2x", start, count); | ||
806 | QDIO_DBF_TEXT4(0, trace, dbf_text); | ||
807 | #endif /* CONFIG_QDIO_DEBUG */ | ||
808 | |||
809 | if (unlikely(q->irq_ptr->state != QDIO_IRQ_STATE_ACTIVE)) | ||
810 | return; | ||
811 | |||
812 | q->handler(q->irq_ptr->cdev, q->qdio_error, q->nr, start, count, | ||
813 | q->irq_ptr->int_parm); | ||
814 | |||
815 | /* for the next time: */ | ||
816 | q->first_to_kick = q->last_move_ftc; | ||
817 | q->qdio_error = 0; | ||
818 | } | ||
819 | |||
820 | static void __qdio_outbound_processing(struct qdio_q *q) | ||
821 | { | ||
822 | int siga_attempts; | ||
823 | |||
824 | qdio_perf_stat_inc(&perf_stats.tasklet_outbound); | ||
825 | |||
826 | /* see comment in qdio_kick_outbound_q */ | ||
827 | siga_attempts = atomic_read(&q->u.out.busy_siga_counter); | ||
828 | while (siga_attempts--) { | ||
829 | atomic_dec(&q->u.out.busy_siga_counter); | ||
830 | qdio_kick_outbound_q(q); | ||
831 | } | ||
832 | |||
833 | BUG_ON(atomic_read(&q->nr_buf_used) < 0); | ||
834 | |||
835 | if (qdio_outbound_q_moved(q)) | ||
836 | qdio_kick_outbound_handler(q); | ||
837 | |||
838 | if (queue_type(q) == QDIO_ZFCP_QFMT) { | ||
839 | if (!pci_out_supported(q) && !qdio_outbound_q_done(q)) | ||
840 | tasklet_schedule(&q->tasklet); | ||
841 | return; | ||
842 | } | ||
843 | |||
844 | /* bail out for HiperSockets unicast queues */ | ||
845 | if (queue_type(q) == QDIO_IQDIO_QFMT && !multicast_outbound(q)) | ||
846 | return; | ||
847 | |||
848 | if (q->u.out.pci_out_enabled) | ||
849 | return; | ||
850 | |||
851 | /* | ||
852 | * Now we know that queue type is either qeth without pci enabled | ||
853 | * or HiperSockets multicast. Make sure buffer switch from PRIMED to | ||
854 | * EMPTY is noticed and outbound_handler is called after some time. | ||
855 | */ | ||
856 | if (qdio_outbound_q_done(q)) | ||
857 | del_timer(&q->u.out.timer); | ||
858 | else { | ||
859 | if (!timer_pending(&q->u.out.timer)) { | ||
860 | mod_timer(&q->u.out.timer, jiffies + 10 * HZ); | ||
861 | qdio_perf_stat_inc(&perf_stats.debug_tl_out_timer); | ||
862 | } | ||
863 | } | ||
864 | } | ||
865 | |||
866 | /* outbound tasklet */ | ||
867 | void qdio_outbound_processing(unsigned long data) | ||
868 | { | ||
869 | struct qdio_q *q = (struct qdio_q *)data; | ||
870 | __qdio_outbound_processing(q); | ||
871 | } | ||
872 | |||
873 | void qdio_outbound_timer(unsigned long data) | ||
874 | { | ||
875 | struct qdio_q *q = (struct qdio_q *)data; | ||
876 | tasklet_schedule(&q->tasklet); | ||
877 | } | ||
878 | |||
879 | /* called from thinint inbound tasklet */ | ||
880 | void qdio_check_outbound_after_thinint(struct qdio_q *q) | ||
881 | { | ||
882 | struct qdio_q *out; | ||
883 | int i; | ||
884 | |||
885 | if (!pci_out_supported(q)) | ||
886 | return; | ||
887 | |||
888 | for_each_output_queue(q->irq_ptr, out, i) | ||
889 | if (!qdio_outbound_q_done(out)) | ||
890 | tasklet_schedule(&out->tasklet); | ||
891 | } | ||
892 | |||
893 | static inline void qdio_set_state(struct qdio_irq *irq_ptr, | ||
894 | enum qdio_irq_states state) | ||
895 | { | ||
896 | #ifdef CONFIG_QDIO_DEBUG | ||
897 | char dbf_text[15]; | ||
898 | |||
899 | QDIO_DBF_TEXT5(0, trace, "newstate"); | ||
900 | sprintf(dbf_text, "%4x%4x", irq_ptr->schid.sch_no, state); | ||
901 | QDIO_DBF_TEXT5(0, trace, dbf_text); | ||
902 | #endif /* CONFIG_QDIO_DEBUG */ | ||
903 | |||
904 | irq_ptr->state = state; | ||
905 | mb(); | ||
906 | } | ||
907 | |||
908 | static void qdio_irq_check_sense(struct subchannel_id schid, struct irb *irb) | ||
909 | { | ||
910 | char dbf_text[15]; | ||
911 | |||
912 | if (irb->esw.esw0.erw.cons) { | ||
913 | sprintf(dbf_text, "sens%4x", schid.sch_no); | ||
914 | QDIO_DBF_TEXT2(1, trace, dbf_text); | ||
915 | QDIO_DBF_HEX0(0, trace, irb, 64); | ||
916 | QDIO_DBF_HEX0(0, trace, irb->ecw, 64); | ||
917 | } | ||
918 | } | ||
919 | |||
920 | /* PCI interrupt handler */ | ||
921 | static void qdio_int_handler_pci(struct qdio_irq *irq_ptr) | ||
922 | { | ||
923 | int i; | ||
924 | struct qdio_q *q; | ||
925 | |||
926 | qdio_perf_stat_inc(&perf_stats.pci_int); | ||
927 | |||
928 | for_each_input_queue(irq_ptr, q, i) | ||
929 | tasklet_schedule(&q->tasklet); | ||
930 | |||
931 | if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)) | ||
932 | return; | ||
933 | |||
934 | for_each_output_queue(irq_ptr, q, i) { | ||
935 | if (qdio_outbound_q_done(q)) | ||
936 | continue; | ||
937 | |||
938 | if (!siga_syncs_out_pci(q)) | ||
939 | qdio_siga_sync_q(q); | ||
940 | |||
941 | tasklet_schedule(&q->tasklet); | ||
942 | } | ||
943 | } | ||
944 | |||
945 | static void qdio_handle_activate_check(struct ccw_device *cdev, | ||
946 | unsigned long intparm, int cstat, int dstat) | ||
947 | { | ||
948 | struct qdio_irq *irq_ptr = cdev->private->qdio_data; | ||
949 | struct qdio_q *q; | ||
950 | char dbf_text[15]; | ||
951 | |||
952 | QDIO_DBF_TEXT2(1, trace, "ick2"); | ||
953 | sprintf(dbf_text, "%s", cdev->dev.bus_id); | ||
954 | QDIO_DBF_TEXT2(1, trace, dbf_text); | ||
955 | QDIO_DBF_HEX2(0, trace, &intparm, sizeof(int)); | ||
956 | QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int)); | ||
957 | QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int)); | ||
958 | |||
959 | if (irq_ptr->nr_input_qs) { | ||
960 | q = irq_ptr->input_qs[0]; | ||
961 | } else if (irq_ptr->nr_output_qs) { | ||
962 | q = irq_ptr->output_qs[0]; | ||
963 | } else { | ||
964 | dump_stack(); | ||
965 | goto no_handler; | ||
966 | } | ||
967 | q->handler(q->irq_ptr->cdev, QDIO_ERROR_ACTIVATE_CHECK_CONDITION, | ||
968 | 0, -1, -1, irq_ptr->int_parm); | ||
969 | no_handler: | ||
970 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED); | ||
971 | } | ||
972 | |||
973 | static void qdio_call_shutdown(struct work_struct *work) | ||
974 | { | ||
975 | struct ccw_device_private *priv; | ||
976 | struct ccw_device *cdev; | ||
977 | |||
978 | priv = container_of(work, struct ccw_device_private, kick_work); | ||
979 | cdev = priv->cdev; | ||
980 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
981 | put_device(&cdev->dev); | ||
982 | } | ||
983 | |||
984 | static void qdio_int_error(struct ccw_device *cdev) | ||
985 | { | ||
986 | struct qdio_irq *irq_ptr = cdev->private->qdio_data; | ||
987 | |||
988 | switch (irq_ptr->state) { | ||
989 | case QDIO_IRQ_STATE_INACTIVE: | ||
990 | case QDIO_IRQ_STATE_CLEANUP: | ||
991 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
992 | break; | ||
993 | case QDIO_IRQ_STATE_ESTABLISHED: | ||
994 | case QDIO_IRQ_STATE_ACTIVE: | ||
995 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_STOPPED); | ||
996 | if (get_device(&cdev->dev)) { | ||
997 | /* Can't call shutdown from interrupt context. */ | ||
998 | PREPARE_WORK(&cdev->private->kick_work, | ||
999 | qdio_call_shutdown); | ||
1000 | queue_work(ccw_device_work, &cdev->private->kick_work); | ||
1001 | } | ||
1002 | break; | ||
1003 | default: | ||
1004 | WARN_ON(1); | ||
1005 | } | ||
1006 | wake_up(&cdev->private->wait_q); | ||
1007 | } | ||
1008 | |||
1009 | static int qdio_establish_check_errors(struct ccw_device *cdev, int cstat, | ||
1010 | int dstat) | ||
1011 | { | ||
1012 | struct qdio_irq *irq_ptr = cdev->private->qdio_data; | ||
1013 | |||
1014 | if (cstat || (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))) { | ||
1015 | QDIO_DBF_TEXT2(1, setup, "eq:ckcon"); | ||
1016 | goto error; | ||
1017 | } | ||
1018 | |||
1019 | if (!(dstat & DEV_STAT_DEV_END)) { | ||
1020 | QDIO_DBF_TEXT2(1, setup, "eq:no de"); | ||
1021 | goto error; | ||
1022 | } | ||
1023 | |||
1024 | if (dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) { | ||
1025 | QDIO_DBF_TEXT2(1, setup, "eq:badio"); | ||
1026 | goto error; | ||
1027 | } | ||
1028 | return 0; | ||
1029 | error: | ||
1030 | QDIO_DBF_HEX2(0, trace, &cstat, sizeof(int)); | ||
1031 | QDIO_DBF_HEX2(0, trace, &dstat, sizeof(int)); | ||
1032 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ERR); | ||
1033 | return 1; | ||
1034 | } | ||
1035 | |||
1036 | static void qdio_establish_handle_irq(struct ccw_device *cdev, int cstat, | ||
1037 | int dstat) | ||
1038 | { | ||
1039 | struct qdio_irq *irq_ptr = cdev->private->qdio_data; | ||
1040 | char dbf_text[15]; | ||
1041 | |||
1042 | sprintf(dbf_text, "qehi%4x", cdev->private->schid.sch_no); | ||
1043 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1044 | QDIO_DBF_TEXT0(0, trace, dbf_text); | ||
1045 | |||
1046 | if (!qdio_establish_check_errors(cdev, cstat, dstat)) | ||
1047 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ESTABLISHED); | ||
1048 | } | ||
1049 | |||
1050 | /* qdio interrupt handler */ | ||
1051 | void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm, | ||
1052 | struct irb *irb) | ||
1053 | { | ||
1054 | struct qdio_irq *irq_ptr = cdev->private->qdio_data; | ||
1055 | int cstat, dstat; | ||
1056 | char dbf_text[15]; | ||
1057 | |||
1058 | qdio_perf_stat_inc(&perf_stats.qdio_int); | ||
1059 | |||
1060 | if (!intparm || !irq_ptr) { | ||
1061 | sprintf(dbf_text, "qihd%4x", cdev->private->schid.sch_no); | ||
1062 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1063 | return; | ||
1064 | } | ||
1065 | |||
1066 | if (IS_ERR(irb)) { | ||
1067 | switch (PTR_ERR(irb)) { | ||
1068 | case -EIO: | ||
1069 | sprintf(dbf_text, "ierr%4x", | ||
1070 | cdev->private->schid.sch_no); | ||
1071 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1072 | qdio_int_error(cdev); | ||
1073 | return; | ||
1074 | case -ETIMEDOUT: | ||
1075 | sprintf(dbf_text, "qtoh%4x", | ||
1076 | cdev->private->schid.sch_no); | ||
1077 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1078 | qdio_int_error(cdev); | ||
1079 | return; | ||
1080 | default: | ||
1081 | WARN_ON(1); | ||
1082 | return; | ||
1083 | } | ||
1084 | } | ||
1085 | qdio_irq_check_sense(irq_ptr->schid, irb); | ||
1086 | |||
1087 | cstat = irb->scsw.cmd.cstat; | ||
1088 | dstat = irb->scsw.cmd.dstat; | ||
1089 | |||
1090 | switch (irq_ptr->state) { | ||
1091 | case QDIO_IRQ_STATE_INACTIVE: | ||
1092 | qdio_establish_handle_irq(cdev, cstat, dstat); | ||
1093 | break; | ||
1094 | |||
1095 | case QDIO_IRQ_STATE_CLEANUP: | ||
1096 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
1097 | break; | ||
1098 | |||
1099 | case QDIO_IRQ_STATE_ESTABLISHED: | ||
1100 | case QDIO_IRQ_STATE_ACTIVE: | ||
1101 | if (cstat & SCHN_STAT_PCI) { | ||
1102 | qdio_int_handler_pci(irq_ptr); | ||
1103 | /* no state change so no need to wake up wait_q */ | ||
1104 | return; | ||
1105 | } | ||
1106 | if ((cstat & ~SCHN_STAT_PCI) || dstat) { | ||
1107 | qdio_handle_activate_check(cdev, intparm, cstat, | ||
1108 | dstat); | ||
1109 | break; | ||
1110 | } | ||
1111 | default: | ||
1112 | WARN_ON(1); | ||
1113 | } | ||
1114 | wake_up(&cdev->private->wait_q); | ||
1115 | } | ||
1116 | |||
1117 | /** | ||
1118 | * qdio_get_ssqd_desc - get qdio subchannel description | ||
1119 | * @cdev: ccw device to get description for | ||
1120 | * | ||
1121 | * Returns a pointer to the saved qdio subchannel description, | ||
1122 | * or NULL for not setup qdio devices. | ||
1123 | */ | ||
1124 | struct qdio_ssqd_desc *qdio_get_ssqd_desc(struct ccw_device *cdev) | ||
1125 | { | ||
1126 | struct qdio_irq *irq_ptr; | ||
1127 | |||
1128 | QDIO_DBF_TEXT0(0, setup, "getssqd"); | ||
1129 | |||
1130 | irq_ptr = cdev->private->qdio_data; | ||
1131 | if (!irq_ptr) | ||
1132 | return NULL; | ||
1133 | |||
1134 | return &irq_ptr->ssqd_desc; | ||
1135 | } | ||
1136 | EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc); | ||
1137 | |||
1138 | /** | ||
1139 | * qdio_cleanup - shutdown queues and free data structures | ||
1140 | * @cdev: associated ccw device | ||
1141 | * @how: use halt or clear to shutdown | ||
1142 | * | ||
1143 | * This function calls qdio_shutdown() for @cdev with method @how | ||
1144 | * and on success qdio_free() for @cdev. | ||
1145 | */ | ||
1146 | int qdio_cleanup(struct ccw_device *cdev, int how) | ||
1147 | { | ||
1148 | struct qdio_irq *irq_ptr; | ||
1149 | char dbf_text[15]; | ||
1150 | int rc; | ||
1151 | |||
1152 | irq_ptr = cdev->private->qdio_data; | ||
1153 | if (!irq_ptr) | ||
1154 | return -ENODEV; | ||
1155 | |||
1156 | sprintf(dbf_text, "qcln%4x", irq_ptr->schid.sch_no); | ||
1157 | QDIO_DBF_TEXT1(0, trace, dbf_text); | ||
1158 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1159 | |||
1160 | rc = qdio_shutdown(cdev, how); | ||
1161 | if (rc == 0) | ||
1162 | rc = qdio_free(cdev); | ||
1163 | return rc; | ||
1164 | } | ||
1165 | EXPORT_SYMBOL_GPL(qdio_cleanup); | ||
1166 | |||
1167 | static void qdio_shutdown_queues(struct ccw_device *cdev) | ||
1168 | { | ||
1169 | struct qdio_irq *irq_ptr = cdev->private->qdio_data; | ||
1170 | struct qdio_q *q; | ||
1171 | int i; | ||
1172 | |||
1173 | for_each_input_queue(irq_ptr, q, i) | ||
1174 | tasklet_disable(&q->tasklet); | ||
1175 | |||
1176 | for_each_output_queue(irq_ptr, q, i) { | ||
1177 | tasklet_disable(&q->tasklet); | ||
1178 | del_timer(&q->u.out.timer); | ||
1179 | } | ||
1180 | } | ||
1181 | |||
1182 | /** | ||
1183 | * qdio_shutdown - shut down a qdio subchannel | ||
1184 | * @cdev: associated ccw device | ||
1185 | * @how: use halt or clear to shutdown | ||
1186 | */ | ||
1187 | int qdio_shutdown(struct ccw_device *cdev, int how) | ||
1188 | { | ||
1189 | struct qdio_irq *irq_ptr; | ||
1190 | int rc; | ||
1191 | unsigned long flags; | ||
1192 | char dbf_text[15]; | ||
1193 | |||
1194 | irq_ptr = cdev->private->qdio_data; | ||
1195 | if (!irq_ptr) | ||
1196 | return -ENODEV; | ||
1197 | |||
1198 | mutex_lock(&irq_ptr->setup_mutex); | ||
1199 | /* | ||
1200 | * Subchannel was already shot down. We cannot prevent being called | ||
1201 | * twice since cio may trigger a shutdown asynchronously. | ||
1202 | */ | ||
1203 | if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) { | ||
1204 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1205 | return 0; | ||
1206 | } | ||
1207 | |||
1208 | sprintf(dbf_text, "qsqs%4x", irq_ptr->schid.sch_no); | ||
1209 | QDIO_DBF_TEXT1(0, trace, dbf_text); | ||
1210 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1211 | |||
1212 | tiqdio_remove_input_queues(irq_ptr); | ||
1213 | qdio_shutdown_queues(cdev); | ||
1214 | qdio_shutdown_debug_entries(irq_ptr, cdev); | ||
1215 | |||
1216 | /* cleanup subchannel */ | ||
1217 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); | ||
1218 | |||
1219 | if (how & QDIO_FLAG_CLEANUP_USING_CLEAR) | ||
1220 | rc = ccw_device_clear(cdev, QDIO_DOING_CLEANUP); | ||
1221 | else | ||
1222 | /* default behaviour is halt */ | ||
1223 | rc = ccw_device_halt(cdev, QDIO_DOING_CLEANUP); | ||
1224 | if (rc) { | ||
1225 | sprintf(dbf_text, "sher%4x", irq_ptr->schid.sch_no); | ||
1226 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1227 | sprintf(dbf_text, "rc=%d", rc); | ||
1228 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1229 | goto no_cleanup; | ||
1230 | } | ||
1231 | |||
1232 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_CLEANUP); | ||
1233 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | ||
1234 | wait_event_interruptible_timeout(cdev->private->wait_q, | ||
1235 | irq_ptr->state == QDIO_IRQ_STATE_INACTIVE || | ||
1236 | irq_ptr->state == QDIO_IRQ_STATE_ERR, | ||
1237 | 10 * HZ); | ||
1238 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); | ||
1239 | |||
1240 | no_cleanup: | ||
1241 | qdio_shutdown_thinint(irq_ptr); | ||
1242 | |||
1243 | /* restore interrupt handler */ | ||
1244 | if ((void *)cdev->handler == (void *)qdio_int_handler) | ||
1245 | cdev->handler = irq_ptr->orig_handler; | ||
1246 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); | ||
1247 | |||
1248 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
1249 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1250 | module_put(THIS_MODULE); | ||
1251 | if (rc) | ||
1252 | return rc; | ||
1253 | return 0; | ||
1254 | } | ||
1255 | EXPORT_SYMBOL_GPL(qdio_shutdown); | ||
1256 | |||
1257 | /** | ||
1258 | * qdio_free - free data structures for a qdio subchannel | ||
1259 | * @cdev: associated ccw device | ||
1260 | */ | ||
1261 | int qdio_free(struct ccw_device *cdev) | ||
1262 | { | ||
1263 | struct qdio_irq *irq_ptr; | ||
1264 | char dbf_text[15]; | ||
1265 | |||
1266 | irq_ptr = cdev->private->qdio_data; | ||
1267 | if (!irq_ptr) | ||
1268 | return -ENODEV; | ||
1269 | |||
1270 | mutex_lock(&irq_ptr->setup_mutex); | ||
1271 | |||
1272 | sprintf(dbf_text, "qfqs%4x", irq_ptr->schid.sch_no); | ||
1273 | QDIO_DBF_TEXT1(0, trace, dbf_text); | ||
1274 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1275 | |||
1276 | cdev->private->qdio_data = NULL; | ||
1277 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1278 | |||
1279 | qdio_release_memory(irq_ptr); | ||
1280 | return 0; | ||
1281 | } | ||
1282 | EXPORT_SYMBOL_GPL(qdio_free); | ||
1283 | |||
1284 | /** | ||
1285 | * qdio_initialize - allocate and establish queues for a qdio subchannel | ||
1286 | * @init_data: initialization data | ||
1287 | * | ||
1288 | * This function first allocates queues via qdio_allocate() and on success | ||
1289 | * establishes them via qdio_establish(). | ||
1290 | */ | ||
1291 | int qdio_initialize(struct qdio_initialize *init_data) | ||
1292 | { | ||
1293 | int rc; | ||
1294 | char dbf_text[15]; | ||
1295 | |||
1296 | sprintf(dbf_text, "qini%4x", init_data->cdev->private->schid.sch_no); | ||
1297 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1298 | QDIO_DBF_TEXT0(0, trace, dbf_text); | ||
1299 | |||
1300 | rc = qdio_allocate(init_data); | ||
1301 | if (rc) | ||
1302 | return rc; | ||
1303 | |||
1304 | rc = qdio_establish(init_data); | ||
1305 | if (rc) | ||
1306 | qdio_free(init_data->cdev); | ||
1307 | return rc; | ||
1308 | } | ||
1309 | EXPORT_SYMBOL_GPL(qdio_initialize); | ||
1310 | |||
1311 | /** | ||
1312 | * qdio_allocate - allocate qdio queues and associated data | ||
1313 | * @init_data: initialization data | ||
1314 | */ | ||
1315 | int qdio_allocate(struct qdio_initialize *init_data) | ||
1316 | { | ||
1317 | struct qdio_irq *irq_ptr; | ||
1318 | char dbf_text[15]; | ||
1319 | |||
1320 | sprintf(dbf_text, "qalc%4x", init_data->cdev->private->schid.sch_no); | ||
1321 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1322 | QDIO_DBF_TEXT0(0, trace, dbf_text); | ||
1323 | |||
1324 | if ((init_data->no_input_qs && !init_data->input_handler) || | ||
1325 | (init_data->no_output_qs && !init_data->output_handler)) | ||
1326 | return -EINVAL; | ||
1327 | |||
1328 | if ((init_data->no_input_qs > QDIO_MAX_QUEUES_PER_IRQ) || | ||
1329 | (init_data->no_output_qs > QDIO_MAX_QUEUES_PER_IRQ)) | ||
1330 | return -EINVAL; | ||
1331 | |||
1332 | if ((!init_data->input_sbal_addr_array) || | ||
1333 | (!init_data->output_sbal_addr_array)) | ||
1334 | return -EINVAL; | ||
1335 | |||
1336 | qdio_allocate_do_dbf(init_data); | ||
1337 | |||
1338 | /* irq_ptr must be in GFP_DMA since it contains ccw1.cda */ | ||
1339 | irq_ptr = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA); | ||
1340 | if (!irq_ptr) | ||
1341 | goto out_err; | ||
1342 | QDIO_DBF_TEXT0(0, setup, "irq_ptr:"); | ||
1343 | QDIO_DBF_HEX0(0, setup, &irq_ptr, sizeof(void *)); | ||
1344 | |||
1345 | mutex_init(&irq_ptr->setup_mutex); | ||
1346 | |||
1347 | /* | ||
1348 | * Allocate a page for the chsc calls in qdio_establish. | ||
1349 | * Must be pre-allocated since a zfcp recovery will call | ||
1350 | * qdio_establish. In case of low memory and swap on a zfcp disk | ||
1351 | * we may not be able to allocate memory otherwise. | ||
1352 | */ | ||
1353 | irq_ptr->chsc_page = get_zeroed_page(GFP_KERNEL); | ||
1354 | if (!irq_ptr->chsc_page) | ||
1355 | goto out_rel; | ||
1356 | |||
1357 | /* qdr is used in ccw1.cda which is u32 */ | ||
1358 | irq_ptr->qdr = kzalloc(sizeof(struct qdr), GFP_KERNEL | GFP_DMA); | ||
1359 | if (!irq_ptr->qdr) | ||
1360 | goto out_rel; | ||
1361 | WARN_ON((unsigned long)irq_ptr->qdr & 0xfff); | ||
1362 | |||
1363 | QDIO_DBF_TEXT0(0, setup, "qdr:"); | ||
1364 | QDIO_DBF_HEX0(0, setup, &irq_ptr->qdr, sizeof(void *)); | ||
1365 | |||
1366 | if (qdio_allocate_qs(irq_ptr, init_data->no_input_qs, | ||
1367 | init_data->no_output_qs)) | ||
1368 | goto out_rel; | ||
1369 | |||
1370 | init_data->cdev->private->qdio_data = irq_ptr; | ||
1371 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_INACTIVE); | ||
1372 | return 0; | ||
1373 | out_rel: | ||
1374 | qdio_release_memory(irq_ptr); | ||
1375 | out_err: | ||
1376 | return -ENOMEM; | ||
1377 | } | ||
1378 | EXPORT_SYMBOL_GPL(qdio_allocate); | ||
1379 | |||
1380 | /** | ||
1381 | * qdio_establish - establish queues on a qdio subchannel | ||
1382 | * @init_data: initialization data | ||
1383 | */ | ||
1384 | int qdio_establish(struct qdio_initialize *init_data) | ||
1385 | { | ||
1386 | char dbf_text[20]; | ||
1387 | struct qdio_irq *irq_ptr; | ||
1388 | struct ccw_device *cdev = init_data->cdev; | ||
1389 | unsigned long saveflags; | ||
1390 | int rc; | ||
1391 | |||
1392 | irq_ptr = cdev->private->qdio_data; | ||
1393 | if (!irq_ptr) | ||
1394 | return -ENODEV; | ||
1395 | |||
1396 | if (cdev->private->state != DEV_STATE_ONLINE) | ||
1397 | return -EINVAL; | ||
1398 | |||
1399 | if (!try_module_get(THIS_MODULE)) | ||
1400 | return -EINVAL; | ||
1401 | |||
1402 | sprintf(dbf_text, "qest%4x", cdev->private->schid.sch_no); | ||
1403 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
1404 | QDIO_DBF_TEXT0(0, trace, dbf_text); | ||
1405 | |||
1406 | mutex_lock(&irq_ptr->setup_mutex); | ||
1407 | qdio_setup_irq(init_data); | ||
1408 | |||
1409 | rc = qdio_establish_thinint(irq_ptr); | ||
1410 | if (rc) { | ||
1411 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1412 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
1413 | return rc; | ||
1414 | } | ||
1415 | |||
1416 | /* establish q */ | ||
1417 | irq_ptr->ccw.cmd_code = irq_ptr->equeue.cmd; | ||
1418 | irq_ptr->ccw.flags = CCW_FLAG_SLI; | ||
1419 | irq_ptr->ccw.count = irq_ptr->equeue.count; | ||
1420 | irq_ptr->ccw.cda = (u32)((addr_t)irq_ptr->qdr); | ||
1421 | |||
1422 | spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags); | ||
1423 | ccw_device_set_options_mask(cdev, 0); | ||
1424 | |||
1425 | rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ESTABLISH, 0, 0); | ||
1426 | if (rc) { | ||
1427 | sprintf(dbf_text, "eq:io%4x", irq_ptr->schid.sch_no); | ||
1428 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1429 | sprintf(dbf_text, "eq:rc%4x", rc); | ||
1430 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1431 | } | ||
1432 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags); | ||
1433 | |||
1434 | if (rc) { | ||
1435 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1436 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
1437 | return rc; | ||
1438 | } | ||
1439 | |||
1440 | wait_event_interruptible_timeout(cdev->private->wait_q, | ||
1441 | irq_ptr->state == QDIO_IRQ_STATE_ESTABLISHED || | ||
1442 | irq_ptr->state == QDIO_IRQ_STATE_ERR, HZ); | ||
1443 | |||
1444 | if (irq_ptr->state != QDIO_IRQ_STATE_ESTABLISHED) { | ||
1445 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1446 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
1447 | return -EIO; | ||
1448 | } | ||
1449 | |||
1450 | qdio_setup_ssqd_info(irq_ptr); | ||
1451 | sprintf(dbf_text, "qib ac%2x", irq_ptr->qib.ac); | ||
1452 | QDIO_DBF_TEXT2(0, setup, dbf_text); | ||
1453 | |||
1454 | /* qebsm is now setup if available, initialize buffer states */ | ||
1455 | qdio_init_buf_states(irq_ptr); | ||
1456 | |||
1457 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1458 | qdio_print_subchannel_info(irq_ptr, cdev); | ||
1459 | qdio_setup_debug_entries(irq_ptr, cdev); | ||
1460 | return 0; | ||
1461 | } | ||
1462 | EXPORT_SYMBOL_GPL(qdio_establish); | ||
1463 | |||
1464 | /** | ||
1465 | * qdio_activate - activate queues on a qdio subchannel | ||
1466 | * @cdev: associated cdev | ||
1467 | */ | ||
1468 | int qdio_activate(struct ccw_device *cdev) | ||
1469 | { | ||
1470 | struct qdio_irq *irq_ptr; | ||
1471 | int rc; | ||
1472 | unsigned long saveflags; | ||
1473 | char dbf_text[20]; | ||
1474 | |||
1475 | irq_ptr = cdev->private->qdio_data; | ||
1476 | if (!irq_ptr) | ||
1477 | return -ENODEV; | ||
1478 | |||
1479 | if (cdev->private->state != DEV_STATE_ONLINE) | ||
1480 | return -EINVAL; | ||
1481 | |||
1482 | mutex_lock(&irq_ptr->setup_mutex); | ||
1483 | if (irq_ptr->state == QDIO_IRQ_STATE_INACTIVE) { | ||
1484 | rc = -EBUSY; | ||
1485 | goto out; | ||
1486 | } | ||
1487 | |||
1488 | sprintf(dbf_text, "qact%4x", irq_ptr->schid.sch_no); | ||
1489 | QDIO_DBF_TEXT2(0, setup, dbf_text); | ||
1490 | QDIO_DBF_TEXT2(0, trace, dbf_text); | ||
1491 | |||
1492 | irq_ptr->ccw.cmd_code = irq_ptr->aqueue.cmd; | ||
1493 | irq_ptr->ccw.flags = CCW_FLAG_SLI; | ||
1494 | irq_ptr->ccw.count = irq_ptr->aqueue.count; | ||
1495 | irq_ptr->ccw.cda = 0; | ||
1496 | |||
1497 | spin_lock_irqsave(get_ccwdev_lock(cdev), saveflags); | ||
1498 | ccw_device_set_options(cdev, CCWDEV_REPORT_ALL); | ||
1499 | |||
1500 | rc = ccw_device_start(cdev, &irq_ptr->ccw, QDIO_DOING_ACTIVATE, | ||
1501 | 0, DOIO_DENY_PREFETCH); | ||
1502 | if (rc) { | ||
1503 | sprintf(dbf_text, "aq:io%4x", irq_ptr->schid.sch_no); | ||
1504 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1505 | sprintf(dbf_text, "aq:rc%4x", rc); | ||
1506 | QDIO_DBF_TEXT2(1, setup, dbf_text); | ||
1507 | } | ||
1508 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), saveflags); | ||
1509 | |||
1510 | if (rc) | ||
1511 | goto out; | ||
1512 | |||
1513 | if (is_thinint_irq(irq_ptr)) | ||
1514 | tiqdio_add_input_queues(irq_ptr); | ||
1515 | |||
1516 | /* wait for subchannel to become active */ | ||
1517 | msleep(5); | ||
1518 | |||
1519 | switch (irq_ptr->state) { | ||
1520 | case QDIO_IRQ_STATE_STOPPED: | ||
1521 | case QDIO_IRQ_STATE_ERR: | ||
1522 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1523 | qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); | ||
1524 | return -EIO; | ||
1525 | default: | ||
1526 | qdio_set_state(irq_ptr, QDIO_IRQ_STATE_ACTIVE); | ||
1527 | rc = 0; | ||
1528 | } | ||
1529 | out: | ||
1530 | mutex_unlock(&irq_ptr->setup_mutex); | ||
1531 | return rc; | ||
1532 | } | ||
1533 | EXPORT_SYMBOL_GPL(qdio_activate); | ||
1534 | |||
1535 | static inline int buf_in_between(int bufnr, int start, int count) | ||
1536 | { | ||
1537 | int end = add_buf(start, count); | ||
1538 | |||
1539 | if (end > start) { | ||
1540 | if (bufnr >= start && bufnr < end) | ||
1541 | return 1; | ||
1542 | else | ||
1543 | return 0; | ||
1544 | } | ||
1545 | |||
1546 | /* wrap-around case */ | ||
1547 | if ((bufnr >= start && bufnr <= QDIO_MAX_BUFFERS_PER_Q) || | ||
1548 | (bufnr < end)) | ||
1549 | return 1; | ||
1550 | else | ||
1551 | return 0; | ||
1552 | } | ||
1553 | |||
1554 | /** | ||
1555 | * handle_inbound - reset processed input buffers | ||
1556 | * @q: queue containing the buffers | ||
1557 | * @callflags: flags | ||
1558 | * @bufnr: first buffer to process | ||
1559 | * @count: how many buffers are emptied | ||
1560 | */ | ||
1561 | static void handle_inbound(struct qdio_q *q, unsigned int callflags, | ||
1562 | int bufnr, int count) | ||
1563 | { | ||
1564 | unsigned long flags; | ||
1565 | int used, rc; | ||
1566 | |||
1567 | /* | ||
1568 | * do_QDIO could run in parallel with the queue tasklet so the | ||
1569 | * upper-layer programm could empty the ACK'ed buffer here. | ||
1570 | * If that happens we must clear the polling flag, otherwise | ||
1571 | * qdio_stop_polling() could set the buffer to NOT_INIT after | ||
1572 | * it was set to EMPTY which would kill us. | ||
1573 | */ | ||
1574 | spin_lock_irqsave(&q->u.in.lock, flags); | ||
1575 | if (q->u.in.polling) | ||
1576 | if (buf_in_between(q->last_move_ftc, bufnr, count)) | ||
1577 | q->u.in.polling = 0; | ||
1578 | |||
1579 | count = set_buf_states(q, bufnr, SLSB_CU_INPUT_EMPTY, count); | ||
1580 | spin_unlock_irqrestore(&q->u.in.lock, flags); | ||
1581 | |||
1582 | used = atomic_add_return(count, &q->nr_buf_used) - count; | ||
1583 | BUG_ON(used + count > QDIO_MAX_BUFFERS_PER_Q); | ||
1584 | |||
1585 | /* no need to signal as long as the adapter had free buffers */ | ||
1586 | if (used) | ||
1587 | return; | ||
1588 | |||
1589 | if (need_siga_in(q)) { | ||
1590 | rc = qdio_siga_input(q); | ||
1591 | if (rc) | ||
1592 | q->qdio_error = rc; | ||
1593 | } | ||
1594 | } | ||
1595 | |||
1596 | /** | ||
1597 | * handle_outbound - process filled outbound buffers | ||
1598 | * @q: queue containing the buffers | ||
1599 | * @callflags: flags | ||
1600 | * @bufnr: first buffer to process | ||
1601 | * @count: how many buffers are filled | ||
1602 | */ | ||
1603 | static void handle_outbound(struct qdio_q *q, unsigned int callflags, | ||
1604 | int bufnr, int count) | ||
1605 | { | ||
1606 | unsigned char state; | ||
1607 | int used; | ||
1608 | |||
1609 | qdio_perf_stat_inc(&perf_stats.outbound_handler); | ||
1610 | |||
1611 | count = set_buf_states(q, bufnr, SLSB_CU_OUTPUT_PRIMED, count); | ||
1612 | used = atomic_add_return(count, &q->nr_buf_used); | ||
1613 | BUG_ON(used > QDIO_MAX_BUFFERS_PER_Q); | ||
1614 | |||
1615 | if (callflags & QDIO_FLAG_PCI_OUT) | ||
1616 | q->u.out.pci_out_enabled = 1; | ||
1617 | else | ||
1618 | q->u.out.pci_out_enabled = 0; | ||
1619 | |||
1620 | if (queue_type(q) == QDIO_IQDIO_QFMT) { | ||
1621 | if (multicast_outbound(q)) | ||
1622 | qdio_kick_outbound_q(q); | ||
1623 | else | ||
1624 | /* | ||
1625 | * One siga-w per buffer required for unicast | ||
1626 | * HiperSockets. | ||
1627 | */ | ||
1628 | while (count--) | ||
1629 | qdio_kick_outbound_q(q); | ||
1630 | goto out; | ||
1631 | } | ||
1632 | |||
1633 | if (need_siga_sync(q)) { | ||
1634 | qdio_siga_sync_q(q); | ||
1635 | goto out; | ||
1636 | } | ||
1637 | |||
1638 | /* try to fast requeue buffers */ | ||
1639 | get_buf_state(q, prev_buf(bufnr), &state); | ||
1640 | if (state != SLSB_CU_OUTPUT_PRIMED) | ||
1641 | qdio_kick_outbound_q(q); | ||
1642 | else { | ||
1643 | QDIO_DBF_TEXT5(0, trace, "fast-req"); | ||
1644 | qdio_perf_stat_inc(&perf_stats.fast_requeue); | ||
1645 | } | ||
1646 | out: | ||
1647 | /* Fixme: could wait forever if called from process context */ | ||
1648 | tasklet_schedule(&q->tasklet); | ||
1649 | } | ||
1650 | |||
1651 | /** | ||
1652 | * do_QDIO - process input or output buffers | ||
1653 | * @cdev: associated ccw_device for the qdio subchannel | ||
1654 | * @callflags: input or output and special flags from the program | ||
1655 | * @q_nr: queue number | ||
1656 | * @bufnr: buffer number | ||
1657 | * @count: how many buffers to process | ||
1658 | */ | ||
1659 | int do_QDIO(struct ccw_device *cdev, unsigned int callflags, | ||
1660 | int q_nr, int bufnr, int count) | ||
1661 | { | ||
1662 | struct qdio_irq *irq_ptr; | ||
1663 | #ifdef CONFIG_QDIO_DEBUG | ||
1664 | char dbf_text[20]; | ||
1665 | |||
1666 | sprintf(dbf_text, "doQD%04x", cdev->private->schid.sch_no); | ||
1667 | QDIO_DBF_TEXT3(0, trace, dbf_text); | ||
1668 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1669 | |||
1670 | if ((bufnr > QDIO_MAX_BUFFERS_PER_Q) || | ||
1671 | (count > QDIO_MAX_BUFFERS_PER_Q) || | ||
1672 | (q_nr > QDIO_MAX_QUEUES_PER_IRQ)) | ||
1673 | return -EINVAL; | ||
1674 | |||
1675 | if (!count) | ||
1676 | return 0; | ||
1677 | |||
1678 | irq_ptr = cdev->private->qdio_data; | ||
1679 | if (!irq_ptr) | ||
1680 | return -ENODEV; | ||
1681 | |||
1682 | #ifdef CONFIG_QDIO_DEBUG | ||
1683 | if (callflags & QDIO_FLAG_SYNC_INPUT) | ||
1684 | QDIO_DBF_HEX3(0, trace, &irq_ptr->input_qs[q_nr], | ||
1685 | sizeof(void *)); | ||
1686 | else | ||
1687 | QDIO_DBF_HEX3(0, trace, &irq_ptr->output_qs[q_nr], | ||
1688 | sizeof(void *)); | ||
1689 | |||
1690 | sprintf(dbf_text, "flag%04x", callflags); | ||
1691 | QDIO_DBF_TEXT3(0, trace, dbf_text); | ||
1692 | sprintf(dbf_text, "qi%02xct%02x", bufnr, count); | ||
1693 | QDIO_DBF_TEXT3(0, trace, dbf_text); | ||
1694 | #endif /* CONFIG_QDIO_DEBUG */ | ||
1695 | |||
1696 | if (irq_ptr->state != QDIO_IRQ_STATE_ACTIVE) | ||
1697 | return -EBUSY; | ||
1698 | |||
1699 | if (callflags & QDIO_FLAG_SYNC_INPUT) | ||
1700 | handle_inbound(irq_ptr->input_qs[q_nr], | ||
1701 | callflags, bufnr, count); | ||
1702 | else if (callflags & QDIO_FLAG_SYNC_OUTPUT) | ||
1703 | handle_outbound(irq_ptr->output_qs[q_nr], | ||
1704 | callflags, bufnr, count); | ||
1705 | else { | ||
1706 | QDIO_DBF_TEXT3(1, trace, "doQD:inv"); | ||
1707 | return -EINVAL; | ||
1708 | } | ||
1709 | return 0; | ||
1710 | } | ||
1711 | EXPORT_SYMBOL_GPL(do_QDIO); | ||
1712 | |||
1713 | static int __init init_QDIO(void) | ||
1714 | { | ||
1715 | int rc; | ||
1716 | |||
1717 | rc = qdio_setup_init(); | ||
1718 | if (rc) | ||
1719 | return rc; | ||
1720 | rc = tiqdio_allocate_memory(); | ||
1721 | if (rc) | ||
1722 | goto out_cache; | ||
1723 | rc = qdio_debug_init(); | ||
1724 | if (rc) | ||
1725 | goto out_ti; | ||
1726 | rc = qdio_setup_perf_stats(); | ||
1727 | if (rc) | ||
1728 | goto out_debug; | ||
1729 | rc = tiqdio_register_thinints(); | ||
1730 | if (rc) | ||
1731 | goto out_perf; | ||
1732 | return 0; | ||
1733 | |||
1734 | out_perf: | ||
1735 | qdio_remove_perf_stats(); | ||
1736 | out_debug: | ||
1737 | qdio_debug_exit(); | ||
1738 | out_ti: | ||
1739 | tiqdio_free_memory(); | ||
1740 | out_cache: | ||
1741 | qdio_setup_exit(); | ||
1742 | return rc; | ||
1743 | } | ||
1744 | |||
1745 | static void __exit exit_QDIO(void) | ||
1746 | { | ||
1747 | tiqdio_unregister_thinints(); | ||
1748 | tiqdio_free_memory(); | ||
1749 | qdio_remove_perf_stats(); | ||
1750 | qdio_debug_exit(); | ||
1751 | qdio_setup_exit(); | ||
1752 | } | ||
1753 | |||
1754 | module_init(init_QDIO); | ||
1755 | module_exit(exit_QDIO); | ||
diff --git a/drivers/s390/cio/qdio_perf.c b/drivers/s390/cio/qdio_perf.c new file mode 100644 index 000000000000..ea01b85b1cc9 --- /dev/null +++ b/drivers/s390/cio/qdio_perf.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * drivers/s390/cio/qdio_perf.c | ||
3 | * | ||
4 | * Copyright IBM Corp. 2008 | ||
5 | * | ||
6 | * Author: Jan Glauber (jang@linux.vnet.ibm.com) | ||
7 | */ | ||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/proc_fs.h> | ||
10 | #include <linux/seq_file.h> | ||
11 | #include <asm/ccwdev.h> | ||
12 | |||
13 | #include "cio.h" | ||
14 | #include "css.h" | ||
15 | #include "device.h" | ||
16 | #include "ioasm.h" | ||
17 | #include "chsc.h" | ||
18 | #include "qdio_debug.h" | ||
19 | #include "qdio_perf.h" | ||
20 | |||
21 | int qdio_performance_stats; | ||
22 | struct qdio_perf_stats perf_stats; | ||
23 | |||
24 | #ifdef CONFIG_PROC_FS | ||
25 | static struct proc_dir_entry *qdio_perf_pde; | ||
26 | #endif | ||
27 | |||
28 | inline void qdio_perf_stat_inc(atomic_long_t *count) | ||
29 | { | ||
30 | if (qdio_performance_stats) | ||
31 | atomic_long_inc(count); | ||
32 | } | ||
33 | |||
34 | inline void qdio_perf_stat_dec(atomic_long_t *count) | ||
35 | { | ||
36 | if (qdio_performance_stats) | ||
37 | atomic_long_dec(count); | ||
38 | } | ||
39 | |||
40 | /* | ||
41 | * procfs functions | ||
42 | */ | ||
43 | static int qdio_perf_proc_show(struct seq_file *m, void *v) | ||
44 | { | ||
45 | seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n", | ||
46 | (long)atomic_long_read(&perf_stats.qdio_int)); | ||
47 | seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n", | ||
48 | (long)atomic_long_read(&perf_stats.pci_int)); | ||
49 | seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n", | ||
50 | (long)atomic_long_read(&perf_stats.thin_int)); | ||
51 | seq_printf(m, "\n"); | ||
52 | seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n", | ||
53 | (long)atomic_long_read(&perf_stats.tasklet_inbound)); | ||
54 | seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n", | ||
55 | (long)atomic_long_read(&perf_stats.tasklet_outbound)); | ||
56 | seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n", | ||
57 | (long)atomic_long_read(&perf_stats.tasklet_thinint), | ||
58 | (long)atomic_long_read(&perf_stats.tasklet_thinint_loop)); | ||
59 | seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n", | ||
60 | (long)atomic_long_read(&perf_stats.thinint_inbound), | ||
61 | (long)atomic_long_read(&perf_stats.thinint_inbound_loop)); | ||
62 | seq_printf(m, "\n"); | ||
63 | seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n", | ||
64 | (long)atomic_long_read(&perf_stats.siga_in)); | ||
65 | seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n", | ||
66 | (long)atomic_long_read(&perf_stats.siga_out)); | ||
67 | seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n", | ||
68 | (long)atomic_long_read(&perf_stats.siga_sync)); | ||
69 | seq_printf(m, "\n"); | ||
70 | seq_printf(m, "Number of inbound transfers\t\t\t: %li\n", | ||
71 | (long)atomic_long_read(&perf_stats.inbound_handler)); | ||
72 | seq_printf(m, "Number of outbound transfers\t\t\t: %li\n", | ||
73 | (long)atomic_long_read(&perf_stats.outbound_handler)); | ||
74 | seq_printf(m, "\n"); | ||
75 | seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n", | ||
76 | (long)atomic_long_read(&perf_stats.fast_requeue)); | ||
77 | seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n", | ||
78 | (long)atomic_long_read(&perf_stats.debug_tl_out_timer)); | ||
79 | seq_printf(m, "Number of stop polling calls\t\t\t: %li\n", | ||
80 | (long)atomic_long_read(&perf_stats.debug_stop_polling)); | ||
81 | seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n", | ||
82 | (long)atomic_long_read(&perf_stats.thinint_inbound_loop2)); | ||
83 | seq_printf(m, "\n"); | ||
84 | return 0; | ||
85 | } | ||
86 | static int qdio_perf_seq_open(struct inode *inode, struct file *filp) | ||
87 | { | ||
88 | return single_open(filp, qdio_perf_proc_show, NULL); | ||
89 | } | ||
90 | |||
91 | static struct file_operations qdio_perf_proc_fops = { | ||
92 | .owner = THIS_MODULE, | ||
93 | .open = qdio_perf_seq_open, | ||
94 | .read = seq_read, | ||
95 | .llseek = seq_lseek, | ||
96 | .release = single_release, | ||
97 | }; | ||
98 | |||
99 | /* | ||
100 | * sysfs functions | ||
101 | */ | ||
102 | static ssize_t qdio_perf_stats_show(struct bus_type *bus, char *buf) | ||
103 | { | ||
104 | return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0); | ||
105 | } | ||
106 | |||
107 | static ssize_t qdio_perf_stats_store(struct bus_type *bus, | ||
108 | const char *buf, size_t count) | ||
109 | { | ||
110 | unsigned long i; | ||
111 | |||
112 | if (strict_strtoul(buf, 16, &i) != 0) | ||
113 | return -EINVAL; | ||
114 | if ((i != 0) && (i != 1)) | ||
115 | return -EINVAL; | ||
116 | if (i == qdio_performance_stats) | ||
117 | return count; | ||
118 | |||
119 | qdio_performance_stats = i; | ||
120 | /* reset performance statistics */ | ||
121 | if (i == 0) | ||
122 | memset(&perf_stats, 0, sizeof(struct qdio_perf_stats)); | ||
123 | return count; | ||
124 | } | ||
125 | |||
126 | static BUS_ATTR(qdio_performance_stats, 0644, qdio_perf_stats_show, | ||
127 | qdio_perf_stats_store); | ||
128 | |||
129 | int __init qdio_setup_perf_stats(void) | ||
130 | { | ||
131 | int rc; | ||
132 | |||
133 | rc = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats); | ||
134 | if (rc) | ||
135 | return rc; | ||
136 | |||
137 | #ifdef CONFIG_PROC_FS | ||
138 | memset(&perf_stats, 0, sizeof(struct qdio_perf_stats)); | ||
139 | qdio_perf_pde = proc_create("qdio_perf", S_IFREG | S_IRUGO, | ||
140 | NULL, &qdio_perf_proc_fops); | ||
141 | #endif | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | void __exit qdio_remove_perf_stats(void) | ||
146 | { | ||
147 | #ifdef CONFIG_PROC_FS | ||
148 | remove_proc_entry("qdio_perf", NULL); | ||
149 | #endif | ||
150 | bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats); | ||
151 | } | ||
diff --git a/drivers/s390/cio/qdio_perf.h b/drivers/s390/cio/qdio_perf.h new file mode 100644 index 000000000000..5c406a8b7387 --- /dev/null +++ b/drivers/s390/cio/qdio_perf.h | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * drivers/s390/cio/qdio_perf.h | ||
3 | * | ||
4 | * Copyright IBM Corp. 2008 | ||
5 | * | ||
6 | * Author: Jan Glauber (jang@linux.vnet.ibm.com) | ||
7 | */ | ||
8 | #ifndef QDIO_PERF_H | ||
9 | #define QDIO_PERF_H | ||
10 | |||
11 | #include <linux/types.h> | ||
12 | #include <linux/device.h> | ||
13 | #include <asm/atomic.h> | ||
14 | |||
15 | struct qdio_perf_stats { | ||
16 | /* interrupt handler calls */ | ||
17 | atomic_long_t qdio_int; | ||
18 | atomic_long_t pci_int; | ||
19 | atomic_long_t thin_int; | ||
20 | |||
21 | /* tasklet runs */ | ||
22 | atomic_long_t tasklet_inbound; | ||
23 | atomic_long_t tasklet_outbound; | ||
24 | atomic_long_t tasklet_thinint; | ||
25 | atomic_long_t tasklet_thinint_loop; | ||
26 | atomic_long_t thinint_inbound; | ||
27 | atomic_long_t thinint_inbound_loop; | ||
28 | atomic_long_t thinint_inbound_loop2; | ||
29 | |||
30 | /* signal adapter calls */ | ||
31 | atomic_long_t siga_out; | ||
32 | atomic_long_t siga_in; | ||
33 | atomic_long_t siga_sync; | ||
34 | |||
35 | /* misc */ | ||
36 | atomic_long_t inbound_handler; | ||
37 | atomic_long_t outbound_handler; | ||
38 | atomic_long_t fast_requeue; | ||
39 | |||
40 | /* for debugging */ | ||
41 | atomic_long_t debug_tl_out_timer; | ||
42 | atomic_long_t debug_stop_polling; | ||
43 | }; | ||
44 | |||
45 | extern struct qdio_perf_stats perf_stats; | ||
46 | extern int qdio_performance_stats; | ||
47 | |||
48 | int qdio_setup_perf_stats(void); | ||
49 | void qdio_remove_perf_stats(void); | ||
50 | |||
51 | extern void qdio_perf_stat_inc(atomic_long_t *count); | ||
52 | extern void qdio_perf_stat_dec(atomic_long_t *count); | ||
53 | |||
54 | #endif | ||
diff --git a/drivers/s390/cio/qdio_setup.c b/drivers/s390/cio/qdio_setup.c new file mode 100644 index 000000000000..f0923a8aceda --- /dev/null +++ b/drivers/s390/cio/qdio_setup.c | |||
@@ -0,0 +1,521 @@ | |||
1 | /* | ||
2 | * driver/s390/cio/qdio_setup.c | ||
3 | * | ||
4 | * qdio queue initialization | ||
5 | * | ||
6 | * Copyright (C) IBM Corp. 2008 | ||
7 | * Author(s): Jan Glauber <jang@linux.vnet.ibm.com> | ||
8 | */ | ||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/slab.h> | ||
11 | #include <asm/qdio.h> | ||
12 | |||
13 | #include "cio.h" | ||
14 | #include "css.h" | ||
15 | #include "device.h" | ||
16 | #include "ioasm.h" | ||
17 | #include "chsc.h" | ||
18 | #include "qdio.h" | ||
19 | #include "qdio_debug.h" | ||
20 | |||
21 | static struct kmem_cache *qdio_q_cache; | ||
22 | |||
23 | /* | ||
24 | * qebsm is only available under 64bit but the adapter sets the feature | ||
25 | * flag anyway, so we manually override it. | ||
26 | */ | ||
27 | static inline int qebsm_possible(void) | ||
28 | { | ||
29 | #ifdef CONFIG_64BIT | ||
30 | return css_general_characteristics.qebsm; | ||
31 | #endif | ||
32 | return 0; | ||
33 | } | ||
34 | |||
35 | /* | ||
36 | * qib_param_field: pointer to 128 bytes or NULL, if no param field | ||
37 | * nr_input_qs: pointer to nr_queues*128 words of data or NULL | ||
38 | */ | ||
39 | static void set_impl_params(struct qdio_irq *irq_ptr, | ||
40 | unsigned int qib_param_field_format, | ||
41 | unsigned char *qib_param_field, | ||
42 | unsigned long *input_slib_elements, | ||
43 | unsigned long *output_slib_elements) | ||
44 | { | ||
45 | struct qdio_q *q; | ||
46 | int i, j; | ||
47 | |||
48 | if (!irq_ptr) | ||
49 | return; | ||
50 | |||
51 | WARN_ON((unsigned long)&irq_ptr->qib & 0xff); | ||
52 | irq_ptr->qib.pfmt = qib_param_field_format; | ||
53 | if (qib_param_field) | ||
54 | memcpy(irq_ptr->qib.parm, qib_param_field, | ||
55 | QDIO_MAX_BUFFERS_PER_Q); | ||
56 | |||
57 | if (!input_slib_elements) | ||
58 | goto output; | ||
59 | |||
60 | for_each_input_queue(irq_ptr, q, i) { | ||
61 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) | ||
62 | q->slib->slibe[j].parms = | ||
63 | input_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j]; | ||
64 | } | ||
65 | output: | ||
66 | if (!output_slib_elements) | ||
67 | return; | ||
68 | |||
69 | for_each_output_queue(irq_ptr, q, i) { | ||
70 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) | ||
71 | q->slib->slibe[j].parms = | ||
72 | output_slib_elements[i * QDIO_MAX_BUFFERS_PER_Q + j]; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | static int __qdio_allocate_qs(struct qdio_q **irq_ptr_qs, int nr_queues) | ||
77 | { | ||
78 | struct qdio_q *q; | ||
79 | int i; | ||
80 | |||
81 | for (i = 0; i < nr_queues; i++) { | ||
82 | q = kmem_cache_alloc(qdio_q_cache, GFP_KERNEL); | ||
83 | if (!q) | ||
84 | return -ENOMEM; | ||
85 | WARN_ON((unsigned long)q & 0xff); | ||
86 | |||
87 | q->slib = (struct slib *) __get_free_page(GFP_KERNEL); | ||
88 | if (!q->slib) { | ||
89 | kmem_cache_free(qdio_q_cache, q); | ||
90 | return -ENOMEM; | ||
91 | } | ||
92 | WARN_ON((unsigned long)q->slib & 0x7ff); | ||
93 | irq_ptr_qs[i] = q; | ||
94 | } | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, int nr_output_qs) | ||
99 | { | ||
100 | int rc; | ||
101 | |||
102 | rc = __qdio_allocate_qs(irq_ptr->input_qs, nr_input_qs); | ||
103 | if (rc) | ||
104 | return rc; | ||
105 | rc = __qdio_allocate_qs(irq_ptr->output_qs, nr_output_qs); | ||
106 | return rc; | ||
107 | } | ||
108 | |||
109 | static void setup_queues_misc(struct qdio_q *q, struct qdio_irq *irq_ptr, | ||
110 | qdio_handler_t *handler, int i) | ||
111 | { | ||
112 | /* must be cleared by every qdio_establish */ | ||
113 | memset(q, 0, ((char *)&q->slib) - ((char *)q)); | ||
114 | memset(q->slib, 0, PAGE_SIZE); | ||
115 | |||
116 | q->irq_ptr = irq_ptr; | ||
117 | q->mask = 1 << (31 - i); | ||
118 | q->nr = i; | ||
119 | q->handler = handler; | ||
120 | } | ||
121 | |||
122 | static void setup_storage_lists(struct qdio_q *q, struct qdio_irq *irq_ptr, | ||
123 | void **sbals_array, char *dbf_text, int i) | ||
124 | { | ||
125 | struct qdio_q *prev; | ||
126 | int j; | ||
127 | |||
128 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
129 | QDIO_DBF_HEX0(0, setup, &q, sizeof(void *)); | ||
130 | |||
131 | q->sl = (struct sl *)((char *)q->slib + PAGE_SIZE / 2); | ||
132 | |||
133 | /* fill in sbal */ | ||
134 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) { | ||
135 | q->sbal[j] = *sbals_array++; | ||
136 | WARN_ON((unsigned long)q->sbal[j] & 0xff); | ||
137 | } | ||
138 | |||
139 | /* fill in slib */ | ||
140 | if (i > 0) { | ||
141 | prev = (q->is_input_q) ? irq_ptr->input_qs[i - 1] | ||
142 | : irq_ptr->output_qs[i - 1]; | ||
143 | prev->slib->nsliba = (unsigned long)q->slib; | ||
144 | } | ||
145 | |||
146 | q->slib->sla = (unsigned long)q->sl; | ||
147 | q->slib->slsba = (unsigned long)&q->slsb.val[0]; | ||
148 | |||
149 | /* fill in sl */ | ||
150 | for (j = 0; j < QDIO_MAX_BUFFERS_PER_Q; j++) | ||
151 | q->sl->element[j].sbal = (unsigned long)q->sbal[j]; | ||
152 | |||
153 | QDIO_DBF_TEXT2(0, setup, "sl-sb-b0"); | ||
154 | QDIO_DBF_HEX2(0, setup, q->sl, sizeof(void *)); | ||
155 | QDIO_DBF_HEX2(0, setup, &q->slsb, sizeof(void *)); | ||
156 | QDIO_DBF_HEX2(0, setup, q->sbal, sizeof(void *)); | ||
157 | } | ||
158 | |||
159 | static void setup_queues(struct qdio_irq *irq_ptr, | ||
160 | struct qdio_initialize *qdio_init) | ||
161 | { | ||
162 | char dbf_text[20]; | ||
163 | struct qdio_q *q; | ||
164 | void **input_sbal_array = qdio_init->input_sbal_addr_array; | ||
165 | void **output_sbal_array = qdio_init->output_sbal_addr_array; | ||
166 | int i; | ||
167 | |||
168 | sprintf(dbf_text, "qfqs%4x", qdio_init->cdev->private->schid.sch_no); | ||
169 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
170 | |||
171 | for_each_input_queue(irq_ptr, q, i) { | ||
172 | sprintf(dbf_text, "in-q%4x", i); | ||
173 | setup_queues_misc(q, irq_ptr, qdio_init->input_handler, i); | ||
174 | |||
175 | q->is_input_q = 1; | ||
176 | spin_lock_init(&q->u.in.lock); | ||
177 | setup_storage_lists(q, irq_ptr, input_sbal_array, dbf_text, i); | ||
178 | input_sbal_array += QDIO_MAX_BUFFERS_PER_Q; | ||
179 | |||
180 | if (is_thinint_irq(irq_ptr)) | ||
181 | tasklet_init(&q->tasklet, tiqdio_inbound_processing, | ||
182 | (unsigned long) q); | ||
183 | else | ||
184 | tasklet_init(&q->tasklet, qdio_inbound_processing, | ||
185 | (unsigned long) q); | ||
186 | } | ||
187 | |||
188 | for_each_output_queue(irq_ptr, q, i) { | ||
189 | sprintf(dbf_text, "outq%4x", i); | ||
190 | setup_queues_misc(q, irq_ptr, qdio_init->output_handler, i); | ||
191 | |||
192 | q->is_input_q = 0; | ||
193 | setup_storage_lists(q, irq_ptr, output_sbal_array, | ||
194 | dbf_text, i); | ||
195 | output_sbal_array += QDIO_MAX_BUFFERS_PER_Q; | ||
196 | |||
197 | tasklet_init(&q->tasklet, qdio_outbound_processing, | ||
198 | (unsigned long) q); | ||
199 | setup_timer(&q->u.out.timer, (void(*)(unsigned long)) | ||
200 | &qdio_outbound_timer, (unsigned long)q); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | static void process_ac_flags(struct qdio_irq *irq_ptr, unsigned char qdioac) | ||
205 | { | ||
206 | if (qdioac & AC1_SIGA_INPUT_NEEDED) | ||
207 | irq_ptr->siga_flag.input = 1; | ||
208 | if (qdioac & AC1_SIGA_OUTPUT_NEEDED) | ||
209 | irq_ptr->siga_flag.output = 1; | ||
210 | if (qdioac & AC1_SIGA_SYNC_NEEDED) | ||
211 | irq_ptr->siga_flag.sync = 1; | ||
212 | if (qdioac & AC1_AUTOMATIC_SYNC_ON_THININT) | ||
213 | irq_ptr->siga_flag.no_sync_ti = 1; | ||
214 | if (qdioac & AC1_AUTOMATIC_SYNC_ON_OUT_PCI) | ||
215 | irq_ptr->siga_flag.no_sync_out_pci = 1; | ||
216 | |||
217 | if (irq_ptr->siga_flag.no_sync_out_pci && | ||
218 | irq_ptr->siga_flag.no_sync_ti) | ||
219 | irq_ptr->siga_flag.no_sync_out_ti = 1; | ||
220 | } | ||
221 | |||
222 | static void check_and_setup_qebsm(struct qdio_irq *irq_ptr, | ||
223 | unsigned char qdioac, unsigned long token) | ||
224 | { | ||
225 | char dbf_text[15]; | ||
226 | |||
227 | if (!(irq_ptr->qib.rflags & QIB_RFLAGS_ENABLE_QEBSM)) | ||
228 | goto no_qebsm; | ||
229 | if (!(qdioac & AC1_SC_QEBSM_AVAILABLE) || | ||
230 | (!(qdioac & AC1_SC_QEBSM_ENABLED))) | ||
231 | goto no_qebsm; | ||
232 | |||
233 | irq_ptr->sch_token = token; | ||
234 | |||
235 | QDIO_DBF_TEXT0(0, setup, "V=V:1"); | ||
236 | sprintf(dbf_text, "%8lx", irq_ptr->sch_token); | ||
237 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
238 | return; | ||
239 | |||
240 | no_qebsm: | ||
241 | irq_ptr->sch_token = 0; | ||
242 | irq_ptr->qib.rflags &= ~QIB_RFLAGS_ENABLE_QEBSM; | ||
243 | QDIO_DBF_TEXT0(0, setup, "noV=V"); | ||
244 | } | ||
245 | |||
246 | static int __get_ssqd_info(struct qdio_irq *irq_ptr) | ||
247 | { | ||
248 | struct chsc_ssqd_area *ssqd; | ||
249 | int rc; | ||
250 | |||
251 | QDIO_DBF_TEXT0(0, setup, "getssqd"); | ||
252 | ssqd = (struct chsc_ssqd_area *)irq_ptr->chsc_page; | ||
253 | memset(ssqd, 0, PAGE_SIZE); | ||
254 | |||
255 | ssqd->request = (struct chsc_header) { | ||
256 | .length = 0x0010, | ||
257 | .code = 0x0024, | ||
258 | }; | ||
259 | ssqd->first_sch = irq_ptr->schid.sch_no; | ||
260 | ssqd->last_sch = irq_ptr->schid.sch_no; | ||
261 | ssqd->ssid = irq_ptr->schid.ssid; | ||
262 | |||
263 | if (chsc(ssqd)) | ||
264 | return -EIO; | ||
265 | rc = chsc_error_from_response(ssqd->response.code); | ||
266 | if (rc) | ||
267 | return rc; | ||
268 | |||
269 | if (!(ssqd->qdio_ssqd.flags & CHSC_FLAG_QDIO_CAPABILITY) || | ||
270 | !(ssqd->qdio_ssqd.flags & CHSC_FLAG_VALIDITY) || | ||
271 | (ssqd->qdio_ssqd.sch != irq_ptr->schid.sch_no)) | ||
272 | return -EINVAL; | ||
273 | |||
274 | memcpy(&irq_ptr->ssqd_desc, &ssqd->qdio_ssqd, | ||
275 | sizeof(struct qdio_ssqd_desc)); | ||
276 | return 0; | ||
277 | } | ||
278 | |||
279 | void qdio_setup_ssqd_info(struct qdio_irq *irq_ptr) | ||
280 | { | ||
281 | unsigned char qdioac; | ||
282 | char dbf_text[15]; | ||
283 | int rc; | ||
284 | |||
285 | rc = __get_ssqd_info(irq_ptr); | ||
286 | if (rc) { | ||
287 | QDIO_DBF_TEXT2(0, setup, "ssqdasig"); | ||
288 | sprintf(dbf_text, "schno%x", irq_ptr->schid.sch_no); | ||
289 | QDIO_DBF_TEXT2(0, setup, dbf_text); | ||
290 | sprintf(dbf_text, "rc:%d", rc); | ||
291 | QDIO_DBF_TEXT2(0, setup, dbf_text); | ||
292 | /* all flags set, worst case */ | ||
293 | qdioac = AC1_SIGA_INPUT_NEEDED | AC1_SIGA_OUTPUT_NEEDED | | ||
294 | AC1_SIGA_SYNC_NEEDED; | ||
295 | } else | ||
296 | qdioac = irq_ptr->ssqd_desc.qdioac1; | ||
297 | |||
298 | check_and_setup_qebsm(irq_ptr, qdioac, irq_ptr->ssqd_desc.sch_token); | ||
299 | process_ac_flags(irq_ptr, qdioac); | ||
300 | |||
301 | sprintf(dbf_text, "qdioac%2x", qdioac); | ||
302 | QDIO_DBF_TEXT2(0, setup, dbf_text); | ||
303 | } | ||
304 | |||
305 | void qdio_release_memory(struct qdio_irq *irq_ptr) | ||
306 | { | ||
307 | struct qdio_q *q; | ||
308 | int i; | ||
309 | |||
310 | /* | ||
311 | * Must check queue array manually since irq_ptr->nr_input_queues / | ||
312 | * irq_ptr->nr_input_queues may not yet be set. | ||
313 | */ | ||
314 | for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) { | ||
315 | q = irq_ptr->input_qs[i]; | ||
316 | if (q) { | ||
317 | free_page((unsigned long) q->slib); | ||
318 | kmem_cache_free(qdio_q_cache, q); | ||
319 | } | ||
320 | } | ||
321 | for (i = 0; i < QDIO_MAX_QUEUES_PER_IRQ; i++) { | ||
322 | q = irq_ptr->output_qs[i]; | ||
323 | if (q) { | ||
324 | free_page((unsigned long) q->slib); | ||
325 | kmem_cache_free(qdio_q_cache, q); | ||
326 | } | ||
327 | } | ||
328 | kfree(irq_ptr->qdr); | ||
329 | free_page(irq_ptr->chsc_page); | ||
330 | free_page((unsigned long) irq_ptr); | ||
331 | } | ||
332 | |||
333 | static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr, | ||
334 | struct qdio_q **irq_ptr_qs, | ||
335 | int i, int nr) | ||
336 | { | ||
337 | irq_ptr->qdr->qdf0[i + nr].sliba = | ||
338 | (unsigned long)irq_ptr_qs[i]->slib; | ||
339 | |||
340 | irq_ptr->qdr->qdf0[i + nr].sla = | ||
341 | (unsigned long)irq_ptr_qs[i]->sl; | ||
342 | |||
343 | irq_ptr->qdr->qdf0[i + nr].slsba = | ||
344 | (unsigned long)&irq_ptr_qs[i]->slsb.val[0]; | ||
345 | |||
346 | irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY; | ||
347 | irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY; | ||
348 | irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY; | ||
349 | irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY; | ||
350 | } | ||
351 | |||
352 | static void setup_qdr(struct qdio_irq *irq_ptr, | ||
353 | struct qdio_initialize *qdio_init) | ||
354 | { | ||
355 | int i; | ||
356 | |||
357 | irq_ptr->qdr->qfmt = qdio_init->q_format; | ||
358 | irq_ptr->qdr->iqdcnt = qdio_init->no_input_qs; | ||
359 | irq_ptr->qdr->oqdcnt = qdio_init->no_output_qs; | ||
360 | irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */ | ||
361 | irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4; | ||
362 | irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib; | ||
363 | irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY; | ||
364 | |||
365 | for (i = 0; i < qdio_init->no_input_qs; i++) | ||
366 | __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0); | ||
367 | |||
368 | for (i = 0; i < qdio_init->no_output_qs; i++) | ||
369 | __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->output_qs, i, | ||
370 | qdio_init->no_input_qs); | ||
371 | } | ||
372 | |||
373 | static void setup_qib(struct qdio_irq *irq_ptr, | ||
374 | struct qdio_initialize *init_data) | ||
375 | { | ||
376 | if (qebsm_possible()) | ||
377 | irq_ptr->qib.rflags |= QIB_RFLAGS_ENABLE_QEBSM; | ||
378 | |||
379 | irq_ptr->qib.qfmt = init_data->q_format; | ||
380 | if (init_data->no_input_qs) | ||
381 | irq_ptr->qib.isliba = | ||
382 | (unsigned long)(irq_ptr->input_qs[0]->slib); | ||
383 | if (init_data->no_output_qs) | ||
384 | irq_ptr->qib.osliba = | ||
385 | (unsigned long)(irq_ptr->output_qs[0]->slib); | ||
386 | memcpy(irq_ptr->qib.ebcnam, init_data->adapter_name, 8); | ||
387 | } | ||
388 | |||
389 | int qdio_setup_irq(struct qdio_initialize *init_data) | ||
390 | { | ||
391 | struct ciw *ciw; | ||
392 | struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data; | ||
393 | int rc; | ||
394 | |||
395 | memset(irq_ptr, 0, ((char *)&irq_ptr->qdr) - ((char *)irq_ptr)); | ||
396 | /* wipes qib.ac, required by ar7063 */ | ||
397 | memset(irq_ptr->qdr, 0, sizeof(struct qdr)); | ||
398 | |||
399 | irq_ptr->int_parm = init_data->int_parm; | ||
400 | irq_ptr->nr_input_qs = init_data->no_input_qs; | ||
401 | irq_ptr->nr_output_qs = init_data->no_output_qs; | ||
402 | |||
403 | irq_ptr->schid = ccw_device_get_subchannel_id(init_data->cdev); | ||
404 | irq_ptr->cdev = init_data->cdev; | ||
405 | setup_queues(irq_ptr, init_data); | ||
406 | |||
407 | setup_qib(irq_ptr, init_data); | ||
408 | qdio_setup_thinint(irq_ptr); | ||
409 | set_impl_params(irq_ptr, init_data->qib_param_field_format, | ||
410 | init_data->qib_param_field, | ||
411 | init_data->input_slib_elements, | ||
412 | init_data->output_slib_elements); | ||
413 | |||
414 | /* fill input and output descriptors */ | ||
415 | setup_qdr(irq_ptr, init_data); | ||
416 | |||
417 | /* qdr, qib, sls, slsbs, slibs, sbales are filled now */ | ||
418 | |||
419 | /* get qdio commands */ | ||
420 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_EQUEUE); | ||
421 | if (!ciw) { | ||
422 | QDIO_DBF_TEXT2(1, setup, "no eq"); | ||
423 | rc = -EINVAL; | ||
424 | goto out_err; | ||
425 | } | ||
426 | irq_ptr->equeue = *ciw; | ||
427 | |||
428 | ciw = ccw_device_get_ciw(init_data->cdev, CIW_TYPE_AQUEUE); | ||
429 | if (!ciw) { | ||
430 | QDIO_DBF_TEXT2(1, setup, "no aq"); | ||
431 | rc = -EINVAL; | ||
432 | goto out_err; | ||
433 | } | ||
434 | irq_ptr->aqueue = *ciw; | ||
435 | |||
436 | /* set new interrupt handler */ | ||
437 | irq_ptr->orig_handler = init_data->cdev->handler; | ||
438 | init_data->cdev->handler = qdio_int_handler; | ||
439 | return 0; | ||
440 | out_err: | ||
441 | qdio_release_memory(irq_ptr); | ||
442 | return rc; | ||
443 | } | ||
444 | |||
445 | void qdio_print_subchannel_info(struct qdio_irq *irq_ptr, | ||
446 | struct ccw_device *cdev) | ||
447 | { | ||
448 | char s[80]; | ||
449 | |||
450 | sprintf(s, "%s ", cdev->dev.bus_id); | ||
451 | |||
452 | switch (irq_ptr->qib.qfmt) { | ||
453 | case QDIO_QETH_QFMT: | ||
454 | sprintf(s + strlen(s), "OSADE "); | ||
455 | break; | ||
456 | case QDIO_ZFCP_QFMT: | ||
457 | sprintf(s + strlen(s), "ZFCP "); | ||
458 | break; | ||
459 | case QDIO_IQDIO_QFMT: | ||
460 | sprintf(s + strlen(s), "HiperSockets "); | ||
461 | break; | ||
462 | } | ||
463 | sprintf(s + strlen(s), "using: "); | ||
464 | |||
465 | if (!is_thinint_irq(irq_ptr)) | ||
466 | sprintf(s + strlen(s), "no"); | ||
467 | sprintf(s + strlen(s), "AdapterInterrupts "); | ||
468 | if (!(irq_ptr->sch_token != 0)) | ||
469 | sprintf(s + strlen(s), "no"); | ||
470 | sprintf(s + strlen(s), "QEBSM "); | ||
471 | if (!(irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)) | ||
472 | sprintf(s + strlen(s), "no"); | ||
473 | sprintf(s + strlen(s), "OutboundPCI "); | ||
474 | if (!css_general_characteristics.aif_tdd) | ||
475 | sprintf(s + strlen(s), "no"); | ||
476 | sprintf(s + strlen(s), "TDD\n"); | ||
477 | printk(KERN_INFO "qdio: %s", s); | ||
478 | |||
479 | memset(s, 0, sizeof(s)); | ||
480 | sprintf(s, "%s SIGA required: ", cdev->dev.bus_id); | ||
481 | if (irq_ptr->siga_flag.input) | ||
482 | sprintf(s + strlen(s), "Read "); | ||
483 | if (irq_ptr->siga_flag.output) | ||
484 | sprintf(s + strlen(s), "Write "); | ||
485 | if (irq_ptr->siga_flag.sync) | ||
486 | sprintf(s + strlen(s), "Sync "); | ||
487 | if (!irq_ptr->siga_flag.no_sync_ti) | ||
488 | sprintf(s + strlen(s), "SyncAI "); | ||
489 | if (!irq_ptr->siga_flag.no_sync_out_ti) | ||
490 | sprintf(s + strlen(s), "SyncOutAI "); | ||
491 | if (!irq_ptr->siga_flag.no_sync_out_pci) | ||
492 | sprintf(s + strlen(s), "SyncOutPCI"); | ||
493 | sprintf(s + strlen(s), "\n"); | ||
494 | printk(KERN_INFO "qdio: %s", s); | ||
495 | } | ||
496 | |||
497 | int __init qdio_setup_init(void) | ||
498 | { | ||
499 | char dbf_text[15]; | ||
500 | |||
501 | qdio_q_cache = kmem_cache_create("qdio_q", sizeof(struct qdio_q), | ||
502 | 256, 0, NULL); | ||
503 | if (!qdio_q_cache) | ||
504 | return -ENOMEM; | ||
505 | |||
506 | /* Check for OSA/FCP thin interrupts (bit 67). */ | ||
507 | sprintf(dbf_text, "thini%1x", | ||
508 | (css_general_characteristics.aif_osa) ? 1 : 0); | ||
509 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
510 | |||
511 | /* Check for QEBSM support in general (bit 58). */ | ||
512 | sprintf(dbf_text, "cssQBS:%1x", | ||
513 | (qebsm_possible()) ? 1 : 0); | ||
514 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
515 | return 0; | ||
516 | } | ||
517 | |||
518 | void __exit qdio_setup_exit(void) | ||
519 | { | ||
520 | kmem_cache_destroy(qdio_q_cache); | ||
521 | } | ||
diff --git a/drivers/s390/cio/qdio_thinint.c b/drivers/s390/cio/qdio_thinint.c new file mode 100644 index 000000000000..9291a771d812 --- /dev/null +++ b/drivers/s390/cio/qdio_thinint.c | |||
@@ -0,0 +1,380 @@ | |||
1 | /* | ||
2 | * linux/drivers/s390/cio/thinint_qdio.c | ||
3 | * | ||
4 | * thin interrupt support for qdio | ||
5 | * | ||
6 | * Copyright 2000-2008 IBM Corp. | ||
7 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com> | ||
8 | * Cornelia Huck <cornelia.huck@de.ibm.com> | ||
9 | * Jan Glauber <jang@linux.vnet.ibm.com> | ||
10 | */ | ||
11 | #include <linux/io.h> | ||
12 | #include <asm/atomic.h> | ||
13 | #include <asm/debug.h> | ||
14 | #include <asm/qdio.h> | ||
15 | #include <asm/airq.h> | ||
16 | #include <asm/isc.h> | ||
17 | |||
18 | #include "cio.h" | ||
19 | #include "ioasm.h" | ||
20 | #include "qdio.h" | ||
21 | #include "qdio_debug.h" | ||
22 | #include "qdio_perf.h" | ||
23 | |||
24 | /* | ||
25 | * Restriction: only 63 iqdio subchannels would have its own indicator, | ||
26 | * after that, subsequent subchannels share one indicator | ||
27 | */ | ||
28 | #define TIQDIO_NR_NONSHARED_IND 63 | ||
29 | #define TIQDIO_NR_INDICATORS (TIQDIO_NR_NONSHARED_IND + 1) | ||
30 | #define TIQDIO_SHARED_IND 63 | ||
31 | |||
32 | /* list of thin interrupt input queues */ | ||
33 | static LIST_HEAD(tiq_list); | ||
34 | |||
35 | /* adapter local summary indicator */ | ||
36 | static unsigned char *tiqdio_alsi; | ||
37 | |||
38 | /* device state change indicators */ | ||
39 | struct indicator_t { | ||
40 | u32 ind; /* u32 because of compare-and-swap performance */ | ||
41 | atomic_t count; /* use count, 0 or 1 for non-shared indicators */ | ||
42 | }; | ||
43 | static struct indicator_t *q_indicators; | ||
44 | |||
45 | static void tiqdio_tasklet_fn(unsigned long data); | ||
46 | static DECLARE_TASKLET(tiqdio_tasklet, tiqdio_tasklet_fn, 0); | ||
47 | |||
48 | static int css_qdio_omit_svs; | ||
49 | |||
50 | static inline unsigned long do_clear_global_summary(void) | ||
51 | { | ||
52 | register unsigned long __fn asm("1") = 3; | ||
53 | register unsigned long __tmp asm("2"); | ||
54 | register unsigned long __time asm("3"); | ||
55 | |||
56 | asm volatile( | ||
57 | " .insn rre,0xb2650000,2,0" | ||
58 | : "+d" (__fn), "=d" (__tmp), "=d" (__time)); | ||
59 | return __time; | ||
60 | } | ||
61 | |||
62 | /* returns addr for the device state change indicator */ | ||
63 | static u32 *get_indicator(void) | ||
64 | { | ||
65 | int i; | ||
66 | |||
67 | for (i = 0; i < TIQDIO_NR_NONSHARED_IND; i++) | ||
68 | if (!atomic_read(&q_indicators[i].count)) { | ||
69 | atomic_set(&q_indicators[i].count, 1); | ||
70 | return &q_indicators[i].ind; | ||
71 | } | ||
72 | |||
73 | /* use the shared indicator */ | ||
74 | atomic_inc(&q_indicators[TIQDIO_SHARED_IND].count); | ||
75 | return &q_indicators[TIQDIO_SHARED_IND].ind; | ||
76 | } | ||
77 | |||
78 | static void put_indicator(u32 *addr) | ||
79 | { | ||
80 | int i; | ||
81 | |||
82 | if (!addr) | ||
83 | return; | ||
84 | i = ((unsigned long)addr - (unsigned long)q_indicators) / | ||
85 | sizeof(struct indicator_t); | ||
86 | atomic_dec(&q_indicators[i].count); | ||
87 | } | ||
88 | |||
89 | void tiqdio_add_input_queues(struct qdio_irq *irq_ptr) | ||
90 | { | ||
91 | struct qdio_q *q; | ||
92 | int i; | ||
93 | |||
94 | /* No TDD facility? If we must use SIGA-s we can also omit SVS. */ | ||
95 | if (!css_qdio_omit_svs && irq_ptr->siga_flag.sync) | ||
96 | css_qdio_omit_svs = 1; | ||
97 | |||
98 | for_each_input_queue(irq_ptr, q, i) { | ||
99 | list_add_rcu(&q->entry, &tiq_list); | ||
100 | synchronize_rcu(); | ||
101 | } | ||
102 | xchg(irq_ptr->dsci, 1); | ||
103 | tasklet_schedule(&tiqdio_tasklet); | ||
104 | } | ||
105 | |||
106 | /* | ||
107 | * we cannot stop the tiqdio tasklet here since it is for all | ||
108 | * thinint qdio devices and it must run as long as there is a | ||
109 | * thinint device left | ||
110 | */ | ||
111 | void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr) | ||
112 | { | ||
113 | struct qdio_q *q; | ||
114 | int i; | ||
115 | |||
116 | for_each_input_queue(irq_ptr, q, i) { | ||
117 | list_del_rcu(&q->entry); | ||
118 | synchronize_rcu(); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | static inline int tiqdio_inbound_q_done(struct qdio_q *q) | ||
123 | { | ||
124 | unsigned char state; | ||
125 | |||
126 | if (!atomic_read(&q->nr_buf_used)) | ||
127 | return 1; | ||
128 | |||
129 | qdio_siga_sync_q(q); | ||
130 | get_buf_state(q, q->first_to_check, &state); | ||
131 | |||
132 | if (state == SLSB_P_INPUT_PRIMED) | ||
133 | /* more work coming */ | ||
134 | return 0; | ||
135 | return 1; | ||
136 | } | ||
137 | |||
138 | static inline int shared_ind(struct qdio_irq *irq_ptr) | ||
139 | { | ||
140 | return irq_ptr->dsci == &q_indicators[TIQDIO_SHARED_IND].ind; | ||
141 | } | ||
142 | |||
143 | static void __tiqdio_inbound_processing(struct qdio_q *q) | ||
144 | { | ||
145 | qdio_perf_stat_inc(&perf_stats.thinint_inbound); | ||
146 | qdio_sync_after_thinint(q); | ||
147 | |||
148 | /* | ||
149 | * Maybe we have work on our outbound queues... at least | ||
150 | * we have to check the PCI capable queues. | ||
151 | */ | ||
152 | qdio_check_outbound_after_thinint(q); | ||
153 | |||
154 | again: | ||
155 | if (!qdio_inbound_q_moved(q)) | ||
156 | return; | ||
157 | |||
158 | qdio_kick_inbound_handler(q); | ||
159 | |||
160 | if (!tiqdio_inbound_q_done(q)) { | ||
161 | qdio_perf_stat_inc(&perf_stats.thinint_inbound_loop); | ||
162 | goto again; | ||
163 | } | ||
164 | |||
165 | qdio_stop_polling(q); | ||
166 | /* | ||
167 | * We need to check again to not lose initiative after | ||
168 | * resetting the ACK state. | ||
169 | */ | ||
170 | if (!tiqdio_inbound_q_done(q)) { | ||
171 | qdio_perf_stat_inc(&perf_stats.thinint_inbound_loop2); | ||
172 | goto again; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | void tiqdio_inbound_processing(unsigned long data) | ||
177 | { | ||
178 | struct qdio_q *q = (struct qdio_q *)data; | ||
179 | |||
180 | __tiqdio_inbound_processing(q); | ||
181 | } | ||
182 | |||
183 | /* check for work on all inbound thinint queues */ | ||
184 | static void tiqdio_tasklet_fn(unsigned long data) | ||
185 | { | ||
186 | struct qdio_q *q; | ||
187 | |||
188 | qdio_perf_stat_inc(&perf_stats.tasklet_thinint); | ||
189 | again: | ||
190 | |||
191 | /* protect tiq_list entries, only changed in activate or shutdown */ | ||
192 | rcu_read_lock(); | ||
193 | |||
194 | list_for_each_entry_rcu(q, &tiq_list, entry) | ||
195 | /* only process queues from changed sets */ | ||
196 | if (*q->irq_ptr->dsci) { | ||
197 | |||
198 | /* only clear it if the indicator is non-shared */ | ||
199 | if (!shared_ind(q->irq_ptr)) | ||
200 | xchg(q->irq_ptr->dsci, 0); | ||
201 | /* | ||
202 | * don't call inbound processing directly since | ||
203 | * that could starve other thinint queues | ||
204 | */ | ||
205 | tasklet_schedule(&q->tasklet); | ||
206 | } | ||
207 | |||
208 | rcu_read_unlock(); | ||
209 | |||
210 | /* | ||
211 | * if we used the shared indicator clear it now after all queues | ||
212 | * were processed | ||
213 | */ | ||
214 | if (atomic_read(&q_indicators[TIQDIO_SHARED_IND].count)) { | ||
215 | xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 0); | ||
216 | |||
217 | /* prevent racing */ | ||
218 | if (*tiqdio_alsi) | ||
219 | xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1); | ||
220 | } | ||
221 | |||
222 | /* check for more work */ | ||
223 | if (*tiqdio_alsi) { | ||
224 | xchg(tiqdio_alsi, 0); | ||
225 | qdio_perf_stat_inc(&perf_stats.tasklet_thinint_loop); | ||
226 | goto again; | ||
227 | } | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * tiqdio_thinint_handler - thin interrupt handler for qdio | ||
232 | * @ind: pointer to adapter local summary indicator | ||
233 | * @drv_data: NULL | ||
234 | */ | ||
235 | static void tiqdio_thinint_handler(void *ind, void *drv_data) | ||
236 | { | ||
237 | qdio_perf_stat_inc(&perf_stats.thin_int); | ||
238 | |||
239 | /* | ||
240 | * SVS only when needed: issue SVS to benefit from iqdio interrupt | ||
241 | * avoidance (SVS clears adapter interrupt suppression overwrite) | ||
242 | */ | ||
243 | if (!css_qdio_omit_svs) | ||
244 | do_clear_global_summary(); | ||
245 | |||
246 | /* | ||
247 | * reset local summary indicator (tiqdio_alsi) to stop adapter | ||
248 | * interrupts for now, the tasklet will clean all dsci's | ||
249 | */ | ||
250 | xchg((u8 *)ind, 0); | ||
251 | tasklet_hi_schedule(&tiqdio_tasklet); | ||
252 | } | ||
253 | |||
254 | static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset) | ||
255 | { | ||
256 | struct scssc_area *scssc_area; | ||
257 | char dbf_text[15]; | ||
258 | void *ptr; | ||
259 | int rc; | ||
260 | |||
261 | scssc_area = (struct scssc_area *)irq_ptr->chsc_page; | ||
262 | memset(scssc_area, 0, PAGE_SIZE); | ||
263 | |||
264 | if (reset) { | ||
265 | scssc_area->summary_indicator_addr = 0; | ||
266 | scssc_area->subchannel_indicator_addr = 0; | ||
267 | } else { | ||
268 | scssc_area->summary_indicator_addr = virt_to_phys(tiqdio_alsi); | ||
269 | scssc_area->subchannel_indicator_addr = | ||
270 | virt_to_phys(irq_ptr->dsci); | ||
271 | } | ||
272 | |||
273 | scssc_area->request = (struct chsc_header) { | ||
274 | .length = 0x0fe0, | ||
275 | .code = 0x0021, | ||
276 | }; | ||
277 | scssc_area->operation_code = 0; | ||
278 | scssc_area->ks = PAGE_DEFAULT_KEY; | ||
279 | scssc_area->kc = PAGE_DEFAULT_KEY; | ||
280 | scssc_area->isc = QDIO_AIRQ_ISC; | ||
281 | scssc_area->schid = irq_ptr->schid; | ||
282 | |||
283 | /* enable the time delay disablement facility */ | ||
284 | if (css_general_characteristics.aif_tdd) | ||
285 | scssc_area->word_with_d_bit = 0x10000000; | ||
286 | |||
287 | rc = chsc(scssc_area); | ||
288 | if (rc) | ||
289 | return -EIO; | ||
290 | |||
291 | rc = chsc_error_from_response(scssc_area->response.code); | ||
292 | if (rc) { | ||
293 | sprintf(dbf_text, "sidR%4x", scssc_area->response.code); | ||
294 | QDIO_DBF_TEXT1(0, trace, dbf_text); | ||
295 | QDIO_DBF_TEXT1(0, setup, dbf_text); | ||
296 | ptr = &scssc_area->response; | ||
297 | QDIO_DBF_HEX2(1, setup, &ptr, QDIO_DBF_SETUP_LEN); | ||
298 | return rc; | ||
299 | } | ||
300 | |||
301 | QDIO_DBF_TEXT2(0, setup, "setscind"); | ||
302 | QDIO_DBF_HEX2(0, setup, &scssc_area->summary_indicator_addr, | ||
303 | sizeof(unsigned long)); | ||
304 | QDIO_DBF_HEX2(0, setup, &scssc_area->subchannel_indicator_addr, | ||
305 | sizeof(unsigned long)); | ||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | /* allocate non-shared indicators and shared indicator */ | ||
310 | int __init tiqdio_allocate_memory(void) | ||
311 | { | ||
312 | q_indicators = kzalloc(sizeof(struct indicator_t) * TIQDIO_NR_INDICATORS, | ||
313 | GFP_KERNEL); | ||
314 | if (!q_indicators) | ||
315 | return -ENOMEM; | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | void tiqdio_free_memory(void) | ||
320 | { | ||
321 | kfree(q_indicators); | ||
322 | } | ||
323 | |||
324 | int __init tiqdio_register_thinints(void) | ||
325 | { | ||
326 | char dbf_text[20]; | ||
327 | |||
328 | isc_register(QDIO_AIRQ_ISC); | ||
329 | tiqdio_alsi = s390_register_adapter_interrupt(&tiqdio_thinint_handler, | ||
330 | NULL, QDIO_AIRQ_ISC); | ||
331 | if (IS_ERR(tiqdio_alsi)) { | ||
332 | sprintf(dbf_text, "regthn%lx", PTR_ERR(tiqdio_alsi)); | ||
333 | QDIO_DBF_TEXT0(0, setup, dbf_text); | ||
334 | tiqdio_alsi = NULL; | ||
335 | isc_unregister(QDIO_AIRQ_ISC); | ||
336 | return -ENOMEM; | ||
337 | } | ||
338 | return 0; | ||
339 | } | ||
340 | |||
341 | int qdio_establish_thinint(struct qdio_irq *irq_ptr) | ||
342 | { | ||
343 | if (!is_thinint_irq(irq_ptr)) | ||
344 | return 0; | ||
345 | |||
346 | /* Check for aif time delay disablement. If installed, | ||
347 | * omit SVS even under LPAR | ||
348 | */ | ||
349 | if (css_general_characteristics.aif_tdd) | ||
350 | css_qdio_omit_svs = 1; | ||
351 | return set_subchannel_ind(irq_ptr, 0); | ||
352 | } | ||
353 | |||
354 | void qdio_setup_thinint(struct qdio_irq *irq_ptr) | ||
355 | { | ||
356 | if (!is_thinint_irq(irq_ptr)) | ||
357 | return; | ||
358 | irq_ptr->dsci = get_indicator(); | ||
359 | QDIO_DBF_HEX1(0, setup, &irq_ptr->dsci, sizeof(void *)); | ||
360 | } | ||
361 | |||
362 | void qdio_shutdown_thinint(struct qdio_irq *irq_ptr) | ||
363 | { | ||
364 | if (!is_thinint_irq(irq_ptr)) | ||
365 | return; | ||
366 | |||
367 | /* reset adapter interrupt indicators */ | ||
368 | put_indicator(irq_ptr->dsci); | ||
369 | set_subchannel_ind(irq_ptr, 1); | ||
370 | } | ||
371 | |||
372 | void __exit tiqdio_unregister_thinints(void) | ||
373 | { | ||
374 | tasklet_disable(&tiqdio_tasklet); | ||
375 | |||
376 | if (tiqdio_alsi) { | ||
377 | s390_unregister_adapter_interrupt(tiqdio_alsi, QDIO_AIRQ_ISC); | ||
378 | isc_unregister(QDIO_AIRQ_ISC); | ||
379 | } | ||
380 | } | ||
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h index 699ac11debd8..1895dbb553cd 100644 --- a/drivers/s390/net/qeth_core.h +++ b/drivers/s390/net/qeth_core.h | |||
@@ -239,11 +239,6 @@ static inline int qeth_is_ipa_enabled(struct qeth_ipa_info *ipa, | |||
239 | /*not used unless the microcode gets patched*/ | 239 | /*not used unless the microcode gets patched*/ |
240 | #define QETH_PCI_TIMER_VALUE(card) 3 | 240 | #define QETH_PCI_TIMER_VALUE(card) 3 |
241 | 241 | ||
242 | #define QETH_MIN_INPUT_THRESHOLD 1 | ||
243 | #define QETH_MAX_INPUT_THRESHOLD 500 | ||
244 | #define QETH_MIN_OUTPUT_THRESHOLD 1 | ||
245 | #define QETH_MAX_OUTPUT_THRESHOLD 300 | ||
246 | |||
247 | /* priority queing */ | 242 | /* priority queing */ |
248 | #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING | 243 | #define QETH_PRIOQ_DEFAULT QETH_NO_PRIO_QUEUEING |
249 | #define QETH_DEFAULT_QUEUE 2 | 244 | #define QETH_DEFAULT_QUEUE 2 |
@@ -811,17 +806,14 @@ int qeth_send_ipa_cmd(struct qeth_card *, struct qeth_cmd_buffer *, | |||
811 | struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *, | 806 | struct qeth_cmd_buffer *qeth_get_ipacmd_buffer(struct qeth_card *, |
812 | enum qeth_ipa_cmds, enum qeth_prot_versions); | 807 | enum qeth_ipa_cmds, enum qeth_prot_versions); |
813 | int qeth_query_setadapterparms(struct qeth_card *); | 808 | int qeth_query_setadapterparms(struct qeth_card *); |
814 | int qeth_check_qdio_errors(struct qdio_buffer *, unsigned int, | 809 | int qeth_check_qdio_errors(struct qdio_buffer *, unsigned int, const char *); |
815 | unsigned int, const char *); | ||
816 | void qeth_queue_input_buffer(struct qeth_card *, int); | 810 | void qeth_queue_input_buffer(struct qeth_card *, int); |
817 | struct sk_buff *qeth_core_get_next_skb(struct qeth_card *, | 811 | struct sk_buff *qeth_core_get_next_skb(struct qeth_card *, |
818 | struct qdio_buffer *, struct qdio_buffer_element **, int *, | 812 | struct qdio_buffer *, struct qdio_buffer_element **, int *, |
819 | struct qeth_hdr **); | 813 | struct qeth_hdr **); |
820 | void qeth_schedule_recovery(struct qeth_card *); | 814 | void qeth_schedule_recovery(struct qeth_card *); |
821 | void qeth_qdio_output_handler(struct ccw_device *, unsigned int, | 815 | void qeth_qdio_output_handler(struct ccw_device *, unsigned int, |
822 | unsigned int, unsigned int, | 816 | int, int, int, unsigned long); |
823 | unsigned int, int, int, | ||
824 | unsigned long); | ||
825 | void qeth_clear_ipacmd_list(struct qeth_card *); | 817 | void qeth_clear_ipacmd_list(struct qeth_card *); |
826 | int qeth_qdio_clear_card(struct qeth_card *, int); | 818 | int qeth_qdio_clear_card(struct qeth_card *, int); |
827 | void qeth_clear_working_pool_list(struct qeth_card *); | 819 | void qeth_clear_working_pool_list(struct qeth_card *); |
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c index 0ac54dc638c2..c3ad89e302bd 100644 --- a/drivers/s390/net/qeth_core_main.c +++ b/drivers/s390/net/qeth_core_main.c | |||
@@ -2073,7 +2073,7 @@ static void qeth_create_qib_param_field_blkt(struct qeth_card *card, | |||
2073 | static int qeth_qdio_activate(struct qeth_card *card) | 2073 | static int qeth_qdio_activate(struct qeth_card *card) |
2074 | { | 2074 | { |
2075 | QETH_DBF_TEXT(SETUP, 3, "qdioact"); | 2075 | QETH_DBF_TEXT(SETUP, 3, "qdioact"); |
2076 | return qdio_activate(CARD_DDEV(card), 0); | 2076 | return qdio_activate(CARD_DDEV(card)); |
2077 | } | 2077 | } |
2078 | 2078 | ||
2079 | static int qeth_dm_act(struct qeth_card *card) | 2079 | static int qeth_dm_act(struct qeth_card *card) |
@@ -2349,16 +2349,11 @@ int qeth_init_qdio_queues(struct qeth_card *card) | |||
2349 | card->qdio.in_q->next_buf_to_init = | 2349 | card->qdio.in_q->next_buf_to_init = |
2350 | card->qdio.in_buf_pool.buf_count - 1; | 2350 | card->qdio.in_buf_pool.buf_count - 1; |
2351 | rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0, | 2351 | rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, 0, |
2352 | card->qdio.in_buf_pool.buf_count - 1, NULL); | 2352 | card->qdio.in_buf_pool.buf_count - 1); |
2353 | if (rc) { | 2353 | if (rc) { |
2354 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); | 2354 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
2355 | return rc; | 2355 | return rc; |
2356 | } | 2356 | } |
2357 | rc = qdio_synchronize(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0); | ||
2358 | if (rc) { | ||
2359 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); | ||
2360 | return rc; | ||
2361 | } | ||
2362 | /* outbound queue */ | 2357 | /* outbound queue */ |
2363 | for (i = 0; i < card->qdio.no_out_queues; ++i) { | 2358 | for (i = 0; i < card->qdio.no_out_queues; ++i) { |
2364 | memset(card->qdio.out_qs[i]->qdio_bufs, 0, | 2359 | memset(card->qdio.out_qs[i]->qdio_bufs, 0, |
@@ -2559,9 +2554,9 @@ int qeth_query_setadapterparms(struct qeth_card *card) | |||
2559 | EXPORT_SYMBOL_GPL(qeth_query_setadapterparms); | 2554 | EXPORT_SYMBOL_GPL(qeth_query_setadapterparms); |
2560 | 2555 | ||
2561 | int qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error, | 2556 | int qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error, |
2562 | unsigned int siga_error, const char *dbftext) | 2557 | const char *dbftext) |
2563 | { | 2558 | { |
2564 | if (qdio_error || siga_error) { | 2559 | if (qdio_error) { |
2565 | QETH_DBF_TEXT(TRACE, 2, dbftext); | 2560 | QETH_DBF_TEXT(TRACE, 2, dbftext); |
2566 | QETH_DBF_TEXT(QERR, 2, dbftext); | 2561 | QETH_DBF_TEXT(QERR, 2, dbftext); |
2567 | QETH_DBF_TEXT_(QERR, 2, " F15=%02X", | 2562 | QETH_DBF_TEXT_(QERR, 2, " F15=%02X", |
@@ -2569,7 +2564,6 @@ int qeth_check_qdio_errors(struct qdio_buffer *buf, unsigned int qdio_error, | |||
2569 | QETH_DBF_TEXT_(QERR, 2, " F14=%02X", | 2564 | QETH_DBF_TEXT_(QERR, 2, " F14=%02X", |
2570 | buf->element[14].flags & 0xff); | 2565 | buf->element[14].flags & 0xff); |
2571 | QETH_DBF_TEXT_(QERR, 2, " qerr=%X", qdio_error); | 2566 | QETH_DBF_TEXT_(QERR, 2, " qerr=%X", qdio_error); |
2572 | QETH_DBF_TEXT_(QERR, 2, " serr=%X", siga_error); | ||
2573 | return 1; | 2567 | return 1; |
2574 | } | 2568 | } |
2575 | return 0; | 2569 | return 0; |
@@ -2622,9 +2616,8 @@ void qeth_queue_input_buffer(struct qeth_card *card, int index) | |||
2622 | card->perf_stats.inbound_do_qdio_start_time = | 2616 | card->perf_stats.inbound_do_qdio_start_time = |
2623 | qeth_get_micros(); | 2617 | qeth_get_micros(); |
2624 | } | 2618 | } |
2625 | rc = do_QDIO(CARD_DDEV(card), | 2619 | rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT, 0, |
2626 | QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT, | 2620 | queue->next_buf_to_init, count); |
2627 | 0, queue->next_buf_to_init, count, NULL); | ||
2628 | if (card->options.performance_stats) | 2621 | if (card->options.performance_stats) |
2629 | card->perf_stats.inbound_do_qdio_time += | 2622 | card->perf_stats.inbound_do_qdio_time += |
2630 | qeth_get_micros() - | 2623 | qeth_get_micros() - |
@@ -2643,14 +2636,13 @@ void qeth_queue_input_buffer(struct qeth_card *card, int index) | |||
2643 | EXPORT_SYMBOL_GPL(qeth_queue_input_buffer); | 2636 | EXPORT_SYMBOL_GPL(qeth_queue_input_buffer); |
2644 | 2637 | ||
2645 | static int qeth_handle_send_error(struct qeth_card *card, | 2638 | static int qeth_handle_send_error(struct qeth_card *card, |
2646 | struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err, | 2639 | struct qeth_qdio_out_buffer *buffer, unsigned int qdio_err) |
2647 | unsigned int siga_err) | ||
2648 | { | 2640 | { |
2649 | int sbalf15 = buffer->buffer->element[15].flags & 0xff; | 2641 | int sbalf15 = buffer->buffer->element[15].flags & 0xff; |
2650 | int cc = siga_err & 3; | 2642 | int cc = qdio_err & 3; |
2651 | 2643 | ||
2652 | QETH_DBF_TEXT(TRACE, 6, "hdsnderr"); | 2644 | QETH_DBF_TEXT(TRACE, 6, "hdsnderr"); |
2653 | qeth_check_qdio_errors(buffer->buffer, qdio_err, siga_err, "qouterr"); | 2645 | qeth_check_qdio_errors(buffer->buffer, qdio_err, "qouterr"); |
2654 | switch (cc) { | 2646 | switch (cc) { |
2655 | case 0: | 2647 | case 0: |
2656 | if (qdio_err) { | 2648 | if (qdio_err) { |
@@ -2662,7 +2654,7 @@ static int qeth_handle_send_error(struct qeth_card *card, | |||
2662 | } | 2654 | } |
2663 | return QETH_SEND_ERROR_NONE; | 2655 | return QETH_SEND_ERROR_NONE; |
2664 | case 2: | 2656 | case 2: |
2665 | if (siga_err & QDIO_SIGA_ERROR_B_BIT_SET) { | 2657 | if (qdio_err & QDIO_ERROR_SIGA_BUSY) { |
2666 | QETH_DBF_TEXT(TRACE, 1, "SIGAcc2B"); | 2658 | QETH_DBF_TEXT(TRACE, 1, "SIGAcc2B"); |
2667 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); | 2659 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); |
2668 | return QETH_SEND_ERROR_KICK_IT; | 2660 | return QETH_SEND_ERROR_KICK_IT; |
@@ -2758,8 +2750,8 @@ static int qeth_flush_buffers_on_no_pci(struct qeth_qdio_out_q *queue) | |||
2758 | return 0; | 2750 | return 0; |
2759 | } | 2751 | } |
2760 | 2752 | ||
2761 | static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int, | 2753 | static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int index, |
2762 | int index, int count) | 2754 | int count) |
2763 | { | 2755 | { |
2764 | struct qeth_qdio_out_buffer *buf; | 2756 | struct qeth_qdio_out_buffer *buf; |
2765 | int rc; | 2757 | int rc; |
@@ -2807,12 +2799,10 @@ static void qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int, | |||
2807 | qeth_get_micros(); | 2799 | qeth_get_micros(); |
2808 | } | 2800 | } |
2809 | qdio_flags = QDIO_FLAG_SYNC_OUTPUT; | 2801 | qdio_flags = QDIO_FLAG_SYNC_OUTPUT; |
2810 | if (under_int) | ||
2811 | qdio_flags |= QDIO_FLAG_UNDER_INTERRUPT; | ||
2812 | if (atomic_read(&queue->set_pci_flags_count)) | 2802 | if (atomic_read(&queue->set_pci_flags_count)) |
2813 | qdio_flags |= QDIO_FLAG_PCI_OUT; | 2803 | qdio_flags |= QDIO_FLAG_PCI_OUT; |
2814 | rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags, | 2804 | rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags, |
2815 | queue->queue_no, index, count, NULL); | 2805 | queue->queue_no, index, count); |
2816 | if (queue->card->options.performance_stats) | 2806 | if (queue->card->options.performance_stats) |
2817 | queue->card->perf_stats.outbound_do_qdio_time += | 2807 | queue->card->perf_stats.outbound_do_qdio_time += |
2818 | qeth_get_micros() - | 2808 | qeth_get_micros() - |
@@ -2866,16 +2856,15 @@ static void qeth_check_outbound_queue(struct qeth_qdio_out_q *queue) | |||
2866 | queue->card->perf_stats.bufs_sent_pack += | 2856 | queue->card->perf_stats.bufs_sent_pack += |
2867 | flush_cnt; | 2857 | flush_cnt; |
2868 | if (flush_cnt) | 2858 | if (flush_cnt) |
2869 | qeth_flush_buffers(queue, 1, index, flush_cnt); | 2859 | qeth_flush_buffers(queue, index, flush_cnt); |
2870 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); | 2860 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
2871 | } | 2861 | } |
2872 | } | 2862 | } |
2873 | } | 2863 | } |
2874 | 2864 | ||
2875 | void qeth_qdio_output_handler(struct ccw_device *ccwdev, unsigned int status, | 2865 | void qeth_qdio_output_handler(struct ccw_device *ccwdev, |
2876 | unsigned int qdio_error, unsigned int siga_error, | 2866 | unsigned int qdio_error, int __queue, int first_element, |
2877 | unsigned int __queue, int first_element, int count, | 2867 | int count, unsigned long card_ptr) |
2878 | unsigned long card_ptr) | ||
2879 | { | 2868 | { |
2880 | struct qeth_card *card = (struct qeth_card *) card_ptr; | 2869 | struct qeth_card *card = (struct qeth_card *) card_ptr; |
2881 | struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue]; | 2870 | struct qeth_qdio_out_q *queue = card->qdio.out_qs[__queue]; |
@@ -2883,15 +2872,12 @@ void qeth_qdio_output_handler(struct ccw_device *ccwdev, unsigned int status, | |||
2883 | int i; | 2872 | int i; |
2884 | 2873 | ||
2885 | QETH_DBF_TEXT(TRACE, 6, "qdouhdl"); | 2874 | QETH_DBF_TEXT(TRACE, 6, "qdouhdl"); |
2886 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { | 2875 | if (qdio_error & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) { |
2887 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) { | 2876 | QETH_DBF_TEXT(TRACE, 2, "achkcond"); |
2888 | QETH_DBF_TEXT(TRACE, 2, "achkcond"); | 2877 | QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card)); |
2889 | QETH_DBF_TEXT_(TRACE, 2, "%s", CARD_BUS_ID(card)); | 2878 | netif_stop_queue(card->dev); |
2890 | QETH_DBF_TEXT_(TRACE, 2, "%08x", status); | 2879 | qeth_schedule_recovery(card); |
2891 | netif_stop_queue(card->dev); | 2880 | return; |
2892 | qeth_schedule_recovery(card); | ||
2893 | return; | ||
2894 | } | ||
2895 | } | 2881 | } |
2896 | if (card->options.performance_stats) { | 2882 | if (card->options.performance_stats) { |
2897 | card->perf_stats.outbound_handler_cnt++; | 2883 | card->perf_stats.outbound_handler_cnt++; |
@@ -2901,8 +2887,7 @@ void qeth_qdio_output_handler(struct ccw_device *ccwdev, unsigned int status, | |||
2901 | for (i = first_element; i < (first_element + count); ++i) { | 2887 | for (i = first_element; i < (first_element + count); ++i) { |
2902 | buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; | 2888 | buffer = &queue->bufs[i % QDIO_MAX_BUFFERS_PER_Q]; |
2903 | /*we only handle the KICK_IT error by doing a recovery */ | 2889 | /*we only handle the KICK_IT error by doing a recovery */ |
2904 | if (qeth_handle_send_error(card, buffer, | 2890 | if (qeth_handle_send_error(card, buffer, qdio_error) |
2905 | qdio_error, siga_error) | ||
2906 | == QETH_SEND_ERROR_KICK_IT){ | 2891 | == QETH_SEND_ERROR_KICK_IT){ |
2907 | netif_stop_queue(card->dev); | 2892 | netif_stop_queue(card->dev); |
2908 | qeth_schedule_recovery(card); | 2893 | qeth_schedule_recovery(card); |
@@ -3164,11 +3149,11 @@ int qeth_do_send_packet_fast(struct qeth_card *card, | |||
3164 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); | 3149 | atomic_set(&queue->state, QETH_OUT_Q_UNLOCKED); |
3165 | if (ctx == NULL) { | 3150 | if (ctx == NULL) { |
3166 | qeth_fill_buffer(queue, buffer, skb); | 3151 | qeth_fill_buffer(queue, buffer, skb); |
3167 | qeth_flush_buffers(queue, 0, index, 1); | 3152 | qeth_flush_buffers(queue, index, 1); |
3168 | } else { | 3153 | } else { |
3169 | flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index); | 3154 | flush_cnt = qeth_eddp_fill_buffer(queue, ctx, index); |
3170 | WARN_ON(buffers_needed != flush_cnt); | 3155 | WARN_ON(buffers_needed != flush_cnt); |
3171 | qeth_flush_buffers(queue, 0, index, flush_cnt); | 3156 | qeth_flush_buffers(queue, index, flush_cnt); |
3172 | } | 3157 | } |
3173 | return 0; | 3158 | return 0; |
3174 | out: | 3159 | out: |
@@ -3221,8 +3206,8 @@ int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue, | |||
3221 | * again */ | 3206 | * again */ |
3222 | if (atomic_read(&buffer->state) != | 3207 | if (atomic_read(&buffer->state) != |
3223 | QETH_QDIO_BUF_EMPTY){ | 3208 | QETH_QDIO_BUF_EMPTY){ |
3224 | qeth_flush_buffers(queue, 0, | 3209 | qeth_flush_buffers(queue, start_index, |
3225 | start_index, flush_count); | 3210 | flush_count); |
3226 | atomic_set(&queue->state, | 3211 | atomic_set(&queue->state, |
3227 | QETH_OUT_Q_UNLOCKED); | 3212 | QETH_OUT_Q_UNLOCKED); |
3228 | return -EBUSY; | 3213 | return -EBUSY; |
@@ -3253,7 +3238,7 @@ int qeth_do_send_packet(struct qeth_card *card, struct qeth_qdio_out_q *queue, | |||
3253 | flush_count += tmp; | 3238 | flush_count += tmp; |
3254 | out: | 3239 | out: |
3255 | if (flush_count) | 3240 | if (flush_count) |
3256 | qeth_flush_buffers(queue, 0, start_index, flush_count); | 3241 | qeth_flush_buffers(queue, start_index, flush_count); |
3257 | else if (!atomic_read(&queue->set_pci_flags_count)) | 3242 | else if (!atomic_read(&queue->set_pci_flags_count)) |
3258 | atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH); | 3243 | atomic_xchg(&queue->state, QETH_OUT_Q_LOCKED_FLUSH); |
3259 | /* | 3244 | /* |
@@ -3274,7 +3259,7 @@ out: | |||
3274 | if (!flush_count && !atomic_read(&queue->set_pci_flags_count)) | 3259 | if (!flush_count && !atomic_read(&queue->set_pci_flags_count)) |
3275 | flush_count += qeth_flush_buffers_on_no_pci(queue); | 3260 | flush_count += qeth_flush_buffers_on_no_pci(queue); |
3276 | if (flush_count) | 3261 | if (flush_count) |
3277 | qeth_flush_buffers(queue, 0, start_index, flush_count); | 3262 | qeth_flush_buffers(queue, start_index, flush_count); |
3278 | } | 3263 | } |
3279 | /* at this point the queue is UNLOCKED again */ | 3264 | /* at this point the queue is UNLOCKED again */ |
3280 | if (queue->card->options.performance_stats && do_pack) | 3265 | if (queue->card->options.performance_stats && do_pack) |
@@ -3686,10 +3671,6 @@ static int qeth_qdio_establish(struct qeth_card *card) | |||
3686 | init_data.q_format = qeth_get_qdio_q_format(card); | 3671 | init_data.q_format = qeth_get_qdio_q_format(card); |
3687 | init_data.qib_param_field_format = 0; | 3672 | init_data.qib_param_field_format = 0; |
3688 | init_data.qib_param_field = qib_param_field; | 3673 | init_data.qib_param_field = qib_param_field; |
3689 | init_data.min_input_threshold = QETH_MIN_INPUT_THRESHOLD; | ||
3690 | init_data.max_input_threshold = QETH_MAX_INPUT_THRESHOLD; | ||
3691 | init_data.min_output_threshold = QETH_MIN_OUTPUT_THRESHOLD; | ||
3692 | init_data.max_output_threshold = QETH_MAX_OUTPUT_THRESHOLD; | ||
3693 | init_data.no_input_qs = 1; | 3674 | init_data.no_input_qs = 1; |
3694 | init_data.no_output_qs = card->qdio.no_out_queues; | 3675 | init_data.no_output_qs = card->qdio.no_out_queues; |
3695 | init_data.input_handler = card->discipline.input_handler; | 3676 | init_data.input_handler = card->discipline.input_handler; |
@@ -3751,8 +3732,9 @@ static int qeth_core_driver_group(const char *buf, struct device *root_dev, | |||
3751 | 3732 | ||
3752 | int qeth_core_hardsetup_card(struct qeth_card *card) | 3733 | int qeth_core_hardsetup_card(struct qeth_card *card) |
3753 | { | 3734 | { |
3735 | struct qdio_ssqd_desc *qdio_ssqd; | ||
3754 | int retries = 3; | 3736 | int retries = 3; |
3755 | int mpno; | 3737 | int mpno = 0; |
3756 | int rc; | 3738 | int rc; |
3757 | 3739 | ||
3758 | QETH_DBF_TEXT(SETUP, 2, "hrdsetup"); | 3740 | QETH_DBF_TEXT(SETUP, 2, "hrdsetup"); |
@@ -3784,7 +3766,10 @@ retry: | |||
3784 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); | 3766 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); |
3785 | return rc; | 3767 | return rc; |
3786 | } | 3768 | } |
3787 | mpno = qdio_get_ssqd_pct(CARD_DDEV(card)); | 3769 | |
3770 | qdio_ssqd = qdio_get_ssqd_desc(CARD_DDEV(card)); | ||
3771 | if (qdio_ssqd) | ||
3772 | mpno = qdio_ssqd->pcnt; | ||
3788 | if (mpno) | 3773 | if (mpno) |
3789 | mpno = min(mpno - 1, QETH_MAX_PORTNO); | 3774 | mpno = min(mpno - 1, QETH_MAX_PORTNO); |
3790 | if (card->info.portno > mpno) { | 3775 | if (card->info.portno > mpno) { |
diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c index f682f7b14480..3fbc3bdec0c5 100644 --- a/drivers/s390/net/qeth_l2_main.c +++ b/drivers/s390/net/qeth_l2_main.c | |||
@@ -726,8 +726,7 @@ tx_drop: | |||
726 | } | 726 | } |
727 | 727 | ||
728 | static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev, | 728 | static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev, |
729 | unsigned int status, unsigned int qdio_err, | 729 | unsigned int qdio_err, unsigned int queue, |
730 | unsigned int siga_err, unsigned int queue, | ||
731 | int first_element, int count, unsigned long card_ptr) | 730 | int first_element, int count, unsigned long card_ptr) |
732 | { | 731 | { |
733 | struct net_device *net_dev; | 732 | struct net_device *net_dev; |
@@ -742,23 +741,20 @@ static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev, | |||
742 | card->perf_stats.inbound_cnt++; | 741 | card->perf_stats.inbound_cnt++; |
743 | card->perf_stats.inbound_start_time = qeth_get_micros(); | 742 | card->perf_stats.inbound_start_time = qeth_get_micros(); |
744 | } | 743 | } |
745 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { | 744 | if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) { |
746 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) { | 745 | QETH_DBF_TEXT(TRACE, 1, "qdinchk"); |
747 | QETH_DBF_TEXT(TRACE, 1, "qdinchk"); | 746 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); |
748 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); | 747 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element, |
749 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element, | 748 | count); |
750 | count); | 749 | QETH_DBF_TEXT_(TRACE, 1, "%04X", queue); |
751 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", queue, status); | 750 | qeth_schedule_recovery(card); |
752 | qeth_schedule_recovery(card); | 751 | return; |
753 | return; | ||
754 | } | ||
755 | } | 752 | } |
756 | for (i = first_element; i < (first_element + count); ++i) { | 753 | for (i = first_element; i < (first_element + count); ++i) { |
757 | index = i % QDIO_MAX_BUFFERS_PER_Q; | 754 | index = i % QDIO_MAX_BUFFERS_PER_Q; |
758 | buffer = &card->qdio.in_q->bufs[index]; | 755 | buffer = &card->qdio.in_q->bufs[index]; |
759 | if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) && | 756 | if (!(qdio_err && |
760 | qeth_check_qdio_errors(buffer->buffer, | 757 | qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr"))) |
761 | qdio_err, siga_err, "qinerr"))) | ||
762 | qeth_l2_process_inbound_buffer(card, buffer, index); | 758 | qeth_l2_process_inbound_buffer(card, buffer, index); |
763 | /* clear buffer and give back to hardware */ | 759 | /* clear buffer and give back to hardware */ |
764 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); | 760 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); |
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c index 06deaee50f6d..22f64aa6dd1f 100644 --- a/drivers/s390/net/qeth_l3_main.c +++ b/drivers/s390/net/qeth_l3_main.c | |||
@@ -2939,8 +2939,7 @@ static int qeth_l3_setup_netdev(struct qeth_card *card) | |||
2939 | } | 2939 | } |
2940 | 2940 | ||
2941 | static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev, | 2941 | static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev, |
2942 | unsigned int status, unsigned int qdio_err, | 2942 | unsigned int qdio_err, unsigned int queue, int first_element, |
2943 | unsigned int siga_err, unsigned int queue, int first_element, | ||
2944 | int count, unsigned long card_ptr) | 2943 | int count, unsigned long card_ptr) |
2945 | { | 2944 | { |
2946 | struct net_device *net_dev; | 2945 | struct net_device *net_dev; |
@@ -2955,23 +2954,21 @@ static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev, | |||
2955 | card->perf_stats.inbound_cnt++; | 2954 | card->perf_stats.inbound_cnt++; |
2956 | card->perf_stats.inbound_start_time = qeth_get_micros(); | 2955 | card->perf_stats.inbound_start_time = qeth_get_micros(); |
2957 | } | 2956 | } |
2958 | if (status & QDIO_STATUS_LOOK_FOR_ERROR) { | 2957 | if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) { |
2959 | if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) { | 2958 | QETH_DBF_TEXT(TRACE, 1, "qdinchk"); |
2960 | QETH_DBF_TEXT(TRACE, 1, "qdinchk"); | 2959 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); |
2961 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); | 2960 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", |
2962 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", | 2961 | first_element, count); |
2963 | first_element, count); | 2962 | QETH_DBF_TEXT_(TRACE, 1, "%04X", queue); |
2964 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", queue, status); | 2963 | qeth_schedule_recovery(card); |
2965 | qeth_schedule_recovery(card); | 2964 | return; |
2966 | return; | ||
2967 | } | ||
2968 | } | 2965 | } |
2969 | for (i = first_element; i < (first_element + count); ++i) { | 2966 | for (i = first_element; i < (first_element + count); ++i) { |
2970 | index = i % QDIO_MAX_BUFFERS_PER_Q; | 2967 | index = i % QDIO_MAX_BUFFERS_PER_Q; |
2971 | buffer = &card->qdio.in_q->bufs[index]; | 2968 | buffer = &card->qdio.in_q->bufs[index]; |
2972 | if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) && | 2969 | if (!(qdio_err && |
2973 | qeth_check_qdio_errors(buffer->buffer, | 2970 | qeth_check_qdio_errors(buffer->buffer, |
2974 | qdio_err, siga_err, "qinerr"))) | 2971 | qdio_err, "qinerr"))) |
2975 | qeth_l3_process_inbound_buffer(card, buffer, index); | 2972 | qeth_l3_process_inbound_buffer(card, buffer, index); |
2976 | /* clear buffer and give back to hardware */ | 2973 | /* clear buffer and give back to hardware */ |
2977 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); | 2974 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); |
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c index 36169c6944fd..fca48b88fc53 100644 --- a/drivers/s390/scsi/zfcp_dbf.c +++ b/drivers/s390/scsi/zfcp_dbf.c | |||
@@ -297,15 +297,13 @@ void zfcp_hba_dbf_event_fsf_unsol(const char *tag, struct zfcp_adapter *adapter, | |||
297 | /** | 297 | /** |
298 | * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure | 298 | * zfcp_hba_dbf_event_qdio - trace event for QDIO related failure |
299 | * @adapter: adapter affected by this QDIO related event | 299 | * @adapter: adapter affected by this QDIO related event |
300 | * @status: as passed by qdio module | ||
301 | * @qdio_error: as passed by qdio module | 300 | * @qdio_error: as passed by qdio module |
302 | * @siga_error: as passed by qdio module | ||
303 | * @sbal_index: first buffer with error condition, as passed by qdio module | 301 | * @sbal_index: first buffer with error condition, as passed by qdio module |
304 | * @sbal_count: number of buffers affected, as passed by qdio module | 302 | * @sbal_count: number of buffers affected, as passed by qdio module |
305 | */ | 303 | */ |
306 | void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status, | 304 | void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, |
307 | unsigned int qdio_error, unsigned int siga_error, | 305 | unsigned int qdio_error, int sbal_index, |
308 | int sbal_index, int sbal_count) | 306 | int sbal_count) |
309 | { | 307 | { |
310 | struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf; | 308 | struct zfcp_hba_dbf_record *r = &adapter->hba_dbf_buf; |
311 | unsigned long flags; | 309 | unsigned long flags; |
@@ -313,9 +311,7 @@ void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *adapter, unsigned int status, | |||
313 | spin_lock_irqsave(&adapter->hba_dbf_lock, flags); | 311 | spin_lock_irqsave(&adapter->hba_dbf_lock, flags); |
314 | memset(r, 0, sizeof(*r)); | 312 | memset(r, 0, sizeof(*r)); |
315 | strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE); | 313 | strncpy(r->tag, "qdio", ZFCP_DBF_TAG_SIZE); |
316 | r->u.qdio.status = status; | ||
317 | r->u.qdio.qdio_error = qdio_error; | 314 | r->u.qdio.qdio_error = qdio_error; |
318 | r->u.qdio.siga_error = siga_error; | ||
319 | r->u.qdio.sbal_index = sbal_index; | 315 | r->u.qdio.sbal_index = sbal_index; |
320 | r->u.qdio.sbal_count = sbal_count; | 316 | r->u.qdio.sbal_count = sbal_count; |
321 | debug_event(adapter->hba_dbf, 0, r, sizeof(*r)); | 317 | debug_event(adapter->hba_dbf, 0, r, sizeof(*r)); |
@@ -398,9 +394,7 @@ static void zfcp_hba_dbf_view_status(char **p, | |||
398 | 394 | ||
399 | static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r) | 395 | static void zfcp_hba_dbf_view_qdio(char **p, struct zfcp_hba_dbf_record_qdio *r) |
400 | { | 396 | { |
401 | zfcp_dbf_out(p, "status", "0x%08x", r->status); | ||
402 | zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error); | 397 | zfcp_dbf_out(p, "qdio_error", "0x%08x", r->qdio_error); |
403 | zfcp_dbf_out(p, "siga_error", "0x%08x", r->siga_error); | ||
404 | zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index); | 398 | zfcp_dbf_out(p, "sbal_index", "0x%02x", r->sbal_index); |
405 | zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count); | 399 | zfcp_dbf_out(p, "sbal_count", "0x%02x", r->sbal_count); |
406 | } | 400 | } |
diff --git a/drivers/s390/scsi/zfcp_dbf.h b/drivers/s390/scsi/zfcp_dbf.h index d04aea604974..0ddb18449d11 100644 --- a/drivers/s390/scsi/zfcp_dbf.h +++ b/drivers/s390/scsi/zfcp_dbf.h | |||
@@ -139,9 +139,7 @@ struct zfcp_hba_dbf_record_status { | |||
139 | } __attribute__ ((packed)); | 139 | } __attribute__ ((packed)); |
140 | 140 | ||
141 | struct zfcp_hba_dbf_record_qdio { | 141 | struct zfcp_hba_dbf_record_qdio { |
142 | u32 status; | ||
143 | u32 qdio_error; | 142 | u32 qdio_error; |
144 | u32 siga_error; | ||
145 | u8 sbal_index; | 143 | u8 sbal_index; |
146 | u8 sbal_count; | 144 | u8 sbal_count; |
147 | } __attribute__ ((packed)); | 145 | } __attribute__ ((packed)); |
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h index 8065b2b224b7..edfdb21591f3 100644 --- a/drivers/s390/scsi/zfcp_ext.h +++ b/drivers/s390/scsi/zfcp_ext.h | |||
@@ -48,9 +48,8 @@ extern void zfcp_rec_dbf_event_action(u8, struct zfcp_erp_action *); | |||
48 | extern void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *); | 48 | extern void zfcp_hba_dbf_event_fsf_response(struct zfcp_fsf_req *); |
49 | extern void zfcp_hba_dbf_event_fsf_unsol(const char *, struct zfcp_adapter *, | 49 | extern void zfcp_hba_dbf_event_fsf_unsol(const char *, struct zfcp_adapter *, |
50 | struct fsf_status_read_buffer *); | 50 | struct fsf_status_read_buffer *); |
51 | extern void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *, | 51 | extern void zfcp_hba_dbf_event_qdio(struct zfcp_adapter *, unsigned int, int, |
52 | unsigned int, unsigned int, unsigned int, | 52 | int); |
53 | int, int); | ||
54 | extern void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *); | 53 | extern void zfcp_san_dbf_event_ct_request(struct zfcp_fsf_req *); |
55 | extern void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *); | 54 | extern void zfcp_san_dbf_event_ct_response(struct zfcp_fsf_req *); |
56 | extern void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *); | 55 | extern void zfcp_san_dbf_event_els_request(struct zfcp_fsf_req *); |
diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c index 72e3094796d4..d6dbd653fde9 100644 --- a/drivers/s390/scsi/zfcp_qdio.c +++ b/drivers/s390/scsi/zfcp_qdio.c | |||
@@ -74,17 +74,15 @@ static void zfcp_qdio_zero_sbals(struct qdio_buffer *sbal[], int first, int cnt) | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | static void zfcp_qdio_int_req(struct ccw_device *cdev, unsigned int status, | 77 | static void zfcp_qdio_int_req(struct ccw_device *cdev, unsigned int qdio_err, |
78 | unsigned int qdio_err, unsigned int siga_err, | 78 | int queue_no, int first, int count, |
79 | unsigned int queue_no, int first, int count, | ||
80 | unsigned long parm) | 79 | unsigned long parm) |
81 | { | 80 | { |
82 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) parm; | 81 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) parm; |
83 | struct zfcp_qdio_queue *queue = &adapter->req_q; | 82 | struct zfcp_qdio_queue *queue = &adapter->req_q; |
84 | 83 | ||
85 | if (unlikely(status & QDIO_STATUS_LOOK_FOR_ERROR)) { | 84 | if (unlikely(qdio_err)) { |
86 | zfcp_hba_dbf_event_qdio(adapter, status, qdio_err, siga_err, | 85 | zfcp_hba_dbf_event_qdio(adapter, qdio_err, first, count); |
87 | first, count); | ||
88 | zfcp_qdio_handler_error(adapter, 140); | 86 | zfcp_qdio_handler_error(adapter, 140); |
89 | return; | 87 | return; |
90 | } | 88 | } |
@@ -129,8 +127,7 @@ static void zfcp_qdio_resp_put_back(struct zfcp_adapter *adapter, int processed) | |||
129 | 127 | ||
130 | count = atomic_read(&queue->count) + processed; | 128 | count = atomic_read(&queue->count) + processed; |
131 | 129 | ||
132 | retval = do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT | QDIO_FLAG_UNDER_INTERRUPT, | 130 | retval = do_QDIO(cdev, QDIO_FLAG_SYNC_INPUT, 0, start, count); |
133 | 0, start, count, NULL); | ||
134 | 131 | ||
135 | if (unlikely(retval)) { | 132 | if (unlikely(retval)) { |
136 | atomic_set(&queue->count, count); | 133 | atomic_set(&queue->count, count); |
@@ -142,9 +139,8 @@ static void zfcp_qdio_resp_put_back(struct zfcp_adapter *adapter, int processed) | |||
142 | } | 139 | } |
143 | } | 140 | } |
144 | 141 | ||
145 | static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int status, | 142 | static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err, |
146 | unsigned int qdio_err, unsigned int siga_err, | 143 | int queue_no, int first, int count, |
147 | unsigned int queue_no, int first, int count, | ||
148 | unsigned long parm) | 144 | unsigned long parm) |
149 | { | 145 | { |
150 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) parm; | 146 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) parm; |
@@ -152,9 +148,8 @@ static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int status, | |||
152 | volatile struct qdio_buffer_element *sbale; | 148 | volatile struct qdio_buffer_element *sbale; |
153 | int sbal_idx, sbale_idx, sbal_no; | 149 | int sbal_idx, sbale_idx, sbal_no; |
154 | 150 | ||
155 | if (unlikely(status & QDIO_STATUS_LOOK_FOR_ERROR)) { | 151 | if (unlikely(qdio_err)) { |
156 | zfcp_hba_dbf_event_qdio(adapter, status, qdio_err, siga_err, | 152 | zfcp_hba_dbf_event_qdio(adapter, qdio_err, first, count); |
157 | first, count); | ||
158 | zfcp_qdio_handler_error(adapter, 147); | 153 | zfcp_qdio_handler_error(adapter, 147); |
159 | return; | 154 | return; |
160 | } | 155 | } |
@@ -362,7 +357,7 @@ int zfcp_qdio_send(struct zfcp_fsf_req *fsf_req) | |||
362 | } | 357 | } |
363 | 358 | ||
364 | retval = do_QDIO(adapter->ccw_device, QDIO_FLAG_SYNC_OUTPUT, 0, first, | 359 | retval = do_QDIO(adapter->ccw_device, QDIO_FLAG_SYNC_OUTPUT, 0, first, |
365 | count, NULL); | 360 | count); |
366 | if (unlikely(retval)) { | 361 | if (unlikely(retval)) { |
367 | zfcp_qdio_zero_sbals(req_q->sbal, first, count); | 362 | zfcp_qdio_zero_sbals(req_q->sbal, first, count); |
368 | return retval; | 363 | return retval; |
@@ -400,10 +395,6 @@ int zfcp_qdio_allocate(struct zfcp_adapter *adapter) | |||
400 | init_data->qib_param_field = NULL; | 395 | init_data->qib_param_field = NULL; |
401 | init_data->input_slib_elements = NULL; | 396 | init_data->input_slib_elements = NULL; |
402 | init_data->output_slib_elements = NULL; | 397 | init_data->output_slib_elements = NULL; |
403 | init_data->min_input_threshold = 1; | ||
404 | init_data->max_input_threshold = 5000; | ||
405 | init_data->min_output_threshold = 1; | ||
406 | init_data->max_output_threshold = 1000; | ||
407 | init_data->no_input_qs = 1; | 398 | init_data->no_input_qs = 1; |
408 | init_data->no_output_qs = 1; | 399 | init_data->no_output_qs = 1; |
409 | init_data->input_handler = zfcp_qdio_int_resp; | 400 | init_data->input_handler = zfcp_qdio_int_resp; |
@@ -436,9 +427,7 @@ void zfcp_qdio_close(struct zfcp_adapter *adapter) | |||
436 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status); | 427 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status); |
437 | spin_unlock(&req_q->lock); | 428 | spin_unlock(&req_q->lock); |
438 | 429 | ||
439 | while (qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR) | 430 | qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR); |
440 | == -EINPROGRESS) | ||
441 | ssleep(1); | ||
442 | 431 | ||
443 | /* cleanup used outbound sbals */ | 432 | /* cleanup used outbound sbals */ |
444 | count = atomic_read(&req_q->count); | 433 | count = atomic_read(&req_q->count); |
@@ -473,7 +462,7 @@ int zfcp_qdio_open(struct zfcp_adapter *adapter) | |||
473 | return -EIO; | 462 | return -EIO; |
474 | } | 463 | } |
475 | 464 | ||
476 | if (qdio_activate(adapter->ccw_device, 0)) { | 465 | if (qdio_activate(adapter->ccw_device)) { |
477 | dev_err(&adapter->ccw_device->dev, | 466 | dev_err(&adapter->ccw_device->dev, |
478 | "Activate of QDIO queues failed.\n"); | 467 | "Activate of QDIO queues failed.\n"); |
479 | goto failed_qdio; | 468 | goto failed_qdio; |
@@ -487,7 +476,7 @@ int zfcp_qdio_open(struct zfcp_adapter *adapter) | |||
487 | } | 476 | } |
488 | 477 | ||
489 | if (do_QDIO(adapter->ccw_device, QDIO_FLAG_SYNC_INPUT, 0, 0, | 478 | if (do_QDIO(adapter->ccw_device, QDIO_FLAG_SYNC_INPUT, 0, 0, |
490 | QDIO_MAX_BUFFERS_PER_Q, NULL)) { | 479 | QDIO_MAX_BUFFERS_PER_Q)) { |
491 | dev_err(&adapter->ccw_device->dev, | 480 | dev_err(&adapter->ccw_device->dev, |
492 | "Init of QDIO response queue failed.\n"); | 481 | "Init of QDIO response queue failed.\n"); |
493 | goto failed_qdio; | 482 | goto failed_qdio; |
@@ -501,9 +490,6 @@ int zfcp_qdio_open(struct zfcp_adapter *adapter) | |||
501 | return 0; | 490 | return 0; |
502 | 491 | ||
503 | failed_qdio: | 492 | failed_qdio: |
504 | while (qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR) | 493 | qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR); |
505 | == -EINPROGRESS) | ||
506 | ssleep(1); | ||
507 | |||
508 | return -EIO; | 494 | return -EIO; |
509 | } | 495 | } |
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c index ed53f14007a2..f2467e936e55 100644 --- a/drivers/scsi/device_handler/scsi_dh_emc.c +++ b/drivers/scsi/device_handler/scsi_dh_emc.c | |||
@@ -416,12 +416,17 @@ static int clariion_bus_notify(struct notifier_block *nb, | |||
416 | unsigned long action, void *data) | 416 | unsigned long action, void *data) |
417 | { | 417 | { |
418 | struct device *dev = data; | 418 | struct device *dev = data; |
419 | struct scsi_device *sdev = to_scsi_device(dev); | 419 | struct scsi_device *sdev; |
420 | struct scsi_dh_data *scsi_dh_data; | 420 | struct scsi_dh_data *scsi_dh_data; |
421 | struct clariion_dh_data *h; | 421 | struct clariion_dh_data *h; |
422 | int i, found = 0; | 422 | int i, found = 0; |
423 | unsigned long flags; | 423 | unsigned long flags; |
424 | 424 | ||
425 | if (!scsi_is_sdev_device(dev)) | ||
426 | return 0; | ||
427 | |||
428 | sdev = to_scsi_device(dev); | ||
429 | |||
425 | if (action == BUS_NOTIFY_ADD_DEVICE) { | 430 | if (action == BUS_NOTIFY_ADD_DEVICE) { |
426 | for (i = 0; clariion_dev_list[i].vendor; i++) { | 431 | for (i = 0; clariion_dev_list[i].vendor; i++) { |
427 | if (!strncmp(sdev->vendor, clariion_dev_list[i].vendor, | 432 | if (!strncmp(sdev->vendor, clariion_dev_list[i].vendor, |
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c index 12ceab7b3662..ae6be87d6a83 100644 --- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c +++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c | |||
@@ -131,11 +131,16 @@ static int hp_sw_bus_notify(struct notifier_block *nb, | |||
131 | unsigned long action, void *data) | 131 | unsigned long action, void *data) |
132 | { | 132 | { |
133 | struct device *dev = data; | 133 | struct device *dev = data; |
134 | struct scsi_device *sdev = to_scsi_device(dev); | 134 | struct scsi_device *sdev; |
135 | struct scsi_dh_data *scsi_dh_data; | 135 | struct scsi_dh_data *scsi_dh_data; |
136 | int i, found = 0; | 136 | int i, found = 0; |
137 | unsigned long flags; | 137 | unsigned long flags; |
138 | 138 | ||
139 | if (!scsi_is_sdev_device(dev)) | ||
140 | return 0; | ||
141 | |||
142 | sdev = to_scsi_device(dev); | ||
143 | |||
139 | if (action == BUS_NOTIFY_ADD_DEVICE) { | 144 | if (action == BUS_NOTIFY_ADD_DEVICE) { |
140 | for (i = 0; hp_sw_dh_data_list[i].vendor; i++) { | 145 | for (i = 0; hp_sw_dh_data_list[i].vendor; i++) { |
141 | if (!strncmp(sdev->vendor, hp_sw_dh_data_list[i].vendor, | 146 | if (!strncmp(sdev->vendor, hp_sw_dh_data_list[i].vendor, |
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c index 6fff077a888d..fdf34b0ec6e1 100644 --- a/drivers/scsi/device_handler/scsi_dh_rdac.c +++ b/drivers/scsi/device_handler/scsi_dh_rdac.c | |||
@@ -608,12 +608,17 @@ static int rdac_bus_notify(struct notifier_block *nb, | |||
608 | unsigned long action, void *data) | 608 | unsigned long action, void *data) |
609 | { | 609 | { |
610 | struct device *dev = data; | 610 | struct device *dev = data; |
611 | struct scsi_device *sdev = to_scsi_device(dev); | 611 | struct scsi_device *sdev; |
612 | struct scsi_dh_data *scsi_dh_data; | 612 | struct scsi_dh_data *scsi_dh_data; |
613 | struct rdac_dh_data *h; | 613 | struct rdac_dh_data *h; |
614 | int i, found = 0; | 614 | int i, found = 0; |
615 | unsigned long flags; | 615 | unsigned long flags; |
616 | 616 | ||
617 | if (!scsi_is_sdev_device(dev)) | ||
618 | return 0; | ||
619 | |||
620 | sdev = to_scsi_device(dev); | ||
621 | |||
617 | if (action == BUS_NOTIFY_ADD_DEVICE) { | 622 | if (action == BUS_NOTIFY_ADD_DEVICE) { |
618 | for (i = 0; rdac_dev_list[i].vendor; i++) { | 623 | for (i = 0; rdac_dev_list[i].vendor; i++) { |
619 | if (!strncmp(sdev->vendor, rdac_dev_list[i].vendor, | 624 | if (!strncmp(sdev->vendor, rdac_dev_list[i].vendor, |
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c index 683bce375c74..f843c1383a4b 100644 --- a/drivers/scsi/ide-scsi.c +++ b/drivers/scsi/ide-scsi.c | |||
@@ -258,19 +258,6 @@ idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) | |||
258 | return ide_stopped; | 258 | return ide_stopped; |
259 | } | 259 | } |
260 | 260 | ||
261 | static ide_startstop_t | ||
262 | idescsi_atapi_abort(ide_drive_t *drive, struct request *rq) | ||
263 | { | ||
264 | debug_log("%s called for %lu\n", __func__, | ||
265 | ((struct ide_atapi_pc *) rq->special)->scsi_cmd->serial_number); | ||
266 | |||
267 | rq->errors |= ERROR_MAX; | ||
268 | |||
269 | idescsi_end_request(drive, 0, 0); | ||
270 | |||
271 | return ide_stopped; | ||
272 | } | ||
273 | |||
274 | static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs) | 261 | static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs) |
275 | { | 262 | { |
276 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); | 263 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
@@ -524,7 +511,6 @@ static ide_driver_t idescsi_driver = { | |||
524 | .do_request = idescsi_do_request, | 511 | .do_request = idescsi_do_request, |
525 | .end_request = idescsi_end_request, | 512 | .end_request = idescsi_end_request, |
526 | .error = idescsi_atapi_error, | 513 | .error = idescsi_atapi_error, |
527 | .abort = idescsi_atapi_abort, | ||
528 | #ifdef CONFIG_IDE_PROC_FS | 514 | #ifdef CONFIG_IDE_PROC_FS |
529 | .proc = idescsi_proc, | 515 | .proc = idescsi_proc, |
530 | #endif | 516 | #endif |
diff --git a/drivers/serial/8250_pnp.c b/drivers/serial/8250_pnp.c index 97c68d021d28..638b68649e79 100644 --- a/drivers/serial/8250_pnp.c +++ b/drivers/serial/8250_pnp.c | |||
@@ -383,21 +383,14 @@ static int __devinit check_name(char *name) | |||
383 | return 0; | 383 | return 0; |
384 | } | 384 | } |
385 | 385 | ||
386 | static int __devinit check_resources(struct pnp_option *option) | 386 | static int __devinit check_resources(struct pnp_dev *dev) |
387 | { | 387 | { |
388 | struct pnp_option *tmp; | 388 | resource_size_t base[] = {0x2f8, 0x3f8, 0x2e8, 0x3e8}; |
389 | if (!option) | 389 | int i; |
390 | return 0; | ||
391 | 390 | ||
392 | for (tmp = option; tmp; tmp = tmp->next) { | 391 | for (i = 0; i < ARRAY_SIZE(base); i++) { |
393 | struct pnp_port *port; | 392 | if (pnp_possible_config(dev, IORESOURCE_IO, base[i], 8)) |
394 | for (port = tmp->port; port; port = port->next) | 393 | return 1; |
395 | if ((port->size == 8) && | ||
396 | ((port->min == 0x2f8) || | ||
397 | (port->min == 0x3f8) || | ||
398 | (port->min == 0x2e8) || | ||
399 | (port->min == 0x3e8))) | ||
400 | return 1; | ||
401 | } | 394 | } |
402 | 395 | ||
403 | return 0; | 396 | return 0; |
@@ -420,10 +413,7 @@ static int __devinit serial_pnp_guess_board(struct pnp_dev *dev, int *flags) | |||
420 | (dev->card && check_name(dev->card->name)))) | 413 | (dev->card && check_name(dev->card->name)))) |
421 | return -ENODEV; | 414 | return -ENODEV; |
422 | 415 | ||
423 | if (check_resources(dev->independent)) | 416 | if (check_resources(dev)) |
424 | return 0; | ||
425 | |||
426 | if (check_resources(dev->dependent)) | ||
427 | return 0; | 417 | return 0; |
428 | 418 | ||
429 | return -ENODEV; | 419 | return -ENODEV; |