mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-22 08:17:17 +07:00
0ee931c4e3
GFP_TEMPORARY was introduced by commit e12ba74d8f
("Group short-lived
and reclaimable kernel allocations") along with __GFP_RECLAIMABLE. It's
primary motivation was to allow users to tell that an allocation is
short lived and so the allocator can try to place such allocations close
together and prevent long term fragmentation. As much as this sounds
like a reasonable semantic it becomes much less clear when to use the
highlevel GFP_TEMPORARY allocation flag. How long is temporary? Can the
context holding that memory sleep? Can it take locks? It seems there is
no good answer for those questions.
The current implementation of GFP_TEMPORARY is basically GFP_KERNEL |
__GFP_RECLAIMABLE which in itself is tricky because basically none of
the existing caller provide a way to reclaim the allocated memory. So
this is rather misleading and hard to evaluate for any benefits.
I have checked some random users and none of them has added the flag
with a specific justification. I suspect most of them just copied from
other existing users and others just thought it might be a good idea to
use without any measuring. This suggests that GFP_TEMPORARY just
motivates for cargo cult usage without any reasoning.
I believe that our gfp flags are quite complex already and especially
those with highlevel semantic should be clearly defined to prevent from
confusion and abuse. Therefore I propose dropping GFP_TEMPORARY and
replace all existing users to simply use GFP_KERNEL. Please note that
SLAB users with shrinkers will still get __GFP_RECLAIMABLE heuristic and
so they will be placed properly for memory fragmentation prevention.
I can see reasons we might want some gfp flag to reflect shorterm
allocations but I propose starting from a clear semantic definition and
only then add users with proper justification.
This was been brought up before LSF this year by Matthew [1] and it
turned out that GFP_TEMPORARY really doesn't have a clear semantic. It
seems to be a heuristic without any measured advantage for most (if not
all) its current users. The follow up discussion has revealed that
opinions on what might be temporary allocation differ a lot between
developers. So rather than trying to tweak existing users into a
semantic which they haven't expected I propose to simply remove the flag
and start from scratch if we really need a semantic for short term
allocations.
[1] http://lkml.kernel.org/r/20170118054945.GD18349@bombadil.infradead.org
[akpm@linux-foundation.org: fix typo]
[akpm@linux-foundation.org: coding-style fixes]
[sfr@canb.auug.org.au: drm/i915: fix up]
Link: http://lkml.kernel.org/r/20170816144703.378d4f4d@canb.auug.org.au
Link: http://lkml.kernel.org/r/20170728091904.14627-1-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Mel Gorman <mgorman@suse.de>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Neil Brown <neilb@suse.de>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
252 lines
6.4 KiB
C
252 lines
6.4 KiB
C
/*
|
|
* Copyright (c) 2015 NVIDIA Corporation. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sub license,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice (including the
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
* of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
* DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include <linux/slab.h>
|
|
#include <linux/delay.h>
|
|
|
|
#include <drm/drm_scdc_helper.h>
|
|
#include <drm/drmP.h>
|
|
|
|
/**
|
|
* DOC: scdc helpers
|
|
*
|
|
* Status and Control Data Channel (SCDC) is a mechanism introduced by the
|
|
* HDMI 2.0 specification. It is a point-to-point protocol that allows the
|
|
* HDMI source and HDMI sink to exchange data. The same I2C interface that
|
|
* is used to access EDID serves as the transport mechanism for SCDC.
|
|
*/
|
|
|
|
#define SCDC_I2C_SLAVE_ADDRESS 0x54
|
|
|
|
/**
|
|
* drm_scdc_read - read a block of data from SCDC
|
|
* @adapter: I2C controller
|
|
* @offset: start offset of block to read
|
|
* @buffer: return location for the block to read
|
|
* @size: size of the block to read
|
|
*
|
|
* Reads a block of data from SCDC, starting at a given offset.
|
|
*
|
|
* Returns:
|
|
* 0 on success, negative error code on failure.
|
|
*/
|
|
ssize_t drm_scdc_read(struct i2c_adapter *adapter, u8 offset, void *buffer,
|
|
size_t size)
|
|
{
|
|
int ret;
|
|
struct i2c_msg msgs[2] = {
|
|
{
|
|
.addr = SCDC_I2C_SLAVE_ADDRESS,
|
|
.flags = 0,
|
|
.len = 1,
|
|
.buf = &offset,
|
|
}, {
|
|
.addr = SCDC_I2C_SLAVE_ADDRESS,
|
|
.flags = I2C_M_RD,
|
|
.len = size,
|
|
.buf = buffer,
|
|
}
|
|
};
|
|
|
|
ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
|
|
if (ret < 0)
|
|
return ret;
|
|
if (ret != ARRAY_SIZE(msgs))
|
|
return -EPROTO;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(drm_scdc_read);
|
|
|
|
/**
|
|
* drm_scdc_write - write a block of data to SCDC
|
|
* @adapter: I2C controller
|
|
* @offset: start offset of block to write
|
|
* @buffer: block of data to write
|
|
* @size: size of the block to write
|
|
*
|
|
* Writes a block of data to SCDC, starting at a given offset.
|
|
*
|
|
* Returns:
|
|
* 0 on success, negative error code on failure.
|
|
*/
|
|
ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset,
|
|
const void *buffer, size_t size)
|
|
{
|
|
struct i2c_msg msg = {
|
|
.addr = SCDC_I2C_SLAVE_ADDRESS,
|
|
.flags = 0,
|
|
.len = 1 + size,
|
|
.buf = NULL,
|
|
};
|
|
void *data;
|
|
int err;
|
|
|
|
data = kmalloc(1 + size, GFP_KERNEL);
|
|
if (!data)
|
|
return -ENOMEM;
|
|
|
|
msg.buf = data;
|
|
|
|
memcpy(data, &offset, sizeof(offset));
|
|
memcpy(data + 1, buffer, size);
|
|
|
|
err = i2c_transfer(adapter, &msg, 1);
|
|
|
|
kfree(data);
|
|
|
|
if (err < 0)
|
|
return err;
|
|
if (err != 1)
|
|
return -EPROTO;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(drm_scdc_write);
|
|
|
|
/**
|
|
* drm_scdc_check_scrambling_status - what is status of scrambling?
|
|
* @adapter: I2C adapter for DDC channel
|
|
*
|
|
* Reads the scrambler status over SCDC, and checks the
|
|
* scrambling status.
|
|
*
|
|
* Returns:
|
|
* True if the scrambling is enabled, false otherwise.
|
|
*/
|
|
|
|
bool drm_scdc_get_scrambling_status(struct i2c_adapter *adapter)
|
|
{
|
|
u8 status;
|
|
int ret;
|
|
|
|
ret = drm_scdc_readb(adapter, SCDC_SCRAMBLER_STATUS, &status);
|
|
if (ret < 0) {
|
|
DRM_ERROR("Failed to read scrambling status, error %d\n", ret);
|
|
return false;
|
|
}
|
|
|
|
return status & SCDC_SCRAMBLING_STATUS;
|
|
}
|
|
EXPORT_SYMBOL(drm_scdc_get_scrambling_status);
|
|
|
|
/**
|
|
* drm_scdc_set_scrambling - enable scrambling
|
|
* @adapter: I2C adapter for DDC channel
|
|
* @enable: bool to indicate if scrambling is to be enabled/disabled
|
|
*
|
|
* Writes the TMDS config register over SCDC channel, and:
|
|
* enables scrambling when enable = 1
|
|
* disables scrambling when enable = 0
|
|
*
|
|
* Returns:
|
|
* True if scrambling is set/reset successfully, false otherwise.
|
|
*/
|
|
|
|
bool drm_scdc_set_scrambling(struct i2c_adapter *adapter, bool enable)
|
|
{
|
|
u8 config;
|
|
int ret;
|
|
|
|
ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
|
|
if (ret < 0) {
|
|
DRM_ERROR("Failed to read tmds config, err=%d\n", ret);
|
|
return false;
|
|
}
|
|
|
|
if (enable)
|
|
config |= SCDC_SCRAMBLING_ENABLE;
|
|
else
|
|
config &= ~SCDC_SCRAMBLING_ENABLE;
|
|
|
|
ret = drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config);
|
|
if (ret < 0) {
|
|
DRM_ERROR("Failed to enable scrambling, error %d\n", ret);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
EXPORT_SYMBOL(drm_scdc_set_scrambling);
|
|
|
|
/**
|
|
* drm_scdc_set_high_tmds_clock_ratio - set TMDS clock ratio
|
|
* @adapter: I2C adapter for DDC channel
|
|
* @set: ret or reset the high clock ratio
|
|
*
|
|
*
|
|
* TMDS clock ratio calculations go like this:
|
|
* TMDS character = 10 bit TMDS encoded value
|
|
*
|
|
* TMDS character rate = The rate at which TMDS characters are
|
|
* transmitted (Mcsc)
|
|
*
|
|
* TMDS bit rate = 10x TMDS character rate
|
|
*
|
|
* As per the spec:
|
|
* TMDS clock rate for pixel clock < 340 MHz = 1x the character
|
|
* rate = 1/10 pixel clock rate
|
|
*
|
|
* TMDS clock rate for pixel clock > 340 MHz = 0.25x the character
|
|
* rate = 1/40 pixel clock rate
|
|
*
|
|
* Writes to the TMDS config register over SCDC channel, and:
|
|
* sets TMDS clock ratio to 1/40 when set = 1
|
|
*
|
|
* sets TMDS clock ratio to 1/10 when set = 0
|
|
*
|
|
* Returns:
|
|
* True if write is successful, false otherwise.
|
|
*/
|
|
bool drm_scdc_set_high_tmds_clock_ratio(struct i2c_adapter *adapter, bool set)
|
|
{
|
|
u8 config;
|
|
int ret;
|
|
|
|
ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config);
|
|
if (ret < 0) {
|
|
DRM_ERROR("Failed to read tmds config, err=%d\n", ret);
|
|
return false;
|
|
}
|
|
|
|
if (set)
|
|
config |= SCDC_TMDS_BIT_CLOCK_RATIO_BY_40;
|
|
else
|
|
config &= ~SCDC_TMDS_BIT_CLOCK_RATIO_BY_40;
|
|
|
|
ret = drm_scdc_writeb(adapter, SCDC_TMDS_CONFIG, config);
|
|
if (ret < 0) {
|
|
DRM_ERROR("Failed to set TMDS clock ratio, error %d\n", ret);
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* The spec says that a source should wait minimum 1ms and maximum
|
|
* 100ms after writing the TMDS config for clock ratio. Lets allow a
|
|
* wait of upto 2ms here.
|
|
*/
|
|
usleep_range(1000, 2000);
|
|
return true;
|
|
}
|
|
EXPORT_SYMBOL(drm_scdc_set_high_tmds_clock_ratio);
|