/* -*- mode: c; c-basic-offset: 8 -*- */12/*3* MCA device support functions4*5* These functions support the ongoing device access API.6*7* (C) 2002 James Bottomley <[email protected]>8*9**-----------------------------------------------------------------------------10**11** This program is free software; you can redistribute it and/or modify12** it under the terms of the GNU General Public License as published by13** the Free Software Foundation; either version 2 of the License, or14** (at your option) any later version.15**16** This program is distributed in the hope that it will be useful,17** but WITHOUT ANY WARRANTY; without even the implied warranty of18** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19** GNU General Public License for more details.20**21** You should have received a copy of the GNU General Public License22** along with this program; if not, write to the Free Software23** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.24**25**-----------------------------------------------------------------------------26*/2728#include <linux/module.h>29#include <linux/device.h>30#include <linux/mca.h>31#include <linux/string.h>3233/**34* mca_device_read_stored_pos - read POS register from stored data35* @mca_dev: device to read from36* @reg: register to read from37*38* Fetch a POS value that was stored at boot time by the kernel39* when it scanned the MCA space. The register value is returned.40* Missing or invalid registers report 0.41*/42unsigned char mca_device_read_stored_pos(struct mca_device *mca_dev, int reg)43{44if(reg < 0 || reg >= 8)45return 0;4647return mca_dev->pos[reg];48}49EXPORT_SYMBOL(mca_device_read_stored_pos);5051/**52* mca_device_read_pos - read POS register from card53* @mca_dev: device to read from54* @reg: register to read from55*56* Fetch a POS value directly from the hardware to obtain the57* current value. This is much slower than58* mca_device_read_stored_pos and may not be invoked from59* interrupt context. It handles the deep magic required for60* onboard devices transparently.61*/62unsigned char mca_device_read_pos(struct mca_device *mca_dev, int reg)63{64struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);6566return mca_bus->f.mca_read_pos(mca_dev, reg);6768return mca_dev->pos[reg];69}70EXPORT_SYMBOL(mca_device_read_pos);717273/**74* mca_device_write_pos - read POS register from card75* @mca_dev: device to write pos register to76* @reg: register to write to77* @byte: byte to write to the POS registers78*79* Store a POS value directly to the hardware. You should not80* normally need to use this function and should have a very good81* knowledge of MCA bus before you do so. Doing this wrongly can82* damage the hardware.83*84* This function may not be used from interrupt context.85*86*/87void mca_device_write_pos(struct mca_device *mca_dev, int reg,88unsigned char byte)89{90struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);9192mca_bus->f.mca_write_pos(mca_dev, reg, byte);93}94EXPORT_SYMBOL(mca_device_write_pos);9596/**97* mca_device_transform_irq - transform the ADF obtained IRQ98* @mca_device: device whose irq needs transforming99* @irq: input irq from ADF100*101* MCA Adapter Definition Files (ADF) contain irq, ioport, memory102* etc. definitions. In systems with more than one bus, these need103* to be transformed through bus mapping functions to get the real104* system global quantities.105*106* This function transforms the interrupt number and returns the107* transformed system global interrupt108*/109int mca_device_transform_irq(struct mca_device *mca_dev, int irq)110{111struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);112113return mca_bus->f.mca_transform_irq(mca_dev, irq);114}115EXPORT_SYMBOL(mca_device_transform_irq);116117/**118* mca_device_transform_ioport - transform the ADF obtained I/O port119* @mca_device: device whose port needs transforming120* @ioport: input I/O port from ADF121*122* MCA Adapter Definition Files (ADF) contain irq, ioport, memory123* etc. definitions. In systems with more than one bus, these need124* to be transformed through bus mapping functions to get the real125* system global quantities.126*127* This function transforms the I/O port number and returns the128* transformed system global port number.129*130* This transformation can be assumed to be linear for port ranges.131*/132int mca_device_transform_ioport(struct mca_device *mca_dev, int port)133{134struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);135136return mca_bus->f.mca_transform_ioport(mca_dev, port);137}138EXPORT_SYMBOL(mca_device_transform_ioport);139140/**141* mca_device_transform_memory - transform the ADF obtained memory142* @mca_device: device whose memory region needs transforming143* @mem: memory region start from ADF144*145* MCA Adapter Definition Files (ADF) contain irq, ioport, memory146* etc. definitions. In systems with more than one bus, these need147* to be transformed through bus mapping functions to get the real148* system global quantities.149*150* This function transforms the memory region start and returns the151* transformed system global memory region (physical).152*153* This transformation can be assumed to be linear for region ranges.154*/155void *mca_device_transform_memory(struct mca_device *mca_dev, void *mem)156{157struct mca_bus *mca_bus = to_mca_bus(mca_dev->dev.parent);158159return mca_bus->f.mca_transform_memory(mca_dev, mem);160}161EXPORT_SYMBOL(mca_device_transform_memory);162163164/**165* mca_device_claimed - check if claimed by driver166* @mca_dev: device to check167*168* Returns 1 if the slot has been claimed by a driver169*/170171int mca_device_claimed(struct mca_device *mca_dev)172{173return mca_dev->driver_loaded;174}175EXPORT_SYMBOL(mca_device_claimed);176177/**178* mca_device_set_claim - set the claim value of the driver179* @mca_dev: device to set value for180* @val: claim value to set (1 claimed, 0 unclaimed)181*/182void mca_device_set_claim(struct mca_device *mca_dev, int val)183{184mca_dev->driver_loaded = val;185}186EXPORT_SYMBOL(mca_device_set_claim);187188/**189* mca_device_status - get the status of the device190* @mca_device: device to get191*192* returns an enumeration of the device status:193*194* MCA_ADAPTER_NORMAL adapter is OK.195* MCA_ADAPTER_NONE no adapter at device (should never happen).196* MCA_ADAPTER_DISABLED adapter is disabled.197* MCA_ADAPTER_ERROR adapter cannot be initialised.198*/199enum MCA_AdapterStatus mca_device_status(struct mca_device *mca_dev)200{201return mca_dev->status;202}203EXPORT_SYMBOL(mca_device_status);204205/**206* mca_device_set_name - set the name of the device207* @mca_device: device to set the name of208* @name: name to set209*/210void mca_device_set_name(struct mca_device *mca_dev, const char *name)211{212if(!mca_dev)213return;214215strlcpy(mca_dev->name, name, sizeof(mca_dev->name));216}217EXPORT_SYMBOL(mca_device_set_name);218219220