[PATCH] pcmcia: move pcmcia resource handling out of cs.c

Move the 16-bit PCMICA resource handling from pcmcia_core.o to pcmcia.o.

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Dominik Brodowski and committed by Linus Torvalds 1a8d4663 e6ea0b9e

+997 -936
+1 -1
drivers/pcmcia/Makefile
··· 10 pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 11 obj-$(CONFIG_PCCARD) += pcmcia_core.o 12 13 - pcmcia-y += ds.o pcmcia_compat.o 14 pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o 15 obj-$(CONFIG_PCMCIA) += pcmcia.o 16
··· 10 pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 11 obj-$(CONFIG_PCCARD) += pcmcia_core.o 12 13 + pcmcia-y += ds.o pcmcia_compat.o pcmcia_resource.o 14 pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o 15 obj-$(CONFIG_PCMCIA) += pcmcia.o 16
+4
drivers/pcmcia/cistpl.c
··· 182 *(u_char *)(ptr+2), *(u_char *)(ptr+3)); 183 return 0; 184 } 185 186 void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 187 u_int len, void *ptr) ··· 241 } 242 } 243 } 244 245 /*====================================================================== 246
··· 182 *(u_char *)(ptr+2), *(u_char *)(ptr+3)); 183 return 0; 184 } 185 + EXPORT_SYMBOL(pcmcia_read_cis_mem); 186 + 187 188 void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 189 u_int len, void *ptr) ··· 239 } 240 } 241 } 242 + EXPORT_SYMBOL(pcmcia_write_cis_mem); 243 + 244 245 /*====================================================================== 246
-935
drivers/pcmcia/cs.c
··· 89 /* Access speed for attribute memory windows */ 90 INT_MODULE_PARM(cis_speed, 300); /* ns */ 91 92 - /* Access speed for IO windows */ 93 - INT_MODULE_PARM(io_speed, 0); /* ns */ 94 - 95 #ifdef DEBUG 96 static int pc_debug; 97 ··· 113 EXPORT_SYMBOL(pcmcia_socket_list); 114 EXPORT_SYMBOL(pcmcia_socket_list_rwsem); 115 116 - 117 - #ifdef CONFIG_PCMCIA_PROBE 118 - /* mask ofIRQs already reserved by other cards, we should avoid using them */ 119 - static u8 pcmcia_used_irq[NR_IRQS]; 120 - #endif 121 122 /*==================================================================== 123 ··· 740 } /* pcmcia_parse_events */ 741 742 743 - /*====================================================================== 744 - 745 - Special stuff for managing IO windows, because they are scarce. 746 - 747 - ======================================================================*/ 748 - 749 - static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base, 750 - ioaddr_t num, u_int lines) 751 - { 752 - int i; 753 - kio_addr_t try, align; 754 - 755 - align = (*base) ? (lines ? 1<<lines : 0) : 1; 756 - if (align && (align < num)) { 757 - if (*base) { 758 - cs_dbg(s, 0, "odd IO request: num %#x align %#lx\n", 759 - num, align); 760 - align = 0; 761 - } else 762 - while (align && (align < num)) align <<= 1; 763 - } 764 - if (*base & ~(align-1)) { 765 - cs_dbg(s, 0, "odd IO request: base %#x align %#lx\n", 766 - *base, align); 767 - align = 0; 768 - } 769 - if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) { 770 - *base = s->io_offset | (*base & 0x0fff); 771 - return 0; 772 - } 773 - /* Check for an already-allocated window that must conflict with 774 - what was asked for. It is a hack because it does not catch all 775 - potential conflicts, just the most obvious ones. */ 776 - for (i = 0; i < MAX_IO_WIN; i++) 777 - if ((s->io[i].NumPorts != 0) && 778 - ((s->io[i].BasePort & (align-1)) == *base)) 779 - return 1; 780 - for (i = 0; i < MAX_IO_WIN; i++) { 781 - if (s->io[i].NumPorts == 0) { 782 - s->io[i].res = pcmcia_find_io_region(*base, num, align, s); 783 - if (s->io[i].res) { 784 - s->io[i].Attributes = attr; 785 - s->io[i].BasePort = *base = s->io[i].res->start; 786 - s->io[i].NumPorts = s->io[i].InUse = num; 787 - break; 788 - } else 789 - return 1; 790 - } else if (s->io[i].Attributes != attr) 791 - continue; 792 - /* Try to extend top of window */ 793 - try = s->io[i].BasePort + s->io[i].NumPorts; 794 - if ((*base == 0) || (*base == try)) 795 - if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start, 796 - s->io[i].res->end + num, s) == 0) { 797 - *base = try; 798 - s->io[i].NumPorts += num; 799 - s->io[i].InUse += num; 800 - break; 801 - } 802 - /* Try to extend bottom of window */ 803 - try = s->io[i].BasePort - num; 804 - if ((*base == 0) || (*base == try)) 805 - if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num, 806 - s->io[i].res->end, s) == 0) { 807 - s->io[i].BasePort = *base = try; 808 - s->io[i].NumPorts += num; 809 - s->io[i].InUse += num; 810 - break; 811 - } 812 - } 813 - return (i == MAX_IO_WIN); 814 - } /* alloc_io_space */ 815 - 816 - static void release_io_space(struct pcmcia_socket *s, ioaddr_t base, 817 - ioaddr_t num) 818 - { 819 - int i; 820 - 821 - for (i = 0; i < MAX_IO_WIN; i++) { 822 - if ((s->io[i].BasePort <= base) && 823 - (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) { 824 - s->io[i].InUse -= num; 825 - /* Free the window if no one else is using it */ 826 - if (s->io[i].InUse == 0) { 827 - s->io[i].NumPorts = 0; 828 - release_resource(s->io[i].res); 829 - kfree(s->io[i].res); 830 - s->io[i].res = NULL; 831 - } 832 - } 833 - } 834 - } 835 - 836 - /*====================================================================== 837 - 838 - Access_configuration_register() reads and writes configuration 839 - registers in attribute memory. Memory window 0 is reserved for 840 - this and the tuple reading services. 841 - 842 - ======================================================================*/ 843 - 844 - int pccard_access_configuration_register(struct pcmcia_socket *s, 845 - unsigned int function, 846 - conf_reg_t *reg) 847 - { 848 - config_t *c; 849 - int addr; 850 - u_char val; 851 - 852 - if (!s || !s->config) 853 - return CS_NO_CARD; 854 - 855 - c = &s->config[function]; 856 - 857 - if (c == NULL) 858 - return CS_NO_CARD; 859 - 860 - if (!(c->state & CONFIG_LOCKED)) 861 - return CS_CONFIGURATION_LOCKED; 862 - 863 - addr = (c->ConfigBase + reg->Offset) >> 1; 864 - 865 - switch (reg->Action) { 866 - case CS_READ: 867 - pcmcia_read_cis_mem(s, 1, addr, 1, &val); 868 - reg->Value = val; 869 - break; 870 - case CS_WRITE: 871 - val = reg->Value; 872 - pcmcia_write_cis_mem(s, 1, addr, 1, &val); 873 - break; 874 - default: 875 - return CS_BAD_ARGS; 876 - break; 877 - } 878 - return CS_SUCCESS; 879 - } /* access_configuration_register */ 880 - EXPORT_SYMBOL(pccard_access_configuration_register); 881 - 882 - 883 - /*====================================================================*/ 884 - 885 - int pccard_get_configuration_info(struct pcmcia_socket *s, 886 - unsigned int function, 887 - config_info_t *config) 888 - { 889 - config_t *c; 890 - 891 - if (!(s->state & SOCKET_PRESENT)) 892 - return CS_NO_CARD; 893 - 894 - config->Function = function; 895 - 896 - #ifdef CONFIG_CARDBUS 897 - if (s->state & SOCKET_CARDBUS) { 898 - memset(config, 0, sizeof(config_info_t)); 899 - config->Vcc = s->socket.Vcc; 900 - config->Vpp1 = config->Vpp2 = s->socket.Vpp; 901 - config->Option = s->cb_dev->subordinate->number; 902 - if (s->state & SOCKET_CARDBUS_CONFIG) { 903 - config->Attributes = CONF_VALID_CLIENT; 904 - config->IntType = INT_CARDBUS; 905 - config->AssignedIRQ = s->irq.AssignedIRQ; 906 - if (config->AssignedIRQ) 907 - config->Attributes |= CONF_ENABLE_IRQ; 908 - config->BasePort1 = s->io[0].BasePort; 909 - config->NumPorts1 = s->io[0].NumPorts; 910 - } 911 - return CS_SUCCESS; 912 - } 913 - #endif 914 - 915 - c = (s->config != NULL) ? &s->config[function] : NULL; 916 - 917 - if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { 918 - config->Attributes = 0; 919 - config->Vcc = s->socket.Vcc; 920 - config->Vpp1 = config->Vpp2 = s->socket.Vpp; 921 - return CS_SUCCESS; 922 - } 923 - 924 - /* !!! This is a hack !!! */ 925 - memcpy(&config->Attributes, &c->Attributes, sizeof(config_t)); 926 - config->Attributes |= CONF_VALID_CLIENT; 927 - config->CardValues = c->CardValues; 928 - config->IRQAttributes = c->irq.Attributes; 929 - config->AssignedIRQ = s->irq.AssignedIRQ; 930 - config->BasePort1 = c->io.BasePort1; 931 - config->NumPorts1 = c->io.NumPorts1; 932 - config->Attributes1 = c->io.Attributes1; 933 - config->BasePort2 = c->io.BasePort2; 934 - config->NumPorts2 = c->io.NumPorts2; 935 - config->Attributes2 = c->io.Attributes2; 936 - config->IOAddrLines = c->io.IOAddrLines; 937 - 938 - return CS_SUCCESS; 939 - } /* get_configuration_info */ 940 - EXPORT_SYMBOL(pccard_get_configuration_info); 941 - 942 - /*====================================================================== 943 - 944 - Return information about this version of Card Services. 945 - 946 - ======================================================================*/ 947 - 948 - int pcmcia_get_card_services_info(servinfo_t *info) 949 - { 950 - unsigned int socket_count = 0; 951 - struct list_head *tmp; 952 - info->Signature[0] = 'C'; 953 - info->Signature[1] = 'S'; 954 - down_read(&pcmcia_socket_list_rwsem); 955 - list_for_each(tmp, &pcmcia_socket_list) 956 - socket_count++; 957 - up_read(&pcmcia_socket_list_rwsem); 958 - info->Count = socket_count; 959 - info->Revision = CS_RELEASE_CODE; 960 - info->CSLevel = 0x0210; 961 - info->VendorString = (char *)release; 962 - return CS_SUCCESS; 963 - } /* get_card_services_info */ 964 - 965 - 966 - /*====================================================================*/ 967 - 968 - int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req) 969 - { 970 - window_t *win; 971 - int w; 972 - 973 - if (!s || !(s->state & SOCKET_PRESENT)) 974 - return CS_NO_CARD; 975 - for (w = idx; w < MAX_WIN; w++) 976 - if (s->state & SOCKET_WIN_REQ(w)) break; 977 - if (w == MAX_WIN) 978 - return CS_NO_MORE_ITEMS; 979 - win = &s->win[w]; 980 - req->Base = win->ctl.res->start; 981 - req->Size = win->ctl.res->end - win->ctl.res->start + 1; 982 - req->AccessSpeed = win->ctl.speed; 983 - req->Attributes = 0; 984 - if (win->ctl.flags & MAP_ATTRIB) 985 - req->Attributes |= WIN_MEMORY_TYPE_AM; 986 - if (win->ctl.flags & MAP_ACTIVE) 987 - req->Attributes |= WIN_ENABLE; 988 - if (win->ctl.flags & MAP_16BIT) 989 - req->Attributes |= WIN_DATA_WIDTH_16; 990 - if (win->ctl.flags & MAP_USE_WAIT) 991 - req->Attributes |= WIN_USE_WAIT; 992 - *handle = win; 993 - return CS_SUCCESS; 994 - } /* get_window */ 995 - EXPORT_SYMBOL(pcmcia_get_window); 996 - 997 /*===================================================================== 998 999 Return the PCI device associated with a card.. ··· 760 761 #endif 762 763 - /*====================================================================== 764 - 765 - Get the current socket state bits. We don't support the latched 766 - SocketState yet: I haven't seen any point for it. 767 - 768 - ======================================================================*/ 769 - 770 - int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status) 771 - { 772 - config_t *c; 773 - int val; 774 - 775 - s->ops->get_status(s, &val); 776 - status->CardState = status->SocketState = 0; 777 - status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0; 778 - status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0; 779 - status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0; 780 - status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0; 781 - if (s->state & SOCKET_SUSPEND) 782 - status->CardState |= CS_EVENT_PM_SUSPEND; 783 - if (!(s->state & SOCKET_PRESENT)) 784 - return CS_NO_CARD; 785 - 786 - c = (s->config != NULL) ? &s->config[function] : NULL; 787 - if ((c != NULL) && (c->state & CONFIG_LOCKED) && 788 - (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) { 789 - u_char reg; 790 - if (c->Present & PRESENT_PIN_REPLACE) { 791 - pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg); 792 - status->CardState |= 793 - (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0; 794 - status->CardState |= 795 - (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0; 796 - status->CardState |= 797 - (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0; 798 - status->CardState |= 799 - (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0; 800 - } else { 801 - /* No PRR? Then assume we're always ready */ 802 - status->CardState |= CS_EVENT_READY_CHANGE; 803 - } 804 - if (c->Present & PRESENT_EXT_STATUS) { 805 - pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg); 806 - status->CardState |= 807 - (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; 808 - } 809 - return CS_SUCCESS; 810 - } 811 - status->CardState |= 812 - (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0; 813 - status->CardState |= 814 - (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0; 815 - status->CardState |= 816 - (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0; 817 - status->CardState |= 818 - (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0; 819 - return CS_SUCCESS; 820 - } /* get_status */ 821 - EXPORT_SYMBOL(pccard_get_status); 822 - 823 - /*====================================================================== 824 - 825 - Change the card address of an already open memory window. 826 - 827 - ======================================================================*/ 828 - 829 - int pcmcia_get_mem_page(window_handle_t win, memreq_t *req) 830 - { 831 - if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 832 - return CS_BAD_HANDLE; 833 - req->Page = 0; 834 - req->CardOffset = win->ctl.card_start; 835 - return CS_SUCCESS; 836 - } /* get_mem_page */ 837 - 838 - int pcmcia_map_mem_page(window_handle_t win, memreq_t *req) 839 - { 840 - struct pcmcia_socket *s; 841 - if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 842 - return CS_BAD_HANDLE; 843 - if (req->Page != 0) 844 - return CS_BAD_PAGE; 845 - s = win->sock; 846 - win->ctl.card_start = req->CardOffset; 847 - if (s->ops->set_mem_map(s, &win->ctl) != 0) 848 - return CS_BAD_OFFSET; 849 - return CS_SUCCESS; 850 - } /* map_mem_page */ 851 - 852 - /*====================================================================== 853 - 854 - Modify a locked socket configuration 855 - 856 - ======================================================================*/ 857 - 858 - int pcmcia_modify_configuration(client_handle_t handle, 859 - modconf_t *mod) 860 - { 861 - struct pcmcia_socket *s; 862 - config_t *c; 863 - 864 - if (CHECK_HANDLE(handle)) 865 - return CS_BAD_HANDLE; 866 - s = SOCKET(handle); c = CONFIG(handle); 867 - if (!(s->state & SOCKET_PRESENT)) 868 - return CS_NO_CARD; 869 - if (!(c->state & CONFIG_LOCKED)) 870 - return CS_CONFIGURATION_LOCKED; 871 - 872 - if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { 873 - if (mod->Attributes & CONF_ENABLE_IRQ) { 874 - c->Attributes |= CONF_ENABLE_IRQ; 875 - s->socket.io_irq = s->irq.AssignedIRQ; 876 - } else { 877 - c->Attributes &= ~CONF_ENABLE_IRQ; 878 - s->socket.io_irq = 0; 879 - } 880 - s->ops->set_socket(s, &s->socket); 881 - } 882 - 883 - if (mod->Attributes & CONF_VCC_CHANGE_VALID) 884 - return CS_BAD_VCC; 885 - 886 - /* We only allow changing Vpp1 and Vpp2 to the same value */ 887 - if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && 888 - (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 889 - if (mod->Vpp1 != mod->Vpp2) 890 - return CS_BAD_VPP; 891 - c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1; 892 - if (s->ops->set_socket(s, &s->socket)) 893 - return CS_BAD_VPP; 894 - } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || 895 - (mod->Attributes & CONF_VPP2_CHANGE_VALID)) 896 - return CS_BAD_VPP; 897 - 898 - return CS_SUCCESS; 899 - } /* modify_configuration */ 900 901 /* register pcmcia_callback */ 902 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) ··· 789 } 790 EXPORT_SYMBOL(pccard_register_pcmcia); 791 792 - /*====================================================================*/ 793 - 794 - int pcmcia_release_configuration(client_handle_t handle) 795 - { 796 - pccard_io_map io = { 0, 0, 0, 0, 1 }; 797 - struct pcmcia_socket *s; 798 - int i; 799 - 800 - if (CHECK_HANDLE(handle) || 801 - !(handle->state & CLIENT_CONFIG_LOCKED)) 802 - return CS_BAD_HANDLE; 803 - handle->state &= ~CLIENT_CONFIG_LOCKED; 804 - s = SOCKET(handle); 805 - 806 - #ifdef CONFIG_CARDBUS 807 - if (handle->state & CLIENT_CARDBUS) 808 - return CS_SUCCESS; 809 - #endif 810 - 811 - if (!(handle->state & CLIENT_STALE)) { 812 - config_t *c = CONFIG(handle); 813 - if (--(s->lock_count) == 0) { 814 - s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ 815 - s->socket.Vpp = 0; 816 - s->socket.io_irq = 0; 817 - s->ops->set_socket(s, &s->socket); 818 - } 819 - if (c->state & CONFIG_IO_REQ) 820 - for (i = 0; i < MAX_IO_WIN; i++) { 821 - if (s->io[i].NumPorts == 0) 822 - continue; 823 - s->io[i].Config--; 824 - if (s->io[i].Config != 0) 825 - continue; 826 - io.map = i; 827 - s->ops->set_io_map(s, &io); 828 - } 829 - c->state &= ~CONFIG_LOCKED; 830 - } 831 - 832 - return CS_SUCCESS; 833 - } /* release_configuration */ 834 - 835 - /*====================================================================== 836 - 837 - Release_io() releases the I/O ranges allocated by a client. This 838 - may be invoked some time after a card ejection has already dumped 839 - the actual socket configuration, so if the client is "stale", we 840 - don't bother checking the port ranges against the current socket 841 - values. 842 - 843 - ======================================================================*/ 844 - 845 - int pcmcia_release_io(client_handle_t handle, io_req_t *req) 846 - { 847 - struct pcmcia_socket *s; 848 - 849 - if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ)) 850 - return CS_BAD_HANDLE; 851 - handle->state &= ~CLIENT_IO_REQ; 852 - s = SOCKET(handle); 853 - 854 - #ifdef CONFIG_CARDBUS 855 - if (handle->state & CLIENT_CARDBUS) 856 - return CS_SUCCESS; 857 - #endif 858 - 859 - if (!(handle->state & CLIENT_STALE)) { 860 - config_t *c = CONFIG(handle); 861 - if (c->state & CONFIG_LOCKED) 862 - return CS_CONFIGURATION_LOCKED; 863 - if ((c->io.BasePort1 != req->BasePort1) || 864 - (c->io.NumPorts1 != req->NumPorts1) || 865 - (c->io.BasePort2 != req->BasePort2) || 866 - (c->io.NumPorts2 != req->NumPorts2)) 867 - return CS_BAD_ARGS; 868 - c->state &= ~CONFIG_IO_REQ; 869 - } 870 - 871 - release_io_space(s, req->BasePort1, req->NumPorts1); 872 - if (req->NumPorts2) 873 - release_io_space(s, req->BasePort2, req->NumPorts2); 874 - 875 - return CS_SUCCESS; 876 - } /* release_io */ 877 - 878 - /*====================================================================*/ 879 - 880 - int pcmcia_release_irq(client_handle_t handle, irq_req_t *req) 881 - { 882 - struct pcmcia_socket *s; 883 - if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ)) 884 - return CS_BAD_HANDLE; 885 - handle->state &= ~CLIENT_IRQ_REQ; 886 - s = SOCKET(handle); 887 - 888 - if (!(handle->state & CLIENT_STALE)) { 889 - config_t *c = CONFIG(handle); 890 - if (c->state & CONFIG_LOCKED) 891 - return CS_CONFIGURATION_LOCKED; 892 - if (c->irq.Attributes != req->Attributes) 893 - return CS_BAD_ATTRIBUTE; 894 - if (s->irq.AssignedIRQ != req->AssignedIRQ) 895 - return CS_BAD_IRQ; 896 - if (--s->irq.Config == 0) { 897 - c->state &= ~CONFIG_IRQ_REQ; 898 - s->irq.AssignedIRQ = 0; 899 - } 900 - } 901 - 902 - if (req->Attributes & IRQ_HANDLE_PRESENT) { 903 - free_irq(req->AssignedIRQ, req->Instance); 904 - } 905 - 906 - #ifdef CONFIG_PCMCIA_PROBE 907 - pcmcia_used_irq[req->AssignedIRQ]--; 908 - #endif 909 - 910 - return CS_SUCCESS; 911 - } /* cs_release_irq */ 912 - 913 - /*====================================================================*/ 914 - 915 - int pcmcia_release_window(window_handle_t win) 916 - { 917 - struct pcmcia_socket *s; 918 - 919 - if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 920 - return CS_BAD_HANDLE; 921 - s = win->sock; 922 - if (!(win->handle->state & CLIENT_WIN_REQ(win->index))) 923 - return CS_BAD_HANDLE; 924 - 925 - /* Shut down memory window */ 926 - win->ctl.flags &= ~MAP_ACTIVE; 927 - s->ops->set_mem_map(s, &win->ctl); 928 - s->state &= ~SOCKET_WIN_REQ(win->index); 929 - 930 - /* Release system memory */ 931 - if (win->ctl.res) { 932 - release_resource(win->ctl.res); 933 - kfree(win->ctl.res); 934 - win->ctl.res = NULL; 935 - } 936 - win->handle->state &= ~CLIENT_WIN_REQ(win->index); 937 - 938 - win->magic = 0; 939 - 940 - return CS_SUCCESS; 941 - } /* release_window */ 942 - 943 - /*====================================================================*/ 944 - 945 - int pcmcia_request_configuration(client_handle_t handle, 946 - config_req_t *req) 947 - { 948 - int i; 949 - u_int base; 950 - struct pcmcia_socket *s; 951 - config_t *c; 952 - pccard_io_map iomap; 953 - 954 - if (CHECK_HANDLE(handle)) 955 - return CS_BAD_HANDLE; 956 - s = SOCKET(handle); 957 - if (!(s->state & SOCKET_PRESENT)) 958 - return CS_NO_CARD; 959 - 960 - #ifdef CONFIG_CARDBUS 961 - if (handle->state & CLIENT_CARDBUS) 962 - return CS_UNSUPPORTED_MODE; 963 - #endif 964 - 965 - if (req->IntType & INT_CARDBUS) 966 - return CS_UNSUPPORTED_MODE; 967 - c = CONFIG(handle); 968 - if (c->state & CONFIG_LOCKED) 969 - return CS_CONFIGURATION_LOCKED; 970 - 971 - /* Do power control. We don't allow changes in Vcc. */ 972 - if (s->socket.Vcc != req->Vcc) 973 - return CS_BAD_VCC; 974 - if (req->Vpp1 != req->Vpp2) 975 - return CS_BAD_VPP; 976 - s->socket.Vpp = req->Vpp1; 977 - if (s->ops->set_socket(s, &s->socket)) 978 - return CS_BAD_VPP; 979 - 980 - c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1; 981 - 982 - /* Pick memory or I/O card, DMA mode, interrupt */ 983 - c->IntType = req->IntType; 984 - c->Attributes = req->Attributes; 985 - if (req->IntType & INT_MEMORY_AND_IO) 986 - s->socket.flags |= SS_IOCARD; 987 - if (req->IntType & INT_ZOOMED_VIDEO) 988 - s->socket.flags |= SS_ZVCARD | SS_IOCARD; 989 - if (req->Attributes & CONF_ENABLE_DMA) 990 - s->socket.flags |= SS_DMA_MODE; 991 - if (req->Attributes & CONF_ENABLE_SPKR) 992 - s->socket.flags |= SS_SPKR_ENA; 993 - if (req->Attributes & CONF_ENABLE_IRQ) 994 - s->socket.io_irq = s->irq.AssignedIRQ; 995 - else 996 - s->socket.io_irq = 0; 997 - s->ops->set_socket(s, &s->socket); 998 - s->lock_count++; 999 - 1000 - /* Set up CIS configuration registers */ 1001 - base = c->ConfigBase = req->ConfigBase; 1002 - c->Present = c->CardValues = req->Present; 1003 - if (req->Present & PRESENT_COPY) { 1004 - c->Copy = req->Copy; 1005 - pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); 1006 - } 1007 - if (req->Present & PRESENT_OPTION) { 1008 - if (s->functions == 1) { 1009 - c->Option = req->ConfigIndex & COR_CONFIG_MASK; 1010 - } else { 1011 - c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK; 1012 - c->Option |= COR_FUNC_ENA|COR_IREQ_ENA; 1013 - if (req->Present & PRESENT_IOBASE_0) 1014 - c->Option |= COR_ADDR_DECODE; 1015 - } 1016 - if (c->state & CONFIG_IRQ_REQ) 1017 - if (!(c->irq.Attributes & IRQ_FORCED_PULSE)) 1018 - c->Option |= COR_LEVEL_REQ; 1019 - pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option); 1020 - mdelay(40); 1021 - } 1022 - if (req->Present & PRESENT_STATUS) { 1023 - c->Status = req->Status; 1024 - pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status); 1025 - } 1026 - if (req->Present & PRESENT_PIN_REPLACE) { 1027 - c->Pin = req->Pin; 1028 - pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin); 1029 - } 1030 - if (req->Present & PRESENT_EXT_STATUS) { 1031 - c->ExtStatus = req->ExtStatus; 1032 - pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus); 1033 - } 1034 - if (req->Present & PRESENT_IOBASE_0) { 1035 - u_char b = c->io.BasePort1 & 0xff; 1036 - pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b); 1037 - b = (c->io.BasePort1 >> 8) & 0xff; 1038 - pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b); 1039 - } 1040 - if (req->Present & PRESENT_IOSIZE) { 1041 - u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1; 1042 - pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b); 1043 - } 1044 - 1045 - /* Configure I/O windows */ 1046 - if (c->state & CONFIG_IO_REQ) { 1047 - iomap.speed = io_speed; 1048 - for (i = 0; i < MAX_IO_WIN; i++) 1049 - if (s->io[i].NumPorts != 0) { 1050 - iomap.map = i; 1051 - iomap.flags = MAP_ACTIVE; 1052 - switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) { 1053 - case IO_DATA_PATH_WIDTH_16: 1054 - iomap.flags |= MAP_16BIT; break; 1055 - case IO_DATA_PATH_WIDTH_AUTO: 1056 - iomap.flags |= MAP_AUTOSZ; break; 1057 - default: 1058 - break; 1059 - } 1060 - iomap.start = s->io[i].BasePort; 1061 - iomap.stop = iomap.start + s->io[i].NumPorts - 1; 1062 - s->ops->set_io_map(s, &iomap); 1063 - s->io[i].Config++; 1064 - } 1065 - } 1066 - 1067 - c->state |= CONFIG_LOCKED; 1068 - handle->state |= CLIENT_CONFIG_LOCKED; 1069 - return CS_SUCCESS; 1070 - } /* request_configuration */ 1071 - 1072 - /*====================================================================== 1073 - 1074 - Request_io() reserves ranges of port addresses for a socket. 1075 - I have not implemented range sharing or alias addressing. 1076 - 1077 - ======================================================================*/ 1078 - 1079 - int pcmcia_request_io(client_handle_t handle, io_req_t *req) 1080 - { 1081 - struct pcmcia_socket *s; 1082 - config_t *c; 1083 - 1084 - if (CHECK_HANDLE(handle)) 1085 - return CS_BAD_HANDLE; 1086 - s = SOCKET(handle); 1087 - if (!(s->state & SOCKET_PRESENT)) 1088 - return CS_NO_CARD; 1089 - 1090 - if (handle->state & CLIENT_CARDBUS) { 1091 - #ifdef CONFIG_CARDBUS 1092 - handle->state |= CLIENT_IO_REQ; 1093 - return CS_SUCCESS; 1094 - #else 1095 - return CS_UNSUPPORTED_FUNCTION; 1096 - #endif 1097 - } 1098 - 1099 - if (!req) 1100 - return CS_UNSUPPORTED_MODE; 1101 - c = CONFIG(handle); 1102 - if (c->state & CONFIG_LOCKED) 1103 - return CS_CONFIGURATION_LOCKED; 1104 - if (c->state & CONFIG_IO_REQ) 1105 - return CS_IN_USE; 1106 - if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) 1107 - return CS_BAD_ATTRIBUTE; 1108 - if ((req->NumPorts2 > 0) && 1109 - (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) 1110 - return CS_BAD_ATTRIBUTE; 1111 - 1112 - if (alloc_io_space(s, req->Attributes1, &req->BasePort1, 1113 - req->NumPorts1, req->IOAddrLines)) 1114 - return CS_IN_USE; 1115 - 1116 - if (req->NumPorts2) { 1117 - if (alloc_io_space(s, req->Attributes2, &req->BasePort2, 1118 - req->NumPorts2, req->IOAddrLines)) { 1119 - release_io_space(s, req->BasePort1, req->NumPorts1); 1120 - return CS_IN_USE; 1121 - } 1122 - } 1123 - 1124 - c->io = *req; 1125 - c->state |= CONFIG_IO_REQ; 1126 - handle->state |= CLIENT_IO_REQ; 1127 - return CS_SUCCESS; 1128 - } /* request_io */ 1129 - 1130 - /*====================================================================== 1131 - 1132 - Request_irq() reserves an irq for this client. 1133 - 1134 - Also, since Linux only reserves irq's when they are actually 1135 - hooked, we don't guarantee that an irq will still be available 1136 - when the configuration is locked. Now that I think about it, 1137 - there might be a way to fix this using a dummy handler. 1138 - 1139 - ======================================================================*/ 1140 - 1141 - #ifdef CONFIG_PCMCIA_PROBE 1142 - static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs) 1143 - { 1144 - return IRQ_NONE; 1145 - } 1146 - #endif 1147 - 1148 - int pcmcia_request_irq(client_handle_t handle, irq_req_t *req) 1149 - { 1150 - struct pcmcia_socket *s; 1151 - config_t *c; 1152 - int ret = CS_IN_USE, irq = 0; 1153 - struct pcmcia_device *p_dev = handle_to_pdev(handle); 1154 - 1155 - if (CHECK_HANDLE(handle)) 1156 - return CS_BAD_HANDLE; 1157 - s = SOCKET(handle); 1158 - if (!(s->state & SOCKET_PRESENT)) 1159 - return CS_NO_CARD; 1160 - c = CONFIG(handle); 1161 - if (c->state & CONFIG_LOCKED) 1162 - return CS_CONFIGURATION_LOCKED; 1163 - if (c->state & CONFIG_IRQ_REQ) 1164 - return CS_IN_USE; 1165 - 1166 - #ifdef CONFIG_PCMCIA_PROBE 1167 - if (s->irq.AssignedIRQ != 0) { 1168 - /* If the interrupt is already assigned, it must be the same */ 1169 - irq = s->irq.AssignedIRQ; 1170 - } else { 1171 - int try; 1172 - u32 mask = s->irq_mask; 1173 - void *data = NULL; 1174 - 1175 - for (try = 0; try < 64; try++) { 1176 - irq = try % 32; 1177 - 1178 - /* marked as available by driver, and not blocked by userspace? */ 1179 - if (!((mask >> irq) & 1)) 1180 - continue; 1181 - 1182 - /* avoid an IRQ which is already used by a PCMCIA card */ 1183 - if ((try < 32) && pcmcia_used_irq[irq]) 1184 - continue; 1185 - 1186 - /* register the correct driver, if possible, of check whether 1187 - * registering a dummy handle works, i.e. if the IRQ isn't 1188 - * marked as used by the kernel resource management core */ 1189 - ret = request_irq(irq, 1190 - (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action, 1191 - ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || 1192 - (s->functions > 1) || 1193 - (irq == s->pci_irq)) ? SA_SHIRQ : 0, 1194 - p_dev->dev.bus_id, 1195 - (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data); 1196 - if (!ret) { 1197 - if (!(req->Attributes & IRQ_HANDLE_PRESENT)) 1198 - free_irq(irq, data); 1199 - break; 1200 - } 1201 - } 1202 - } 1203 - #endif 1204 - if (ret) { 1205 - if (!s->pci_irq) 1206 - return ret; 1207 - irq = s->pci_irq; 1208 - } 1209 - 1210 - if (ret && req->Attributes & IRQ_HANDLE_PRESENT) { 1211 - if (request_irq(irq, req->Handler, 1212 - ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || 1213 - (s->functions > 1) || 1214 - (irq == s->pci_irq)) ? SA_SHIRQ : 0, 1215 - p_dev->dev.bus_id, req->Instance)) 1216 - return CS_IN_USE; 1217 - } 1218 - 1219 - c->irq.Attributes = req->Attributes; 1220 - s->irq.AssignedIRQ = req->AssignedIRQ = irq; 1221 - s->irq.Config++; 1222 - 1223 - c->state |= CONFIG_IRQ_REQ; 1224 - handle->state |= CLIENT_IRQ_REQ; 1225 - 1226 - #ifdef CONFIG_PCMCIA_PROBE 1227 - pcmcia_used_irq[irq]++; 1228 - #endif 1229 - 1230 - return CS_SUCCESS; 1231 - } /* pcmcia_request_irq */ 1232 - 1233 - /*====================================================================== 1234 - 1235 - Request_window() establishes a mapping between card memory space 1236 - and system memory space. 1237 - 1238 - ======================================================================*/ 1239 - 1240 - int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh) 1241 - { 1242 - struct pcmcia_socket *s; 1243 - window_t *win; 1244 - u_long align; 1245 - int w; 1246 - 1247 - if (CHECK_HANDLE(*handle)) 1248 - return CS_BAD_HANDLE; 1249 - s = (*handle)->Socket; 1250 - if (!(s->state & SOCKET_PRESENT)) 1251 - return CS_NO_CARD; 1252 - if (req->Attributes & (WIN_PAGED | WIN_SHARED)) 1253 - return CS_BAD_ATTRIBUTE; 1254 - 1255 - /* Window size defaults to smallest available */ 1256 - if (req->Size == 0) 1257 - req->Size = s->map_size; 1258 - align = (((s->features & SS_CAP_MEM_ALIGN) || 1259 - (req->Attributes & WIN_STRICT_ALIGN)) ? 1260 - req->Size : s->map_size); 1261 - if (req->Size & (s->map_size-1)) 1262 - return CS_BAD_SIZE; 1263 - if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || 1264 - (req->Base & (align-1))) 1265 - return CS_BAD_BASE; 1266 - if (req->Base) 1267 - align = 0; 1268 - 1269 - /* Allocate system memory window */ 1270 - for (w = 0; w < MAX_WIN; w++) 1271 - if (!(s->state & SOCKET_WIN_REQ(w))) break; 1272 - if (w == MAX_WIN) 1273 - return CS_OUT_OF_RESOURCE; 1274 - 1275 - win = &s->win[w]; 1276 - win->magic = WINDOW_MAGIC; 1277 - win->index = w; 1278 - win->handle = *handle; 1279 - win->sock = s; 1280 - 1281 - if (!(s->features & SS_CAP_STATIC_MAP)) { 1282 - win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align, 1283 - (req->Attributes & WIN_MAP_BELOW_1MB), s); 1284 - if (!win->ctl.res) 1285 - return CS_IN_USE; 1286 - } 1287 - (*handle)->state |= CLIENT_WIN_REQ(w); 1288 - 1289 - /* Configure the socket controller */ 1290 - win->ctl.map = w+1; 1291 - win->ctl.flags = 0; 1292 - win->ctl.speed = req->AccessSpeed; 1293 - if (req->Attributes & WIN_MEMORY_TYPE) 1294 - win->ctl.flags |= MAP_ATTRIB; 1295 - if (req->Attributes & WIN_ENABLE) 1296 - win->ctl.flags |= MAP_ACTIVE; 1297 - if (req->Attributes & WIN_DATA_WIDTH_16) 1298 - win->ctl.flags |= MAP_16BIT; 1299 - if (req->Attributes & WIN_USE_WAIT) 1300 - win->ctl.flags |= MAP_USE_WAIT; 1301 - win->ctl.card_start = 0; 1302 - if (s->ops->set_mem_map(s, &win->ctl) != 0) 1303 - return CS_BAD_ARGS; 1304 - s->state |= SOCKET_WIN_REQ(w); 1305 - 1306 - /* Return window handle */ 1307 - if (s->features & SS_CAP_STATIC_MAP) { 1308 - req->Base = win->ctl.static_start; 1309 - } else { 1310 - req->Base = win->ctl.res->start; 1311 - } 1312 - *wh = win; 1313 - 1314 - return CS_SUCCESS; 1315 - } /* request_window */ 1316 1317 /*====================================================================== 1318 ··· 965 ======================================================================*/ 966 /* in alpha order */ 967 EXPORT_SYMBOL(pcmcia_eject_card); 968 - EXPORT_SYMBOL(pcmcia_get_card_services_info); 969 - EXPORT_SYMBOL(pcmcia_get_mem_page); 970 EXPORT_SYMBOL(pcmcia_insert_card); 971 - EXPORT_SYMBOL(pcmcia_map_mem_page); 972 - EXPORT_SYMBOL(pcmcia_modify_configuration); 973 - EXPORT_SYMBOL(pcmcia_release_configuration); 974 - EXPORT_SYMBOL(pcmcia_release_io); 975 - EXPORT_SYMBOL(pcmcia_release_irq); 976 - EXPORT_SYMBOL(pcmcia_release_window); 977 EXPORT_SYMBOL(pcmcia_replace_cis); 978 - EXPORT_SYMBOL(pcmcia_request_configuration); 979 - EXPORT_SYMBOL(pcmcia_request_io); 980 - EXPORT_SYMBOL(pcmcia_request_irq); 981 - EXPORT_SYMBOL(pcmcia_request_window); 982 EXPORT_SYMBOL(pcmcia_resume_card); 983 EXPORT_SYMBOL(pcmcia_suspend_card); 984
··· 89 /* Access speed for attribute memory windows */ 90 INT_MODULE_PARM(cis_speed, 300); /* ns */ 91 92 #ifdef DEBUG 93 static int pc_debug; 94 ··· 116 EXPORT_SYMBOL(pcmcia_socket_list); 117 EXPORT_SYMBOL(pcmcia_socket_list_rwsem); 118 119 120 /*==================================================================== 121 ··· 748 } /* pcmcia_parse_events */ 749 750 751 /*===================================================================== 752 753 Return the PCI device associated with a card.. ··· 1022 1023 #endif 1024 1025 1026 /* register pcmcia_callback */ 1027 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) ··· 1188 } 1189 EXPORT_SYMBOL(pccard_register_pcmcia); 1190 1191 1192 /*====================================================================== 1193 ··· 1888 ======================================================================*/ 1889 /* in alpha order */ 1890 EXPORT_SYMBOL(pcmcia_eject_card); 1891 EXPORT_SYMBOL(pcmcia_insert_card); 1892 EXPORT_SYMBOL(pcmcia_replace_cis); 1893 EXPORT_SYMBOL(pcmcia_resume_card); 1894 EXPORT_SYMBOL(pcmcia_suspend_card); 1895
+989
drivers/pcmcia/pcmcia_resource.c
···
··· 1 + /* 2 + * PCMCIA 16-bit resource management functions 3 + * 4 + * The initial developer of the original code is David A. Hinds 5 + * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds 6 + * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 7 + * 8 + * Copyright (C) 1999 David A. Hinds 9 + * Copyright (C) 2004-2005 Dominik Brodowski 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + * 15 + */ 16 + 17 + #include <linux/config.h> 18 + #include <linux/module.h> 19 + #include <linux/kernel.h> 20 + #include <linux/interrupt.h> 21 + #include <linux/delay.h> 22 + #include <linux/pci.h> 23 + #include <linux/device.h> 24 + 25 + #define IN_CARD_SERVICES 26 + #include <pcmcia/version.h> 27 + #include <pcmcia/cs_types.h> 28 + #include <pcmcia/ss.h> 29 + #include <pcmcia/cs.h> 30 + #include <pcmcia/bulkmem.h> 31 + #include <pcmcia/cistpl.h> 32 + #include <pcmcia/cisreg.h> 33 + #include <pcmcia/ds.h> 34 + 35 + #include "cs_internal.h" 36 + #include "ds_internal.h" 37 + 38 + 39 + static const char *release = "Linux Kernel Card Services"; 40 + 41 + /* Access speed for IO windows */ 42 + static int io_speed = 0; 43 + module_param(io_speed, int, 0444); 44 + 45 + 46 + #ifdef CONFIG_PCMCIA_PROBE 47 + /* mask of IRQs already reserved by other cards, we should avoid using them */ 48 + static u8 pcmcia_used_irq[NR_IRQS]; 49 + #endif 50 + 51 + 52 + #ifdef DEBUG 53 + extern int ds_pc_debug; 54 + #define cs_socket_name(skt) ((skt)->dev.class_id) 55 + 56 + #define ds_dbg(skt, lvl, fmt, arg...) do { \ 57 + if (ds_pc_debug >= lvl) \ 58 + printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \ 59 + cs_socket_name(skt) , ## arg); \ 60 + } while (0) 61 + #else 62 + #define ds_dbg(lvl, fmt, arg...) do { } while (0) 63 + #endif 64 + 65 + 66 + 67 + /** alloc_io_space 68 + * 69 + * Special stuff for managing IO windows, because they are scarce 70 + */ 71 + 72 + static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base, 73 + ioaddr_t num, u_int lines) 74 + { 75 + int i; 76 + kio_addr_t try, align; 77 + 78 + align = (*base) ? (lines ? 1<<lines : 0) : 1; 79 + if (align && (align < num)) { 80 + if (*base) { 81 + ds_dbg(s, 0, "odd IO request: num %#x align %#lx\n", 82 + num, align); 83 + align = 0; 84 + } else 85 + while (align && (align < num)) align <<= 1; 86 + } 87 + if (*base & ~(align-1)) { 88 + ds_dbg(s, 0, "odd IO request: base %#x align %#lx\n", 89 + *base, align); 90 + align = 0; 91 + } 92 + if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) { 93 + *base = s->io_offset | (*base & 0x0fff); 94 + return 0; 95 + } 96 + /* Check for an already-allocated window that must conflict with 97 + * what was asked for. It is a hack because it does not catch all 98 + * potential conflicts, just the most obvious ones. 99 + */ 100 + for (i = 0; i < MAX_IO_WIN; i++) 101 + if ((s->io[i].NumPorts != 0) && 102 + ((s->io[i].BasePort & (align-1)) == *base)) 103 + return 1; 104 + for (i = 0; i < MAX_IO_WIN; i++) { 105 + if (s->io[i].NumPorts == 0) { 106 + s->io[i].res = pcmcia_find_io_region(*base, num, align, s); 107 + if (s->io[i].res) { 108 + s->io[i].Attributes = attr; 109 + s->io[i].BasePort = *base = s->io[i].res->start; 110 + s->io[i].NumPorts = s->io[i].InUse = num; 111 + break; 112 + } else 113 + return 1; 114 + } else if (s->io[i].Attributes != attr) 115 + continue; 116 + /* Try to extend top of window */ 117 + try = s->io[i].BasePort + s->io[i].NumPorts; 118 + if ((*base == 0) || (*base == try)) 119 + if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start, 120 + s->io[i].res->end + num, s) == 0) { 121 + *base = try; 122 + s->io[i].NumPorts += num; 123 + s->io[i].InUse += num; 124 + break; 125 + } 126 + /* Try to extend bottom of window */ 127 + try = s->io[i].BasePort - num; 128 + if ((*base == 0) || (*base == try)) 129 + if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num, 130 + s->io[i].res->end, s) == 0) { 131 + s->io[i].BasePort = *base = try; 132 + s->io[i].NumPorts += num; 133 + s->io[i].InUse += num; 134 + break; 135 + } 136 + } 137 + return (i == MAX_IO_WIN); 138 + } /* alloc_io_space */ 139 + 140 + 141 + static void release_io_space(struct pcmcia_socket *s, ioaddr_t base, 142 + ioaddr_t num) 143 + { 144 + int i; 145 + 146 + for (i = 0; i < MAX_IO_WIN; i++) { 147 + if ((s->io[i].BasePort <= base) && 148 + (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) { 149 + s->io[i].InUse -= num; 150 + /* Free the window if no one else is using it */ 151 + if (s->io[i].InUse == 0) { 152 + s->io[i].NumPorts = 0; 153 + release_resource(s->io[i].res); 154 + kfree(s->io[i].res); 155 + s->io[i].res = NULL; 156 + } 157 + } 158 + } 159 + } /* release_io_space */ 160 + 161 + 162 + /** pccard_access_configuration_register 163 + * 164 + * Access_configuration_register() reads and writes configuration 165 + * registers in attribute memory. Memory window 0 is reserved for 166 + * this and the tuple reading services. 167 + */ 168 + 169 + int pccard_access_configuration_register(struct pcmcia_socket *s, 170 + unsigned int function, 171 + conf_reg_t *reg) 172 + { 173 + config_t *c; 174 + int addr; 175 + u_char val; 176 + 177 + if (!s || !s->config) 178 + return CS_NO_CARD; 179 + 180 + c = &s->config[function]; 181 + 182 + if (c == NULL) 183 + return CS_NO_CARD; 184 + 185 + if (!(c->state & CONFIG_LOCKED)) 186 + return CS_CONFIGURATION_LOCKED; 187 + 188 + addr = (c->ConfigBase + reg->Offset) >> 1; 189 + 190 + switch (reg->Action) { 191 + case CS_READ: 192 + pcmcia_read_cis_mem(s, 1, addr, 1, &val); 193 + reg->Value = val; 194 + break; 195 + case CS_WRITE: 196 + val = reg->Value; 197 + pcmcia_write_cis_mem(s, 1, addr, 1, &val); 198 + break; 199 + default: 200 + return CS_BAD_ARGS; 201 + break; 202 + } 203 + return CS_SUCCESS; 204 + } /* pccard_access_configuration_register */ 205 + EXPORT_SYMBOL(pccard_access_configuration_register); 206 + 207 + 208 + int pccard_get_configuration_info(struct pcmcia_socket *s, 209 + unsigned int function, 210 + config_info_t *config) 211 + { 212 + config_t *c; 213 + 214 + if (!(s->state & SOCKET_PRESENT)) 215 + return CS_NO_CARD; 216 + 217 + config->Function = function; 218 + 219 + #ifdef CONFIG_CARDBUS 220 + if (s->state & SOCKET_CARDBUS) { 221 + memset(config, 0, sizeof(config_info_t)); 222 + config->Vcc = s->socket.Vcc; 223 + config->Vpp1 = config->Vpp2 = s->socket.Vpp; 224 + config->Option = s->cb_dev->subordinate->number; 225 + if (s->state & SOCKET_CARDBUS_CONFIG) { 226 + config->Attributes = CONF_VALID_CLIENT; 227 + config->IntType = INT_CARDBUS; 228 + config->AssignedIRQ = s->irq.AssignedIRQ; 229 + if (config->AssignedIRQ) 230 + config->Attributes |= CONF_ENABLE_IRQ; 231 + config->BasePort1 = s->io[0].BasePort; 232 + config->NumPorts1 = s->io[0].NumPorts; 233 + } 234 + return CS_SUCCESS; 235 + } 236 + #endif 237 + 238 + c = (s->config != NULL) ? &s->config[function] : NULL; 239 + 240 + if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { 241 + config->Attributes = 0; 242 + config->Vcc = s->socket.Vcc; 243 + config->Vpp1 = config->Vpp2 = s->socket.Vpp; 244 + return CS_SUCCESS; 245 + } 246 + 247 + /* !!! This is a hack !!! */ 248 + memcpy(&config->Attributes, &c->Attributes, sizeof(config_t)); 249 + config->Attributes |= CONF_VALID_CLIENT; 250 + config->CardValues = c->CardValues; 251 + config->IRQAttributes = c->irq.Attributes; 252 + config->AssignedIRQ = s->irq.AssignedIRQ; 253 + config->BasePort1 = c->io.BasePort1; 254 + config->NumPorts1 = c->io.NumPorts1; 255 + config->Attributes1 = c->io.Attributes1; 256 + config->BasePort2 = c->io.BasePort2; 257 + config->NumPorts2 = c->io.NumPorts2; 258 + config->Attributes2 = c->io.Attributes2; 259 + config->IOAddrLines = c->io.IOAddrLines; 260 + 261 + return CS_SUCCESS; 262 + } /* pccard_get_configuration_info */ 263 + EXPORT_SYMBOL(pccard_get_configuration_info); 264 + 265 + 266 + /** pcmcia_get_card_services_info 267 + * 268 + * Return information about this version of Card Services 269 + */ 270 + 271 + int pcmcia_get_card_services_info(servinfo_t *info) 272 + { 273 + unsigned int socket_count = 0; 274 + struct list_head *tmp; 275 + info->Signature[0] = 'C'; 276 + info->Signature[1] = 'S'; 277 + down_read(&pcmcia_socket_list_rwsem); 278 + list_for_each(tmp, &pcmcia_socket_list) 279 + socket_count++; 280 + up_read(&pcmcia_socket_list_rwsem); 281 + info->Count = socket_count; 282 + info->Revision = CS_RELEASE_CODE; 283 + info->CSLevel = 0x0210; 284 + info->VendorString = (char *)release; 285 + return CS_SUCCESS; 286 + } /* get_card_services_info */ 287 + EXPORT_SYMBOL(pcmcia_get_card_services_info); 288 + 289 + 290 + /** pcmcia_get_window 291 + */ 292 + int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, 293 + int idx, win_req_t *req) 294 + { 295 + window_t *win; 296 + int w; 297 + 298 + if (!s || !(s->state & SOCKET_PRESENT)) 299 + return CS_NO_CARD; 300 + for (w = idx; w < MAX_WIN; w++) 301 + if (s->state & SOCKET_WIN_REQ(w)) 302 + break; 303 + if (w == MAX_WIN) 304 + return CS_NO_MORE_ITEMS; 305 + win = &s->win[w]; 306 + req->Base = win->ctl.res->start; 307 + req->Size = win->ctl.res->end - win->ctl.res->start + 1; 308 + req->AccessSpeed = win->ctl.speed; 309 + req->Attributes = 0; 310 + if (win->ctl.flags & MAP_ATTRIB) 311 + req->Attributes |= WIN_MEMORY_TYPE_AM; 312 + if (win->ctl.flags & MAP_ACTIVE) 313 + req->Attributes |= WIN_ENABLE; 314 + if (win->ctl.flags & MAP_16BIT) 315 + req->Attributes |= WIN_DATA_WIDTH_16; 316 + if (win->ctl.flags & MAP_USE_WAIT) 317 + req->Attributes |= WIN_USE_WAIT; 318 + *handle = win; 319 + return CS_SUCCESS; 320 + } /* pcmcia_get_window */ 321 + EXPORT_SYMBOL(pcmcia_get_window); 322 + 323 + 324 + /** pccard_get_status 325 + * 326 + * Get the current socket state bits. We don't support the latched 327 + * SocketState yet: I haven't seen any point for it. 328 + */ 329 + 330 + int pccard_get_status(struct pcmcia_socket *s, unsigned int function, 331 + cs_status_t *status) 332 + { 333 + config_t *c; 334 + int val; 335 + 336 + s->ops->get_status(s, &val); 337 + status->CardState = status->SocketState = 0; 338 + status->CardState |= (val & SS_DETECT) ? CS_EVENT_CARD_DETECT : 0; 339 + status->CardState |= (val & SS_CARDBUS) ? CS_EVENT_CB_DETECT : 0; 340 + status->CardState |= (val & SS_3VCARD) ? CS_EVENT_3VCARD : 0; 341 + status->CardState |= (val & SS_XVCARD) ? CS_EVENT_XVCARD : 0; 342 + if (s->state & SOCKET_SUSPEND) 343 + status->CardState |= CS_EVENT_PM_SUSPEND; 344 + if (!(s->state & SOCKET_PRESENT)) 345 + return CS_NO_CARD; 346 + 347 + c = (s->config != NULL) ? &s->config[function] : NULL; 348 + if ((c != NULL) && (c->state & CONFIG_LOCKED) && 349 + (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) { 350 + u_char reg; 351 + if (c->Present & PRESENT_PIN_REPLACE) { 352 + pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg); 353 + status->CardState |= 354 + (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0; 355 + status->CardState |= 356 + (reg & PRR_READY_STATUS) ? CS_EVENT_READY_CHANGE : 0; 357 + status->CardState |= 358 + (reg & PRR_BVD2_STATUS) ? CS_EVENT_BATTERY_LOW : 0; 359 + status->CardState |= 360 + (reg & PRR_BVD1_STATUS) ? CS_EVENT_BATTERY_DEAD : 0; 361 + } else { 362 + /* No PRR? Then assume we're always ready */ 363 + status->CardState |= CS_EVENT_READY_CHANGE; 364 + } 365 + if (c->Present & PRESENT_EXT_STATUS) { 366 + pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg); 367 + status->CardState |= 368 + (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; 369 + } 370 + return CS_SUCCESS; 371 + } 372 + status->CardState |= 373 + (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0; 374 + status->CardState |= 375 + (val & SS_BATDEAD) ? CS_EVENT_BATTERY_DEAD : 0; 376 + status->CardState |= 377 + (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0; 378 + status->CardState |= 379 + (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0; 380 + return CS_SUCCESS; 381 + } /* pccard_get_status */ 382 + EXPORT_SYMBOL(pccard_get_status); 383 + 384 + 385 + /** pcmcia_get_mem_page 386 + * 387 + * Change the card address of an already open memory window. 388 + */ 389 + int pcmcia_get_mem_page(window_handle_t win, memreq_t *req) 390 + { 391 + if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 392 + return CS_BAD_HANDLE; 393 + req->Page = 0; 394 + req->CardOffset = win->ctl.card_start; 395 + return CS_SUCCESS; 396 + } /* pcmcia_get_mem_page */ 397 + EXPORT_SYMBOL(pcmcia_get_mem_page); 398 + 399 + 400 + int pcmcia_map_mem_page(window_handle_t win, memreq_t *req) 401 + { 402 + struct pcmcia_socket *s; 403 + if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 404 + return CS_BAD_HANDLE; 405 + if (req->Page != 0) 406 + return CS_BAD_PAGE; 407 + s = win->sock; 408 + win->ctl.card_start = req->CardOffset; 409 + if (s->ops->set_mem_map(s, &win->ctl) != 0) 410 + return CS_BAD_OFFSET; 411 + return CS_SUCCESS; 412 + } /* pcmcia_map_mem_page */ 413 + EXPORT_SYMBOL(pcmcia_map_mem_page); 414 + 415 + 416 + /** pcmcia_modify_configuration 417 + * 418 + * Modify a locked socket configuration 419 + */ 420 + int pcmcia_modify_configuration(client_handle_t handle, 421 + modconf_t *mod) 422 + { 423 + struct pcmcia_socket *s; 424 + config_t *c; 425 + 426 + if (CHECK_HANDLE(handle)) 427 + return CS_BAD_HANDLE; 428 + s = SOCKET(handle); 429 + c = CONFIG(handle); 430 + if (!(s->state & SOCKET_PRESENT)) 431 + return CS_NO_CARD; 432 + if (!(c->state & CONFIG_LOCKED)) 433 + return CS_CONFIGURATION_LOCKED; 434 + 435 + if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { 436 + if (mod->Attributes & CONF_ENABLE_IRQ) { 437 + c->Attributes |= CONF_ENABLE_IRQ; 438 + s->socket.io_irq = s->irq.AssignedIRQ; 439 + } else { 440 + c->Attributes &= ~CONF_ENABLE_IRQ; 441 + s->socket.io_irq = 0; 442 + } 443 + s->ops->set_socket(s, &s->socket); 444 + } 445 + 446 + if (mod->Attributes & CONF_VCC_CHANGE_VALID) 447 + return CS_BAD_VCC; 448 + 449 + /* We only allow changing Vpp1 and Vpp2 to the same value */ 450 + if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && 451 + (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 452 + if (mod->Vpp1 != mod->Vpp2) 453 + return CS_BAD_VPP; 454 + c->Vpp1 = c->Vpp2 = s->socket.Vpp = mod->Vpp1; 455 + if (s->ops->set_socket(s, &s->socket)) 456 + return CS_BAD_VPP; 457 + } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || 458 + (mod->Attributes & CONF_VPP2_CHANGE_VALID)) 459 + return CS_BAD_VPP; 460 + 461 + return CS_SUCCESS; 462 + } /* modify_configuration */ 463 + EXPORT_SYMBOL(pcmcia_modify_configuration); 464 + 465 + 466 + int pcmcia_release_configuration(client_handle_t handle) 467 + { 468 + pccard_io_map io = { 0, 0, 0, 0, 1 }; 469 + struct pcmcia_socket *s; 470 + int i; 471 + 472 + if (CHECK_HANDLE(handle) || 473 + !(handle->state & CLIENT_CONFIG_LOCKED)) 474 + return CS_BAD_HANDLE; 475 + handle->state &= ~CLIENT_CONFIG_LOCKED; 476 + s = SOCKET(handle); 477 + 478 + #ifdef CONFIG_CARDBUS 479 + if (handle->state & CLIENT_CARDBUS) 480 + return CS_SUCCESS; 481 + #endif 482 + 483 + if (!(handle->state & CLIENT_STALE)) { 484 + config_t *c = CONFIG(handle); 485 + if (--(s->lock_count) == 0) { 486 + s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ 487 + s->socket.Vpp = 0; 488 + s->socket.io_irq = 0; 489 + s->ops->set_socket(s, &s->socket); 490 + } 491 + if (c->state & CONFIG_IO_REQ) 492 + for (i = 0; i < MAX_IO_WIN; i++) { 493 + if (s->io[i].NumPorts == 0) 494 + continue; 495 + s->io[i].Config--; 496 + if (s->io[i].Config != 0) 497 + continue; 498 + io.map = i; 499 + s->ops->set_io_map(s, &io); 500 + } 501 + c->state &= ~CONFIG_LOCKED; 502 + } 503 + 504 + return CS_SUCCESS; 505 + } /* pcmcia_release_configuration */ 506 + EXPORT_SYMBOL(pcmcia_release_configuration); 507 + 508 + 509 + /** pcmcia_release_io 510 + * 511 + * Release_io() releases the I/O ranges allocated by a client. This 512 + * may be invoked some time after a card ejection has already dumped 513 + * the actual socket configuration, so if the client is "stale", we 514 + * don't bother checking the port ranges against the current socket 515 + * values. 516 + */ 517 + int pcmcia_release_io(client_handle_t handle, io_req_t *req) 518 + { 519 + struct pcmcia_socket *s; 520 + 521 + if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IO_REQ)) 522 + return CS_BAD_HANDLE; 523 + handle->state &= ~CLIENT_IO_REQ; 524 + s = SOCKET(handle); 525 + 526 + #ifdef CONFIG_CARDBUS 527 + if (handle->state & CLIENT_CARDBUS) 528 + return CS_SUCCESS; 529 + #endif 530 + 531 + if (!(handle->state & CLIENT_STALE)) { 532 + config_t *c = CONFIG(handle); 533 + if (c->state & CONFIG_LOCKED) 534 + return CS_CONFIGURATION_LOCKED; 535 + if ((c->io.BasePort1 != req->BasePort1) || 536 + (c->io.NumPorts1 != req->NumPorts1) || 537 + (c->io.BasePort2 != req->BasePort2) || 538 + (c->io.NumPorts2 != req->NumPorts2)) 539 + return CS_BAD_ARGS; 540 + c->state &= ~CONFIG_IO_REQ; 541 + } 542 + 543 + release_io_space(s, req->BasePort1, req->NumPorts1); 544 + if (req->NumPorts2) 545 + release_io_space(s, req->BasePort2, req->NumPorts2); 546 + 547 + return CS_SUCCESS; 548 + } /* pcmcia_release_io */ 549 + EXPORT_SYMBOL(pcmcia_release_io); 550 + 551 + 552 + int pcmcia_release_irq(client_handle_t handle, irq_req_t *req) 553 + { 554 + struct pcmcia_socket *s; 555 + if (CHECK_HANDLE(handle) || !(handle->state & CLIENT_IRQ_REQ)) 556 + return CS_BAD_HANDLE; 557 + handle->state &= ~CLIENT_IRQ_REQ; 558 + s = SOCKET(handle); 559 + 560 + if (!(handle->state & CLIENT_STALE)) { 561 + config_t *c = CONFIG(handle); 562 + if (c->state & CONFIG_LOCKED) 563 + return CS_CONFIGURATION_LOCKED; 564 + if (c->irq.Attributes != req->Attributes) 565 + return CS_BAD_ATTRIBUTE; 566 + if (s->irq.AssignedIRQ != req->AssignedIRQ) 567 + return CS_BAD_IRQ; 568 + if (--s->irq.Config == 0) { 569 + c->state &= ~CONFIG_IRQ_REQ; 570 + s->irq.AssignedIRQ = 0; 571 + } 572 + } 573 + 574 + if (req->Attributes & IRQ_HANDLE_PRESENT) { 575 + free_irq(req->AssignedIRQ, req->Instance); 576 + } 577 + 578 + #ifdef CONFIG_PCMCIA_PROBE 579 + pcmcia_used_irq[req->AssignedIRQ]--; 580 + #endif 581 + 582 + return CS_SUCCESS; 583 + } /* pcmcia_release_irq */ 584 + EXPORT_SYMBOL(pcmcia_release_irq); 585 + 586 + 587 + int pcmcia_release_window(window_handle_t win) 588 + { 589 + struct pcmcia_socket *s; 590 + 591 + if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 592 + return CS_BAD_HANDLE; 593 + s = win->sock; 594 + if (!(win->handle->state & CLIENT_WIN_REQ(win->index))) 595 + return CS_BAD_HANDLE; 596 + 597 + /* Shut down memory window */ 598 + win->ctl.flags &= ~MAP_ACTIVE; 599 + s->ops->set_mem_map(s, &win->ctl); 600 + s->state &= ~SOCKET_WIN_REQ(win->index); 601 + 602 + /* Release system memory */ 603 + if (win->ctl.res) { 604 + release_resource(win->ctl.res); 605 + kfree(win->ctl.res); 606 + win->ctl.res = NULL; 607 + } 608 + win->handle->state &= ~CLIENT_WIN_REQ(win->index); 609 + 610 + win->magic = 0; 611 + 612 + return CS_SUCCESS; 613 + } /* pcmcia_release_window */ 614 + EXPORT_SYMBOL(pcmcia_release_window); 615 + 616 + 617 + int pcmcia_request_configuration(client_handle_t handle, 618 + config_req_t *req) 619 + { 620 + int i; 621 + u_int base; 622 + struct pcmcia_socket *s; 623 + config_t *c; 624 + pccard_io_map iomap; 625 + 626 + if (CHECK_HANDLE(handle)) 627 + return CS_BAD_HANDLE; 628 + s = SOCKET(handle); 629 + if (!(s->state & SOCKET_PRESENT)) 630 + return CS_NO_CARD; 631 + 632 + #ifdef CONFIG_CARDBUS 633 + if (handle->state & CLIENT_CARDBUS) 634 + return CS_UNSUPPORTED_MODE; 635 + #endif 636 + 637 + if (req->IntType & INT_CARDBUS) 638 + return CS_UNSUPPORTED_MODE; 639 + c = CONFIG(handle); 640 + if (c->state & CONFIG_LOCKED) 641 + return CS_CONFIGURATION_LOCKED; 642 + 643 + /* Do power control. We don't allow changes in Vcc. */ 644 + if (s->socket.Vcc != req->Vcc) 645 + return CS_BAD_VCC; 646 + if (req->Vpp1 != req->Vpp2) 647 + return CS_BAD_VPP; 648 + s->socket.Vpp = req->Vpp1; 649 + if (s->ops->set_socket(s, &s->socket)) 650 + return CS_BAD_VPP; 651 + 652 + c->Vcc = req->Vcc; c->Vpp1 = c->Vpp2 = req->Vpp1; 653 + 654 + /* Pick memory or I/O card, DMA mode, interrupt */ 655 + c->IntType = req->IntType; 656 + c->Attributes = req->Attributes; 657 + if (req->IntType & INT_MEMORY_AND_IO) 658 + s->socket.flags |= SS_IOCARD; 659 + if (req->IntType & INT_ZOOMED_VIDEO) 660 + s->socket.flags |= SS_ZVCARD | SS_IOCARD; 661 + if (req->Attributes & CONF_ENABLE_DMA) 662 + s->socket.flags |= SS_DMA_MODE; 663 + if (req->Attributes & CONF_ENABLE_SPKR) 664 + s->socket.flags |= SS_SPKR_ENA; 665 + if (req->Attributes & CONF_ENABLE_IRQ) 666 + s->socket.io_irq = s->irq.AssignedIRQ; 667 + else 668 + s->socket.io_irq = 0; 669 + s->ops->set_socket(s, &s->socket); 670 + s->lock_count++; 671 + 672 + /* Set up CIS configuration registers */ 673 + base = c->ConfigBase = req->ConfigBase; 674 + c->Present = c->CardValues = req->Present; 675 + if (req->Present & PRESENT_COPY) { 676 + c->Copy = req->Copy; 677 + pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); 678 + } 679 + if (req->Present & PRESENT_OPTION) { 680 + if (s->functions == 1) { 681 + c->Option = req->ConfigIndex & COR_CONFIG_MASK; 682 + } else { 683 + c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK; 684 + c->Option |= COR_FUNC_ENA|COR_IREQ_ENA; 685 + if (req->Present & PRESENT_IOBASE_0) 686 + c->Option |= COR_ADDR_DECODE; 687 + } 688 + if (c->state & CONFIG_IRQ_REQ) 689 + if (!(c->irq.Attributes & IRQ_FORCED_PULSE)) 690 + c->Option |= COR_LEVEL_REQ; 691 + pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option); 692 + mdelay(40); 693 + } 694 + if (req->Present & PRESENT_STATUS) { 695 + c->Status = req->Status; 696 + pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status); 697 + } 698 + if (req->Present & PRESENT_PIN_REPLACE) { 699 + c->Pin = req->Pin; 700 + pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin); 701 + } 702 + if (req->Present & PRESENT_EXT_STATUS) { 703 + c->ExtStatus = req->ExtStatus; 704 + pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus); 705 + } 706 + if (req->Present & PRESENT_IOBASE_0) { 707 + u_char b = c->io.BasePort1 & 0xff; 708 + pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b); 709 + b = (c->io.BasePort1 >> 8) & 0xff; 710 + pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b); 711 + } 712 + if (req->Present & PRESENT_IOSIZE) { 713 + u_char b = c->io.NumPorts1 + c->io.NumPorts2 - 1; 714 + pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b); 715 + } 716 + 717 + /* Configure I/O windows */ 718 + if (c->state & CONFIG_IO_REQ) { 719 + iomap.speed = io_speed; 720 + for (i = 0; i < MAX_IO_WIN; i++) 721 + if (s->io[i].NumPorts != 0) { 722 + iomap.map = i; 723 + iomap.flags = MAP_ACTIVE; 724 + switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) { 725 + case IO_DATA_PATH_WIDTH_16: 726 + iomap.flags |= MAP_16BIT; break; 727 + case IO_DATA_PATH_WIDTH_AUTO: 728 + iomap.flags |= MAP_AUTOSZ; break; 729 + default: 730 + break; 731 + } 732 + iomap.start = s->io[i].BasePort; 733 + iomap.stop = iomap.start + s->io[i].NumPorts - 1; 734 + s->ops->set_io_map(s, &iomap); 735 + s->io[i].Config++; 736 + } 737 + } 738 + 739 + c->state |= CONFIG_LOCKED; 740 + handle->state |= CLIENT_CONFIG_LOCKED; 741 + return CS_SUCCESS; 742 + } /* pcmcia_request_configuration */ 743 + EXPORT_SYMBOL(pcmcia_request_configuration); 744 + 745 + 746 + /** pcmcia_request_io 747 + * 748 + * Request_io() reserves ranges of port addresses for a socket. 749 + * I have not implemented range sharing or alias addressing. 750 + */ 751 + int pcmcia_request_io(client_handle_t handle, io_req_t *req) 752 + { 753 + struct pcmcia_socket *s; 754 + config_t *c; 755 + 756 + if (CHECK_HANDLE(handle)) 757 + return CS_BAD_HANDLE; 758 + s = SOCKET(handle); 759 + if (!(s->state & SOCKET_PRESENT)) 760 + return CS_NO_CARD; 761 + 762 + if (handle->state & CLIENT_CARDBUS) { 763 + #ifdef CONFIG_CARDBUS 764 + handle->state |= CLIENT_IO_REQ; 765 + return CS_SUCCESS; 766 + #else 767 + return CS_UNSUPPORTED_FUNCTION; 768 + #endif 769 + } 770 + 771 + if (!req) 772 + return CS_UNSUPPORTED_MODE; 773 + c = CONFIG(handle); 774 + if (c->state & CONFIG_LOCKED) 775 + return CS_CONFIGURATION_LOCKED; 776 + if (c->state & CONFIG_IO_REQ) 777 + return CS_IN_USE; 778 + if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) 779 + return CS_BAD_ATTRIBUTE; 780 + if ((req->NumPorts2 > 0) && 781 + (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) 782 + return CS_BAD_ATTRIBUTE; 783 + 784 + if (alloc_io_space(s, req->Attributes1, &req->BasePort1, 785 + req->NumPorts1, req->IOAddrLines)) 786 + return CS_IN_USE; 787 + 788 + if (req->NumPorts2) { 789 + if (alloc_io_space(s, req->Attributes2, &req->BasePort2, 790 + req->NumPorts2, req->IOAddrLines)) { 791 + release_io_space(s, req->BasePort1, req->NumPorts1); 792 + return CS_IN_USE; 793 + } 794 + } 795 + 796 + c->io = *req; 797 + c->state |= CONFIG_IO_REQ; 798 + handle->state |= CLIENT_IO_REQ; 799 + return CS_SUCCESS; 800 + } /* pcmcia_request_io */ 801 + EXPORT_SYMBOL(pcmcia_request_io); 802 + 803 + 804 + /** pcmcia_request_irq 805 + * 806 + * Request_irq() reserves an irq for this client. 807 + * 808 + * Also, since Linux only reserves irq's when they are actually 809 + * hooked, we don't guarantee that an irq will still be available 810 + * when the configuration is locked. Now that I think about it, 811 + * there might be a way to fix this using a dummy handler. 812 + */ 813 + 814 + #ifdef CONFIG_PCMCIA_PROBE 815 + static irqreturn_t test_action(int cpl, void *dev_id, struct pt_regs *regs) 816 + { 817 + return IRQ_NONE; 818 + } 819 + #endif 820 + 821 + int pcmcia_request_irq(client_handle_t handle, irq_req_t *req) 822 + { 823 + struct pcmcia_socket *s; 824 + config_t *c; 825 + int ret = CS_IN_USE, irq = 0; 826 + struct pcmcia_device *p_dev = handle_to_pdev(handle); 827 + 828 + if (CHECK_HANDLE(handle)) 829 + return CS_BAD_HANDLE; 830 + s = SOCKET(handle); 831 + if (!(s->state & SOCKET_PRESENT)) 832 + return CS_NO_CARD; 833 + c = CONFIG(handle); 834 + if (c->state & CONFIG_LOCKED) 835 + return CS_CONFIGURATION_LOCKED; 836 + if (c->state & CONFIG_IRQ_REQ) 837 + return CS_IN_USE; 838 + 839 + #ifdef CONFIG_PCMCIA_PROBE 840 + if (s->irq.AssignedIRQ != 0) { 841 + /* If the interrupt is already assigned, it must be the same */ 842 + irq = s->irq.AssignedIRQ; 843 + } else { 844 + int try; 845 + u32 mask = s->irq_mask; 846 + void *data = NULL; 847 + 848 + for (try = 0; try < 64; try++) { 849 + irq = try % 32; 850 + 851 + /* marked as available by driver, and not blocked by userspace? */ 852 + if (!((mask >> irq) & 1)) 853 + continue; 854 + 855 + /* avoid an IRQ which is already used by a PCMCIA card */ 856 + if ((try < 32) && pcmcia_used_irq[irq]) 857 + continue; 858 + 859 + /* register the correct driver, if possible, of check whether 860 + * registering a dummy handle works, i.e. if the IRQ isn't 861 + * marked as used by the kernel resource management core */ 862 + ret = request_irq(irq, 863 + (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Handler : test_action, 864 + ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || 865 + (s->functions > 1) || 866 + (irq == s->pci_irq)) ? SA_SHIRQ : 0, 867 + p_dev->dev.bus_id, 868 + (req->Attributes & IRQ_HANDLE_PRESENT) ? req->Instance : data); 869 + if (!ret) { 870 + if (!(req->Attributes & IRQ_HANDLE_PRESENT)) 871 + free_irq(irq, data); 872 + break; 873 + } 874 + } 875 + } 876 + #endif 877 + if (ret) { 878 + if (!s->pci_irq) 879 + return ret; 880 + irq = s->pci_irq; 881 + } 882 + 883 + if (ret && req->Attributes & IRQ_HANDLE_PRESENT) { 884 + if (request_irq(irq, req->Handler, 885 + ((req->Attributes & IRQ_TYPE_DYNAMIC_SHARING) || 886 + (s->functions > 1) || 887 + (irq == s->pci_irq)) ? SA_SHIRQ : 0, 888 + p_dev->dev.bus_id, req->Instance)) 889 + return CS_IN_USE; 890 + } 891 + 892 + c->irq.Attributes = req->Attributes; 893 + s->irq.AssignedIRQ = req->AssignedIRQ = irq; 894 + s->irq.Config++; 895 + 896 + c->state |= CONFIG_IRQ_REQ; 897 + handle->state |= CLIENT_IRQ_REQ; 898 + 899 + #ifdef CONFIG_PCMCIA_PROBE 900 + pcmcia_used_irq[irq]++; 901 + #endif 902 + 903 + return CS_SUCCESS; 904 + } /* pcmcia_request_irq */ 905 + EXPORT_SYMBOL(pcmcia_request_irq); 906 + 907 + 908 + /** pcmcia_request_window 909 + * 910 + * Request_window() establishes a mapping between card memory space 911 + * and system memory space. 912 + */ 913 + int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh) 914 + { 915 + struct pcmcia_socket *s; 916 + window_t *win; 917 + u_long align; 918 + int w; 919 + 920 + if (CHECK_HANDLE(*handle)) 921 + return CS_BAD_HANDLE; 922 + s = (*handle)->Socket; 923 + if (!(s->state & SOCKET_PRESENT)) 924 + return CS_NO_CARD; 925 + if (req->Attributes & (WIN_PAGED | WIN_SHARED)) 926 + return CS_BAD_ATTRIBUTE; 927 + 928 + /* Window size defaults to smallest available */ 929 + if (req->Size == 0) 930 + req->Size = s->map_size; 931 + align = (((s->features & SS_CAP_MEM_ALIGN) || 932 + (req->Attributes & WIN_STRICT_ALIGN)) ? 933 + req->Size : s->map_size); 934 + if (req->Size & (s->map_size-1)) 935 + return CS_BAD_SIZE; 936 + if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || 937 + (req->Base & (align-1))) 938 + return CS_BAD_BASE; 939 + if (req->Base) 940 + align = 0; 941 + 942 + /* Allocate system memory window */ 943 + for (w = 0; w < MAX_WIN; w++) 944 + if (!(s->state & SOCKET_WIN_REQ(w))) break; 945 + if (w == MAX_WIN) 946 + return CS_OUT_OF_RESOURCE; 947 + 948 + win = &s->win[w]; 949 + win->magic = WINDOW_MAGIC; 950 + win->index = w; 951 + win->handle = *handle; 952 + win->sock = s; 953 + 954 + if (!(s->features & SS_CAP_STATIC_MAP)) { 955 + win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align, 956 + (req->Attributes & WIN_MAP_BELOW_1MB), s); 957 + if (!win->ctl.res) 958 + return CS_IN_USE; 959 + } 960 + (*handle)->state |= CLIENT_WIN_REQ(w); 961 + 962 + /* Configure the socket controller */ 963 + win->ctl.map = w+1; 964 + win->ctl.flags = 0; 965 + win->ctl.speed = req->AccessSpeed; 966 + if (req->Attributes & WIN_MEMORY_TYPE) 967 + win->ctl.flags |= MAP_ATTRIB; 968 + if (req->Attributes & WIN_ENABLE) 969 + win->ctl.flags |= MAP_ACTIVE; 970 + if (req->Attributes & WIN_DATA_WIDTH_16) 971 + win->ctl.flags |= MAP_16BIT; 972 + if (req->Attributes & WIN_USE_WAIT) 973 + win->ctl.flags |= MAP_USE_WAIT; 974 + win->ctl.card_start = 0; 975 + if (s->ops->set_mem_map(s, &win->ctl) != 0) 976 + return CS_BAD_ARGS; 977 + s->state |= SOCKET_WIN_REQ(w); 978 + 979 + /* Return window handle */ 980 + if (s->features & SS_CAP_STATIC_MAP) { 981 + req->Base = win->ctl.static_start; 982 + } else { 983 + req->Base = win->ctl.res->start; 984 + } 985 + *wh = win; 986 + 987 + return CS_SUCCESS; 988 + } /* pcmcia_request_window */ 989 + EXPORT_SYMBOL(pcmcia_request_window);
+3
drivers/pcmcia/rsrc_mgr.c
··· 112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s); 113 return -ENOMEM; 114 } 115 116 struct resource *pcmcia_find_io_region(unsigned long base, int num, 117 unsigned long align, struct pcmcia_socket *s) ··· 121 return s->resource_ops->find_io(base, num, align, s); 122 return NULL; 123 } 124 125 struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, 126 int low, struct pcmcia_socket *s) ··· 130 return s->resource_ops->find_mem(base, num, align, low, s); 131 return NULL; 132 } 133 134 void release_resource_db(struct pcmcia_socket *s) 135 {
··· 112 return s->resource_ops->adjust_io_region(res, r_start, r_end, s); 113 return -ENOMEM; 114 } 115 + EXPORT_SYMBOL(pcmcia_adjust_io_region); 116 117 struct resource *pcmcia_find_io_region(unsigned long base, int num, 118 unsigned long align, struct pcmcia_socket *s) ··· 120 return s->resource_ops->find_io(base, num, align, s); 121 return NULL; 122 } 123 + EXPORT_SYMBOL(pcmcia_find_io_region); 124 125 struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align, 126 int low, struct pcmcia_socket *s) ··· 128 return s->resource_ops->find_mem(base, num, align, low, s); 129 return NULL; 130 } 131 + EXPORT_SYMBOL(pcmcia_find_mem_region); 132 133 void release_resource_db(struct pcmcia_socket *s) 134 {