* Copyright 2010-2017 Intel Corporation.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* Disclaimer: The codes contained in these modules may be specific to
* the Intel Software Development Platform codenamed Knights Ferry,
* and the Intel product codenamed Knights Corner, and are not backward
* compatible with other Intel products. Additionally, Intel will NOT
* support the codes or instruction set in future products.
* Intel offers no warranty of any kind regarding the code. This code is
* licensed on an "AS IS" basis and Intel is not obligated to provide
* any support, assistance, installation, training, or other services
* of any kind. Intel is also not obligated to provide any updates,
* enhancements or extensions. Intel specifically disclaims any warranty
* of merchantability, non-infringement, fitness for any particular
* purpose, and any other warranty.
* Further, Intel disclaims all liability of any kind, including but
* not limited to liability for infringement of any proprietary rights,
* relating to the use of the code, even if Intel is notified of the
* possibility of such liability. Except as expressly stated in an Intel
* license agreement provided with this code and agreed upon with Intel,
* no license, express or implied, by estoppel or otherwise, to any
* intellectual property rights is granted herein.
int mic_psmi_open(struct file
*filp
)
bd_info_t
*bd_info
= mic_data
.dd_bi
[0];
if (!bd_info
->bi_ctx
.bi_psmi
.enabled
)
((filp
)->private_data
) = &bd_info
->bi_ctx
;
extern int usagemode_param
;
ssize_t
mic_psmi_read(struct file
* filp
, char __user
*buf
,
size_t count
, loff_t
*pos
)
unsigned int pg_no
, pg_off
, bytes
;
mic_ctx_t
*mic_ctx
= ((filp
)->private_data
);
struct mic_psmi_ctx
*psmi_ctx
= &mic_ctx
->bi_psmi
;
if (FAMILY_ABR
== mic_ctx
->bi_family
&&
USAGE_MODE_NORMAL
!= usagemode_param
)
mem_size
= MIC_APERTURE_SIZE
;
mem_size
= psmi_ctx
->dma_mem_size
;
if (*pos
>= mem_size
|| count
<= 0)
if (*pos
+ count
> mem_size
)
/* read aperture memory */
if (USAGE_MODE_NORMAL
!= usagemode_param
) {
mic_ctx
->aper
.va
+ *pos
, count
))
/* read host memory allocated for psmi handler */
pg_no
= *pos
/ MIC_PSMI_PAGE_SIZE
;
pg_off
= *pos
% MIC_PSMI_PAGE_SIZE
;
while (total_bytes
< count
) {
pci_dma_sync_single_for_cpu(mic_ctx
->bi_pdev
,
psmi_ctx
->dma_tbl
[pg_no
+ 1].pa
,
MIC_PSMI_PAGE_SIZE
, PCI_DMA_BIDIRECTIONAL
);
bytes
= MIC_PSMI_PAGE_SIZE
- pg_off
;
if (total_bytes
+ bytes
> count
)
bytes
= count
- total_bytes
;
(void *)psmi_ctx
->va_tbl
[pg_no
].pa
+ pg_off
, bytes
))
/* Only the first page needs an offset */
static ssize_t
show_mem_size(struct device
*dev
,
struct device_attribute
*attr
, char *buf
)
mic_ctx_t
*mic_ctx
= dev_get_drvdata(dev
);
struct mic_psmi_ctx
*psmi_ctx
= &mic_ctx
->bi_psmi
;
return snprintf(buf
, PAGE_SIZE
, "%ld\n",
(unsigned long)psmi_ctx
->dma_mem_size
);
static DEVICE_ATTR(mem_size
, S_IRUGO
, show_mem_size
, NULL
);
static struct attribute
*psmi_attributes
[] = {
struct attribute_group psmi_attr_group
= {
#if (defined(RHEL_RELEASE_CODE) && \
(LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32))) || \
LINUX_VERSION_CODE > KERNEL_VERSION(2,6,34)
static ssize_t
mic_psmi_read_ptes(struct file
*filp
, struct kobject
*kobj
,
struct bin_attribute
*attr
, char *buf
, loff_t pos
, size_t size
)
static ssize_t
mic_psmi_read_ptes(struct kobject
*kobj
,
struct bin_attribute
*attr
, char *buf
, loff_t pos
, size_t size
)
struct device
*dev
= container_of(kobj
, struct device
, kobj
);
struct mic_psmi_ctx
*psmi_ctx
=
&((mic_ctx_t
*)dev_get_drvdata(dev
))->bi_psmi
;
if (pos
>= psmi_ctx
->dma_tbl_size
|| size
<= 0)
if (pos
+ size
> psmi_ctx
->dma_tbl_size
)
size
= psmi_ctx
->dma_tbl_size
- pos
;
memcpy(buf
, psmi_ctx
->dma_tbl
, size
);
struct bin_attribute mic_psmi_ptes_attr
= {
.read
= mic_psmi_read_ptes
extern bool mic_psmi_enable
;
module_param_named(psmi
, mic_psmi_enable
, bool, S_IRUSR
);
MODULE_PARM_DESC(psmi
, "Enable/disable mic psmi");